Do you want the x and y coordinates on the mouse on the screen?
Then indeed base.mouseWatcherNode.getMouse() returns the fraction of the screen at which the mouse is (0.5,0.5 as the center).
Or do you want the x and y coordinates of the position inside the game world where the mouse is pointing?
Then this might help: panda3d.org/manual/index.php … 3D_Objects
Yep, I’m looking for the coordinates in the game world. Slowly trying to figure this example out. Thanks. I can’t seem so far to figure where I read the coordinates in the world though.
Do you mean that, considering the camera’s view-plane to be a plane located in the world, you want the coordinates of a point on that plane based on a given mouse coordinate? If so, surely that would be a 3D point, not a 2D point?
If that is what you want, and there’s nothing in the API that provides it, I think that it should largely be a matter of trigonometry. I think that the following should be more or less correct:
Let the input mouse coordinates be “mouseX” and “mouseY”, specified both in the range [-1, 1].
Find the camera’s position, which we’ll call “posCam”, the world-space depth of the near-plane, “nearDepth”, and the world-space width-and-height size of the camera’s film, “filmSize”. I’m not sure that the results of the Lens class’s “getNear” and “getFilmSize” will get quite the values desired here; if not, I think that you should be able to use the “extrude” method, passing in a 2D point of (1, 1) to specify a corner of the near-plane, and then examine the result returned in the “near_point” parameter.
Let the output 3D vector be “result”.
Find the camera’s right-, up- and forward- vectors (using something along the lines of “camera.getQuat().getForward()” and the similar “getRight()” and “getUp()” methods); we’ll here call them “camForward” and “camRight”.
result = camForwardnearDepth + mouseXfilmSize.xcamRight + mouseYfilmSize.y*camUp
If you just want the coordinates relative to the plane, that would seem to just be a multiple of the mouse coordinates that you already have.
(I’ve used worldZ above because you’ve used your world-space y-axis as the depth axis.)
Regarding the mutiplication and addition of 0.5 above, I checked, and in my version of Panda at least (1.8.0, I think) mouse coordinates range from (-1, -1) at the bottom-left of the screen to (1, 1) at the top-right, if I recall correctly. Hence, in order for the mouse to map from (0, 0) at the bottom-left to (filmSize.x, filmSize.y) at the top-right we halve the range of the mouse coordinates (so that they cover a range of 1 instead of 2) and then shift them so that (0, 0) is at the bottom-left rather than the centre.