Collider
TheCollider struct represents an axis-aligned bounding box (AABB) with sweep-based collision detection.
Struct Definition
Constructor
Collider(glm::vec3 pos1, glm::vec3 pos2)
Creates an AABB from two corner points. Parameters:pos1- Minimum corner (x1, y1, z1), defaults to originpos2- Maximum corner (x2, y2, z2), defaults to origin
Operators
Collider operator+(const glm::vec3& pos)
Translates the collider by a vector offset. Parameters:pos- Offset to add to both corners
bool operator&(const Collider& other)
Checks if two AABBs overlap (static intersection test). Parameters:other- The collider to test against
true if the AABBs intersect
Algorithm:
- Computes overlap distance on each axis
- Returns
trueonly if all three axes have positive overlap
Collision Detection
collide()
static_col- The static collider to test againstvelocity- Movement vector for this frame
std::pair of:
float- Entry time [0..1] where collision occurs (1.0 = no collision)glm::vec3- Collision normal vector (unit vector or zero)
- Compute entry/exit times for each axis using swept AABB formula
- Early reject if all entry times are negative (already overlapping from behind)
- Early reject if any entry time > 1.0 (won’t reach collision this frame)
- Find latest entry time and earliest exit time across all axes
- Reject if entry > exit (no overlap period)
- Determine collision normal from the axis with latest entry time
AABB Sweep Theory
Swept AABB collision detects the first moment a moving box touches a static box:Entry/Exit Times
For each axis, compute when the moving AABB’s trailing edge enters and leading edge exits the static AABB:Collision Window
A collision occurs when all three axes overlap:Normal Vector
The collision normal points away from the static collider along the axis that had the latest entry:Usage Example
Integration with Entity Physics
InEntity::update(), collision detection runs in 3 passes: