Sign in to follow this  
Frisker

Collision between a cube and a triangle.

Recommended Posts

Hello, I got an airplane and a terrain I want to check collision between. I've considerd to make a bounding box around the plane and check collision between the bounding box and the terrain. I dont load in the terrain from a bitmap but from a mesh and I then organize the triangles in a array. I thought to check all the triangles in my bounding box against the triangles in the terrain the plane is hovering over. So far so good, But what is the fastest equation for doin an intersecton?, and is there possibly an even more optimized way to check a box against a triangle?. Thanks in advance!.

Share this post


Link to post
Share on other sites
Unless you need greater accuracy, I would use a sphere, as it will be quite a bit easier. A discrete sphere-triangle test requires only a point-to-triangle closest-point test, which you should be able to find online (or ask here if you can't find it). From there you can determine a boolean result, plus penetration depth and direction if needed.

Other options might be ellipsoids or capsules. If you want to use an AABB or OBB, you'll most likely want to use the separating axis theorem, which is a bit more complicated to implement.

Share this post


Link to post
Share on other sites
Sorry for my late reply.

I checked some functions on google but the only thing I found was intersection between triangles and a point ray. I would be very thankfull if you could link me to a site that describes the sphere to triangle intersection or even better if you have the time to give me a code example :-) (I prefer C#). I havnt got into very advanced math yet (due to my age) so I would be gratefull if it was written in an 'easy' language. Thanks in advance, Frisker

Share this post


Link to post
Share on other sites
When I just need an intersection test, I typically go to Dave Eberly's web site Geometric Tools. I also recommend picking up one of his books; his Wild Magic library (that comes with the books) is sometimes a useful source of various code.

Once you know how to collide a sphere with a triangle, you will realize that testing 1,000,000 triangles each frame is fairly inefficient, and you'll want to put your triangles into some sort of spatial hierarchy (octree, quadtree, etc). At that point, you could do worse than reading Christer Ericson's book on Real-Time Collision Detection; it's fairly thorough.

Share this post


Link to post
Share on other sites
Well, I have already divided all the triangles into an array (it's called space divison right?). I downloaded the pdf Distance Point - Triangle from your geometry site. To be honest I didn't know about 50% of the mysterious signs he used in his calculations. Should I put down game programmering until my math skill has been increased? :-(

Share this post


Link to post
Share on other sites
Quote:
Original post by Frisker
Well, I have already divided all the triangles into an array (it's called space divison right?). I downloaded the pdf Distance Point - Triangle from your geometry site. To be honest I didn't know about 50% of the mysterious signs he used in his calculations. Should I put down game programmering until my math skill has been increased? :-(
Hehe, don't be discouraged by Dave's materials. They're great references, but are also quite dense, mathematically speaking. If you get stuck on something you can always post here and ask for help.

As for the point-triangle closest-point test, it's based on some (relatively) simple calculus and linear algebra (specifically constrained minimization of a quadratic equation). There are other ways to formulate the problem as well that might be somewhat more intuitive.

Share this post


Link to post
Share on other sites
Thanks for the answer!. So I wonder if anyone here could explain the point-to-triangle distance equation here with quite simple mathematics?. I've studied linear equations so I suppose it wont be any problems :-) (Or should I make a new post about the matter?).

Share this post


Link to post
Share on other sites

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