www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: javamak on December 28, 2015, 07:58:37 am

Title: Converting mouse position back and forth to WS returns different values
Post by: javamak on December 28, 2015, 07:58:37 am
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.
Title: Re: Converting mouse position back and forth to WS returns different values
Post by: EgonOlsen on December 28, 2015, 10:31:01 am
Why are you normalizing the reprojected vector? Don't do that.
Title: Re: Converting mouse position back and forth to WS returns different values
Post by: javamak on December 28, 2015, 11:00:49 am
I tried without normalize still I get same result.
Title: Re: Converting mouse position back and forth to WS returns different values
Post by: MichaelJPCT on December 28, 2015, 12:57:28 pm
reproject2d3dws returns a direction vector, not a position in world space. project3d2d requires a position in world space as input.
Title: Re: Converting mouse position back and forth to WS returns different values
Post by: EgonOlsen on December 28, 2015, 03:24:06 pm
That's right. If the camera has moved, you have to add it's position to the returned vector.
Title: Re: Converting mouse position back and forth to WS returns different values
Post by: javamak on December 28, 2015, 05:47:37 pm
Thanks that worked.