bool intersect(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); } AABB a({0, 0, 0}, {10, 10, 10}); AABB b({5, 5, 5}, {15, 15, 15}); if (intersect(a, b)) { std::cout << "AABBs intersect!" << std::endl; }
Vec3 center(const AABB& a) { return (a.min + a.max) * 0.5f; } AABB a({0, 0, 0}, {10, 10, 10}); Vec3 center = center(a); std::cout << "Center: " << center.x << ", " << center.y << ", " << center.z << std::endl;These examples do not specify an external package library, as AABB is a common data structure that can be implemented in any C++ program. However, there are various 3D graphics libraries and physics engines that include AABBs in their implementations, such as OpenGL, DirectX, and the Box2D physics engine.