Renames & Bugfixes

Renamed BoundingBox & BoundingSphere to Box & Sphere
Forces are forcefully cleared
This commit is contained in:
Diren D Bharwani 2022-11-14 15:35:02 +08:00
parent 3c61b7519b
commit 9515fcca4f
16 changed files with 175 additions and 145 deletions

View File

@ -223,7 +223,7 @@ namespace SHADE
{
if (!component)
return;
ImGui::PushID(component);
const auto componentType = rttr::type::get(*component);
SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active");
ImGui::SameLine();
@ -246,7 +246,7 @@ namespace SHADE
if (collider->GetType() == SHCollisionShape::Type::BOX)
{
SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
const auto* BOX = reinterpret_cast<const SHBoundingBox*>(collider->GetShape());
const auto* BOX = reinterpret_cast<const SHBox*>(collider->GetShape());
SHEditorWidgets::DragVec3
(
"Half Extents", { "X", "Y", "Z" },
@ -256,7 +256,7 @@ namespace SHADE
else if (collider->GetType() == SHCollisionShape::Type::SPHERE)
{
SHEditorWidgets::BeginPanel(std::format("{} Sphere #{}", ICON_MD_CIRCLE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
const auto* SPHERE = reinterpret_cast<const SHBoundingSphere*>(collider->GetShape());
const auto* SPHERE = reinterpret_cast<const SHSphere*>(collider->GetShape());
SHEditorWidgets::DragFloat
(
"Radius",
@ -322,6 +322,7 @@ namespace SHADE
}
}
else DrawContextMenu(component);
ImGui::PopID();
}
template<>

View File

@ -11,7 +11,7 @@
#include <SHpch.h>
// Primary Header
#include "SHBoundingBox.h"
#include "SHBox.h"
// Project Headers
#include "Math/SHMathHelpers.h"
#include "Math/SHRay.h"
@ -24,13 +24,13 @@ namespace SHADE
/* Constructors & Destructor Definitions */
/*-----------------------------------------------------------------------------------*/
SHBoundingBox::SHBoundingBox() noexcept
SHBox::SHBox() noexcept
: RelativeExtents { SHVec3::One }
{
type = Type::BOX;
}
SHBoundingBox::SHBoundingBox(const SHVec3& c, const SHVec3& hE) noexcept
SHBox::SHBox(const SHVec3& c, const SHVec3& hE) noexcept
: RelativeExtents { SHVec3::One }
{
type = Type::BOX;
@ -40,7 +40,7 @@ namespace SHADE
}
SHBoundingBox::SHBoundingBox(const SHBoundingBox& rhs) noexcept
SHBox::SHBox(const SHBox& rhs) noexcept
{
if (this == &rhs)
return;
@ -52,7 +52,7 @@ namespace SHADE
RelativeExtents = rhs.RelativeExtents;
}
SHBoundingBox::SHBoundingBox(SHBoundingBox&& rhs) noexcept
SHBox::SHBox(SHBox&& rhs) noexcept
{
type = Type::BOX;
@ -65,7 +65,7 @@ namespace SHADE
/* Operator Overload Definitions */
/*-----------------------------------------------------------------------------------*/
SHBoundingBox& SHBoundingBox::operator=(const SHBoundingBox& rhs) noexcept
SHBox& SHBox::operator=(const SHBox& rhs) noexcept
{
if (rhs.type != Type::BOX)
{
@ -81,7 +81,7 @@ namespace SHADE
return *this;
}
SHBoundingBox& SHBoundingBox::operator=(SHBoundingBox&& rhs) noexcept
SHBox& SHBox::operator=(SHBox&& rhs) noexcept
{
if (rhs.type != Type::BOX)
{
@ -101,27 +101,27 @@ namespace SHADE
/* Getter Function Definitions */
/*-----------------------------------------------------------------------------------*/
SHVec3 SHBoundingBox::GetCenter() const noexcept
SHVec3 SHBox::GetCenter() const noexcept
{
return Center;
}
SHVec3 SHBoundingBox::GetWorldExtents() const noexcept
SHVec3 SHBox::GetWorldExtents() const noexcept
{
return Extents;
}
const SHVec3& SHBoundingBox::GetRelativeExtents() const noexcept
const SHVec3& SHBox::GetRelativeExtents() const noexcept
{
return RelativeExtents;
}
SHVec3 SHBoundingBox::GetMin() const noexcept
SHVec3 SHBox::GetMin() const noexcept
{
return SHVec3{ Center.x - Extents.x, Center.y - Extents.y, Center.z - Extents.z };
}
SHVec3 SHBoundingBox::GetMax() const noexcept
SHVec3 SHBox::GetMax() const noexcept
{
return SHVec3{ Center.x + Extents.x, Center.y + Extents.y, Center.z + Extents.z };
}
@ -130,22 +130,22 @@ namespace SHADE
/* Setter Function Definitions */
/*-----------------------------------------------------------------------------------*/
void SHBoundingBox::SetCenter(const SHVec3& newCenter) noexcept
void SHBox::SetCenter(const SHVec3& newCenter) noexcept
{
Center = newCenter;
}
void SHBoundingBox::SetWorldExtents(const SHVec3& newWorldExtents) noexcept
void SHBox::SetWorldExtents(const SHVec3& newWorldExtents) noexcept
{
Extents = newWorldExtents;
}
void SHBoundingBox::SetRelativeExtents(const SHVec3& newRelativeExtents) noexcept
void SHBox::SetRelativeExtents(const SHVec3& newRelativeExtents) noexcept
{
RelativeExtents = newRelativeExtents;
}
void SHBoundingBox::SetMin(const SHVec3& min) noexcept
void SHBox::SetMin(const SHVec3& min) noexcept
{
const SHVec3 MAX = GetMax();
@ -153,7 +153,7 @@ namespace SHADE
Extents = SHVec3::Abs((MAX - min) * 0.5f);
}
void SHBoundingBox::SetMax(const SHVec3& max) noexcept
void SHBox::SetMax(const SHVec3& max) noexcept
{
const SHVec3 MIN = GetMin();
@ -161,13 +161,13 @@ namespace SHADE
Extents = SHVec3::Abs((max - MIN) * 0.5f);
}
void SHBoundingBox::SetMinMax(const SHVec3& min, const SHVec3& max) noexcept
void SHBox::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> SHBoundingBox::GetVertices() const noexcept
std::vector<SHVec3> SHBox::GetVertices() const noexcept
{
std::vector<SHVec3> vertices{ 8 };
GetCorners(vertices.data());
@ -178,27 +178,27 @@ namespace SHADE
/* Public Function Member Definitions */
/*-----------------------------------------------------------------------------------*/
bool SHBoundingBox::TestPoint(const SHVec3& point) noexcept
bool SHBox::TestPoint(const SHVec3& point) noexcept
{
return BoundingBox::Contains(point);
}
bool SHBoundingBox::Raycast(const SHRay& ray, float& distance) noexcept
bool SHBox::Raycast(const SHRay& ray, float& distance) noexcept
{
return BoundingBox::Intersects(ray.position, ray.direction, distance);
}
bool SHBoundingBox::Contains(const SHBoundingBox& rhs) const noexcept
bool SHBox::Contains(const SHBox& rhs) const noexcept
{
return BoundingBox::Contains(rhs);
}
float SHBoundingBox::Volume() const noexcept
float SHBox::Volume() const noexcept
{
return 8.0f * (Extents.x * Extents.y * Extents.z);
}
float SHBoundingBox::SurfaceArea() const noexcept
float SHBox::SurfaceArea() const noexcept
{
return 8.0f * ((Extents.x * Extents.y)
+ (Extents.x * Extents.z)
@ -209,21 +209,21 @@ namespace SHADE
/* Static Function Member Definitions */
/*-----------------------------------------------------------------------------------*/
SHBoundingBox SHBoundingBox::Combine(const SHBoundingBox& lhs, const SHBoundingBox& rhs) noexcept
SHBox SHBox::Combine(const SHBox& lhs, const SHBox& rhs) noexcept
{
SHBoundingBox result;
SHBox result;
CreateMerged(result, lhs, rhs);
return result;
}
bool SHBoundingBox::Intersect(const SHBoundingBox& lhs, const SHBoundingBox& rhs) noexcept
bool SHBox::Intersect(const SHBox& lhs, const SHBox& rhs) noexcept
{
return lhs.Intersects(rhs);
}
SHBoundingBox SHBoundingBox::BuildFromBoxes(const SHBoundingBox* boxes, size_t numBoxes) noexcept
SHBox SHBox::BuildFromBoxes(const SHBox* boxes, size_t numBoxes) noexcept
{
SHBoundingBox result;
SHBox result;
for (size_t i = 1; i < numBoxes; ++i)
CreateMerged(result, boxes[i - 1], boxes[i]);
@ -231,9 +231,9 @@ namespace SHADE
return result;
}
SHBoundingBox SHBoundingBox::BuildFromVertices(const SHVec3* vertices, size_t numVertices, size_t stride) noexcept
SHBox SHBox::BuildFromVertices(const SHVec3* vertices, size_t numVertices, size_t stride) noexcept
{
SHBoundingBox result;
SHBox result;
CreateFromPoints(result, numVertices, vertices, stride);
return result;
}

View File

@ -22,7 +22,7 @@ namespace SHADE
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
class SH_API SHBoundingBox : public SHShape,
class SH_API SHBox : public SHShape,
private DirectX::BoundingBox
{
public:
@ -36,19 +36,19 @@ namespace SHADE
/* Constructors & Destructor */
/*---------------------------------------------------------------------------------*/
~SHBoundingBox () override = default;
~SHBox () override = default;
SHBoundingBox () noexcept;
SHBoundingBox (const SHVec3& center, const SHVec3& halfExtents) noexcept;
SHBoundingBox (const SHBoundingBox& rhs) noexcept;
SHBoundingBox (SHBoundingBox&& rhs) noexcept;
SHBox () noexcept;
SHBox (const SHVec3& center, const SHVec3& halfExtents) noexcept;
SHBox (const SHBox& rhs) noexcept;
SHBox (SHBox&& rhs) noexcept;
/*---------------------------------------------------------------------------------*/
/* Operator Overloads */
/*---------------------------------------------------------------------------------*/
SHBoundingBox& operator= (const SHBoundingBox& rhs) noexcept;
SHBoundingBox& operator= (SHBoundingBox&& rhs) noexcept;
SHBox& operator= (const SHBox& rhs) noexcept;
SHBox& operator= (SHBox&& rhs) noexcept;
/*---------------------------------------------------------------------------------*/
/* Getter Functions */
@ -79,7 +79,7 @@ namespace SHADE
[[nodiscard]] bool TestPoint (const SHVec3& point) noexcept override;
[[nodiscard]] bool Raycast (const SHRay& ray, float& distance) noexcept override;
[[nodiscard]] bool Contains (const SHBoundingBox& rhs) const noexcept;
[[nodiscard]] bool Contains (const SHBox& rhs) const noexcept;
[[nodiscard]] float Volume () const noexcept;
[[nodiscard]] float SurfaceArea () const noexcept;
@ -87,10 +87,10 @@ namespace SHADE
/* Static Function Members */
/*---------------------------------------------------------------------------------*/
[[nodiscard]] static SHBoundingBox Combine (const SHBoundingBox& lhs, const SHBoundingBox& rhs) noexcept;
[[nodiscard]] static bool Intersect (const SHBoundingBox& lhs, const SHBoundingBox& rhs) noexcept;
[[nodiscard]] static SHBoundingBox BuildFromBoxes (const SHBoundingBox* boxes, size_t numBoxes) noexcept;
[[nodiscard]] static SHBoundingBox BuildFromVertices (const SHVec3* vertices, size_t numVertices, size_t stride = 0) noexcept;
[[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;
private:
/*---------------------------------------------------------------------------------*/

View File

@ -11,7 +11,7 @@
#include <SHpch.h>
// Primary Header
#include "SHBoundingSphere.h"
#include "SHSphere.h"
// Project Headers
#include "Math/SHMathHelpers.h"
#include "Math/SHRay.h"
@ -24,13 +24,13 @@ namespace SHADE
/* Constructors & Destructor Definitions */
/*-----------------------------------------------------------------------------------*/
SHBoundingSphere::SHBoundingSphere() noexcept
SHSphere::SHSphere() noexcept
: RelativeRadius { 1.0f }
{
type = Type::SPHERE;
}
SHBoundingSphere::SHBoundingSphere(const SHVec3& center, float radius) noexcept
SHSphere::SHSphere(const SHVec3& center, float radius) noexcept
: RelativeRadius { 1.0f }
{
type = Type::SPHERE;
@ -39,7 +39,7 @@ namespace SHADE
Radius = radius;
}
SHBoundingSphere::SHBoundingSphere(const SHBoundingSphere& rhs) noexcept
SHSphere::SHSphere(const SHSphere& rhs) noexcept
{
if (this == &rhs)
return;
@ -51,7 +51,7 @@ namespace SHADE
RelativeRadius = rhs.RelativeRadius;
}
SHBoundingSphere::SHBoundingSphere(SHBoundingSphere&& rhs) noexcept
SHSphere::SHSphere(SHSphere&& rhs) noexcept
{
type = Type::SPHERE;
@ -64,7 +64,7 @@ namespace SHADE
/* Operator Overload Definitions */
/*-----------------------------------------------------------------------------------*/
SHBoundingSphere& SHBoundingSphere::operator=(const SHBoundingSphere& rhs) noexcept
SHSphere& SHSphere::operator=(const SHSphere& rhs) noexcept
{
if (rhs.type != Type::SPHERE)
{
@ -80,7 +80,7 @@ namespace SHADE
return *this;
}
SHBoundingSphere& SHBoundingSphere::operator=(SHBoundingSphere&& rhs) noexcept
SHSphere& SHSphere::operator=(SHSphere&& rhs) noexcept
{
if (rhs.type != Type::SPHERE)
{
@ -100,17 +100,17 @@ namespace SHADE
/* Getter Function Definitions */
/*-----------------------------------------------------------------------------------*/
SHVec3 SHBoundingSphere::GetCenter() const noexcept
SHVec3 SHSphere::GetCenter() const noexcept
{
return Center;
}
float SHBoundingSphere::GetWorldRadius() const noexcept
float SHSphere::GetWorldRadius() const noexcept
{
return Radius;
}
float SHBoundingSphere::GetRelativeRadius() const noexcept
float SHSphere::GetRelativeRadius() const noexcept
{
return RelativeRadius;
}
@ -119,17 +119,17 @@ namespace SHADE
/* Setter Function Definitions */
/*-----------------------------------------------------------------------------------*/
void SHBoundingSphere::SetCenter(const SHVec3& center) noexcept
void SHSphere::SetCenter(const SHVec3& center) noexcept
{
Center = center;
}
void SHBoundingSphere::SetWorldRadius(float newWorldRadius) noexcept
void SHSphere::SetWorldRadius(float newWorldRadius) noexcept
{
Radius = newWorldRadius;
}
void SHBoundingSphere::SetRelativeRadius(float newRelativeRadius) noexcept
void SHSphere::SetRelativeRadius(float newRelativeRadius) noexcept
{
RelativeRadius = newRelativeRadius;
}
@ -138,27 +138,27 @@ namespace SHADE
/* Public Function Member Definitions */
/*-----------------------------------------------------------------------------------*/
bool SHBoundingSphere::TestPoint(const SHVec3& point) noexcept
bool SHSphere::TestPoint(const SHVec3& point) noexcept
{
return BoundingSphere::Contains(point);
}
bool SHBoundingSphere::Raycast(const SHRay& ray, float& distance) noexcept
bool SHSphere::Raycast(const SHRay& ray, float& distance) noexcept
{
return Intersects(ray.position, ray.direction, distance);
}
bool SHBoundingSphere::Contains(const SHBoundingSphere& rhs) const noexcept
bool SHSphere::Contains(const SHSphere& rhs) const noexcept
{
return BoundingSphere::Contains(rhs);
}
float SHBoundingSphere::Volume() const noexcept
float SHSphere::Volume() const noexcept
{
return (4.0f / 3.0f) * SHMath::PI * (Radius * Radius * Radius);
}
float SHBoundingSphere::SurfaceArea() const noexcept
float SHSphere::SurfaceArea() const noexcept
{
return 4.0f * SHMath::PI * (Radius * Radius);
}
@ -167,21 +167,21 @@ namespace SHADE
/* Static Function Member Definitions */
/*-----------------------------------------------------------------------------------*/
SHBoundingSphere SHBoundingSphere::Combine(const SHBoundingSphere& lhs, const SHBoundingSphere& rhs) noexcept
SHSphere SHSphere::Combine(const SHSphere& lhs, const SHSphere& rhs) noexcept
{
SHBoundingSphere result;
SHSphere result;
CreateMerged(result, lhs, rhs);
return result;
}
bool SHBoundingSphere::Intersect(const SHBoundingSphere& lhs, const SHBoundingSphere& rhs) noexcept
bool SHSphere::Intersect(const SHSphere& lhs, const SHSphere& rhs) noexcept
{
return lhs.Intersects(rhs);
}
SHBoundingSphere SHBoundingSphere::BuildFromSpheres(const SHBoundingSphere* spheres, size_t numSpheres) noexcept
SHSphere SHSphere::BuildFromSpheres(const SHSphere* spheres, size_t numSpheres) noexcept
{
SHBoundingSphere result;
SHSphere result;
for (size_t i = 1; i < numSpheres; ++i)
CreateMerged(result, spheres[i - 1], spheres[i]);
@ -189,9 +189,9 @@ namespace SHADE
return result;
}
SHBoundingSphere SHBoundingSphere::BuildFromVertices(const SHVec3* vertices, size_t numVertices, size_t stride) noexcept
SHSphere SHSphere::BuildFromVertices(const SHVec3* vertices, size_t numVertices, size_t stride) noexcept
{
SHBoundingSphere result;
SHSphere result;
CreateFromPoints(result, numVertices, vertices, stride);
return result;
}

View File

@ -22,7 +22,7 @@ namespace SHADE
/* Type Definitions */
/*-----------------------------------------------------------------------------------*/
class SH_API SHBoundingSphere : public SHShape,
class SH_API SHSphere : public SHShape,
private DirectX::BoundingSphere
{
public:
@ -30,19 +30,19 @@ namespace SHADE
/* Constructors & Destructor */
/*---------------------------------------------------------------------------------*/
SHBoundingSphere () noexcept;
SHBoundingSphere (const SHVec3& center, float radius) noexcept;
SHBoundingSphere (const SHBoundingSphere& rhs) noexcept;
SHBoundingSphere (SHBoundingSphere&& rhs) noexcept;
SHSphere () noexcept;
SHSphere (const SHVec3& center, float radius) noexcept;
SHSphere (const SHSphere& rhs) noexcept;
SHSphere (SHSphere&& rhs) noexcept;
~SHBoundingSphere () override = default;
~SHSphere () override = default;
/*---------------------------------------------------------------------------------*/
/* Operator Overloads */
/*---------------------------------------------------------------------------------*/
SHBoundingSphere& operator= (const SHBoundingSphere& rhs) noexcept;
SHBoundingSphere& operator= (SHBoundingSphere&& rhs) noexcept;
SHSphere& operator= (const SHSphere& rhs) noexcept;
SHSphere& operator= (SHSphere&& rhs) noexcept;
/*---------------------------------------------------------------------------------*/
/* Getter Functions */
@ -67,7 +67,7 @@ namespace SHADE
[[nodiscard]] bool TestPoint (const SHVec3& point) noexcept override;
[[nodiscard]] bool Raycast (const SHRay& ray, float& distance) noexcept override;
[[nodiscard]] bool Contains (const SHBoundingSphere& rhs) const noexcept;
[[nodiscard]] bool Contains (const SHSphere& rhs) const noexcept;
[[nodiscard]] float Volume () const noexcept;
[[nodiscard]] float SurfaceArea () const noexcept;
@ -76,10 +76,10 @@ namespace SHADE
/* Static Function Members */
/*---------------------------------------------------------------------------------*/
[[nodiscard]] static SHBoundingSphere Combine (const SHBoundingSphere& lhs, const SHBoundingSphere& rhs) noexcept;
[[nodiscard]] static bool Intersect (const SHBoundingSphere& lhs, const SHBoundingSphere& rhs) noexcept;
[[nodiscard]] static SHBoundingSphere BuildFromSpheres (const SHBoundingSphere* spheres, size_t numSpheres) noexcept;
[[nodiscard]] static SHBoundingSphere BuildFromVertices (const SHVec3* vertices, size_t numVertices, size_t stride = 0) noexcept;
[[nodiscard]] static SHSphere Combine (const SHSphere& lhs, const SHSphere& rhs) noexcept;
[[nodiscard]] static bool Intersect (const SHSphere& lhs, const SHSphere& rhs) noexcept;
[[nodiscard]] static SHSphere BuildFromSpheres (const SHSphere* spheres, size_t numSpheres) noexcept;
[[nodiscard]] static SHSphere BuildFromVertices (const SHVec3* vertices, size_t numVertices, size_t stride = 0) noexcept;
private:
/*---------------------------------------------------------------------------------*/

View File

@ -95,7 +95,7 @@ namespace SHADE
{
case SHCollisionShape::Type::BOX:
{
auto* box = reinterpret_cast<SHBoundingBox*>(collisionShape.shape);
auto* box = reinterpret_cast<SHBox*>(collisionShape.shape);
const SHVec3& RELATIVE_EXTENTS = box->GetRelativeExtents();
// Recompute world extents based on new scale and fixed relative extents
@ -106,7 +106,7 @@ namespace SHADE
}
case SHCollisionShape::Type::SPHERE:
{
auto* sphere = reinterpret_cast<SHBoundingSphere*>(collisionShape.shape);
auto* sphere = reinterpret_cast<SHSphere*>(collisionShape.shape);
const float RELATIVE_RADIUS = sphere->GetRelativeRadius();
// Recompute world radius based on new scale and fixed radius

View File

@ -14,8 +14,8 @@
// Project Headers
#include "ECS_Base/Components/SHComponent.h"
#include "Math/Geometry/SHBoundingBox.h"
#include "Math/Geometry/SHBoundingSphere.h"
#include "Math/Geometry/SHBox.h"
#include "Math/Geometry/SHSphere.h"
#include "SHCollisionShape.h"
//namespace SHADE

View File

@ -13,8 +13,8 @@
// Primary Header
#include "SHCollisionShape.h"
// Project Headers
#include "Math/Geometry/SHBoundingBox.h"
#include "Math/Geometry/SHBoundingSphere.h"
#include "Math/Geometry/SHBox.h"
#include "Math/Geometry/SHSphere.h"
#include "Math/SHMathHelpers.h"
#include "Reflection/SHReflectionMetadata.h"
#include "SHColliderComponent.h"
@ -37,12 +37,12 @@ namespace SHADE
{
case Type::BOX:
{
shape = new SHBoundingBox{ SHVec3::Zero, SHVec3::One };
shape = new SHBox{ SHVec3::Zero, SHVec3::One };
break;
}
case Type::SPHERE:
{
shape = new SHBoundingSphere{ SHVec3::Zero, 0.5f };
shape = new SHSphere{ SHVec3::Zero, 0.5f };
break;
}
default: break;
@ -186,10 +186,10 @@ namespace SHADE
type = Type::BOX;
delete shape;
shape = new SHBoundingBox{ positionOffset, WORLD_EXTENTS };
shape = new SHBox{ positionOffset, WORLD_EXTENTS };
}
auto* box = reinterpret_cast<SHBoundingBox*>(shape);
auto* box = reinterpret_cast<SHBox*>(shape);
box->SetWorldExtents(WORLD_EXTENTS);
box->SetRelativeExtents(halfExtents);
}
@ -209,10 +209,10 @@ namespace SHADE
type = Type::SPHERE;
delete shape;
shape = new SHBoundingSphere{ positionOffset, WORLD_RADIUS };
shape = new SHSphere{ positionOffset, WORLD_RADIUS };
}
auto* sphere = reinterpret_cast<SHBoundingSphere*>(shape);
auto* sphere = reinterpret_cast<SHSphere*>(shape);
sphere->SetWorldRadius(WORLD_RADIUS);
}
@ -255,12 +255,12 @@ namespace SHADE
{
case Type::BOX:
{
reinterpret_cast<SHBoundingBox*>(shape)->SetCenter(positionOffset);
reinterpret_cast<SHBox*>(shape)->SetCenter(positionOffset);
break;
}
case Type::SPHERE:
{
reinterpret_cast<SHBoundingSphere*>(shape)->SetCenter(positionOffset);
reinterpret_cast<SHSphere*>(shape)->SetCenter(positionOffset);
break;
}
default: break;
@ -283,16 +283,16 @@ namespace SHADE
{
case Type::BOX:
{
const auto* RHS_BOX = reinterpret_cast<const SHBoundingBox*>(rhs);
const auto* RHS_BOX = reinterpret_cast<const SHBox*>(rhs);
shape = new SHBoundingBox{ positionOffset, RHS_BOX->GetWorldExtents() };
shape = new SHBox{ positionOffset, RHS_BOX->GetWorldExtents() };
break;
}
case Type::SPHERE:
{
const auto* RHS_SPHERE = reinterpret_cast<const SHBoundingSphere*>(rhs);
const auto* RHS_SPHERE = reinterpret_cast<const SHSphere*>(rhs);
shape = new SHBoundingSphere{ positionOffset, RHS_SPHERE->GetWorldRadius() };
shape = new SHSphere{ positionOffset, RHS_SPHERE->GetWorldRadius() };
break;
}
default: break;

View File

@ -309,7 +309,7 @@ namespace SHADE
, boxShape.GetRotationOffset()
};
const auto* BOX = reinterpret_cast<const SHBoundingBox*>(boxShape.GetShape());
const auto* BOX = reinterpret_cast<const SHBox*>(boxShape.GetShape());
rp3d::BoxShape* newBox = factory->createBoxShape(BOX->GetWorldExtents());
rp3dBody->addCollider(newBox, OFFSETS);
@ -317,7 +317,7 @@ namespace SHADE
void SHPhysicsObject::syncBoxShape(int index, SHCollisionShape& boxShape) const noexcept
{
const auto* BOX = reinterpret_cast<const SHBoundingBox*>(boxShape.GetShape());
const auto* BOX = reinterpret_cast<const SHBox*>(boxShape.GetShape());
auto* rp3dCollider = rp3dBody->getCollider(index);
auto* rp3dBox = reinterpret_cast<rp3d::BoxShape*>(rp3dCollider->getCollisionShape());
@ -342,7 +342,7 @@ namespace SHADE
, sphereShape.GetRotationOffset()
};
const auto* SPHERE = reinterpret_cast<const SHBoundingSphere*>(sphereShape.GetShape());
const auto* SPHERE = reinterpret_cast<const SHSphere*>(sphereShape.GetShape());
rp3d::SphereShape* newSphere = factory->createSphereShape(SPHERE->GetWorldRadius());
rp3dBody->addCollider(newSphere, OFFSETS);
@ -350,7 +350,7 @@ namespace SHADE
void SHPhysicsObject::syncSphereShape(int index, SHCollisionShape& sphereShape) const noexcept
{
const auto* SPHERE = reinterpret_cast<const SHBoundingSphere*>(sphereShape.GetShape());
const auto* SPHERE = reinterpret_cast<const SHSphere*>(sphereShape.GetShape());
auto* rp3dCollider = rp3dBody->getCollider(index);
auto* rp3dSphere = reinterpret_cast<rp3d::SphereShape*>(rp3dCollider->getCollisionShape());

View File

@ -124,8 +124,8 @@ namespace SHADE
for (const auto& COLLIDER : COLLIDER_SET)
{
// Skip inactive colliders
//if (!SHSceneManager::CheckNodeAndComponentsActive<SHColliderComponent>(COLLIDER.GetEID()))
// continue;
if (!SHSceneManager::CheckNodeAndComponentsActive<SHColliderComponent>(COLLIDER.GetEID()))
continue;
for (auto& collisionShape : COLLIDER.GetCollisionShapes())
{
@ -181,7 +181,7 @@ namespace SHADE
return;
}
auto* BOX = reinterpret_cast<const SHBoundingBox*>(collisionShape.GetShape());
auto* BOX = reinterpret_cast<const SHBox*>(collisionShape.GetShape());
// Calculate final position & orientation
const SHVec3 FINAL_POS = colliderComponent.GetPosition() + collisionShape.GetPositionOffset();
@ -221,7 +221,7 @@ namespace SHADE
return;
}
auto* SPHERE = reinterpret_cast<const SHBoundingSphere*>(collisionShape.GetShape());
auto* SPHERE = reinterpret_cast<const SHSphere*>(collisionShape.GetShape());
const SHColour COLLIDER_COLOUR = collisionShape.IsTrigger() ? SHColour::PURPLE : SHColour::GREEN;

View File

@ -225,44 +225,51 @@ namespace SHADE
void SHPhysicsSystem::AddForce(EntityID eid, const SHVec3& force) noexcept
{
auto* physicsObject = objectManager.GetPhysicsObject(eid);
const auto* PHYSICS_OBJECT = objectManager.GetPhysicsObject(eid);
PHYSICS_OBJECT->GetRigidBody()->applyWorldForceAtCenterOfMass(force);
}
void SHPhysicsSystem::AddForceAtLocalPos(EntityID eid, const SHVec3& force, const SHVec3& localPos) noexcept
{
auto* physicsObject = objectManager.GetPhysicsObject(eid);
const auto* PHYSICS_OBJECT = objectManager.GetPhysicsObject(eid);
PHYSICS_OBJECT->GetRigidBody()->applyWorldForceAtLocalPosition(force, localPos);
}
void SHPhysicsSystem::AddForceAtWorldPos(EntityID eid, const SHVec3& force, const SHVec3& worldPos) noexcept
{
auto* physicsObject = objectManager.GetPhysicsObject(eid);
const auto* PHYSICS_OBJECT = objectManager.GetPhysicsObject(eid);
PHYSICS_OBJECT->GetRigidBody()->applyWorldForceAtWorldPosition(force, worldPos);
}
void SHPhysicsSystem::AddRelativeForce(EntityID eid, const SHVec3& relativeForce) noexcept
{
auto* physicsObject = objectManager.GetPhysicsObject(eid);
const auto* PHYSICS_OBJECT = objectManager.GetPhysicsObject(eid);
PHYSICS_OBJECT->GetRigidBody()->applyLocalForceAtCenterOfMass(relativeForce);
}
void SHPhysicsSystem::AddRelativeForceAtLocalPos(EntityID eid, const SHVec3& relativeForce, const SHVec3& localPos) noexcept
{
auto* physicsObject = objectManager.GetPhysicsObject(eid);
const auto* PHYSICS_OBJECT = objectManager.GetPhysicsObject(eid);
PHYSICS_OBJECT->GetRigidBody()->applyLocalForceAtLocalPosition(relativeForce, localPos);
}
void SHPhysicsSystem::AddRelativeForceAtWorldPos(EntityID eid, const SHVec3& relativeForce, const SHVec3& worldPos) noexcept
{
auto* physicsObject = objectManager.GetPhysicsObject(eid);
const auto* PHYSICS_OBJECT = objectManager.GetPhysicsObject(eid);
PHYSICS_OBJECT->GetRigidBody()->applyLocalForceAtWorldPosition(relativeForce, worldPos);
}
void SHPhysicsSystem::AddTorque(EntityID eid, const SHVec3& torque) noexcept
{
auto* physicsObject = objectManager.GetPhysicsObject(eid);
const auto* PHYSICS_OBJECT = objectManager.GetPhysicsObject(eid);
PHYSICS_OBJECT->GetRigidBody()->applyWorldTorque(torque);
}
void SHPhysicsSystem::AddRelativeTorque(EntityID eid, const SHVec3& relativeTorque) noexcept
{
auto* physicsObject = objectManager.GetPhysicsObject(eid);
const auto* PHYSICS_OBJECT = objectManager.GetPhysicsObject(eid);
PHYSICS_OBJECT->GetRigidBody()->applyLocalTorque(relativeTorque);
}
/*-----------------------------------------------------------------------------------*/
@ -387,7 +394,7 @@ namespace SHADE
, SHColliderComponent* colliderComponent
) noexcept
{
if (!transformComponent || !SHSceneManager::CheckNodeAndComponentsActive<SHTransformComponent>(physicsObject.entityID))
if (!transformComponent)
return;
const SHVec3& WORLD_POS = transformComponent->GetWorldPosition();
@ -461,7 +468,7 @@ namespace SHADE
}
// Set transform for rendering
if (transformComponent && SHSceneManager::CheckNodeAndComponentsActive<SHTransformComponent>(physicsObject.entityID))
if (transformComponent)
{
transformComponent->SetWorldPosition(renderPos);
transformComponent->SetWorldOrientation(renderRot);

View File

@ -139,6 +139,14 @@ namespace SHADE
physicsSystem->worldState.world->update(static_cast<rp3d::decimal>(FIXED_DT));
// Clear all forces of every body in the scene after each update
for (auto& physicsObject : physicsSystem->objectManager.physicsObjects | std::views::values)
{
auto* rp3dRigidBody = physicsObject.GetRigidBody();
rp3dRigidBody->resetForce();
rp3dRigidBody->resetTorque();
}
accumulatedTime -= FIXED_DT;
++count;
}

View File

@ -1,8 +1,8 @@
#pragma once
#include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Graphics/MiddleEnd/Materials/SHMaterialSpec.h"
#include "Math/Geometry/SHBoundingBox.h"
#include "Math/Geometry/SHBoundingSphere.h"
#include "Math/Geometry/SHBox.h"
#include "Math/Geometry/SHSphere.h"
#include "Physics/Interface/SHCollisionShape.h"
#include "Resource/SHResourceManager.h"
#include "Math/Vector/SHVec2.h"
@ -130,13 +130,13 @@ namespace YAML
{
case SHCollisionShape::Type::BOX:
{
const auto* BOX = reinterpret_cast<const SHBoundingBox*>(rhs.GetShape());
const auto* BOX = reinterpret_cast<const SHBox*>(rhs.GetShape());
node[HalfExtents] = BOX->GetRelativeExtents();
}
break;
case SHCollisionShape::Type::SPHERE:
{
const auto* SPHERE = reinterpret_cast<const SHBoundingSphere*>(rhs.GetShape());
const auto* SPHERE = reinterpret_cast<const SHSphere*>(rhs.GetShape());
node[Radius] = SPHERE->GetRelativeRadius();
}
break;

View File

@ -47,35 +47,35 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
Vector3 BoxCollider::Center::get()
{
return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetCenter());
return Convert::ToCLI(getNativeBoundObject<SHBox>().GetCenter());
}
void BoxCollider::Center::set(Vector3 value)
{
getNativeBoundObject<SHBoundingBox>().SetCenter(Convert::ToNative(value));
getNativeBoundObject<SHBox>().SetCenter(Convert::ToNative(value));
}
Vector3 BoxCollider::HalfExtents::get()
{
return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetWorldExtents());
return Convert::ToCLI(getNativeBoundObject<SHBox>().GetWorldExtents());
}
void BoxCollider::HalfExtents::set(Vector3 value)
{
getNativeBoundObject<SHBoundingBox>().SetWorldExtents(Convert::ToNative(value));
getNativeBoundObject<SHBox>().SetWorldExtents(Convert::ToNative(value));
}
Vector3 BoxCollider::Min::get()
{
return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetMin());
return Convert::ToCLI(getNativeBoundObject<SHBox>().GetMin());
}
void BoxCollider::Min::set(Vector3 value)
{
getNativeBoundObject<SHBoundingBox>().SetMin(Convert::ToNative(value));
getNativeBoundObject<SHBox>().SetMin(Convert::ToNative(value));
}
Vector3 BoxCollider::Max::get()
{
return Convert::ToCLI(getNativeBoundObject<SHBoundingBox>().GetMax());
return Convert::ToCLI(getNativeBoundObject<SHBox>().GetMax());
}
void BoxCollider::Max::set(Vector3 value)
{
getNativeBoundObject<SHBoundingBox>().SetMax(Convert::ToNative(value));
getNativeBoundObject<SHBox>().SetMax(Convert::ToNative(value));
}
/*---------------------------------------------------------------------------------*/
@ -83,11 +83,11 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
bool BoxCollider::TestPoint(Vector3 point)
{
return getNativeBoundObject<SHBoundingBox>().TestPoint(Convert::ToNative(point));
return getNativeBoundObject<SHBox>().TestPoint(Convert::ToNative(point));
}
bool BoxCollider::Raycast(Ray ray, float maxDistance)
{
return getNativeBoundObject<SHBoundingBox>().Raycast(Convert::ToNative(ray), maxDistance);
return getNativeBoundObject<SHBox>().Raycast(Convert::ToNative(ray), maxDistance);
}
/*---------------------------------------------------------------------------------*/
@ -95,19 +95,19 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
Vector3 SphereCollider::Center::get()
{
return Convert::ToCLI(getNativeBoundObject<SHBoundingSphere>().GetCenter());
return Convert::ToCLI(getNativeBoundObject<SHSphere>().GetCenter());
}
void SphereCollider::Center::set(Vector3 value)
{
getNativeBoundObject<SHBoundingSphere>().SetCenter(Convert::ToNative(value));
getNativeBoundObject<SHSphere>().SetCenter(Convert::ToNative(value));
}
float SphereCollider::Radius::get()
{
return getNativeBoundObject<SHBoundingSphere>().GetWorldRadius();
return getNativeBoundObject<SHSphere>().GetWorldRadius();
}
void SphereCollider::Radius::set(float value)
{
getNativeBoundObject<SHBoundingSphere>().SetWorldRadius(value);
getNativeBoundObject<SHSphere>().SetWorldRadius(value);
}
/*---------------------------------------------------------------------------------*/
@ -115,11 +115,11 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/
bool SphereCollider::TestPoint(Vector3 point)
{
return getNativeBoundObject<SHBoundingBox>().TestPoint(Convert::ToNative(point));
return getNativeBoundObject<SHBox>().TestPoint(Convert::ToNative(point));
}
bool SphereCollider::Raycast(Ray ray, float maxDistance)
{
return getNativeBoundObject<SHBoundingBox>().Raycast(Convert::ToNative(ray), maxDistance);
return getNativeBoundObject<SHBox>().Raycast(Convert::ToNative(ray), maxDistance);
}
/*---------------------------------------------------------------------------------*/

View File

@ -190,6 +190,10 @@ namespace SHADE
GetNativeComponent()->AddRelativeForceAtWorldPos(Convert::ToNative(relativeForce), Convert::ToNative(worldPos));
}
Vector3 RigidBody::GetForce()
{
return Convert::ToCLI(GetNativeComponent()->GetForce());
}
/*---------------------------------------------------------------------------------*/
/* Torque Functions */
/*---------------------------------------------------------------------------------*/
@ -202,4 +206,10 @@ namespace SHADE
{
GetNativeComponent()->AddRelativeTorque(Convert::ToNative(relativeTorque));
}
Vector3 RigidBody::GetTorque()
{
return Convert::ToCLI(GetNativeComponent()->GetTorque());
}
}

View File

@ -145,11 +145,15 @@ namespace SHADE
void AddRelativeForceAtLocalPos(Vector3 relativeForce, Vector3 localPos);
void AddRelativeForceAtWorldPos(Vector3 relativeForce, Vector3 worldPos);
Vector3 GetForce();
/*-----------------------------------------------------------------------------*/
/* Torque Functions */
/*-----------------------------------------------------------------------------*/
void AddTorque(Vector3 force);
void AddRelativeTorque(Vector3 relativeForce);
Vector3 GetTorque();
};
}