Absolute mouse world coordinates


I am playing around with JME and loving it (very new to this 3D malarkey). I have a simple app that I'm playing around with; with a view to doing a simple board game.

At the moment I have some textured tri-meshes that I can select using the mouse, this works OK. I want to be able to click a point on the screen and have the 'piece' move there; however I am having problems getting the correct coords from the screen coords. I am using

display.getWorldCoordinates(Vector2f screenPosition, float zPos)

and it is the zPos that I don't really get.

How do I work out the correct value given that all pieces are at 0 on the z plane? A value of 0 and x and y values are way too small, and a value of 1 and they are way too big. The best I can do at the moment is guestimate a value (around 0.96), but this is because I don't understand what the zPos should be.

Sorry if this is a dumb question, but I am only familiar with 2D programming.


Did u see HelloMousePick demo from getting started tutorial? Maybe it could help you.

Yeah thanks, that what I have lifted the most of the code from, and it works for selecting objects on the screen.

But say if I try to draw a line from an object to where the mouse is pointing, the coords are wrong as described above.


i have the same problem  :frowning:

Just for the record, and any future searches:

The solution to the problem was very simple; with the zPos value set to 0 getWorldCoordinates gives the coords of the mouse which in my case was one unit from the camera. Therefore if the camera is 25 units above the xy plane and the mouse is 1 unit from the camera, just multiply the x and y cords of the mouse