Hi Guys
I am not sure if this is the right place to put this topic.
I was trying to use the picking code (I am using the camera which can be moved on the scene):
//Get the mouse position
Vector2f mousePosition = new Vector2f(MouseInput.get().getXAbsolute(), MouseInput.get().getYAbsolute());
//Create a pick ray from the display
Vector3f worldCoords = DisplaySystem.getDisplaySystem().getWorldCoordinates(mousePosition, 0);
Vector3f worldCoords2 = DisplaySystem.getDisplaySystem().getWorldCoordinates(mousePosition, 1);
Ray ray = new Ray(worldCoords, worldCoords2.subtractLocal(
worldCoords).normalizeLocal());
//Find the results (Use which ever method suits your needs
PickResults results = new TrianglePickResults();
//PickResults results = new BoundingPickResults();
//We normally want the distance to see which object is closest
results.setCheckDistance(true);
//Get the results from a node
rootNode.findPick(ray, results);
//Loop the results
for (int i = 0; i < results.getNumber(); i++) {
PickData hit = results.getPickData(i);
System.out.println("Hit: " + hit.getTargetMesh().getName() + "(" + hit.getDistance() + ")");
}
When I run this code, nothing has happened, so I take the data from Ray and I drew a line between the:
ray.getOrigin() and ray.getDirection().
Each Line was from mouse position to the centre of the coordinate system.
So I thought that I should use camera location and original ray.origin.
First created a Ray:
Ray ray3 = new Ray(camera.getCamera().getLocation(),ray.getOrigin());
Next I drew the Line (using ray3.getOrigin(), ray3.getDirection()) and it was looking ok, short line was directed in the object, but the object was not picked:(
Any idea where I made an error?
Thanks for any help:)
Zbiszko