Implemented a custom physics engine #316

Merged
direnbharwani merged 95 commits from SHPhysics into main 2023-01-23 15:55:45 +08:00
13 changed files with 171 additions and 122 deletions
Showing only changes of commit 22c0a14081 - Show all commits

View File

@ -10,7 +10,7 @@
namespace SHADE
{
class SHBox;
class SHAABB;
class SHRay;
class SH_API SHCameraArmComponent final: public SHComponent

View File

@ -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"

View File

@ -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<const SHBox*>(collider->GetShape());
//const auto* BOX = reinterpret_cast<const SHAABB*>(collider->GetShape());
//SHEditorWidgets::DragVec3
//(
// "Half Extents", { "X", "Y", "Z" },

View File

@ -11,7 +11,7 @@
#include <SHpch.h>
// 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<SHVec3> SHBox::GetVertices() const noexcept
std::vector<SHVec3> SHAABB::GetVertices() const noexcept
{
std::vector<SHVec3> 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;
}

View File

@ -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<SHVec3> 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. <br/>
* 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;
};

View File

@ -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. <br/>
* 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

View File

@ -105,7 +105,7 @@ namespace SHADE
/* Getter Functions Definitions */
/*-----------------------------------------------------------------------------------*/
const std::vector<SHBox>& SHAABBTree::GetAABBs() const noexcept
const std::vector<SHAABB>& SHAABBTree::GetAABBs() const noexcept
{
static AABBs aabbs;
static std::stack<int32_t> 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<SHCollisionShapeID>& SHAABBTree::Query(SHCollisionShapeID id, const SHBox& AABB) const noexcept
const std::vector<SHCollisionShapeID>& SHAABBTree::Query(SHCollisionShapeID id, const SHAABB& AABB) const noexcept
{
static std::vector<SHCollisionShapeID> potentialCollisions;
static std::stack<int32_t> 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<uint32_t>::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);

View File

@ -32,7 +32,7 @@ namespace SHADE
/* Type Definitions */
/*---------------------------------------------------------------------------------*/
using AABBs = std::vector<SHBox>;
using AABBs = std::vector<SHAABB>;
/*---------------------------------------------------------------------------------*/
/* 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<SHCollisionShapeID>& Query(SHCollisionShapeID id, const SHBox& AABB) const noexcept;
[[nodiscard]] const std::vector<SHCollisionShapeID>& Query(SHCollisionShapeID id, const SHAABB& AABB) const noexcept;
[[nodiscard]] const std::vector<SHCollisionShapeID>& 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

View File

@ -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:
/*---------------------------------------------------------------------------------*/

View File

@ -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 } };
}

View File

@ -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:
/*---------------------------------------------------------------------------------*/

View File

@ -132,7 +132,7 @@ namespace YAML
{
case SHCollisionShape::Type::BOX:
{
//const auto* BOX = reinterpret_cast<const SHBox*>(rhs.GetShape());
//const auto* BOX = reinterpret_cast<const SHAABB*>(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<SHVec3>());
}
break;
case SHCollisionShape::Type::SPHERE:

View File

@ -128,39 +128,39 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
Vector3 BoxCollider::Center::get()
{
//return Convert::ToCLI(getNativeCollisionShape<SHBox>().GetCenter());
//return Convert::ToCLI(getNativeCollisionShape<SHAABB>().GetCenter());
return Vector3::Zero;
}
void BoxCollider::Center::set(Vector3 value)
{
//getNativeCollisionShape<SHBox>().SetCenter(Convert::ToNative(value));
//getNativeCollisionShape<SHAABB>().SetCenter(Convert::ToNative(value));
}
Vector3 BoxCollider::HalfExtents::get()
{
//return Convert::ToCLI(getNativeCollisionShape<SHBox>().GetWorldExtents());
//return Convert::ToCLI(getNativeCollisionShape<SHAABB>().GetWorldExtents());
return Vector3::Zero;
}
void BoxCollider::HalfExtents::set(Vector3 value)
{
//getNativeCollisionShape<SHBox>().SetWorldExtents(Convert::ToNative(value));
//getNativeCollisionShape<SHAABB>().SetWorldExtents(Convert::ToNative(value));
}
Vector3 BoxCollider::Min::get()
{
//return Convert::ToCLI(getNativeCollisionShape<SHBox>().GetMin());
//return Convert::ToCLI(getNativeCollisionShape<SHAABB>().GetMin());
return Vector3::Zero;
}
void BoxCollider::Min::set(Vector3 value)
{
//getNativeCollisionShape<SHBox>().SetMin(Convert::ToNative(value));
//getNativeCollisionShape<SHAABB>().SetMin(Convert::ToNative(value));
}
Vector3 BoxCollider::Max::get()
{
//return Convert::ToCLI(getNativeCollisionShape<SHBox>().GetMax());
//return Convert::ToCLI(getNativeCollisionShape<SHAABB>().GetMax());
return Vector3::Zero;
}
void BoxCollider::Max::set(Vector3 value)
{
//getNativeCollisionShape<SHBox>().SetMax(Convert::ToNative(value));
//getNativeCollisionShape<SHAABB>().SetMax(Convert::ToNative(value));
}
/*---------------------------------------------------------------------------------*/
@ -168,12 +168,12 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
bool BoxCollider::TestPoint(Vector3 point)
{
//return getNativeCollisionShape<SHBox>().TestPoint(Convert::ToNative(point));
//return getNativeCollisionShape<SHAABB>().TestPoint(Convert::ToNative(point));
return false;
}
bool BoxCollider::Raycast(Ray ray, float maxDistance)
{
//return getNativeCollisionShape<SHBox>().Raycast(Convert::ToNative(ray));
//return getNativeCollisionShape<SHAABB>().Raycast(Convert::ToNative(ray));
return false;
}