Jump to content
  • Advertisement
Sign in to follow this  
Charles Thomas

trouble casting a ray

This topic is 4902 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm having trouble casting a ray from the camera. I'm trying cast a ray from the position of the mouse. I have calculated the camera axises and I've normalized the mouse coordinates so that both the x and y position go from -1 to 1. I'm trying to see where the ray intersects along the plan where y = 0. The camera is always 10 units above the ground. n = eye - look I've tried rotating my normalized n vector, by the offset of the tan(mousey * fov) and I've tried several other methods, most of which I've forgotten. Any help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
i'm assuming you use openGL.

take vector
[mouseX,mouseY,1,0] (with x,y from -1 to 1)
and compute
direction=inverse(projection_matrix_as_loaded_into_GL*modelview_matrix_as_loaded_into_GL)*[mouseX,mouseY,1,0]
You should get direction.
Idea is simple: points is transformed to screen that way:
(projection_matrix_as_loaded_into_GL*modelview_matrix_as_loaded_into_GL)*direction

What we need is essentially opposite,

direction=inverse(projection_matrix_as_loaded_into_GL*modelview_matrix_as_loaded_into_GL)*screen_point

(result needs to be normalized)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!