Sign in to follow this  

Checking if a 'ray' intersects cube

This topic is 2544 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 have a position(x,y,z) and two angles(x and y angles).--camera position and angle in this situation
I need to know if the 'ray cast out by the camera' intersects a bounding box(cube).

I know this is probably general mathematics knowledge for some of you but I have no idea how to do it.

Share this post


Link to post
Share on other sites
First convert your position and angles to a ray origin and direction using a spherical-to-Cartesian coordinate conversion. (Or, if you have a transform matrix for the camera, you can simply extract the forward direction vector directly from the matrix.)

Then, perform a ray-vs.-axis-aligned-box test using either the separating axis test or the slab-based clipping method. (The latter will do a little unnecessary work if you don't need the intersection point, but is an option nevertheless.)

For details on the intersection test(s), try searching for terms such as 'ray aabb intersection', 'ray box intersection', and so forth.

Share this post


Link to post
Share on other sites

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