Converting mouse position back and forth to WS returns different values

Started by javamak, December 28, 2015, 07:58:37 AM

Previous topic - Next topic

javamak

Hello,

I am do some 2D drawing in bottom of the screen so trying to convert the 2D position into 3D using reproject2D3DWS method and doing some calculations and converting back into 2D using project3D2D method. But I always get the returned 2D values around the middle of the screen.

here is a sample code to reproduce it.

System.out.println("X:"+e.getX() +",Y:"+e.getY());
      SimpleVector v = Interact2D.reproject2D3DWS(jpctPanel.getWorld().getCamera(), jpctPanel.getBuffer(),
            e.getX(), e.getY()).normalize();
      System.out.println(Interact2D.project3D2D(jpctPanel.getCamera(), jpctPanel.getBuffer(), v));

Mouse coord: X:420,Y:458
Output of above code: (904.2925,487.36615,0.0047869836)

X:1480,Y:402
(909.04944,487.11993,0.0047874274)

any help.

Thanks.

EgonOlsen


javamak


MichaelJPCT

reproject2d3dws returns a direction vector, not a position in world space. project3d2d requires a position in world space as input.

EgonOlsen

That's right. If the camera has moved, you have to add it's position to the returned vector.