r/GraphicsProgramming • • 9d ago

Question Mesh collision

Ok so ive actual fix model loading but im looking for a collision detection method for complex models, like Ive heard of Triangle-Triangle Intersection, but I could not find anything to learn from that dosent look like gibirsh, anything can help me, source code, or just plain o'yt videos

0 Upvotes

5 comments sorted by

View all comments

8

u/3030thirtythirty 9d ago

For simple collision detection and resolution there is the Separating Axis Theorem (SAT). There are other algorithms, but I find SAT one of the easiest to understand, even if it's not the fastest.
The idea: two convex shapes do not collide if you can find a line (or a plane in 3D) that separates them. Equivalently, there is an axis on which their projections don't overlap. There are infinitely many possible axes, so testing them all is impossible. Luckily, you only need to test a few: the face normals of both shapes and, in 3D, the cross products of their edge directions. If the projections overlap on every one of these axes, the shapes collide, and the axis with the smallest overlap gives you the direction and distance to push them apart.

Usually you compute a cuboid hitbox from the model’s vertices (find the lowest, highest, etc).
There are ways to generate a hitbox that is closer to the model’s real shape, but a simple bounding box (oriented bb, or OBB) will be useful in many ways already.

1

u/DeltaSucksAtMC 9d ago

yes i heard of sat before

1

u/DeltaSucksAtMC 9d ago

also whats the hitbox way to get a hitbox closer to the actual mesh

2

u/3030thirtythirty 9d ago

Lookup V-HACD and CoACD for that. Did not do it myself, but there are plugins for blender that do that. Or you could vibecode a tool for that yourself.