views:

472

answers:

3

I am creating a CAD like program, creating modelvisual3D objects. How do i do collision detection between my objects(modelvisual3d) using MeshGeometry3D. Do i have to compare every triangle in the moving object against the still standing objects?

What will be my best way to do collision detection?

A: 

It depends on how precise your collision detection needs to be.

There is no built-in collision detection in WPF's 3D library. If you need high precision, you'll need to compare every triangle.

That being said, you can start with comparing bounding boxes and/or bounding spheres. This is always a good first step, since it can quickly eliminate most cases. If you don't need precision collision detection, this alone may be fine.

Reed Copsey
A: 

To add to Reed's answer (based on my answer here):

After you've eliminated most of your objects via the bounding box/sphere to bounding box/sphere test you should test the triangles of your test object(s) against the other object's bounding box/sphere first before checking triangle/triangle collisions. This will eliminate a lot more cases.

To rule out a collision you'll have to check all the triangles in the test object, but to find a case where you'll need to go down to the triangle/triangle case you only need to find the first triangle that interacts with the bounding box/sphere of the other object.

ChrisF
A: 

Look at the SAT theorem (Separating Axes Theorem), it's the fastest and easiest one out there.

The theory about this is that if you can draw a line which separates the triangles, then they're not colliding.

As is said, first do an AABB earlier detection, and when two objects collide, test each polygon of object A against each polygon of object B.

Starting in 2D, to test if two polygons collide, you get the extents of them in the possible axes (in this case X and Y), if those extents intersect, then the poligons are colliding.

On this page you can find a very good explanation on how it works and how to apply it: http://www.metanetsoftware.com/technique/tutorialA.html

To apply it to 3D simply use the edges of each polygon as the separating axes. If the extents on those axes intersect, then the polygons are colliding.

Also, this method resolves collission for moving objects, giving also the momentum of collision (resolve the relative angular velocity, substracting velocity B from velocity A, this way the problem is reduced to a moving object and a static one, and add the velocity in the axis you are testing to the extent of the polygon A, if they intersect, rest the original extent of the polygon and you will get the momentum of collission).

Gusman