Camera World Coordinates Picking

Hello,



I try very hard to implement picking with mouse cursor position on screen not with center of screen like in your tutorial. I have done following. I added a RawInputListener to the inputManager. I save the mouseScreen x and y coordinates in a Vector2f object. My picking code looks like this (it’s pretty equal to your “center picking” code).



[java]

CollisionResults results = new CollisionResults();



Camera camera = praxitelesCamera.getCamera();

Vector3f mouseCursorWorldCoordinates = camera.getWorldCoordinates(PraxitelesApplication.getMousePosition(), 0.1f);

Ray ray = new Ray(mouseCursorWorldCoordinates, camera.getDirection());

com.jme3.scene.Node rootNode = PraxitelesApplication.findInstance().getApplication().getRootNode();

rootNode.updateGeometricState();

rootNode.collideWith(ray, results);

[/java]



If I look to the getWorldCoordinates code from Camera, I see that the width and height of the camera is needed. This is set to 640*480 in my case. However, my canvas is part of a swing environment and can be resized in any form. Do I have to set the width and height of the camera if my canvas resizes? (Debbugging tells me that width and height of camera is independant of canvas width and height, so, obviously the canvas does not update the camera’s width and height). My second question would be what is a “good” value for the z-coordinate of getWorldCoordinates method of Camera? My third question is if the ray is calculated correctly no matter if you are in orth or perspective mode. I assume the world to be orth only the rendering is perspective.

Thanks for help.



Regards,

Equi

http://hub.jmonkeyengine.org/groups/development-discussion-jme3/forum/topic/mouse-picking-2/

See jme3test.collision.TestMousePick