跳转到内容

碰撞检测入门

物理系统一般分为宽阶段(Broad Phase)和窄阶段(Narrow Phase)碰撞检测,以及约束求解与积分。本章以 AABB 为例介绍最基础的碰撞检测。

// 示例:轴对齐包围盒(AABB)相交检测
struct AABB { Vec3 min, max; };
bool Intersects(const AABB& a, const AABB& b) {
return a.min.x <= b.max.x && a.max.x >= b.min.x &&
a.min.y <= b.max.y && a.max.y >= b.min.y &&
a.min.z <= b.max.z && a.max.z >= b.min.z;
}