Hi everyone,
Here are some snippets of my code:
[java] private void initKeys() {
inputManager.addMapping(“Pick”, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
inputManager.addListener(analogListener, new String[]{“Pick”});
}
private AnalogListener analogListener = new AnalogListener() {
public void onAnalog(String name, float intensity, float tpf) {
if (name.equals("Pick")) {
// Reset results list.
CollisionResults results = new CollisionResults();
// Convert screen click to 3d position
Vector2f click2d = inputManager.getCursorPosition();
Vector3f click3d = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 0f).clone();
Vector3f dir = cam.getWorldCoordinates(new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal();
// Aim the ray from the clicked spot forwards.
Ray ray = new Ray(click3d, dir);
// Collect intersections between ray and all nodes in results list.
rootNode.collideWith(ray, results);
// (Print the results so we see what is going on:)
for (int i = 0; i 0) {
// The closest result is the target that the player picked:
Geometry target = results.getClosestCollision().getGeometry();
// Here comes the action:
System.out.println(target.getName());
}
} // else if ...
}
};[/java]
So the problem I am experiencing is that every time I click, the button press is being registered more than once. In electrical engineering, the way to solve a similar problem is called debouncing. I was wondering if there is a simple way to solve this problem, as I would like to register the click just once. Thanks!