Mouse picking problems


I have been stuck all afternoon trying to figure out how to pick objects with the mouse. Guess it is probably a ridiculously easy solution to this, but I cannot figure it out, so I thought I might as well ask.

I need to be able to “pick” objects in the scene with the mouse. Cursor must be able to move in and out of the game window and the mouse is not linked to any movement. The tutorial picks objects much like in an fps game, I want to pick objects like “select unit” in a traditional strategy game.

This is from the tutorial:

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

I guess I need something like this:

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

Problem is that I only get the mouse position as relative screen position, not as a position in the game.

Anybody have a hint to get me going again?

you can use the camera to convert from 2d cam coordinates to 3d world coordinates. Using a raw mouse listener you can listen to the mouse x/y location.

That did the trick. Thank you so much. :slight_smile: