Changed Collider to CollisionShape for improved clarity

This commit is contained in:
Diren D Bharwani 2022-11-07 18:19:39 +08:00
parent 4e02f64133
commit 70dcad1313
15 changed files with 129 additions and 129 deletions

View File

@ -114,8 +114,8 @@ namespace Sandbox
racoonTransform.SetWorldPosition({ -3.0f, -2.0f, -5.0f }); racoonTransform.SetWorldPosition({ -3.0f, -2.0f, -5.0f });
racoonCollider.AddBoundingBox(); racoonCollider.AddBoundingBox();
racoonCollider.GetCollider(0).SetPositionOffset(SHVec3(0.0f,0.5f,0.0f)); racoonCollider.GetCollisionShape(0).SetPositionOffset(SHVec3(0.0f,0.5f,0.0f));
racoonCollider.GetCollider(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f)); racoonCollider.GetCollisionShape(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f));
auto racoonItemLocation = SHEntityManager::CreateEntity<SHTransformComponent>(); auto racoonItemLocation = SHEntityManager::CreateEntity<SHTransformComponent>();
auto& racoonItemLocationTransform = *SHComponentManager::GetComponent_s<SHTransformComponent>(racoonItemLocation); auto& racoonItemLocationTransform = *SHComponentManager::GetComponent_s<SHTransformComponent>(racoonItemLocation);
@ -140,13 +140,13 @@ namespace Sandbox
itemCollider.AddBoundingBox(); itemCollider.AddBoundingBox();
itemCollider.AddBoundingBox(SHVec3(2.0f,2.0f,2.0f)); itemCollider.AddBoundingBox(SHVec3(2.0f,2.0f,2.0f));
itemCollider.GetCollider(1).SetIsTrigger(true); itemCollider.GetCollisionShape(1).SetIsTrigger(true);
itemCollider.GetCollider(0).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f)); itemCollider.GetCollisionShape(0).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f));
itemCollider.GetCollider(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f)); itemCollider.GetCollisionShape(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f));
itemCollider.GetCollider(1).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f)); itemCollider.GetCollisionShape(1).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f));
itemCollider.GetCollider(1).SetBoundingBox(SHVec3(1.0f, 1.0f, 1.0f)); itemCollider.GetCollisionShape(1).SetBoundingBox(SHVec3(1.0f, 1.0f, 1.0f));
itemRigidBody.SetInterpolate(false); itemRigidBody.SetInterpolate(false);
itemRigidBody.SetFreezeRotationX(true); itemRigidBody.SetFreezeRotationX(true);
@ -168,8 +168,8 @@ namespace Sandbox
AITransform.SetWorldPosition({ -8.0f, -2.0f, 2.5f }); AITransform.SetWorldPosition({ -8.0f, -2.0f, 2.5f });
AICollider.AddBoundingBox(); AICollider.AddBoundingBox();
AICollider.GetCollider(0).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f)); AICollider.GetCollisionShape(0).SetPositionOffset(SHVec3(0.0f, 0.5f, 0.0f));
AICollider.GetCollider(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f)); AICollider.GetCollisionShape(0).SetBoundingBox(SHVec3(0.5f, 0.5f, 0.5f));
AIRigidBody.SetInterpolate(false); AIRigidBody.SetInterpolate(false);
AIRigidBody.SetFreezeRotationX(true); AIRigidBody.SetFreezeRotationX(true);

View File

@ -234,21 +234,21 @@ namespace SHADE
{ {
DrawContextMenu(component); DrawContextMenu(component);
auto& colliders = component->GetColliders(); auto& colliders = component->GetCollisionShapes();
int const size = static_cast<int>(colliders.size()); int const size = static_cast<int>(colliders.size());
ImGui::BeginChild("Colliders", { 0.0f, colliders.empty() ? 1.0f : 250.0f }, true); ImGui::BeginChild("Collision Shapes", { 0.0f, colliders.empty() ? 1.0f : 250.0f }, true);
std::optional<int> colliderToDelete{ std::nullopt }; std::optional<int> colliderToDelete{ std::nullopt };
for (int i{}; i < size; ++i) for (int i{}; i < size; ++i)
{ {
ImGui::PushID(i); ImGui::PushID(i);
SHCollider* collider = &component->GetCollider(i); SHCollisionShape* collider = &component->GetCollisionShape(i);
auto cursorPos = ImGui::GetCursorPos(); auto cursorPos = ImGui::GetCursorPos();
//collider->IsTrigger //collider->IsTrigger
if (collider->GetType() == SHCollider::Type::BOX) if (collider->GetType() == SHCollisionShape::Type::BOX)
{ {
SHEditorWidgets::BeginPanel(std::format("{} Box Collider #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
SHEditorWidgets::CheckBox("Is Trigger", [collider]() {return collider->IsTrigger(); }, [collider](bool const& value) {collider->SetIsTrigger(value); }, "Is Trigger"); SHEditorWidgets::CheckBox("Is Trigger", [collider]() {return collider->IsTrigger(); }, [collider](bool const& value) {collider->SetIsTrigger(value); }, "Is Trigger");
auto box = reinterpret_cast<SHBoundingBox*>(collider->GetShape()); auto box = reinterpret_cast<SHBoundingBox*>(collider->GetShape());
SHEditorWidgets::DragVec3 SHEditorWidgets::DragVec3
@ -257,9 +257,9 @@ namespace SHADE
[box, transformComponent] { return (box->GetHalfExtents() * 2.0f) / transformComponent->GetWorldScale(); }, [box, transformComponent] { return (box->GetHalfExtents() * 2.0f) / transformComponent->GetWorldScale(); },
[collider](SHVec3 const& vec) { collider->SetBoundingBox(vec); }); [collider](SHVec3 const& vec) { collider->SetBoundingBox(vec); });
} }
else if (collider->GetType() == SHCollider::Type::SPHERE) else if (collider->GetType() == SHCollisionShape::Type::SPHERE)
{ {
SHEditorWidgets::BeginPanel(std::format("{} Sphere Collider #{}", ICON_MD_CIRCLE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y }); SHEditorWidgets::BeginPanel(std::format("{} Sphere #{}", ICON_MD_CIRCLE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
SHEditorWidgets::CheckBox("Is Trigger", [collider]() {return collider->IsTrigger(); }, [collider](bool const& value) {collider->SetIsTrigger(value); }, "Is Trigger"); SHEditorWidgets::CheckBox("Is Trigger", [collider]() {return collider->IsTrigger(); }, [collider](bool const& value) {collider->SetIsTrigger(value); }, "Is Trigger");
auto sphere = reinterpret_cast<SHBoundingSphere*>(collider->GetShape()); auto sphere = reinterpret_cast<SHBoundingSphere*>(collider->GetShape());
SHEditorWidgets::DragFloat SHEditorWidgets::DragFloat
@ -273,7 +273,7 @@ namespace SHADE
}, },
[collider](float const& value) { collider->SetBoundingSphere(value); }); [collider](float const& value) { collider->SetBoundingSphere(value); });
} }
else if (collider->GetType() == SHCollider::Type::CAPSULE) else if (collider->GetType() == SHCollisionShape::Type::CAPSULE)
{ {
} }

View File

@ -48,17 +48,17 @@ namespace SHADE
return orientation.ToEuler(); return orientation.ToEuler();
} }
const SHColliderComponent::Colliders& SHColliderComponent::GetColliders() const noexcept const SHColliderComponent::CollisionShapes& SHColliderComponent::GetCollisionShapes() const noexcept
{ {
return colliders; return collisionShapes;
} }
SHCollider& SHColliderComponent::GetCollider(int index) SHCollisionShape& SHColliderComponent::GetCollisionShape(int index)
{ {
if (index < 0 || static_cast<size_t>(index) >= colliders.size()) if (index < 0 || static_cast<size_t>(index) >= collisionShapes.size())
throw std::invalid_argument("Out-of-range access!"); throw std::invalid_argument("Out-of-range access!");
return colliders[index]; return collisionShapes[index];
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -83,9 +83,9 @@ namespace SHADE
return nullptr; return nullptr;
} }
static constexpr auto TYPE = SHCollider::Type::BOX; static constexpr auto TYPE = SHCollisionShape::Type::BOX;
auto& collider = colliders.emplace_back(SHCollider{ GetEID(), TYPE }); auto& collider = collisionShapes.emplace_back(SHCollisionShape{ GetEID(), TYPE });
collider.entityID = GetEID(); collider.entityID = GetEID();
collider.SetPositionOffset(posOffset); collider.SetPositionOffset(posOffset);
@ -105,9 +105,9 @@ namespace SHADE
return nullptr; return nullptr;
} }
static constexpr auto TYPE = SHCollider::Type::SPHERE; static constexpr auto TYPE = SHCollisionShape::Type::SPHERE;
auto& collider = colliders.emplace_back(SHCollider{ GetEID(), TYPE }); auto& collider = collisionShapes.emplace_back(SHCollisionShape{ GetEID(), TYPE });
collider.entityID = GetEID(); collider.entityID = GetEID();
collider.SetPositionOffset(posOffset); collider.SetPositionOffset(posOffset);
@ -121,12 +121,12 @@ namespace SHADE
void SHColliderComponent::RemoveCollider(int index) void SHColliderComponent::RemoveCollider(int index)
{ {
if (index < 0 || static_cast<size_t>(index) >= colliders.size()) if (index < 0 || static_cast<size_t>(index) >= collisionShapes.size())
throw std::invalid_argument("Out-of-range access!"); throw std::invalid_argument("Out-of-range access!");
int idx = 0; int idx = 0;
auto it = colliders.begin(); auto it = collisionShapes.begin();
for (; it != colliders.end(); ++it) for (; it != collisionShapes.end(); ++it)
{ {
if (idx == index) if (idx == index)
break; break;
@ -134,7 +134,7 @@ namespace SHADE
++idx; ++idx;
} }
it = colliders.erase(it); it = collisionShapes.erase(it);
// Notify Physics System // Notify Physics System
if (!system) if (!system)

View File

@ -14,7 +14,7 @@
// Project Headers // Project Headers
#include "ECS_Base/Components/SHComponent.h" #include "ECS_Base/Components/SHComponent.h"
#include "Physics/SHCollider.h" #include "Physics/SHCollisionShape.h"
#include "Math/Geometry/SHBoundingBox.h" #include "Math/Geometry/SHBoundingBox.h"
#include "Math/Geometry/SHBoundingSphere.h" #include "Math/Geometry/SHBoundingSphere.h"
@ -43,7 +43,7 @@ namespace SHADE
/* Type Definitions */ /* Type Definitions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
using Colliders = std::vector<SHCollider>; using CollisionShapes = std::vector<SHCollisionShape>;
public: public:
@ -67,14 +67,14 @@ namespace SHADE
/* Getter Functions */ /* Getter Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
[[nodiscard]] bool HasChanged () const noexcept; [[nodiscard]] bool HasChanged () const noexcept;
[[nodiscard]] const SHVec3& GetPosition () const noexcept; [[nodiscard]] const SHVec3& GetPosition () const noexcept;
[[nodiscard]] const SHQuaternion& GetOrientation () const noexcept; [[nodiscard]] const SHQuaternion& GetOrientation () const noexcept;
[[nodiscard]] SHVec3 GetRotation () const noexcept; [[nodiscard]] SHVec3 GetRotation () const noexcept;
[[nodiscard]] const Colliders& GetColliders () const noexcept; [[nodiscard]] const CollisionShapes& GetCollisionShapes() const noexcept;
[[nodiscard]] SHCollider& GetCollider (int index); [[nodiscard]] SHCollisionShape& GetCollisionShape (int index);
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Function Members */ /* Function Members */
@ -98,7 +98,7 @@ namespace SHADE
SHVec3 position; SHVec3 position;
SHQuaternion orientation; SHQuaternion orientation;
Colliders colliders; CollisionShapes collisionShapes;
RTTR_ENABLE() RTTR_ENABLE()
}; };

View File

@ -11,7 +11,7 @@
#include <SHpch.h> #include <SHpch.h>
// Primary Header // Primary Header
#include "SHCollider.h" #include "SHCollisionShape.h"
// Project Headers // Project Headers
#include "Math/Geometry/SHBoundingBox.h" #include "Math/Geometry/SHBoundingBox.h"
#include "Math/Geometry/SHBoundingSphere.h" #include "Math/Geometry/SHBoundingSphere.h"
@ -25,7 +25,7 @@ namespace SHADE
/* Constructors & Destructor Definitions */ /* Constructors & Destructor Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHCollider::SHCollider(EntityID eid, Type colliderType, const SHPhysicsMaterial& physicsMaterial) SHCollisionShape::SHCollisionShape(EntityID eid, Type colliderType, const SHPhysicsMaterial& physicsMaterial)
: type { colliderType } : type { colliderType }
, entityID { eid } , entityID { eid }
, isTrigger { false } , isTrigger { false }
@ -49,7 +49,7 @@ namespace SHADE
} }
} }
SHCollider::SHCollider(const SHCollider& rhs) noexcept SHCollisionShape::SHCollisionShape(const SHCollisionShape& rhs) noexcept
: type { rhs.type} : type { rhs.type}
, entityID { rhs.entityID } , entityID { rhs.entityID }
, isTrigger { rhs.isTrigger } , isTrigger { rhs.isTrigger }
@ -61,7 +61,7 @@ namespace SHADE
CopyShape(rhs.shape); CopyShape(rhs.shape);
} }
SHCollider::SHCollider(SHCollider&& rhs) noexcept SHCollisionShape::SHCollisionShape(SHCollisionShape&& rhs) noexcept
: type { rhs.type} : type { rhs.type}
, entityID { rhs.entityID } , entityID { rhs.entityID }
, isTrigger { rhs.isTrigger } , isTrigger { rhs.isTrigger }
@ -73,7 +73,7 @@ namespace SHADE
CopyShape(rhs.shape); CopyShape(rhs.shape);
} }
SHCollider::~SHCollider() noexcept SHCollisionShape::~SHCollisionShape() noexcept
{ {
shape = nullptr; shape = nullptr;
} }
@ -82,7 +82,7 @@ namespace SHADE
/* Operator Overload Definitions */ /* Operator Overload Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
SHCollider& SHCollider::operator=(const SHCollider& rhs) noexcept SHCollisionShape& SHCollisionShape::operator=(const SHCollisionShape& rhs) noexcept
{ {
if (this == &rhs) if (this == &rhs)
return *this; return *this;
@ -100,7 +100,7 @@ namespace SHADE
return *this; return *this;
} }
SHCollider& SHCollider::operator=(SHCollider&& rhs) noexcept SHCollisionShape& SHCollisionShape::operator=(SHCollisionShape&& rhs) noexcept
{ {
type = rhs.type; type = rhs.type;
entityID = rhs.entityID; entityID = rhs.entityID;
@ -119,52 +119,52 @@ namespace SHADE
/* Getter Function Definitions */ /* Getter Function Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
bool SHCollider::HasChanged() const noexcept bool SHCollisionShape::HasChanged() const noexcept
{ {
return dirty; return dirty;
} }
bool SHCollider::IsTrigger() const noexcept bool SHCollisionShape::IsTrigger() const noexcept
{ {
return isTrigger; return isTrigger;
} }
SHCollider::Type SHCollider::GetType() const noexcept SHCollisionShape::Type SHCollisionShape::GetType() const noexcept
{ {
return type; return type;
} }
float SHCollider::GetFriction() const noexcept float SHCollisionShape::GetFriction() const noexcept
{ {
return material.GetFriction(); return material.GetFriction();
} }
float SHCollider::GetBounciness() const noexcept float SHCollisionShape::GetBounciness() const noexcept
{ {
return material.GetBounciness(); return material.GetBounciness();
} }
float SHCollider::GetDensity() const noexcept float SHCollisionShape::GetDensity() const noexcept
{ {
return material.GetDensity(); return material.GetDensity();
} }
const SHPhysicsMaterial& SHCollider::GetMaterial() const noexcept const SHPhysicsMaterial& SHCollisionShape::GetMaterial() const noexcept
{ {
return material; return material;
} }
const SHVec3& SHCollider::GetPositionOffset() const noexcept const SHVec3& SHCollisionShape::GetPositionOffset() const noexcept
{ {
return positionOffset; return positionOffset;
} }
const SHVec3& SHCollider::GetRotationOffset() const noexcept const SHVec3& SHCollisionShape::GetRotationOffset() const noexcept
{ {
return rotationOffset; return rotationOffset;
} }
SHShape* SHCollider::GetShape() noexcept SHShape* SHCollisionShape::GetShape() noexcept
{ {
dirty = true; dirty = true;
return shape; return shape;
@ -174,7 +174,7 @@ namespace SHADE
/* Setter Function Definitions */ /* Setter Function Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SHCollider::SetBoundingBox(const SHVec3& halfExtents) void SHCollisionShape::SetBoundingBox(const SHVec3& halfExtents)
{ {
dirty = true; dirty = true;
@ -199,7 +199,7 @@ namespace SHADE
} }
} }
void SHCollider::SetBoundingSphere(float radius) void SHCollisionShape::SetBoundingSphere(float radius)
{ {
dirty = true; dirty = true;
@ -230,37 +230,37 @@ namespace SHADE
} }
void SHCollider::SetIsTrigger(bool trigger) noexcept void SHCollisionShape::SetIsTrigger(bool trigger) noexcept
{ {
dirty = true; dirty = true;
isTrigger = trigger; isTrigger = trigger;
} }
void SHCollider::SetFriction(float friction) noexcept void SHCollisionShape::SetFriction(float friction) noexcept
{ {
dirty = true; dirty = true;
material.SetFriction(friction); material.SetFriction(friction);
} }
void SHCollider::SetBounciness(float bounciness) noexcept void SHCollisionShape::SetBounciness(float bounciness) noexcept
{ {
dirty = true; dirty = true;
material.SetBounciness(bounciness); material.SetBounciness(bounciness);
} }
void SHCollider::SetDensity(float density) noexcept void SHCollisionShape::SetDensity(float density) noexcept
{ {
dirty = true; dirty = true;
material.SetDensity(density); material.SetDensity(density);
} }
void SHCollider::SetMaterial(const SHPhysicsMaterial& newMaterial) noexcept void SHCollisionShape::SetMaterial(const SHPhysicsMaterial& newMaterial) noexcept
{ {
dirty = true; dirty = true;
material = newMaterial; material = newMaterial;
} }
void SHCollider::SetPositionOffset(const SHVec3& posOffset) noexcept void SHCollisionShape::SetPositionOffset(const SHVec3& posOffset) noexcept
{ {
dirty = true; dirty = true;
positionOffset = posOffset; positionOffset = posOffset;
@ -281,7 +281,7 @@ namespace SHADE
} }
} }
void SHCollider::SetRotationOffset(const SHVec3& rotOffset) noexcept void SHCollisionShape::SetRotationOffset(const SHVec3& rotOffset) noexcept
{ {
dirty = true; dirty = true;
rotationOffset = rotOffset; rotationOffset = rotOffset;
@ -291,7 +291,7 @@ namespace SHADE
/* Private Function Member Definitions */ /* Private Function Member Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
void SHCollider::CopyShape(const SHShape* rhs) void SHCollisionShape::CopyShape(const SHShape* rhs)
{ {
switch (type) switch (type)
{ {
@ -320,14 +320,14 @@ RTTR_REGISTRATION
using namespace SHADE; using namespace SHADE;
using namespace rttr; using namespace rttr;
registration::enumeration<SHCollider::Type>("Collider Type") registration::enumeration<SHCollisionShape::Type>("Collider Type")
( (
value("Box", SHCollider::Type::BOX), value("Box", SHCollisionShape::Type::BOX),
value("Sphere", SHCollider::Type::SPHERE) value("Sphere", SHCollisionShape::Type::SPHERE)
// TODO(Diren): Add More Shapes // TODO(Diren): Add More Shapes
); );
registration::class_<SHCollider>("Collider") registration::class_<SHCollisionShape>("Collider")
.property("Position Offset", &SHCollider::GetPositionOffset, &SHCollider::SetPositionOffset) .property("Position Offset", &SHCollisionShape::GetPositionOffset, &SHCollisionShape::SetPositionOffset)
.property("Rotation Offset", &SHCollider::GetRotationOffset, &SHCollider::SetRotationOffset) (metadata(META::angleInRad, true)); .property("Rotation Offset", &SHCollisionShape::GetRotationOffset, &SHCollisionShape::SetRotationOffset) (metadata(META::angleInRad, true));
} }

View File

@ -24,7 +24,7 @@ namespace SHADE
/* Type Definitions */ /* Type Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
class SH_API SHCollider class SH_API SHCollisionShape
{ {
private: private:
@ -51,18 +51,18 @@ namespace SHADE
/* Constructors & Destructor */ /* Constructors & Destructor */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SHCollider (EntityID eid, Type colliderType = Type::BOX, const SHPhysicsMaterial& physicsMaterial = SHPhysicsMaterial::DEFAULT); SHCollisionShape (EntityID eid, Type colliderType = Type::BOX, const SHPhysicsMaterial& physicsMaterial = SHPhysicsMaterial::DEFAULT);
SHCollider (const SHCollider& rhs) noexcept; SHCollisionShape (const SHCollisionShape& rhs) noexcept;
SHCollider (SHCollider&& rhs) noexcept; SHCollisionShape (SHCollisionShape&& rhs) noexcept;
~SHCollider () noexcept; ~SHCollisionShape () noexcept;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Operator Overloads */ /* Operator Overloads */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SHCollider& operator=(const SHCollider& rhs) noexcept; SHCollisionShape& operator=(const SHCollisionShape& rhs) noexcept;
SHCollider& operator=(SHCollider&& rhs) noexcept; SHCollisionShape& operator=(SHCollisionShape&& rhs) noexcept;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Getter Functions */ /* Getter Functions */

