Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Ray collision help?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Richard Goodrum   Members   -  Reputation: 107

Like
0Likes
Like

Posted 08 February 2012 - 12:01 PM

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.

Sponsor:

#2 clb   Members   -  Reputation: 1796

Like
1Likes
Like

Posted 08 February 2012 - 12:37 PM

First choose whether you want to use axis-aligned bounding boxes (AABB), or oriented bounding boxes (OBB).

To generate the optimal minimum AABB for a model, see AABB::SetFrom(pointArray);
To generate the optimal minimum OBB for a model, google for the "Rotating Calipers" method.
To intersect a ray against an AABB, see AABB::IntersectRayAABB.
To intersect a ray against an OBB, see OBB::Intersects(Ray).

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.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

#3 Richard Goodrum   Members   -  Reputation: 107

Like
0Likes
Like

Posted 08 February 2012 - 04:14 PM

Thanks for the information! I will attempt to implement this, I figured as much with the frame buffer.

#4 Richard Goodrum   Members   -  Reputation: 107

Like
0Likes
Like

Posted 11 February 2012 - 12:20 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS