From 22c0a14081e2109de18a977382dd4412cbc38b4e Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Fri, 23 Dec 2022 00:55:36 +0800 Subject: [PATCH] Renamed SHBox to SHAABB for clarity The future SHBox will represent an OBB --- .../src/Camera/SHCameraArmComponent.h | 2 +- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 2 +- .../Inspector/SHEditorComponentView.hpp | 2 +- .../Math/Geometry/{SHBox.cpp => SHAABB.cpp} | 74 +++++------- .../src/Math/Geometry/{SHBox.h => SHAABB.h} | 114 ++++++++++++++---- SHADE_Engine/src/Math/Geometry/SHSphere.h | 16 +-- .../Broadphase/SHDynamicAABBTree.cpp | 38 +++--- .../Collision/Broadphase/SHDynamicAABBTree.h | 10 +- .../CollisionShapes/SHCollisionShape.h | 4 +- .../SHSphereCollisionShape.cpp | 4 +- .../CollisionShapes/SHSphereCollisionShape.h | 2 +- .../src/Serialization/SHYAMLConverters.h | 5 +- SHADE_Managed/src/Components/Collider.cxx | 20 +-- 13 files changed, 171 insertions(+), 122 deletions(-) rename SHADE_Engine/src/Math/Geometry/{SHBox.cpp => SHAABB.cpp} (71%) rename SHADE_Engine/src/Math/Geometry/{SHBox.h => SHAABB.h} (55%) diff --git a/SHADE_Engine/src/Camera/SHCameraArmComponent.h b/SHADE_Engine/src/Camera/SHCameraArmComponent.h index 9d8ec853..dfae1cd5 100644 --- a/SHADE_Engine/src/Camera/SHCameraArmComponent.h +++ b/SHADE_Engine/src/Camera/SHCameraArmComponent.h @@ -10,7 +10,7 @@ namespace SHADE { - class SHBox; + class SHAABB; class SHRay; class SH_API SHCameraArmComponent final: public SHComponent diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index d94bd3f8..af7d0f98 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -10,7 +10,7 @@ #include "Scene/SHSceneManager.h" #include "ECS_Base/Managers/SHSystemManager.h" #include "Editor/SHEditor.h" -#include "Math/Geometry/SHBox.h" +#include "Math/Geometry/SHAABB.h" #include "Math/SHRay.h" #include "Physics/System/SHPhysicsSystem.h" diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 2bbc0305..622a2d37 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -346,7 +346,7 @@ namespace SHADE { //SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); // - //const auto* BOX = reinterpret_cast(collider->GetShape()); + //const auto* BOX = reinterpret_cast(collider->GetShape()); //SHEditorWidgets::DragVec3 //( // "Half Extents", { "X", "Y", "Z" }, diff --git a/SHADE_Engine/src/Math/Geometry/SHBox.cpp b/SHADE_Engine/src/Math/Geometry/SHAABB.cpp similarity index 71% rename from SHADE_Engine/src/Math/Geometry/SHBox.cpp rename to SHADE_Engine/src/Math/Geometry/SHAABB.cpp index 05595fe1..8a44457f 100644 --- a/SHADE_Engine/src/Math/Geometry/SHBox.cpp +++ b/SHADE_Engine/src/Math/Geometry/SHAABB.cpp @@ -11,7 +11,7 @@ #include // Primary Header -#include "SHBox.h" +#include "SHAABB.h" // Project Headers #include "Math/SHMathHelpers.h" #include "Math/SHRay.h" @@ -24,14 +24,12 @@ namespace SHADE /* Constructors & Destructor Definitions */ /*-----------------------------------------------------------------------------------*/ - SHBox::SHBox() noexcept - : RelativeExtents { SHVec3::One } + SHAABB::SHAABB() noexcept { type = Type::BOX; } - SHBox::SHBox(const SHVec3& c, const SHVec3& hE) noexcept - : RelativeExtents { SHVec3::One } + SHAABB::SHAABB(const SHVec3& c, const SHVec3& hE) noexcept { type = Type::BOX; @@ -40,7 +38,7 @@ namespace SHADE } - SHBox::SHBox(const SHBox& rhs) noexcept + SHAABB::SHAABB(const SHAABB& rhs) noexcept { if (this == &rhs) return; @@ -49,23 +47,21 @@ namespace SHADE Center = rhs.Center; Extents = rhs.Extents; - RelativeExtents = rhs.RelativeExtents; } - SHBox::SHBox(SHBox&& rhs) noexcept + SHAABB::SHAABB(SHAABB&& rhs) noexcept { type = Type::BOX; Center = rhs.Center; Extents = rhs.Extents; - RelativeExtents = rhs.RelativeExtents; } /*-----------------------------------------------------------------------------------*/ /* Operator Overload Definitions */ /*-----------------------------------------------------------------------------------*/ - SHBox& SHBox::operator=(const SHBox& rhs) noexcept + SHAABB& SHAABB::operator=(const SHAABB& rhs) noexcept { if (rhs.type != Type::BOX) { @@ -75,13 +71,12 @@ namespace SHADE { Center = rhs.Center; Extents = rhs.Extents; - RelativeExtents = rhs.RelativeExtents; } return *this; } - SHBox& SHBox::operator=(SHBox&& rhs) noexcept + SHAABB& SHAABB::operator=(SHAABB&& rhs) noexcept { if (rhs.type != Type::BOX) { @@ -91,7 +86,6 @@ namespace SHADE { Center = rhs.Center; Extents = rhs.Extents; - RelativeExtents = rhs.RelativeExtents; } return *this; @@ -101,27 +95,22 @@ namespace SHADE /* Getter Function Definitions */ /*-----------------------------------------------------------------------------------*/ - SHVec3 SHBox::GetCenter() const noexcept + SHVec3 SHAABB::GetCenter() const noexcept { return Center; } - SHVec3 SHBox::GetWorldExtents() const noexcept + SHVec3 SHAABB::GetWorldExtents() const noexcept { return Extents; } - const SHVec3& SHBox::GetRelativeExtents() const noexcept - { - return RelativeExtents; - } - - SHVec3 SHBox::GetMin() const noexcept + SHVec3 SHAABB::GetMin() const noexcept { return SHVec3{ Center.x - Extents.x, Center.y - Extents.y, Center.z - Extents.z }; } - SHVec3 SHBox::GetMax() const noexcept + SHVec3 SHAABB::GetMax() const noexcept { return SHVec3{ Center.x + Extents.x, Center.y + Extents.y, Center.z + Extents.z }; } @@ -130,22 +119,17 @@ namespace SHADE /* Setter Function Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHBox::SetCenter(const SHVec3& newCenter) noexcept + void SHAABB::SetCenter(const SHVec3& newCenter) noexcept { Center = newCenter; } - void SHBox::SetWorldExtents(const SHVec3& newWorldExtents) noexcept + void SHAABB::SetWorldExtents(const SHVec3& newWorldExtents) noexcept { Extents = newWorldExtents; } - void SHBox::SetRelativeExtents(const SHVec3& newRelativeExtents) noexcept - { - RelativeExtents = newRelativeExtents; - } - - void SHBox::SetMin(const SHVec3& min) noexcept + void SHAABB::SetMin(const SHVec3& min) noexcept { const SHVec3 MAX = GetMax(); @@ -153,7 +137,7 @@ namespace SHADE Extents = SHVec3::Abs((MAX - min) * 0.5f); } - void SHBox::SetMax(const SHVec3& max) noexcept + void SHAABB::SetMax(const SHVec3& max) noexcept { const SHVec3 MIN = GetMin(); @@ -161,13 +145,13 @@ namespace SHADE Extents = SHVec3::Abs((max - MIN) * 0.5f); } - void SHBox::SetMinMax(const SHVec3& min, const SHVec3& max) noexcept + void SHAABB::SetMinMax(const SHVec3& min, const SHVec3& max) noexcept { Center = SHVec3::Lerp(min, max, 0.5f); Extents = SHVec3::Abs((max - min) * 0.5f); } - std::vector SHBox::GetVertices() const noexcept + std::vector SHAABB::GetVertices() const noexcept { std::vector vertices{ 8 }; GetCorners(vertices.data()); @@ -178,12 +162,12 @@ namespace SHADE /* Public Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ - bool SHBox::TestPoint(const SHVec3& point) const noexcept + bool SHAABB::TestPoint(const SHVec3& point) const noexcept { return BoundingBox::Contains(point); } - SHRaycastResult SHBox::Raycast(const SHRay& ray) const noexcept + SHRaycastResult SHAABB::Raycast(const SHRay& ray) const noexcept { SHRaycastResult result; @@ -197,17 +181,17 @@ namespace SHADE return result; } - bool SHBox::Contains(const SHBox& rhs) const noexcept + bool SHAABB::Contains(const SHAABB& rhs) const noexcept { return BoundingBox::Contains(rhs) == CONTAINS; } - float SHBox::Volume() const noexcept + float SHAABB::Volume() const noexcept { return 8.0f * (Extents.x * Extents.y * Extents.z); } - float SHBox::SurfaceArea() const noexcept + float SHAABB::SurfaceArea() const noexcept { return 8.0f * ((Extents.x * Extents.y) + (Extents.x * Extents.z) @@ -218,21 +202,21 @@ namespace SHADE /* Static Function Member Definitions */ /*-----------------------------------------------------------------------------------*/ - SHBox SHBox::Combine(const SHBox& lhs, const SHBox& rhs) noexcept + SHAABB SHAABB::Combine(const SHAABB& lhs, const SHAABB& rhs) noexcept { - SHBox result; + SHAABB result; CreateMerged(result, lhs, rhs); return result; } - bool SHBox::Intersect(const SHBox& lhs, const SHBox& rhs) noexcept + bool SHAABB::Intersect(const SHAABB& lhs, const SHAABB& rhs) noexcept { return lhs.Intersects(rhs); } - SHBox SHBox::BuildFromBoxes(const SHBox* boxes, size_t numBoxes) noexcept + SHAABB SHAABB::BuildFromBoxes(const SHAABB* boxes, size_t numBoxes) noexcept { - SHBox result; + SHAABB result; for (size_t i = 1; i < numBoxes; ++i) CreateMerged(result, boxes[i - 1], boxes[i]); @@ -240,9 +224,9 @@ namespace SHADE return result; } - SHBox SHBox::BuildFromVertices(const SHVec3* vertices, size_t numVertices, size_t stride) noexcept + SHAABB SHAABB::BuildFromVertices(const SHVec3* vertices, size_t numVertices, size_t stride) noexcept { - SHBox result; + SHAABB result; CreateFromPoints(result, numVertices, vertices, stride); return result; } diff --git a/SHADE_Engine/src/Math/Geometry/SHBox.h b/SHADE_Engine/src/Math/Geometry/SHAABB.h similarity index 55% rename from SHADE_Engine/src/Math/Geometry/SHBox.h rename to SHADE_Engine/src/Math/Geometry/SHAABB.h index 63383c00..46608ded 100644 --- a/SHADE_Engine/src/Math/Geometry/SHBox.h +++ b/SHADE_Engine/src/Math/Geometry/SHAABB.h @@ -22,7 +22,7 @@ namespace SHADE /* Type Definitions */ /*-----------------------------------------------------------------------------------*/ - class SH_API SHBox : public SHShape, + class SH_API SHAABB : public SHShape, private DirectX::BoundingBox { public: @@ -36,19 +36,19 @@ namespace SHADE /* Constructors & Destructor */ /*---------------------------------------------------------------------------------*/ - ~SHBox () override = default; + ~SHAABB () override = default; - SHBox () noexcept; - SHBox (const SHVec3& center, const SHVec3& halfExtents) noexcept; - SHBox (const SHBox& rhs) noexcept; - SHBox (SHBox&& rhs) noexcept; + SHAABB () noexcept; + SHAABB (const SHVec3& center, const SHVec3& halfExtents) noexcept; + SHAABB (const SHAABB& rhs) noexcept; + SHAABB (SHAABB&& rhs) noexcept; /*---------------------------------------------------------------------------------*/ /* Operator Overloads */ /*---------------------------------------------------------------------------------*/ - SHBox& operator= (const SHBox& rhs) noexcept; - SHBox& operator= (SHBox&& rhs) noexcept; + SHAABB& operator= (const SHAABB& rhs) noexcept; + SHAABB& operator= (SHAABB&& rhs) noexcept; /*---------------------------------------------------------------------------------*/ /* Getter Functions */ @@ -56,7 +56,6 @@ namespace SHADE [[nodiscard]] SHVec3 GetCenter () const noexcept; [[nodiscard]] SHVec3 GetWorldExtents () const noexcept; - [[nodiscard]] const SHVec3& GetRelativeExtents () const noexcept; [[nodiscard]] SHVec3 GetMin () const noexcept; [[nodiscard]] SHVec3 GetMax () const noexcept; [[nodiscard]] std::vector GetVertices () const noexcept; @@ -67,7 +66,6 @@ namespace SHADE void SetCenter (const SHVec3& newCenter) noexcept; void SetWorldExtents (const SHVec3& newWorldExtents) noexcept; - void SetRelativeExtents (const SHVec3& newRelativeExtents) noexcept; void SetMin (const SHVec3& min) noexcept; void SetMax (const SHVec3& max) noexcept; void SetMinMax (const SHVec3& min, const SHVec3& max) noexcept; @@ -76,28 +74,96 @@ namespace SHADE /* Function Members */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] bool TestPoint (const SHVec3& point) const noexcept override; - [[nodiscard]] SHRaycastResult Raycast (const SHRay& ray) const noexcept override; + /** + * @brief + * Checks if a point is inside the aabb. + * @param point + * The point to check. + * @return + * True if the point is inside the aabb. + */ + [[nodiscard]] bool TestPoint (const SHVec3& point) const noexcept override; - [[nodiscard]] bool Contains (const SHBox& rhs) const noexcept; - [[nodiscard]] float Volume () const noexcept; - [[nodiscard]] float SurfaceArea () const noexcept; + /** + * @brief + * Casts a ray against the aabb. + * @param ray + * The ray to cast. + * @return + * The result of the raycast.
+ * See the corresponding header for the contents of the raycast result object. + */ + [[nodiscard]] SHRaycastResult Raycast (const SHRay& ray) const noexcept override; + + /** + * @brief + * Checks if an entire other aabb is contained by this aabb. + * @param rhs + * The aabb to check. + * @return + * True if the other sphere is completely contained by this aabb. + */ + [[nodiscard]] bool Contains (const SHAABB& rhs) const noexcept; + + /** + * @brief + * Calculates the volume of the aabb. + */ + [[nodiscard]] float Volume () const noexcept; + + /** + * @brief + * Calculates the surface area of the aabb. + */ + [[nodiscard]] float SurfaceArea () const noexcept; /*---------------------------------------------------------------------------------*/ /* Static Function Members */ /*---------------------------------------------------------------------------------*/ - [[nodiscard]] static SHBox Combine (const SHBox& lhs, const SHBox& rhs) noexcept; - [[nodiscard]] static bool Intersect (const SHBox& lhs, const SHBox& rhs) noexcept; - [[nodiscard]] static SHBox BuildFromBoxes (const SHBox* boxes, size_t numBoxes) noexcept; - [[nodiscard]] static SHBox BuildFromVertices (const SHVec3* vertices, size_t numVertices, size_t stride = 0) noexcept; + /** + * @brief + * Combines two aabbs to form a larger aabb. + * If one aabb is completely contained by the other, the result is the larger aabb. + * @return + * The combined aabb. + */ + [[nodiscard]] static SHAABB Combine (const SHAABB& lhs, const SHAABB& rhs) noexcept; - private: - /*---------------------------------------------------------------------------------*/ - /* Data Members */ - /*---------------------------------------------------------------------------------*/ + /** + * @brief + * Checks if two aabbs are intersecting. + * @return + * True if they are intersecting. + */ + [[nodiscard]] static bool Intersect (const SHAABB& lhs, const SHAABB& rhs) noexcept; - SHVec3 RelativeExtents; + /** + * @brief + * Builds a single aabb from multiple aabbs. + * @param spheres + * The set of aabbs to build from. + * @param numSpheres + * The number of aabbs in the set to build from. + * @return + * An aabb that contains all the spheres in the set. + */ + [[nodiscard]] static SHAABB BuildFromBoxes (const SHAABB* boxes, size_t numBoxes) noexcept; + + /** + * @brief + * Builds a aabb from a set of vertices. + * @param vertices + * The vertices to build a aabb from. + * @param numVertices + * The number of vertices in the set to build from. + * @param stride + * The stride between each vertex, in the instance there is data in between each + * vertex that does not define the geometry of the object. + * @return + * An aabb that contains all the vertices in the set. + */ + [[nodiscard]] static SHAABB BuildFromVertices (const SHVec3* vertices, size_t numVertices, size_t stride = 0) noexcept; }; diff --git a/SHADE_Engine/src/Math/Geometry/SHSphere.h b/SHADE_Engine/src/Math/Geometry/SHSphere.h index 91771a21..80a21aa4 100644 --- a/SHADE_Engine/src/Math/Geometry/SHSphere.h +++ b/SHADE_Engine/src/Math/Geometry/SHSphere.h @@ -56,7 +56,7 @@ namespace SHADE * @return * True if the point is inside the sphere. */ - [[nodiscard]] bool TestPoint (const SHVec3& point) const noexcept override; + [[nodiscard]] bool TestPoint (const SHVec3& point) const noexcept override; /** * @brief @@ -67,7 +67,7 @@ namespace SHADE * The result of the raycast.
* See the corresponding header for the contents of the raycast result object. */ - [[nodiscard]] SHRaycastResult Raycast (const SHRay& ray) const noexcept override; + [[nodiscard]] SHRaycastResult Raycast (const SHRay& ray) const noexcept override; /** * @brief @@ -77,19 +77,19 @@ namespace SHADE * @return * True if the other sphere is completely contained by this sphere. */ - [[nodiscard]] bool Contains (const SHSphere& rhs) const noexcept; + [[nodiscard]] bool Contains (const SHSphere& rhs) const noexcept; /** * @brief * Calculates the volume of the sphere. */ - [[nodiscard]] float Volume () const noexcept; + [[nodiscard]] float Volume () const noexcept; /** * @brief * Calculates the surface area of the sphere. */ - [[nodiscard]] float SurfaceArea () const noexcept; + [[nodiscard]] float SurfaceArea () const noexcept; /*---------------------------------------------------------------------------------*/ @@ -103,7 +103,7 @@ namespace SHADE * @return * The combined sphere. */ - [[nodiscard]] static SHSphere Combine (const SHSphere& lhs, const SHSphere& rhs) noexcept; + [[nodiscard]] static SHSphere Combine (const SHSphere& lhs, const SHSphere& rhs) noexcept; /** * @brief @@ -111,7 +111,7 @@ namespace SHADE * @return * True if they are intersecting. */ - [[nodiscard]] static bool Intersect (const SHSphere& lhs, const SHSphere& rhs) noexcept; + [[nodiscard]] static bool Intersect (const SHSphere& lhs, const SHSphere& rhs) noexcept; /** * @brief @@ -123,7 +123,7 @@ namespace SHADE * @return * A sphere that contains all the spheres in the set. */ - [[nodiscard]] static SHSphere BuildFromSpheres (const SHSphere* spheres, size_t numSpheres) noexcept; + [[nodiscard]] static SHSphere BuildFromSpheres (const SHSphere* spheres, size_t numSpheres) noexcept; /** * @brief diff --git a/SHADE_Engine/src/Physics/Collision/Broadphase/SHDynamicAABBTree.cpp b/SHADE_Engine/src/Physics/Collision/Broadphase/SHDynamicAABBTree.cpp index 540d5375..5fa93021 100644 --- a/SHADE_Engine/src/Physics/Collision/Broadphase/SHDynamicAABBTree.cpp +++ b/SHADE_Engine/src/Physics/Collision/Broadphase/SHDynamicAABBTree.cpp @@ -105,7 +105,7 @@ namespace SHADE /* Getter Functions Definitions */ /*-----------------------------------------------------------------------------------*/ - const std::vector& SHAABBTree::GetAABBs() const noexcept + const std::vector& SHAABBTree::GetAABBs() const noexcept { static AABBs aabbs; static std::stack nodeIndices; @@ -142,7 +142,7 @@ namespace SHADE /* Public Member Functions Definitions */ /*-----------------------------------------------------------------------------------*/ - void SHAABBTree::Insert(SHCollisionShapeID id, const SHBox& AABB) + void SHAABBTree::Insert(SHCollisionShapeID id, const SHAABB& AABB) { const int32_t NEW_INDEX = allocateNode(); @@ -170,7 +170,7 @@ namespace SHADE insertLeaf(NEW_INDEX); } - void SHAABBTree::Update(SHCollisionShapeID id, const SHBox& AABB) + void SHAABBTree::Update(SHCollisionShapeID id, const SHAABB& AABB) { // Get node index const int32_t INDEX_TO_UPDATE = nodeMap[id]; @@ -206,7 +206,7 @@ namespace SHADE freeNode(INDEX_TO_REMOVE); } - const std::vector& SHAABBTree::Query(SHCollisionShapeID id, const SHBox& AABB) const noexcept + const std::vector& SHAABBTree::Query(SHCollisionShapeID id, const SHAABB& AABB) const noexcept { static std::vector potentialCollisions; static std::stack nodeIndices; @@ -226,7 +226,7 @@ namespace SHADE continue; const Node& NODE = nodes[INDEX]; - if (!SHBox::Intersect(AABB, NODE.AABB)) + if (!SHAABB::Intersect(AABB, NODE.AABB)) continue; // Avoid checking against shapes of the same composite collider (and itself) @@ -328,12 +328,12 @@ namespace SHADE // Find best sibling for new leaf // Utilise Surface Area Heuristic - const SHBox& LEAF_AABB = nodes[index].AABB; + const SHAABB& LEAF_AABB = nodes[index].AABB; uint32_t searchIndex = root; while (!isLeaf(searchIndex)) { - const SHBox COMBINED_AABB = SHBox::Combine(LEAF_AABB, nodes[searchIndex].AABB); + const SHAABB COMBINED_AABB = SHAABB::Combine(LEAF_AABB, nodes[searchIndex].AABB); const float COMBINED_AREA = COMBINED_AABB.SurfaceArea(); const float INHERITED_COST = 2.0f * (COMBINED_AREA - nodes[searchIndex].AABB.SurfaceArea()); @@ -344,8 +344,8 @@ namespace SHADE float leftCost = 0.0f; float rightCost = 0.0f; - const float LEFT_COMBINED_AREA = SHBox::Combine(LEAF_AABB, nodes[LEFT_INDEX].AABB).SurfaceArea(); - const float RIGHT_COMBINED_AREA = SHBox::Combine(LEAF_AABB, nodes[RIGHT_INDEX].AABB).SurfaceArea(); + const float LEFT_COMBINED_AREA = SHAABB::Combine(LEAF_AABB, nodes[LEFT_INDEX].AABB).SurfaceArea(); + const float RIGHT_COMBINED_AREA = SHAABB::Combine(LEAF_AABB, nodes[RIGHT_INDEX].AABB).SurfaceArea(); // Compute cost for descending into the left if (isLeaf(LEFT_INDEX)) @@ -377,7 +377,7 @@ namespace SHADE Node& newParent = nodes[NEW_PARENT]; newParent.parent = OLD_PARENT; newParent.id = SHCollisionShapeID{ MAX_EID, std::numeric_limits::max() }; - newParent.AABB = SHBox::Combine(LEAF_AABB, nodes[BEST_SIBLING].AABB); + newParent.AABB = SHAABB::Combine(LEAF_AABB, nodes[BEST_SIBLING].AABB); newParent.height = nodes[BEST_SIBLING].height + 1; newParent.left = BEST_SIBLING; @@ -437,7 +437,7 @@ namespace SHADE const Node& RIGHT_NODE = nodes[RIGHT_INDEX]; nodes[index].height = 1 + SHMath::Max(LEFT_NODE.height, RIGHT_NODE.height); - nodes[index].AABB = SHBox::Combine(LEFT_NODE.AABB, RIGHT_NODE.AABB); + nodes[index].AABB = SHAABB::Combine(LEFT_NODE.AABB, RIGHT_NODE.AABB); // Sync up to the root index = nodes[index].parent; @@ -506,8 +506,8 @@ namespace SHADE nodeA.right = G; nodeG.parent = index; - nodeA.AABB = SHBox::Combine(nodeB.AABB, nodeG.AABB); - nodeC.AABB = SHBox::Combine(nodeA.AABB, nodeF.AABB); + nodeA.AABB = SHAABB::Combine(nodeB.AABB, nodeG.AABB); + nodeC.AABB = SHAABB::Combine(nodeA.AABB, nodeF.AABB); nodeA.height = 1 + SHMath::Max(nodeB.height, nodeG.height); nodeC.height = 1 + SHMath::Max(nodeA.height, nodeF.height); @@ -518,8 +518,8 @@ namespace SHADE nodeA.right = F; nodeF.parent = index; - nodeA.AABB = SHBox::Combine(nodeB.AABB, nodeF.AABB); - nodeC.AABB = SHBox::Combine(nodeA.AABB, nodeG.AABB); + nodeA.AABB = SHAABB::Combine(nodeB.AABB, nodeF.AABB); + nodeC.AABB = SHAABB::Combine(nodeA.AABB, nodeG.AABB); nodeA.height = 1 + SHMath::Max(nodeB.height, nodeF.height); nodeC.height = 1 + SHMath::Max(nodeA.height, nodeG.height); @@ -569,8 +569,8 @@ namespace SHADE nodeA.left = E; nodeE.parent = index; - nodeA.AABB = SHBox::Combine(nodeC.AABB, nodeE.AABB); - nodeB.AABB = SHBox::Combine(nodeA.AABB, nodeD.AABB); + nodeA.AABB = SHAABB::Combine(nodeC.AABB, nodeE.AABB); + nodeB.AABB = SHAABB::Combine(nodeA.AABB, nodeD.AABB); nodeA.height = 1 + SHMath::Max(nodeC.height, nodeE.height); nodeB.height = 1 + SHMath::Max(nodeA.height, nodeD.height); @@ -581,8 +581,8 @@ namespace SHADE nodeA.left = D; nodeD.parent = index; - nodeA.AABB = SHBox::Combine(nodeC.AABB, nodeD.AABB); - nodeB.AABB = SHBox::Combine(nodeA.AABB, nodeE.AABB); + nodeA.AABB = SHAABB::Combine(nodeC.AABB, nodeD.AABB); + nodeB.AABB = SHAABB::Combine(nodeA.AABB, nodeE.AABB); nodeA.height = 1 + SHMath::Max(nodeC.height, nodeD.height); nodeB.height = 1 + SHMath::Max(nodeA.height, nodeE.height); diff --git a/SHADE_Engine/src/Physics/Collision/Broadphase/SHDynamicAABBTree.h b/SHADE_Engine/src/Physics/Collision/Broadphase/SHDynamicAABBTree.h index 420f30e7..32b5095a 100644 --- a/SHADE_Engine/src/Physics/Collision/Broadphase/SHDynamicAABBTree.h +++ b/SHADE_Engine/src/Physics/Collision/Broadphase/SHDynamicAABBTree.h @@ -32,7 +32,7 @@ namespace SHADE /* Type Definitions */ /*---------------------------------------------------------------------------------*/ - using AABBs = std::vector; + using AABBs = std::vector; /*---------------------------------------------------------------------------------*/ /* Data Members */ @@ -67,11 +67,11 @@ namespace SHADE /* Member Functions */ /*---------------------------------------------------------------------------------*/ - void Insert (SHCollisionShapeID id, const SHBox& AABB); - void Update (SHCollisionShapeID id, const SHBox& AABB); + void Insert (SHCollisionShapeID id, const SHAABB& AABB); + void Update (SHCollisionShapeID id, const SHAABB& AABB); void Remove (SHCollisionShapeID id) noexcept; - [[nodiscard]] const std::vector& Query(SHCollisionShapeID id, const SHBox& AABB) const noexcept; + [[nodiscard]] const std::vector& Query(SHCollisionShapeID id, const SHAABB& AABB) const noexcept; [[nodiscard]] const std::vector& Query(const SHRay& ray, float distance) const noexcept; private: @@ -103,7 +103,7 @@ namespace SHADE /* Data Members */ /*-------------------------------------------------------------------------------*/ - SHBox AABB; + SHAABB AABB; SHCollisionShapeID id; // Used to lookup the collision shape & entity for culling against itself union diff --git a/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHCollisionShape.h b/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHCollisionShape.h index 0690b071..61f2b43c 100644 --- a/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHCollisionShape.h +++ b/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHCollisionShape.h @@ -17,7 +17,7 @@ #include "Physics/Collision/CollisionTags/SHCollisionTags.h" #include "Physics/Collision/SHPhysicsMaterial.h" #include "SHCollisionShapeID.h" -#include "Math/Geometry/SHBox.h" +#include "Math/Geometry/SHAABB.h" #include "Math/Transform/SHTransform.h" namespace SHADE @@ -131,7 +131,7 @@ namespace SHADE virtual void ComputeTransforms () noexcept = 0; [[nodiscard]] virtual SHMatrix GetInertiaTensor (float mass) const noexcept = 0; [[nodiscard]] virtual SHMatrix ComputeWorldTransform () const noexcept = 0; - [[nodiscard]] virtual SHBox ComputeAABB () const noexcept = 0; + [[nodiscard]] virtual SHAABB ComputeAABB () const noexcept = 0; protected: /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHSphereCollisionShape.cpp b/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHSphereCollisionShape.cpp index 30497f36..71d965c5 100644 --- a/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHSphereCollisionShape.cpp +++ b/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHSphereCollisionShape.cpp @@ -227,9 +227,9 @@ namespace SHADE ); } - SHBox SHSphereCollisionShape::ComputeAABB() const noexcept + SHAABB SHSphereCollisionShape::ComputeAABB() const noexcept { - return SHBox{ Center, SHVec3{ Radius } }; + return SHAABB{ Center, SHVec3{ Radius } }; } diff --git a/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHSphereCollisionShape.h b/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHSphereCollisionShape.h index eb41f93c..6e119cd1 100644 --- a/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHSphereCollisionShape.h +++ b/SHADE_Engine/src/Physics/Collision/CollisionShapes/SHSphereCollisionShape.h @@ -128,7 +128,7 @@ namespace SHADE [[nodiscard]] SHMatrix ComputeWorldTransform () const noexcept override; - [[nodiscard]] SHBox ComputeAABB () const noexcept override; + [[nodiscard]] SHAABB ComputeAABB () const noexcept override; private: /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Serialization/SHYAMLConverters.h b/SHADE_Engine/src/Serialization/SHYAMLConverters.h index b225a9a4..59ee532a 100644 --- a/SHADE_Engine/src/Serialization/SHYAMLConverters.h +++ b/SHADE_Engine/src/Serialization/SHYAMLConverters.h @@ -132,7 +132,7 @@ namespace YAML { case SHCollisionShape::Type::BOX: { - //const auto* BOX = reinterpret_cast(rhs.GetShape()); + //const auto* BOX = reinterpret_cast(rhs.GetShape()); //node[HalfExtents] = BOX->GetRelativeExtents(); } break; @@ -170,8 +170,7 @@ namespace YAML { case SHCollisionShape::Type::BOX: { - //if (node[HalfExtents].IsDefined()) - // rhs.SetBoundingBox(node[HalfExtents].as()); + } break; case SHCollisionShape::Type::SPHERE: diff --git a/SHADE_Managed/src/Components/Collider.cxx b/SHADE_Managed/src/Components/Collider.cxx index 1c84637a..3dd1446e 100644 --- a/SHADE_Managed/src/Components/Collider.cxx +++ b/SHADE_Managed/src/Components/Collider.cxx @@ -128,39 +128,39 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ Vector3 BoxCollider::Center::get() { - //return Convert::ToCLI(getNativeCollisionShape().GetCenter()); + //return Convert::ToCLI(getNativeCollisionShape().GetCenter()); return Vector3::Zero; } void BoxCollider::Center::set(Vector3 value) { - //getNativeCollisionShape().SetCenter(Convert::ToNative(value)); + //getNativeCollisionShape().SetCenter(Convert::ToNative(value)); } Vector3 BoxCollider::HalfExtents::get() { - //return Convert::ToCLI(getNativeCollisionShape().GetWorldExtents()); + //return Convert::ToCLI(getNativeCollisionShape().GetWorldExtents()); return Vector3::Zero; } void BoxCollider::HalfExtents::set(Vector3 value) { - //getNativeCollisionShape().SetWorldExtents(Convert::ToNative(value)); + //getNativeCollisionShape().SetWorldExtents(Convert::ToNative(value)); } Vector3 BoxCollider::Min::get() { - //return Convert::ToCLI(getNativeCollisionShape().GetMin()); + //return Convert::ToCLI(getNativeCollisionShape().GetMin()); return Vector3::Zero; } void BoxCollider::Min::set(Vector3 value) { - //getNativeCollisionShape().SetMin(Convert::ToNative(value)); + //getNativeCollisionShape().SetMin(Convert::ToNative(value)); } Vector3 BoxCollider::Max::get() { - //return Convert::ToCLI(getNativeCollisionShape().GetMax()); + //return Convert::ToCLI(getNativeCollisionShape().GetMax()); return Vector3::Zero; } void BoxCollider::Max::set(Vector3 value) { - //getNativeCollisionShape().SetMax(Convert::ToNative(value)); + //getNativeCollisionShape().SetMax(Convert::ToNative(value)); } /*---------------------------------------------------------------------------------*/ @@ -168,12 +168,12 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ bool BoxCollider::TestPoint(Vector3 point) { - //return getNativeCollisionShape().TestPoint(Convert::ToNative(point)); + //return getNativeCollisionShape().TestPoint(Convert::ToNative(point)); return false; } bool BoxCollider::Raycast(Ray ray, float maxDistance) { - //return getNativeCollisionShape().Raycast(Convert::ToNative(ray)); + //return getNativeCollisionShape().Raycast(Convert::ToNative(ray)); return false; }