Author Topic: getting world coordinates of point at specific distance from camera  (Read 2140 times)

Offline saadasif21

  • byte
  • *
  • Posts: 3
    • View Profile
Hi geeks,
i have been trying to get world coordinates at specific distance from camera. i cant use collision detection because i do not have object at that point. I’m at my wits’ end!

let me explain briefly,
lets suppose my camera is at (0,0,-50) and i cant have any object in my world. If i tap anywhere on my 2d screen, where in the world space at z=0 that tap goes. please help
please ask if you need further clarification.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: getting world coordinates of point at specific distance from camera
« Reply #1 on: November 07, 2017, 07:40:45 am »
You can use this for example: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Interact2D.html#reproject2D3DWS(com.threed.jpct.Camera, com.threed.jpct.FrameBuffer, int, int, float)

I'm not sure if it does exactly what you want, because you are talking about z=0 in world space here!? However, this method takes z in camera space (which is actually natural, because that's the space into which your taps are going). Just remember that z=0 in camera space isn't a bright idea, so use 1 for 10 or whatever fits you instead.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: getting world coordinates of point at specific distance from camera
« Reply #2 on: November 07, 2017, 07:55:56 am »
This thread contains some example code btw (for desktop jPCT, but the idea still applies): http://www.jpct.net/forum2/index.php/topic,2413.0.html

Offline saadasif21

  • byte
  • *
  • Posts: 3
    • View Profile
Re: getting world coordinates of point at specific distance from camera
« Reply #3 on: November 08, 2017, 10:09:33 am »
Thanks for your help,
I got out of that mess by using
Interact2D.reproject2D3D(world.getCamera(), fb, x, y);
 Thanks again :)