From 56077b7c86386d844aa26a68743d553f512b2891 Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 25 Jan 2024 19:09:36 -0500 Subject: [PATCH] Implement AABB --- include/J3ML/Geometry/AABB.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/include/J3ML/Geometry/AABB.h b/include/J3ML/Geometry/AABB.h index c13e0b3..9958c13 100644 --- a/include/J3ML/Geometry/AABB.h +++ b/include/J3ML/Geometry/AABB.h @@ -3,17 +3,26 @@ #include #include "Plane.h" #include "Sphere.h" +#include "OBB.h" +#include "LineSegment.h" using namespace LinearAlgebra; namespace Geometry { + // A 3D axis-aligned bounding box + // This data structure can be used to represent coarse bounds of objects, in situations where detailed triangle-level + // computations can be avoided. In physics systems, bounding boxes are used as an efficient early-out test for geometry + // intersection queries. + // the 'Axis-aligned' part in the name means that the local axes of this bounding box are restricted to align with the + // axes of the world space coordinate system. This makes computation involving AABB's very fast, since AABB's cannot + // be arbitrarily oriented in the space with respect to each other. + // If you need to represent a box in 3D space with arbitrary orientation, see the class OBB. */ + class AABB { static AABB FromCenterAndSize(const Vector3 FromSize); - float MinX(); - // Returns the smallest sphere that contains this AABB. // This function computes the minimal volume sphere that contains all the points inside this AABB Sphere MinimalEnclosingSphere() const; @@ -51,12 +60,25 @@ namespace Geometry OBB Transform(const Matrix3x3& transform); OBB Transform(const Matrix4x4& transform); OBB Transform(const Quaternion& transform); - bool Contains(const Vector3& point) const; bool Contains(const LineSegment& lineSegment) const; bool Contains(const AABB& aabb) const; bool Contains(const OBB& obb) const; bool Contains(const Sphere& sphere) const; - bool C + bool Contains(const Triangle& triange) const; + bool Contains(const Polygon& polygon) const; + bool Contains(const Frustum& frustum) const; + bool Contains(const Polyhedron& polyhedron) const; + bool Contains(const Capsule& capsule) const; + // Tests whether this AABB and the given object intersect. + bool Intersects(const Ray& ray, float dNear, float dFar) const; + bool Intersects(const Capsule& capsule) const; + bool Intersects(const Triangle& triangle) const; + bool Intersects(const Polygon& polygon) const; + bool Intersects(const Frustum& frustum) const; + bool Intersects(const Polyhedron& polyhedron) const; + TriangleMesh Triangulate(int numFacesX, int numFacesY, int numFacesZ, bool ccwIsFrontFacing) const; + AABB Intersection(const AABB& rhs) const; + bool IntersectLineAABB(const Vector3& linePos, const Vector3& lineDir, float tNear, float tFar) const; }; }