Advertisement Jump to content
Sign in to follow this  
Charles Thomas

trouble casting a ray

This topic is 5058 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
i'm assuming you use openGL.

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

What we need is essentially opposite,


(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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!