projecting rays into the screen

Started by loongy, April 03, 2011, 05:01:42 PM

Previous topic - Next topic

loongy

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?

Kaiidyn

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

loongy

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

EgonOlsen

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.

loongy

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!