Sign in to follow this  

Ray Casting with a moving camera

This topic is 4865 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

I've read some threads/articles/samples about ray casting from mouse coordinates for picking/etc. But, they all seem to use a "static" camera, ie the camera stays still and world moves around it, and they cast a ray in the positive z direction. (negative z in OpenGL) Well in my game, my camera moves around by changing the view matrix. The couple of example ray casting methods I've seen(they're all essentially the same, of course), don't take camera position/rotation into account, as they're assigning a straight 1.0 to the direction vector's z component and the like. So I guess my main question is: how do you take into account for camera position, and probably more important, rotation in the ray casting algorithm? My guess is at the very end, after calculating the ray in screen space and translating it, though admittedly I don't have enough of a grasp on the concept to make an informed guess. Right now I'm using DirectX (if it isn't clear already, lol), but any help in OpenGL is fine too. Just so the concept's clear. Thanks.

Share this post


Link to post
Share on other sites
well it's still just ray casting, so make a ray that's at your camera's origin and goes to a point along your camera's view vector that intersects with the back plane of the view frustum (basically scale your camera's view vector to be the lenght of your frustums far clip plane). everything else should be exactly the same.

also, if you're talking about the algorithms that use openGLs picking method (i think it's like the pick buffer or something that's very openGL specific) the reason all the rays are in the -z direction is because after you've applied the view matrix you're camera will be looking in the -z direction. it doesn't matter how you represent it in your world, after all the transforms all methods are the same.

-me

Share this post


Link to post
Share on other sites
If you know how to get ray direction vector for case camera looks straight at -z direction, for case camera looks in other direction you just need to transform your rays from camera's frame of reference to world's frame of reference. So you need to multiply it with inverse of camera matrix you use to transform your vertices.

Share this post


Link to post
Share on other sites
heh, forgot OpenGL had picking support built in. nevermind on that.

But as for the suggestions, thanks a lot. I'm at work so I can't really try it out, but I understand basically what I need to do, so everything should work out.

Share this post


Link to post
Share on other sites

This topic is 4865 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this