View File

@ -128,13 +128,13 @@ namespace SHADE
/* Public Function Member Definitions */ /* Public Function Member Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
int SHPhysicsObject::AddCollider(SHCollider* collider) int SHPhysicsObject::AddCollider(SHCollisionShape* collider)
{ {
const rp3d::Transform OFFSETS{ collider->GetPositionOffset(), collider->GetRotationOffset() }; const rp3d::Transform OFFSETS{ collider->GetPositionOffset(), collider->GetRotationOffset() };
switch (collider->GetType()) switch (collider->GetType())
{ {
case SHCollider::Type::BOX: case SHCollisionShape::Type::BOX:
{ {
const auto* box = reinterpret_cast<SHBoundingBox*>(collider->GetShape()); const auto* box = reinterpret_cast<SHBoundingBox*>(collider->GetShape());
rp3d::BoxShape* newBox = factory->createBoxShape(box->GetHalfExtents()); rp3d::BoxShape* newBox = factory->createBoxShape(box->GetHalfExtents());
@ -142,7 +142,7 @@ namespace SHADE
rp3dBody->addCollider(newBox, OFFSETS); rp3dBody->addCollider(newBox, OFFSETS);
break; break;
} }
case SHCollider::Type::SPHERE: case SHCollisionShape::Type::SPHERE:
{ {
const auto* sphere = reinterpret_cast<SHBoundingSphere*>(collider->GetShape()); const auto* sphere = reinterpret_cast<SHBoundingSphere*>(collider->GetShape());
rp3d::SphereShape* newSphere = factory->createSphereShape(sphere->GetRadius()); rp3d::SphereShape* newSphere = factory->createSphereShape(sphere->GetRadius());
@ -173,7 +173,7 @@ namespace SHADE
void SHPhysicsObject::SyncColliders(SHColliderComponent* c) const noexcept void SHPhysicsObject::SyncColliders(SHColliderComponent* c) const noexcept
{ {
int index = 0; int index = 0;
for (auto& collider : c->colliders) for (auto& collider : c->collisionShapes)
{ {
if (!collider.dirty) if (!collider.dirty)
continue; continue;
@ -188,7 +188,7 @@ namespace SHADE
switch (collider.GetType()) switch (collider.GetType())
{ {
case SHCollider::Type::BOX: case SHCollisionShape::Type::BOX:
{ {
const auto* box = reinterpret_cast<SHBoundingBox*>(collider.GetShape()); const auto* box = reinterpret_cast<SHBoundingBox*>(collider.GetShape());
@ -197,7 +197,7 @@ namespace SHADE
break; break;
} }
case SHCollider::Type::SPHERE: case SHCollisionShape::Type::SPHERE:
{ {
const auto* sphere = reinterpret_cast<SHBoundingSphere*>(collider.GetShape()); const auto* sphere = reinterpret_cast<SHBoundingSphere*>(collider.GetShape());

View File

@ -69,7 +69,7 @@ namespace SHADE
/* Function Members */ /* Function Members */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
int AddCollider (SHCollider* collider); int AddCollider (SHCollisionShape* collider);
void RemoveCollider (int index); void RemoveCollider (int index);
void SyncColliders (SHColliderComponent* c) const noexcept; void SyncColliders (SHColliderComponent* c) const noexcept;

View File

@ -348,7 +348,7 @@ namespace SHADE
factory.destroyPhysicsWorld(world); factory.destroyPhysicsWorld(world);
} }
void SHPhysicsSystem::AddCollisionShape(EntityID entityID, SHCollider* collider) void SHPhysicsSystem::AddCollisionShape(EntityID entityID, SHCollisionShape* collider)
{ {
auto* physicsObject = GetPhysicsObject(entityID); auto* physicsObject = GetPhysicsObject(entityID);
@ -735,7 +735,7 @@ namespace SHADE
// Add collision shapes back into the body // Add collision shapes back into the body
if (colliderComponent != nullptr) if (colliderComponent != nullptr)
{ {
for (auto& collider : colliderComponent->colliders) for (auto& collider : colliderComponent->collisionShapes)
physicsObject->AddCollider(&collider); physicsObject->AddCollider(&collider);
} }
} }
@ -756,7 +756,7 @@ namespace SHADE
} }
// Add Collision Shapes // Add Collision Shapes
for (auto& collider : colliderComponent->colliders) for (auto& collider : colliderComponent->collisionShapes)
physicsObject->AddCollider(&collider); physicsObject->AddCollider(&collider);
} }
} }
@ -801,7 +801,7 @@ namespace SHADE
rp3d::Transform{ colliderComponent->position, colliderComponent->orientation } rp3d::Transform{ colliderComponent->position, colliderComponent->orientation }
); );
for (auto& collider : colliderComponent->colliders) for (auto& collider : colliderComponent->collisionShapes)
physicsObject->AddCollider(&collider); physicsObject->AddCollider(&collider);
} }
} }

