Jump to content
  • Advertisement
Sign in to follow this  
Necrolyte

Checking if a 'ray' intersects cube

This topic is 2759 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
Advertisement
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
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!