Author Topic: Converting mouse position back and forth to WS returns different values  (Read 2516 times)

Offline javamak

  • byte
  • *
  • Posts: 13
    • View Profile
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Converting mouse position back and forth to WS returns different values
« Reply #1 on: December 28, 2015, 10:31:01 am »
Why are you normalizing the reprojected vector? Don't do that.

Offline javamak

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Converting mouse position back and forth to WS returns different values
« Reply #2 on: December 28, 2015, 11:00:49 am »
I tried without normalize still I get same result.

Offline MichaelJPCT

  • float
  • ****
  • Posts: 264
    • View Profile
Re: Converting mouse position back and forth to WS returns different values
« Reply #3 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Converting mouse position back and forth to WS returns different values
« Reply #4 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.

Offline javamak

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Converting mouse position back and forth to WS returns different values
« Reply #5 on: December 28, 2015, 05:47:37 pm »
Thanks that worked.