View File

@ -114,7 +114,7 @@ namespace SHADE
void Init () override; void Init () override;
void Exit () override; void Exit () override;
void AddCollisionShape (EntityID entityID, SHCollider* collider); void AddCollisionShape (EntityID entityID, SHCollisionShape* collider);
void RemoveCollisionShape (EntityID entityID, int index); void RemoveCollisionShape (EntityID entityID, int index);
void onContact (const rp3d::CollisionCallback::CallbackData& callbackData) override; void onContact (const rp3d::CollisionCallback::CallbackData& callbackData) override;

View File

@ -75,14 +75,14 @@ namespace SHADE
return SHComponentManager::GetComponent_s<SHRigidBodyComponent>(ids[ENTITY_B]); return SHComponentManager::GetComponent_s<SHRigidBodyComponent>(ids[ENTITY_B]);
} }
const SHCollider* SHCollisionEvent::GetColliderA() const noexcept const SHCollisionShape* SHCollisionEvent::GetColliderA() const noexcept
{ {
return &SHComponentManager::GetComponent<SHColliderComponent>(ids[ENTITY_A])->GetCollider(ids[COLLIDER_A]); return &SHComponentManager::GetComponent<SHColliderComponent>(ids[ENTITY_A])->GetCollisionShape(ids[COLLIDER_A]);
} }
const SHCollider* SHCollisionEvent::GetColliderB() const noexcept const SHCollisionShape* SHCollisionEvent::GetColliderB() const noexcept
{ {
return &SHComponentManager::GetComponent<SHColliderComponent>(ids[ENTITY_B])->GetCollider(ids[COLLIDER_B]); return &SHComponentManager::GetComponent<SHColliderComponent>(ids[ENTITY_B])->GetCollisionShape(ids[COLLIDER_B]);
} }
SHCollisionEvent::State SHCollisionEvent::GetCollisionState() const noexcept SHCollisionEvent::State SHCollisionEvent::GetCollisionState() const noexcept

View File

@ -24,7 +24,7 @@ namespace SHADE
struct SHPhysicsColliderAddedEvent struct SHPhysicsColliderAddedEvent
{ {
EntityID entityID; EntityID entityID;
SHCollider::Type colliderType; SHCollisionShape::Type colliderType;
int colliderIndex; int colliderIndex;
}; };
@ -88,8 +88,8 @@ namespace SHADE
[[nodiscard]] EntityID GetEntityB () const noexcept; [[nodiscard]] EntityID GetEntityB () const noexcept;
[[nodiscard]] const SHRigidBodyComponent* GetRigidBodyA () const noexcept; [[nodiscard]] const SHRigidBodyComponent* GetRigidBodyA () const noexcept;
[[nodiscard]] const SHRigidBodyComponent* GetRigidBodyB () const noexcept; [[nodiscard]] const SHRigidBodyComponent* GetRigidBodyB () const noexcept;
[[nodiscard]] const SHCollider* GetColliderA () const noexcept; [[nodiscard]] const SHCollisionShape* GetColliderA () const noexcept;
[[nodiscard]] const SHCollider* GetColliderB () const noexcept; [[nodiscard]] const SHCollisionShape* GetColliderB () const noexcept;
[[nodiscard]] State GetCollisionState () const noexcept; [[nodiscard]] State GetCollisionState () const noexcept;
private: private:

