Sign in to follow this  

Ray collision help?

This topic is 2167 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 creating a game using OpenGL and c++ for my final year project and I've got a quick question about using rays for collisions. I understand the theory behind it but I'm having an issue implementing it. I'm loading my models using Assimp and I'm trying to create a bounding box around the models so that I can check for a ray-box intersection, but when the transformations are applied during rendering, the box does not move with the model. I have created my own vertex and fragment shaders that draws the models. What approach is best for situation? Should I find a way to also move the bounding box, or is there another method to help with this? I considered using a frame buffer object from the point of view of the ray but I think this is overcomplicating things. I'm using rays as the game is a first person sniping game, and bullets would move too fast to find the box intersections.

Share this post


Link to post
Share on other sites
First choose whether you want to use axis-aligned bounding boxes ([url="http://clb.demon.fi/MathGeoLib/docs/AABB_summary.php"]AABB[/url]), or oriented bounding boxes ([url="http://clb.demon.fi/MathGeoLib/docs/OBB_summary.php"]OBB[/url]).

To generate the optimal minimum AABB for a model, see [url="http://clb.demon.fi/MathGeoLib/docs/AABB_SetFrom.php"]AABB::SetFrom(pointArray);[/url]
To generate the optimal minimum OBB for a model, google for the "Rotating Calipers" method.
To intersect a ray against an AABB, see [url="http://clb.demon.fi/MathGeoLib/docs/AABB_IntersectRayAABB.php"]AABB::IntersectRayAABB[/url].
To intersect a ray against an OBB, see [url="http://clb.demon.fi/MathGeoLib/docs/OBB_Intersects.php"]OBB::Intersects(Ray)[/url].

To perform the ray-box intersection test, update the box and ray coordinates into same coordinate space (i.e. world space, or object's local space) for the test. This means that you update your box representation along with the transform of your object to avoid "the box does not move with the model" issue you described.

Trying to go the route of rendering the object into a frame buffer and doing per-pixel tests to check for intersection is a poor idea due to added latency and performance costs.

Share this post


Link to post
Share on other sites
Thanks for the information! I will attempt to implement this, I figured as much with the frame buffer.

Share this post


Link to post
Share on other sites
Hi I tried to implement the AABB bounding box, but when I apply the model's transformation matrix the values are incorrect. I think this is something to do with the rotation in th matrix. After debugging i found a lot of the values were low numbers. To apply the transformations I set each corner of the box and applied the transformation to each one, then circled between them to find the lowest value.

Share this post


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