This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file shows the algorithms for detecting 3D AABB-AABB, sphere-sphere and AABB-sphere collisions together with collision normal and penetration. | |
// - This was thought for use with an ECS system, specifically flecs. https://www.flecs.dev/flecs/ | |
// - Based on https://gamedevelopment.tutsplus.com/how-to-create-a-custom-2d-physics-engine-the-basics-and-impulse-resolution--gamedev-6331t | |
// - This won't compile as-is, you have to provide your own math functions. | |
// - An AABB is represented by a center, min and max coordinates. The code assumes that an AABB's min corners coords are always less than the max corners. | |
// - A sphere is represented by a center and a radius. | |
// - Uses double-precision floating point numbers for translation, penetration, AABBs and sphere's radius. Single precision for everything else. You can change this easily. | |
// - Supports scale. | |
// - For AABBs, scale is applied to its extents. | |
// - For spheres, scale vector components are averaged and applied to the radius. That is, it works |