View File

@ -3,7 +3,7 @@
#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h" #include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h"
#include "Math/Geometry/SHBoundingBox.h" #include "Math/Geometry/SHBoundingBox.h"
#include "Math/Geometry/SHBoundingSphere.h" #include "Math/Geometry/SHBoundingSphere.h"
#include "Physics/SHCollider.h" #include "Physics/SHCollisionShape.h"
#include "Resource/SHResourceManager.h" #include "Resource/SHResourceManager.h"
#include "Math/Vector/SHVec2.h" #include "Math/Vector/SHVec2.h"
#include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec3.h"
@ -101,7 +101,7 @@ namespace YAML
}; };
template<> template<>
struct convert<SHCollider> struct convert<SHCollisionShape>
{ {
static constexpr const char* IsTrigger = "Is Trigger"; static constexpr const char* IsTrigger = "Is Trigger";
@ -114,33 +114,33 @@ namespace YAML
static constexpr const char* Density = "Density"; static constexpr const char* Density = "Density";
static constexpr const char* PositionOffset = "Position Offset"; static constexpr const char* PositionOffset = "Position Offset";
static Node encode(SHCollider& rhs) static Node encode(SHCollisionShape& rhs)
{ {
Node node; Node node;
node[IsTrigger] = rhs.IsTrigger(); node[IsTrigger] = rhs.IsTrigger();
rttr::type const shapeRttrType = rttr::type::get<SHCollider::Type>(); rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration(); rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
SHCollider::Type colliderType = rhs.GetType(); SHCollisionShape::Type colliderType = rhs.GetType();
node[Type] = enumAlign.value_to_name(colliderType).data(); node[Type] = enumAlign.value_to_name(colliderType).data();
switch (colliderType) switch (colliderType)
{ {
case SHCollider::Type::BOX: case SHCollisionShape::Type::BOX:
{ {
auto const bb = reinterpret_cast<SHBoundingBox*>(rhs.GetShape()); auto const bb = reinterpret_cast<SHBoundingBox*>(rhs.GetShape());
node[HalfExtents] = bb->GetHalfExtents(); node[HalfExtents] = bb->GetHalfExtents();
} }
break; break;
case SHCollider::Type::SPHERE: case SHCollisionShape::Type::SPHERE:
{ {
auto const bs = reinterpret_cast<SHBoundingSphere*>(rhs.GetShape()); auto const bs = reinterpret_cast<SHBoundingSphere*>(rhs.GetShape());
node[Radius] = bs->GetRadius(); node[Radius] = bs->GetRadius();
} }
break; break;
case SHCollider::Type::CAPSULE: break; case SHCollisionShape::Type::CAPSULE: break;
default:; default:;
} }
@ -151,33 +151,33 @@ namespace YAML
return node; return node;
} }
static bool decode(Node const& node, SHCollider& rhs) static bool decode(Node const& node, SHCollisionShape& rhs)
{ {
if (node[IsTrigger].IsDefined()) if (node[IsTrigger].IsDefined())
rhs.SetIsTrigger(node[IsTrigger].as<bool>()); rhs.SetIsTrigger(node[IsTrigger].as<bool>());
if (!node[Type].IsDefined()) if (!node[Type].IsDefined())
return false; return false;
rttr::type const shapeRttrType = rttr::type::get<SHCollider::Type>(); rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration(); rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
bool ok; bool ok;
const SHCollider::Type colliderType = enumAlign.name_to_value(node[Type].as<std::string>()).convert<SHCollider::Type>(&ok); const SHCollisionShape::Type colliderType = enumAlign.name_to_value(node[Type].as<std::string>()).convert<SHCollisionShape::Type>(&ok);
if (!ok) if (!ok)
return false; return false;
switch (colliderType) switch (colliderType)
{ {
case SHCollider::Type::BOX: case SHCollisionShape::Type::BOX:
{ {
if (node[HalfExtents].IsDefined()) if (node[HalfExtents].IsDefined())
rhs.SetBoundingBox(node[HalfExtents].as<SHVec3>() * 2.0f); rhs.SetBoundingBox(node[HalfExtents].as<SHVec3>() * 2.0f);
} }
break; break;
case SHCollider::Type::SPHERE: case SHCollisionShape::Type::SPHERE:
{ {
if (node[Radius].IsDefined()) if (node[Radius].IsDefined())
rhs.SetBoundingSphere(node[Radius].as<float>()); rhs.SetBoundingSphere(node[Radius].as<float>());
} }
break; break;
case SHCollider::Type::CAPSULE: break; case SHCollisionShape::Type::CAPSULE: break;
default:; default:;
} }
if (node[Friction].IsDefined()) if (node[Friction].IsDefined())
@ -200,12 +200,12 @@ namespace YAML
static Node encode(SHColliderComponent& rhs) static Node encode(SHColliderComponent& rhs)
{ {
Node node, collidersNode; Node node, collidersNode;
auto const& colliders = rhs.GetColliders(); auto const& colliders = rhs.GetCollisionShapes();
int const numColliders = static_cast<int>(colliders.size()); int const numColliders = static_cast<int>(colliders.size());
for (int i = 0; i < numColliders; ++i) for (int i = 0; i < numColliders; ++i)
{ {
auto& collider = rhs.GetCollider(i); auto& collider = rhs.GetCollisionShape(i);
Node colliderNode = convert<SHCollider>::encode(collider); Node colliderNode = convert<SHCollisionShape>::encode(collider);
if (colliderNode.IsDefined()) if (colliderNode.IsDefined())
collidersNode[i] = colliderNode; collidersNode[i] = colliderNode;
} }
@ -219,21 +219,21 @@ namespace YAML
int numColliders{}; int numColliders{};
for (auto const& colliderNode : node[Colliders]) for (auto const& colliderNode : node[Colliders])
{ {
rttr::type const shapeRttrType = rttr::type::get<SHCollider::Type>(); rttr::type const shapeRttrType = rttr::type::get<SHCollisionShape::Type>();
rttr::enumeration const enumAlign = shapeRttrType.get_enumeration(); rttr::enumeration const enumAlign = shapeRttrType.get_enumeration();
bool ok = false; bool ok = false;
const SHCollider::Type colliderType = enumAlign.name_to_value(colliderNode[convert<SHCollider>::Type].as<std::string>()).convert<SHCollider::Type>(&ok); const SHCollisionShape::Type colliderType = enumAlign.name_to_value(colliderNode[convert<SHCollisionShape>::Type].as<std::string>()).convert<SHCollisionShape::Type>(&ok);
if (!ok) if (!ok)
return false; return false;
switch (colliderType) switch (colliderType)
{ {
case SHCollider::Type::BOX: rhs.AddBoundingBox(); break; case SHCollisionShape::Type::BOX: rhs.AddBoundingBox(); break;
case SHCollider::Type::SPHERE: rhs.AddBoundingSphere(); break; case SHCollisionShape::Type::SPHERE: rhs.AddBoundingSphere(); break;
case SHCollider::Type::CAPSULE: break; case SHCollisionShape::Type::CAPSULE: break;
default:; default:;
} }
YAML::convert<SHCollider>::decode(colliderNode, rhs.GetCollider(numColliders++)); YAML::convert<SHCollisionShape>::decode(colliderNode, rhs.GetCollisionShape(numColliders++));
} }
} }
return true; return true;

View File

@ -150,7 +150,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
int Collider::CollisionShapeCount::get() int Collider::CollisionShapeCount::get()
{ {
return static_cast<int>(GetNativeComponent()->GetColliders().size()); return static_cast<int>(GetNativeComponent()->GetCollisionShapes().size());
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -230,18 +230,18 @@ namespace SHADE
// Populate the list // Populate the list
int i = 0; int i = 0;
for (const auto& collider : GetNativeComponent()->GetColliders()) for (const auto& collider : GetNativeComponent()->GetCollisionShapes())
{ {
CollisionShape^ bound = nullptr; CollisionShape^ bound = nullptr;
switch (collider.GetType()) switch (collider.GetType())
{ {
case SHCollider::Type::BOX: case SHCollisionShape::Type::BOX:
bound = gcnew BoxCollider(i, Owner.GetEntity()); bound = gcnew BoxCollider(i, Owner.GetEntity());
break; break;
case SHCollider::Type::SPHERE: case SHCollisionShape::Type::SPHERE:
bound = gcnew SphereCollider(i, Owner.GetEntity()); bound = gcnew SphereCollider(i, Owner.GetEntity());
break; break;
case SHCollider::Type::CAPSULE: case SHCollisionShape::Type::CAPSULE:
// TODO // TODO
break; break;
default: default:

View File

@ -27,11 +27,11 @@ namespace SHADE
try try
{ {
auto& bounds = collider->GetCollider(arrayIndex); auto& shape = collider->GetCollisionShape(arrayIndex);
if (bounds.GetType() != SHCollider::Type::BOX) if (shape.GetType() != SHCollisionShape::Type::BOX)
throw gcnew System::InvalidOperationException("Attempted to retrieve invalid ColliderBound."); throw gcnew System::InvalidOperationException("Attempted to retrieve invalid ColliderBound.");
return reinterpret_cast<CollisionShapeType&>(bounds); return reinterpret_cast<CollisionShapeType&>(shape);
} }
catch (std::invalid_argument&) catch (std::invalid_argument&)
{ {