Picking with camera

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

one more note:) I am using StandardGame

ok, I made a small change but still it does not worked:(

Ray ray3 = new Ray(camera.getCamera().getLocation(),ray.getDirection());



So I created a small test:)
I thought that to check if Ray should aim in the object I will create an bullet }:-@
I created an object MyBox (extends Box) which contain additional attribute direction (I take it from created ray i.e.: ray.getDirection)

on my game state I put updating the position of the MyBox:

MyBox myBox = (MyBox)node;
        Vector3f loc = myBox.getLocalTranslation();
        loc.addLocal(myBox.direction.mult(0.2f));
       
        myBox.setLocalTranslation(loc);


so the result is that that my bullet is pierce the "picked" object, but still:
rootNode.findPick(ray3, results);
does not give me results:(

any thoughts?