Shirakumo / trial

A fully-fledged Common Lisp game engine
https://shirakumo.github.io/trial
zlib License
985 stars 47 forks source link

Convex Polyhedral Collision Detection #51

Closed Shinmera closed 1 year ago

Shinmera commented 1 year ago

This PR primarily implement the Voronoi Clip algorithm for collision detection between convex polyhedra.

V-Clip is a very robust and fast algorithm that can be a suitable alternative to more common algorithms like GJK+EPA. Unlike GJK however it requires more pre-processing to create support structures that describe the voronoi regions of the various polyhedra features. Unlike GJK it also cannot serve as a general framework for collisions between arbitrary primitives that aren't triangulated.

Nevertheless I thought it worth implementing as an alternative.

Unfortunately despite getting the exact same results as the reference v-clip implementation, I did not get correct results for several rather trivial example cases between two cubes (see the v-clip example demo). Thus I also implemented GJK and EPA, which seemed to work correctly on first try, so that's nice.

GJK will take over for any two shapes that don't have tailored collision detection functions, and V-Clip can be used by coercing any primitive to a v-clip:mesh.