1
Support / How to get world coordinates from mouse coordinates
« on: November 20, 2011, 04:44:01 am »
I'm not trying to "pick" anything. I just want to get the world coordinates (at plane z=0) from the mouse coordinates. Seems like the method I need to use would be Interact2D.reproject2D3DWS, however it doesn't give me ability to choose z=0. (it assumes z=1). Even with the assumption of z=1, the result seems incorrect.
From other examples in the forums it seems that the result of reproject2D3DWS gives a "direction" and not a "position".
Here's my code:
public void mouseMoved(MouseEvent e) {
double x=currentMouseX=e.getX();
double y=currentMouseY=e.getY();
System.out.printf("Mouse screen: %d %d\n",currentMouseX,currentMouseY);
System.out.println("Mouse position: "+Interact2D.reproject2D3DWS(world.getCamera(), buffer, currentMouseX, currentMouseY).toString());
}
It just gives me nonsense.
Other information:
I adjusted my camera position to be at (6,6,6) with camera orientation pointing to the origin, and camera "up" being the vector normal to the camera orientation such that "z" is up.
Tom
From other examples in the forums it seems that the result of reproject2D3DWS gives a "direction" and not a "position".
Here's my code:
public void mouseMoved(MouseEvent e) {
double x=currentMouseX=e.getX();
double y=currentMouseY=e.getY();
System.out.printf("Mouse screen: %d %d\n",currentMouseX,currentMouseY);
System.out.println("Mouse position: "+Interact2D.reproject2D3DWS(world.getCamera(), buffer, currentMouseX, currentMouseY).toString());
}
It just gives me nonsense.
Other information:
I adjusted my camera position to be at (6,6,6) with camera orientation pointing to the origin, and camera "up" being the vector normal to the camera orientation such that "z" is up.
Tom