Author Topic: projecting rays into the screen  (Read 3737 times)

Offline loongy

  • byte
  • *
  • Posts: 8
    • View Profile
projecting rays into the screen
« on: April 03, 2011, 05:01:42 pm »
i want to project a ray into the 3d world by touching the screen and using those 3d co ordinates.
i am not trying to select objects, but i want to move an object to the projected position.
i know the y component of the resulting projected vector (cuz the object must always be at a specific y height)

any ideas?

Offline Kaiidyn

  • long
  • ***
  • Posts: 103
    • View Profile
Re: projecting rays into the screen
« Reply #1 on: April 03, 2011, 07:44:29 pm »
Take a look at my topic here, it might help
http://www.jpct.net/forum2/index.php/topic,1803.0.html
Clean code is simple and direct. Clean code reads like well-written prose. Clean code never obscures the designer’s intent but rather is full of crisp abstractions and straightforward lines of control. - Grady Booch

Offline loongy

  • byte
  • *
  • Posts: 8
    • View Profile
Re: projecting rays into the screen
« Reply #2 on: April 04, 2011, 11:18:08 am »
that won't work for this situation.
i started this thread because none of the other threads seem to work when i implemented their code.
i am trying to touch the screen (2d co-ordinates) and then cast a ray into the 3d world perpendicular to the screen.
its similar to the method of 2d to 3d object picking except i am now trying to move the object i have picked by clicking the screen

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: projecting rays into the screen
« Reply #3 on: April 04, 2011, 11:30:03 am »
It's actually a simple vector equation once you have the position and direction vector. The position vector should be the camera position and the direction vector is the vector returned by the reproject...WS-method. If y of the target plane is known, you end up with three equations and two unknown variables x and z...that's pretty easy to solve on paper. I have some code lying around that does this iirc...i just can't post it right now, because i'm on holiday. Maybe wednesday if you still need it then.

Offline loongy

  • byte
  • *
  • Posts: 8
    • View Profile
Re: projecting rays into the screen
« Reply #4 on: April 04, 2011, 11:38:11 am »
no its okay i found out how to do it.
i followed the method for object picking and it didnt really work.
i sat down and re did it all and now it works so i guess there was something simple that i just overlooked.
thanks all!