Quick question about picking

Hi,

I would like to pick objects under a (movable) crosshair on the screen.



Ray ray = new Ray(cam.getLocation(), cam.getDirection());



casts a ray from the center of the screen along the camera direction.



For my case i think i need a ray cast through 2 Points: crosshair.getWorldTranslation() and cam.getLocation().



Anyone a quick idea how to solve this in an easy way?



Thanks

General advice on picking:

You can pick your friends.

You can pick your nose.

It is unwise to pick your friend’s nose.



Back to the real topic, here is the method (paraphrased a bit) that I use to get a ray from a mouse click. Need to have access to the camera somehow and pass the mouse cursor location:

[java]

protected Ray getScreenRay( Vector2f cursor ) {

Camera cam = …getCamera();



Vector3f clickFar = cam.getWorldCoordinates( cursor, 1 );

Vector3f clickNear = cam.getWorldCoordinates( cursor, 0 );

Ray mouseRay = new Ray( clickNear, clickFar.subtractLocal(clickNear).normalizeLocal());



return mouseRay;

}[/java]

2 Likes

@pspeed I WAS JUST THINKING THAT XD lol…

great, you have fun :wink:



but thanks, now i can stop picking my nose.