Skeleton for Reworked Physics Debug Draw
This commit is contained in:
parent
f8417f6116
commit
4731df28f0
|
@ -101,7 +101,6 @@ namespace Sandbox
|
|||
SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsPreUpdate>();
|
||||
SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsFixedUpdate>();
|
||||
SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsPostUpdate>();
|
||||
SHSystemManager::RegisterRoutine<SHPhysicsSystem, SHPhysicsSystem::PhysicsDebugDraw>();
|
||||
|
||||
SHSystemManager::RegisterRoutine<SHTransformSystem, SHTransformSystem::TransformPostPhysicsUpdate>();
|
||||
SHSystemManager::RegisterRoutine<SHDebugDrawSystem, SHDebugDrawSystem::ProcessPointsRoutine>();
|
||||
|
@ -160,12 +159,12 @@ namespace Sandbox
|
|||
SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, 0.016f);
|
||||
editor->PollPicking();
|
||||
|
||||
static bool drawColliders = false;
|
||||
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::F10))
|
||||
{
|
||||
drawColliders = !drawColliders;
|
||||
SHSystemManager::GetSystem<SHPhysicsSystem>()->SetDrawColliders(drawColliders);
|
||||
}
|
||||
//static bool drawColliders = false;
|
||||
//if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::F10))
|
||||
//{
|
||||
// drawColliders = !drawColliders;
|
||||
// SHSystemManager::GetSystem<SHPhysicsSystem>()->SetDrawColliders(drawColliders);
|
||||
//}
|
||||
}
|
||||
// Finish all graphics jobs first
|
||||
graphicsSystem->AwaitGraphicsExecution();
|
||||
|
|
|
@ -246,21 +246,21 @@ namespace SHADE
|
|||
if (collider->GetType() == SHCollisionShape::Type::BOX)
|
||||
{
|
||||
SHEditorWidgets::BeginPanel(std::format("{} Box #{}", ICON_FA_CUBE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
|
||||
auto box = reinterpret_cast<SHBoundingBox*>(collider->GetShape());
|
||||
const auto* BOX = reinterpret_cast<const SHBoundingBox*>(collider->GetShape());
|
||||
SHEditorWidgets::DragVec3
|
||||
(
|
||||
"Half Extents", { "X", "Y", "Z" },
|
||||
[box] { return box->GetRelativeExtents(); },
|
||||
[BOX] { return BOX->GetRelativeExtents(); },
|
||||
[collider](SHVec3 const& vec) { collider->SetBoundingBox(vec); });
|
||||
}
|
||||
else if (collider->GetType() == SHCollisionShape::Type::SPHERE)
|
||||
{
|
||||
SHEditorWidgets::BeginPanel(std::format("{} Sphere #{}", ICON_MD_CIRCLE, i).data(), { ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y });
|
||||
auto sphere = reinterpret_cast<SHBoundingSphere*>(collider->GetShape());
|
||||
const auto* SPHERE = reinterpret_cast<const SHBoundingSphere*>(collider->GetShape());
|
||||
SHEditorWidgets::DragFloat
|
||||
(
|
||||
"Radius",
|
||||
[sphere] { return sphere->GetRelativeRadius(); },
|
||||
[SPHERE] { return SPHERE->GetRelativeRadius(); },
|
||||
[collider](float const& value) { collider->SetBoundingSphere(value); });
|
||||
}
|
||||
else if (collider->GetType() == SHCollisionShape::Type::CAPSULE)
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace SHADE
|
|||
|
||||
});
|
||||
|
||||
for (uint32_t i = 1; i <= SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES); ++i)
|
||||
for (uint32_t i = 1; i <= SHUtilities::ConvertEnum(SH_LIGHT_TYPE::NUM_TYPES); ++i)
|
||||
{
|
||||
lightBindings.push_back (SHVkDescriptorSetLayout::Binding
|
||||
{
|
||||
|
|
|
@ -379,7 +379,7 @@ namespace SHADE
|
|||
SHComponentManager::CreateComponentSparseSet<SHLightComponent>();
|
||||
|
||||
logicalDevice = device;
|
||||
uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES);
|
||||
uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ConvertEnum(SH_LIGHT_TYPE::NUM_TYPES);
|
||||
|
||||
std::vector<uint32_t> variableSizes{ NUM_LIGHT_TYPES };
|
||||
std::fill (variableSizes.begin(), variableSizes.end(), 1);
|
||||
|
@ -431,7 +431,7 @@ namespace SHADE
|
|||
/***************************************************************************/
|
||||
void SHLightingSubSystem::Run(SHMatrix const& viewMat, uint32_t frameIndex) noexcept
|
||||
{
|
||||
static uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES);
|
||||
static uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ConvertEnum(SH_LIGHT_TYPE::NUM_TYPES);
|
||||
|
||||
auto& lightComps = SHComponentManager::GetDense<SHLightComponent>();
|
||||
bool expanded = false;
|
||||
|
@ -451,7 +451,7 @@ namespace SHADE
|
|||
|
||||
for (auto& light : lightComps)
|
||||
{
|
||||
auto enumValue = SHUtilities::ToUnderlying(light.GetLightData().type);
|
||||
auto enumValue = SHUtilities::ConvertEnum(light.GetLightData().type);
|
||||
|
||||
// First we want to make sure the light is already bound to the system. if it
|
||||
// isn't, we write it to the correct buffer.
|
||||
|
@ -491,7 +491,7 @@ namespace SHADE
|
|||
// is a new buffer. If some expansion was detected, update descriptor sets.
|
||||
if (expanded)
|
||||
{
|
||||
uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ToUnderlying(SH_LIGHT_TYPE::NUM_TYPES);
|
||||
uint32_t constexpr NUM_LIGHT_TYPES = SHUtilities::ConvertEnum(SH_LIGHT_TYPE::NUM_TYPES);
|
||||
for (uint32_t i = 0; i < NUM_LIGHT_TYPES; ++i)
|
||||
{
|
||||
UpdateDescSet(i);
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace SHADE
|
|||
{
|
||||
case SHCollisionShape::Type::BOX:
|
||||
{
|
||||
auto* box = reinterpret_cast<SHBoundingBox*>(collisionShape.GetShape());
|
||||
auto* box = reinterpret_cast<SHBoundingBox*>(collisionShape.shape);
|
||||
const SHVec3& RELATIVE_EXTENTS = box->GetRelativeExtents();
|
||||
|
||||
// Recompute world extents based on new scale and fixed relative extents
|
||||
|
@ -99,7 +99,7 @@ namespace SHADE
|
|||
}
|
||||
case SHCollisionShape::Type::SPHERE:
|
||||
{
|
||||
auto* sphere = reinterpret_cast<SHBoundingSphere*>(collisionShape.GetShape());
|
||||
auto* sphere = reinterpret_cast<SHBoundingSphere*>(collisionShape.shape);
|
||||
const float RELATIVE_RADIUS = sphere->GetRelativeRadius();
|
||||
|
||||
// Recompute world radius based on new scale and fixed radius
|
||||
|
|
|
@ -164,9 +164,8 @@ namespace SHADE
|
|||
return rotationOffset;
|
||||
}
|
||||
|
||||
SHShape* SHCollisionShape::GetShape() noexcept
|
||||
const SHShape* SHCollisionShape::GetShape() const noexcept
|
||||
{
|
||||
dirty = true;
|
||||
return shape;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ namespace SHADE
|
|||
[[nodiscard]] const SHVec3& GetPositionOffset () const noexcept;
|
||||
[[nodiscard]] const SHVec3& GetRotationOffset () const noexcept;
|
||||
|
||||
[[nodiscard]] SHShape* GetShape () noexcept;
|
||||
[[nodiscard]] const SHShape* GetShape () const noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Setter Functions */
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
/****************************************************************************************
|
||||
* \file SHPhysicsDebugDrawSystem.cpp
|
||||
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||
* \brief Implementation for the Physics Debug Draw System
|
||||
*
|
||||
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
****************************************************************************************/
|
||||
|
||||
#include <SHpch.h>
|
||||
|
||||
// Primary Header
|
||||
#include "SHPhysicsDebugDrawSystem.h"
|
||||
|
||||
// Project Headers
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Static Data Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
const SHPhysicsDebugDrawSystem::DebugDrawFunction SHPhysicsDebugDrawSystem::drawFunctions[SHPhysicsDebugDrawSystem::NUM_FLAGS] =
|
||||
{
|
||||
SHPhysicsDebugDrawSystem::drawColliders
|
||||
, SHPhysicsDebugDrawSystem::drawColliderAABBs
|
||||
, SHPhysicsDebugDrawSystem::drawBroadPhaseAABBs
|
||||
, SHPhysicsDebugDrawSystem::drawContactPoints
|
||||
, SHPhysicsDebugDrawSystem::drawContactNormals
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
SHPhysicsDebugDrawSystem::SHPhysicsDebugDrawSystem() noexcept
|
||||
: debugDrawFlags { 0 }
|
||||
, physicsSystem { nullptr }
|
||||
, rp3dDebugRenderer { nullptr }
|
||||
{
|
||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER)] =
|
||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER_AABB)] = SHColour::YELLOW;
|
||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::BROAD_PHASE_AABB)] = SHColour::CYAN;
|
||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_POINTS)] = SHColour::RED;
|
||||
debugColours[SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_NORMALS)] = SHColour::RED;
|
||||
}
|
||||
|
||||
SHPhysicsDebugDrawSystem::PhysicsDebugDrawRoutine::PhysicsDebugDrawRoutine()
|
||||
: SHSystemRoutine { "Physics Debug Draw", true }
|
||||
{}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Getter Function Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
bool SHPhysicsDebugDrawSystem::GetDebugDrawFlag(DebugDrawFlags flag) const noexcept
|
||||
{
|
||||
const auto INT_FLAG = SHUtilities::ConvertEnum(flag);
|
||||
if (INT_FLAG < 0 || INT_FLAG >= NUM_FLAGS)
|
||||
{
|
||||
SHLOG_ERROR("Invalid Debug Draw Flag Passed {} in. Unable to get debug draw state!", INT_FLAG)
|
||||
return false;
|
||||
}
|
||||
|
||||
return debugDrawFlags & 1U << SHUtilities::ConvertEnum(flag);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Setter Function Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
void SHPhysicsDebugDrawSystem::SetDebugDrawFlag(DebugDrawFlags flag, bool value) noexcept
|
||||
{
|
||||
const auto INT_FLAG = SHUtilities::ConvertEnum(flag);
|
||||
if (INT_FLAG < 0 || INT_FLAG >= NUM_FLAGS)
|
||||
{
|
||||
SHLOG_ERROR("Invalid Debug Draw Flag Passed {} in. Unable to set debug draw state!", INT_FLAG)
|
||||
return;
|
||||
}
|
||||
|
||||
value ? (debugDrawFlags |= 1U << INT_FLAG) : (debugDrawFlags &= ~(1U << INT_FLAG));
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Public Function Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
void SHPhysicsDebugDrawSystem::Init()
|
||||
{
|
||||
SHASSERT(physicsSystem == nullptr, "Non-existent physics system attached to the physics debug draw system!")
|
||||
physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
}
|
||||
|
||||
void SHPhysicsDebugDrawSystem::Exit()
|
||||
{
|
||||
physicsSystem = nullptr;
|
||||
}
|
||||
|
||||
void SHPhysicsDebugDrawSystem::PhysicsDebugDrawRoutine::Execute(double) noexcept
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Private Function Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
void SHPhysicsDebugDrawSystem::drawColliders(rp3d::DebugRenderer* debugRenderer) noexcept
|
||||
{
|
||||
auto* debugDrawSystem = SHSystemManager::GetSystem<SHDebugDrawSystem>();
|
||||
if (debugDrawSystem == nullptr)
|
||||
{
|
||||
SHLOG_ERROR("Unable to get a debug draw system for Physics Debug Drawing!")
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& COLLIDER_SET = SHComponentManager::GetDense<SHColliderComponent>();
|
||||
for (const auto& COLLIDER : COLLIDER_SET)
|
||||
{
|
||||
// Get the colliders of each component
|
||||
const SHVec3& POS = COLLIDER.GetPosition();
|
||||
const SHQuaternion& ROT = COLLIDER.GetOrientation();
|
||||
|
||||
for (auto& collisionShape : COLLIDER.GetCollisionShapes())
|
||||
{
|
||||
switch (collisionShape.GetType())
|
||||
{
|
||||
case SHCollisionShape::Type::BOX:
|
||||
{
|
||||
auto* BOX = reinterpret_cast<const SHBoundingBox*>(collisionShape.GetShape());
|
||||
|
||||
break;
|
||||
}
|
||||
case SHCollisionShape::Type::SPHERE:
|
||||
{
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SHPhysicsDebugDrawSystem::drawColliderAABBs(rp3d::DebugRenderer* debugRenderer) noexcept
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SHPhysicsDebugDrawSystem::drawBroadPhaseAABBs(rp3d::DebugRenderer* debugRenderer) noexcept
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SHPhysicsDebugDrawSystem::drawContactPoints(rp3d::DebugRenderer* debugRenderer) noexcept
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SHPhysicsDebugDrawSystem::drawContactNormals(rp3d::DebugRenderer* debugRenderer) noexcept
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // namespace SHADE
|
|
@ -0,0 +1,120 @@
|
|||
/****************************************************************************************
|
||||
* \file SHPhysicsDebugDrawSystem.h
|
||||
* \author Diren D Bharwani, diren.dbharwani, 390002520
|
||||
* \brief Interface for the Physics Debug Draw System
|
||||
*
|
||||
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
|
||||
* disclosure of this file or its contents without the prior written consent
|
||||
* of DigiPen Institute of Technology is prohibited.
|
||||
****************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <reactphysics3d/reactphysics3d.h>
|
||||
|
||||
// Project Headers
|
||||
#include "ECS_Base/System/SHSystemRoutine.h"
|
||||
#include "Math/SHColour.h"
|
||||
#include "SHPhysicsSystem.h"
|
||||
#include "Tools/SHUtilities.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
class SH_API SHPhysicsDebugDrawSystem : public SHSystem
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
enum class DebugDrawFlags
|
||||
{
|
||||
COLLIDER
|
||||
, COLLIDER_AABB
|
||||
, BROAD_PHASE_AABB
|
||||
, CONTACT_POINTS
|
||||
, CONTACT_NORMALS
|
||||
|
||||
, NUM_FLAGS
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
SHPhysicsDebugDrawSystem() noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
bool GetDebugDrawFlag(DebugDrawFlags flag) const noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Setter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
void SetDebugDrawFlag(DebugDrawFlags flag, bool value) noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Function Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
void Init() override;
|
||||
void Exit() override;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* System Routines */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
class SH_API PhysicsDebugDrawRoutine : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
|
||||
PhysicsDebugDrawRoutine();
|
||||
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Function Members */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
void Execute(double dt) noexcept override;
|
||||
};
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
using DebugDrawFunction = void(*)(rp3d::DebugRenderer*) noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
static constexpr int NUM_FLAGS = SHUtilities::ConvertEnum(DebugDrawFlags::NUM_FLAGS);
|
||||
|
||||
static const DebugDrawFunction drawFunctions[NUM_FLAGS];
|
||||
|
||||
uint8_t debugDrawFlags;
|
||||
SHPhysicsSystem* physicsSystem;
|
||||
rp3d::DebugRenderer* rp3dDebugRenderer;
|
||||
SHColour debugColours[NUM_FLAGS];
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Function Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
static void drawColliders (rp3d::DebugRenderer* debugRenderer) noexcept;
|
||||
static void drawColliderAABBs (rp3d::DebugRenderer* debugRenderer) noexcept;
|
||||
static void drawBroadPhaseAABBs (rp3d::DebugRenderer* debugRenderer) noexcept;
|
||||
static void drawContactPoints (rp3d::DebugRenderer* debugRenderer) noexcept;
|
||||
static void drawContactNormals (rp3d::DebugRenderer* debugRenderer) noexcept;
|
||||
};
|
||||
|
||||
} // namespace SHADE
|
|
@ -136,16 +136,16 @@ namespace SHADE
|
|||
{
|
||||
case SHCollisionShape::Type::BOX:
|
||||
{
|
||||
const auto* box = reinterpret_cast<SHBoundingBox*>(collider->GetShape());
|
||||
rp3d::BoxShape* newBox = factory->createBoxShape(box->GetWorldExtents());
|
||||
const auto* BOX = reinterpret_cast<const SHBoundingBox*>(collider->GetShape());
|
||||
rp3d::BoxShape* newBox = factory->createBoxShape(BOX->GetWorldExtents());
|
||||
|
||||
rp3dBody->addCollider(newBox, OFFSETS);
|
||||
break;
|
||||
}
|
||||
case SHCollisionShape::Type::SPHERE:
|
||||
{
|
||||
const auto* sphere = reinterpret_cast<SHBoundingSphere*>(collider->GetShape());
|
||||
rp3d::SphereShape* newSphere = factory->createSphereShape(sphere->GetWorldRadius());
|
||||
const auto* SPHERE = reinterpret_cast<const SHBoundingSphere*>(collider->GetShape());
|
||||
rp3d::SphereShape* newSphere = factory->createSphereShape(SPHERE->GetWorldRadius());
|
||||
|
||||
rp3dBody->addCollider(newSphere, OFFSETS);
|
||||
break;
|
||||
|
@ -190,19 +190,19 @@ namespace SHADE
|
|||
{
|
||||
case SHCollisionShape::Type::BOX:
|
||||
{
|
||||
const auto* box = reinterpret_cast<SHBoundingBox*>(collider.GetShape());
|
||||
const auto* BOX = reinterpret_cast<const SHBoundingBox*>(collider.GetShape());
|
||||
|
||||
auto* rp3dBoxShape = reinterpret_cast<rp3d::BoxShape*>(rp3dCollider->getCollisionShape());
|
||||
rp3dBoxShape->setHalfExtents(box->GetWorldExtents());
|
||||
rp3dBoxShape->setHalfExtents(BOX->GetWorldExtents());
|
||||
|
||||
break;
|
||||
}
|
||||
case SHCollisionShape::Type::SPHERE:
|
||||
{
|
||||
const auto* sphere = reinterpret_cast<SHBoundingSphere*>(collider.GetShape());
|
||||
const auto* SPHERE = reinterpret_cast<const SHBoundingSphere*>(collider.GetShape());
|
||||
|
||||
auto* rp3dSphereShape = reinterpret_cast<rp3d::SphereShape*>(rp3dCollider->getCollisionShape());
|
||||
rp3dSphereShape->setRadius(sphere->GetWorldRadius());
|
||||
rp3dSphereShape->setRadius(SPHERE->GetWorldRadius());
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ namespace SHADE
|
|||
|
||||
SHPhysicsSystem::SHPhysicsSystem()
|
||||
: worldUpdated { false }
|
||||
, debugDrawFlags { 0 }
|
||||
, interpolationFactor { 0.0 }
|
||||
, fixedDT { 60.0 }
|
||||
, world { nullptr }
|
||||
|
@ -50,11 +49,6 @@ namespace SHADE
|
|||
: SHSystemRoutine { "Physics PostUpdate", false }
|
||||
{}
|
||||
|
||||
SHPhysicsSystem::PhysicsDebugDraw::PhysicsDebugDraw()
|
||||
: SHSystemRoutine { "Physics DebugDraw", true }
|
||||
{}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Getter Function Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -107,29 +101,9 @@ namespace SHADE
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool SHPhysicsSystem::GetDrawColliders() const noexcept
|
||||
const SHPhysicsSystem::EntityObjectMap& SHPhysicsSystem::GetPhysicsObjects() const noexcept
|
||||
{
|
||||
return debugDrawFlags & SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER);
|
||||
}
|
||||
|
||||
bool SHPhysicsSystem::GetDrawColliderAABBs() const noexcept
|
||||
{
|
||||
return debugDrawFlags & SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER_AABB);
|
||||
}
|
||||
|
||||
bool SHPhysicsSystem::GetDrawBroadPhase() const noexcept
|
||||
{
|
||||
return debugDrawFlags & SHUtilities::ConvertEnum(DebugDrawFlags::BROAD_PHASE_AABB);
|
||||
}
|
||||
|
||||
bool SHPhysicsSystem::GetDrawContactPoints() const noexcept
|
||||
{
|
||||
return debugDrawFlags & SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_POINTS);
|
||||
}
|
||||
|
||||
bool SHPhysicsSystem::GetDrawContactNormals() const noexcept
|
||||
{
|
||||
return debugDrawFlags & SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_NORMALS);
|
||||
return map;
|
||||
}
|
||||
|
||||
const SHPhysicsSystem::CollisionEvents& SHPhysicsSystem::GetCollisionInfo() const noexcept
|
||||
|
@ -214,96 +188,6 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::SetDrawColliders(bool shouldDraw) noexcept
|
||||
{
|
||||
static constexpr auto FLAG_VALUE = SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER);
|
||||
shouldDraw ? debugDrawFlags |= FLAG_VALUE : debugDrawFlags &= ~(FLAG_VALUE);
|
||||
|
||||
if (world == nullptr)
|
||||
{
|
||||
SHLOGV_WARNING("No physics world has been initialised!")
|
||||
return;
|
||||
}
|
||||
|
||||
world->getDebugRenderer().setIsDebugItemDisplayed
|
||||
(
|
||||
rp3d::DebugRenderer::DebugItem::COLLISION_SHAPE,
|
||||
shouldDraw
|
||||
);
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::SetDrawColliderAABBs(bool shouldDraw) noexcept
|
||||
{
|
||||
static constexpr auto FLAG_VALUE = SHUtilities::ConvertEnum(DebugDrawFlags::COLLIDER_AABB);
|
||||
shouldDraw ? debugDrawFlags |= FLAG_VALUE : debugDrawFlags &= ~(FLAG_VALUE);
|
||||
|
||||
if (world == nullptr)
|
||||
{
|
||||
SHLOGV_WARNING("No physics world has been initialised!")
|
||||
return;
|
||||
}
|
||||
|
||||
world->getDebugRenderer().setIsDebugItemDisplayed
|
||||
(
|
||||
rp3d::DebugRenderer::DebugItem::COLLIDER_AABB,
|
||||
shouldDraw
|
||||
);
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::SetDrawBroadPhase(bool shouldDraw) noexcept
|
||||
{
|
||||
static constexpr auto FLAG_VALUE = SHUtilities::ConvertEnum(DebugDrawFlags::BROAD_PHASE_AABB);
|
||||
shouldDraw ? debugDrawFlags |= FLAG_VALUE : debugDrawFlags &= ~(FLAG_VALUE);
|
||||
|
||||
if (world == nullptr)
|
||||
{
|
||||
SHLOGV_WARNING("No physics world has been initialised!")
|
||||
return;
|
||||
}
|
||||
|
||||
world->getDebugRenderer().setIsDebugItemDisplayed
|
||||
(
|
||||
rp3d::DebugRenderer::DebugItem::COLLIDER_BROADPHASE_AABB,
|
||||
shouldDraw
|
||||
);
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::SetDrawContactPoints(bool shouldDraw) noexcept
|
||||
{
|
||||
static constexpr auto FLAG_VALUE = SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_POINTS);
|
||||
shouldDraw ? debugDrawFlags |= FLAG_VALUE : debugDrawFlags &= ~(FLAG_VALUE);
|
||||
|
||||
if (world == nullptr)
|
||||
{
|
||||
SHLOGV_WARNING("No physics world has been initialised!")
|
||||
return;
|
||||
}
|
||||
|
||||
world->getDebugRenderer().setIsDebugItemDisplayed
|
||||
(
|
||||
rp3d::DebugRenderer::DebugItem::CONTACT_POINT,
|
||||
shouldDraw
|
||||
);
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::SetDrawContactNormals(bool shouldDraw) noexcept
|
||||
{
|
||||
static constexpr auto FLAG_VALUE = SHUtilities::ConvertEnum(DebugDrawFlags::CONTACT_NORMALS);
|
||||
shouldDraw ? debugDrawFlags |= FLAG_VALUE : debugDrawFlags &= ~(FLAG_VALUE);
|
||||
|
||||
if (world == nullptr)
|
||||
{
|
||||
SHLOGV_WARNING("No physics world has been initialised!")
|
||||
return;
|
||||
}
|
||||
|
||||
world->getDebugRenderer().setIsDebugItemDisplayed
|
||||
(
|
||||
rp3d::DebugRenderer::DebugItem::CONTACT_NORMAL,
|
||||
shouldDraw
|
||||
);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Public Function Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -497,40 +381,6 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::PhysicsDebugDraw::Execute(double) noexcept
|
||||
{
|
||||
const auto* PHYSICS_SYSTEM = reinterpret_cast<SHPhysicsSystem*>(GetSystem());
|
||||
if (PHYSICS_SYSTEM->debugDrawFlags == 0)
|
||||
return;
|
||||
|
||||
auto* debugDrawSystem = SHSystemManager::GetSystem<SHDebugDrawSystem>();
|
||||
if (debugDrawSystem == nullptr)
|
||||
{
|
||||
SHLOGV_ERROR("Unable to debug draw physics objects due to missing SHDebugDrawSystem!");
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& RP3D_DEBUG_RENDERER = PHYSICS_SYSTEM->world->getDebugRenderer();
|
||||
|
||||
const auto& LINES = RP3D_DEBUG_RENDERER.getLines();
|
||||
const auto& TRIANGLES = RP3D_DEBUG_RENDERER.getTriangles();
|
||||
|
||||
// Draw all lines
|
||||
for (uint32_t i = 0; i < RP3D_DEBUG_RENDERER.getNbLines(); ++i)
|
||||
{
|
||||
const auto& LINE = LINES[i];
|
||||
debugDrawSystem->DrawLine(SHColour{ LINE.color1 }, LINE.point1, LINE.point2);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < RP3D_DEBUG_RENDERER.getNbTriangles(); ++i)
|
||||
{
|
||||
const auto& TRIANGLE = TRIANGLES[i];
|
||||
SHColour triColour{ TRIANGLE.color1 };
|
||||
triColour.a() = 1.0f;
|
||||
debugDrawSystem->DrawTri(triColour, TRIANGLE.point1, TRIANGLE.point2, TRIANGLE.point3);
|
||||
}
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::onContact(const CallbackData& callbackData)
|
||||
{
|
||||
for (uint32_t i = 0; i < callbackData.getNbContactPairs(); ++i)
|
||||
|
|
|
@ -36,11 +36,21 @@ namespace SHADE
|
|||
class SH_API SHPhysicsSystem final : public SHSystem
|
||||
, public rp3d::EventListener
|
||||
{
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Friends */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
friend class SHPhysicsDebugDrawSystem;
|
||||
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
using CollisionEvents = std::vector<SHCollisionEvent>;
|
||||
using EntityObjectMap = std::unordered_map<EntityID, SHPhysicsObject>;
|
||||
|
||||
struct WorldSettings
|
||||
{
|
||||
SHVec3 gravity;
|
||||
|
@ -49,17 +59,6 @@ namespace SHADE
|
|||
bool sleepingEnabled;
|
||||
};
|
||||
|
||||
using CollisionEvents = std::vector<SHCollisionEvent>;
|
||||
|
||||
enum class DebugDrawFlags : uint8_t
|
||||
{
|
||||
COLLIDER = 1
|
||||
, COLLIDER_AABB = 2
|
||||
, BROAD_PHASE_AABB = 4
|
||||
, CONTACT_POINTS = 8
|
||||
, CONTACT_NORMALS = 16
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -70,23 +69,17 @@ namespace SHADE
|
|||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
[[nodiscard]] double GetFixedDT () const noexcept;
|
||||
[[nodiscard]] double GetFixedDT () const noexcept;
|
||||
|
||||
[[nodiscard]] bool IsSleepingEnabled () const noexcept;
|
||||
[[nodiscard]] bool IsSleepingEnabled () const noexcept;
|
||||
|
||||
[[nodiscard]] SHVec3 GetWorldGravity () const noexcept;
|
||||
[[nodiscard]] uint16_t GetNumberVelocityIterations () const noexcept;
|
||||
[[nodiscard]] uint16_t GetNumberPositionIterations () const noexcept;
|
||||
[[nodiscard]] SHVec3 GetWorldGravity () const noexcept;
|
||||
[[nodiscard]] uint16_t GetNumberVelocityIterations () const noexcept;
|
||||
[[nodiscard]] uint16_t GetNumberPositionIterations () const noexcept;
|
||||
|
||||
[[nodiscard]] bool GetDrawColliders () const noexcept;
|
||||
[[nodiscard]] bool GetDrawColliderAABBs () const noexcept;
|
||||
[[nodiscard]] bool GetDrawBroadPhase () const noexcept;
|
||||
[[nodiscard]] bool GetDrawContactPoints () const noexcept;
|
||||
[[nodiscard]] bool GetDrawContactNormals () const noexcept;
|
||||
|
||||
[[nodiscard]] const CollisionEvents& GetCollisionInfo () const noexcept;
|
||||
[[nodiscard]] const CollisionEvents& GetTriggerInfo () const noexcept;
|
||||
|
||||
[[nodiscard]] const EntityObjectMap& GetPhysicsObjects () const noexcept;
|
||||
[[nodiscard]] const CollisionEvents& GetCollisionInfo () const noexcept;
|
||||
[[nodiscard]] const CollisionEvents& GetTriggerInfo () const noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Setter Functions */
|
||||
|
@ -100,13 +93,6 @@ namespace SHADE
|
|||
|
||||
void SetWorldSettings (const WorldSettings& settings) const noexcept;
|
||||
|
||||
// TODO(Diren): Can the debug draw flags be done through an enum?
|
||||
void SetDrawColliders (bool shouldDraw) noexcept;
|
||||
void SetDrawColliderAABBs (bool shouldDraw) noexcept;
|
||||
void SetDrawBroadPhase (bool shouldDraw) noexcept;
|
||||
void SetDrawContactPoints (bool shouldDraw) noexcept;
|
||||
void SetDrawContactNormals (bool shouldDraw) noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Function Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -127,47 +113,57 @@ namespace SHADE
|
|||
class SH_API PhysicsPreUpdate final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
|
||||
PhysicsPreUpdate();
|
||||
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Function Members */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
|
||||
void Execute(double dt) noexcept override;
|
||||
};
|
||||
|
||||
class SH_API PhysicsFixedUpdate final : public SHFixedSystemRoutine
|
||||
{
|
||||
public:
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
|
||||
PhysicsFixedUpdate();
|
||||
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Function Members */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
|
||||
void Execute (double dt) noexcept override;
|
||||
};
|
||||
|
||||
class SH_API PhysicsPostUpdate final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Constructors & Destructor */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
|
||||
PhysicsPostUpdate();
|
||||
void Execute(double dt) noexcept override;
|
||||
};
|
||||
|
||||
class SH_API PhysicsDebugDraw final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
PhysicsDebugDraw();
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Function Members */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
|
||||
void Execute(double dt) noexcept override;
|
||||
};
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
using EntityObjectMap = std::unordered_map<EntityID, SHPhysicsObject>;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
bool worldUpdated;
|
||||
uint8_t debugDrawFlags;
|
||||
|
||||
double interpolationFactor;
|
||||
double fixedDT;
|
||||
|
|
|
@ -130,14 +130,14 @@ namespace YAML
|
|||
{
|
||||
case SHCollisionShape::Type::BOX:
|
||||
{
|
||||
auto const bb = reinterpret_cast<SHBoundingBox*>(rhs.GetShape());
|
||||
node[HalfExtents] = bb->GetRelativeExtents();
|
||||
const auto* BOX = reinterpret_cast<const SHBoundingBox*>(rhs.GetShape());
|
||||
node[HalfExtents] = BOX->GetRelativeExtents();
|
||||
}
|
||||
break;
|
||||
case SHCollisionShape::Type::SPHERE:
|
||||
{
|
||||
auto const bs = reinterpret_cast<SHBoundingSphere*>(rhs.GetShape());
|
||||
node[Radius] = bs->GetRelativeRadius();
|
||||
const auto* SPHERE = reinterpret_cast<const SHBoundingSphere*>(rhs.GetShape());
|
||||
node[Radius] = SPHERE->GetRelativeRadius();
|
||||
}
|
||||
break;
|
||||
case SHCollisionShape::Type::CAPSULE: break;
|
||||
|
|
|
@ -35,22 +35,12 @@ namespace SHADE
|
|||
/**
|
||||
* @brief Converts an enum class member from it's type to any other type.
|
||||
* @tparam InputType Restricted to an enum class
|
||||
* @tparam OutputType The type to convert the enum class member to. Defaults to int.
|
||||
* @tparam OutputType The type to convert the enum class member to. Defaults to the underlying type.
|
||||
* @param[in] enumClassMember A member of the specified enum class.
|
||||
* @returns The value of the enum class member in the output type.
|
||||
*/
|
||||
template <IsEnum InputType, IsIntegral OutputType = std::underlying_type_t<InputType>>
|
||||
static constexpr OutputType ConvertEnum(InputType enumClassMember) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Converts an enum class member from it's type to the underlying type.
|
||||
* @tparam Enum Restricted to an enum class
|
||||
* @param[in] value A member of the specified enum class.
|
||||
* @returns The value of the enum class member in the output type.
|
||||
*/
|
||||
template<typename Enum>
|
||||
static constexpr typename std::underlying_type_t<Enum> ToUnderlying (Enum value) noexcept;
|
||||
|
||||
};
|
||||
|
||||
} // namespace SHADE
|
||||
|
|
|
@ -24,11 +24,4 @@ namespace SHADE
|
|||
{
|
||||
return static_cast<OutputType>(enumClassMember);
|
||||
}
|
||||
|
||||
template<typename Enum>
|
||||
constexpr typename std::underlying_type_t<Enum> SHUtilities::ToUnderlying(Enum value) noexcept
|
||||
{
|
||||
return static_cast<typename std::underlying_type_t<Enum>>(value);
|
||||
}
|
||||
|
||||
} // namespace SHADE
|
Loading…
Reference in New Issue