Implemented a custom physics engine #316
|
@ -4,7 +4,7 @@
|
|||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0, y: 3, z: 0}
|
||||
Translate: {x: 0.0700113177, y: 2.5, z: 0}
|
||||
Rotate: {x: -0, y: 0, z: -0}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
IsActive: true
|
||||
|
@ -19,14 +19,14 @@
|
|||
Interpolate: true
|
||||
Sleeping Enabled: true
|
||||
Freeze Position X: false
|
||||
Freeze Position Y: true
|
||||
Freeze Position Y: false
|
||||
Freeze Position Z: false
|
||||
Freeze Rotation X: false
|
||||
Freeze Rotation Y: false
|
||||
Freeze Rotation Z: false
|
||||
IsActive: true
|
||||
Collider Component:
|
||||
DrawColliders: true
|
||||
DrawColliders: false
|
||||
Colliders:
|
||||
- Is Trigger: false
|
||||
Type: Sphere
|
||||
|
@ -65,8 +65,8 @@
|
|||
NumberOfChildren: 0
|
||||
Components:
|
||||
Transform Component:
|
||||
Translate: {x: 0, y: -2.5, z: 0}
|
||||
Rotate: {x: 0, y: 0, z: 0}
|
||||
Translate: {x: 0, y: 0, z: 0}
|
||||
Rotate: {x: -0, y: 0, z: -0}
|
||||
Scale: {x: 1, y: 1, z: 1}
|
||||
IsActive: true
|
||||
RigidBody Component:
|
||||
|
@ -87,11 +87,11 @@
|
|||
Freeze Rotation Z: false
|
||||
IsActive: true
|
||||
Collider Component:
|
||||
DrawColliders: true
|
||||
DrawColliders: false
|
||||
Colliders:
|
||||
- Is Trigger: false
|
||||
Type: Sphere
|
||||
Radius: 5
|
||||
Radius: 2.5
|
||||
Friction: 0.400000006
|
||||
Bounciness: 0
|
||||
Density: 1
|
||||
|
@ -127,7 +127,7 @@
|
|||
Freeze Rotation Z: false
|
||||
IsActive: true
|
||||
Collider Component:
|
||||
DrawColliders: true
|
||||
DrawColliders: false
|
||||
Colliders:
|
||||
- Is Trigger: false
|
||||
Type: Sphere
|
||||
|
|
|
@ -185,12 +185,6 @@ namespace Sandbox
|
|||
#endif
|
||||
SHSceneManager::SceneUpdate(0.016f);
|
||||
#ifdef SHEDITOR
|
||||
static bool drawBP = false;
|
||||
if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::RIGHT_CTRL))
|
||||
{
|
||||
drawBP = !drawBP;
|
||||
SHSystemManager::GetSystem<SHPhysicsDebugDrawSystem>()->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::BROADPHASE, drawBP);
|
||||
}
|
||||
|
||||
SHSystemManager::RunRoutines(editor->editorState != SHEditor::State::PLAY, SHFrameRateController::GetRawDeltaTime());
|
||||
editor->PollPicking();
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "Serialization/SHSerialization.h"
|
||||
#include "Serialization/Configurations/SHConfigurationManager.h"
|
||||
#include "Editor/EditorWindow/SHEditorWindowManager.h"
|
||||
#include "Physics/System/SHPhysicsDebugDrawSystem.h"
|
||||
|
||||
const std::string LAYOUT_FOLDER_PATH{ std::string(ASSET_ROOT) + "/Editor/Layouts" };
|
||||
|
||||
|
@ -202,6 +203,26 @@ namespace SHADE
|
|||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("Physics Settings"))
|
||||
{
|
||||
if (auto* physicsDebugDraw = SHSystemManager::GetSystem<SHPhysicsDebugDrawSystem>())
|
||||
{
|
||||
bool drawColliders = physicsDebugDraw->GetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::COLLIDERS);
|
||||
if (ImGui::Checkbox("Draw Colliders", &drawColliders))
|
||||
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::COLLIDERS, drawColliders);
|
||||
|
||||
bool drawContactPoints = physicsDebugDraw->GetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::CONTACTS);
|
||||
if (ImGui::Checkbox("Draw Contact Points", &drawContactPoints))
|
||||
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::CONTACTS, drawContactPoints);
|
||||
|
||||
bool drawBroadphase = physicsDebugDraw->GetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::BROADPHASE);
|
||||
if (ImGui::Checkbox("Draw Broadphase", &drawBroadphase))
|
||||
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::BROADPHASE, drawBroadphase);
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,11 @@ namespace SHADE
|
|||
/* Getter Functions Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
const SHContactManager::ContactPoints& SHPhysicsWorld::GetContactPoints() const noexcept
|
||||
{
|
||||
return contactManager.GetContactPoints();
|
||||
}
|
||||
|
||||
const SHContactManager::TriggerEvents& SHPhysicsWorld::GetTriggerEvents() const noexcept
|
||||
{
|
||||
return contactManager.GetTriggerEvents();
|
||||
|
|
|
@ -72,6 +72,7 @@ namespace SHADE
|
|||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
const SHContactManager::ContactPoints& GetContactPoints () const noexcept;
|
||||
const SHContactManager::TriggerEvents& GetTriggerEvents () const noexcept;
|
||||
const SHContactManager::CollisionEvents& GetCollisionEvents () const noexcept;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace SHADE
|
|||
{
|
||||
auto* physicsDebugDrawSystem = reinterpret_cast<SHPhysicsDebugDrawSystem*>(GetSystem());
|
||||
|
||||
if (!physicsDebugDrawSystem->GetFlagState(DebugDrawFlags::ACTIVE))
|
||||
if (!physicsDebugDrawSystem->IsDebugDrawActive())
|
||||
return;
|
||||
|
||||
auto* debugDrawSystem = SHSystemManager::GetSystem<SHDebugDrawSystem>();
|
||||
|
@ -74,7 +74,14 @@ namespace SHADE
|
|||
|
||||
if (DRAW_CONTACTS)
|
||||
{
|
||||
// TODO
|
||||
const SHColour& CONTACT_COLOUR = physicsDebugDrawSystem->DEBUG_DRAW_COLOURS[SHUtilities::ConvertEnum(Colours::CONTACT)];
|
||||
|
||||
const auto& CONTACT_POINTS = physicsSystem->physicsWorld->GetContactPoints();
|
||||
for (auto& contactPoint : CONTACT_POINTS)
|
||||
{
|
||||
const SHMatrix TRS = SHMatrix::Transform(contactPoint, SHQuaternion::Identity, SHVec3{ 0.1f });
|
||||
debugDrawSystem->DrawCube(TRS, CONTACT_COLOUR);
|
||||
}
|
||||
}
|
||||
|
||||
if (DRAW_RAYCASTS)
|
||||
|
|
|
@ -44,6 +44,11 @@ namespace SHADE
|
|||
/* Getter Function Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
||||
bool SHPhysicsDebugDrawSystem::IsDebugDrawActive() const noexcept
|
||||
{
|
||||
return flags & ACTIVE_FLAG;
|
||||
}
|
||||
|
||||
bool SHPhysicsDebugDrawSystem::GetFlagState(DebugDrawFlags flag) const noexcept
|
||||
{
|
||||
const uint8_t ENUM_VALUE = SHUtilities::ConvertEnum(flag);
|
||||
|
@ -58,6 +63,10 @@ namespace SHADE
|
|||
{
|
||||
const uint8_t ENUM_VALUE = SHUtilities::ConvertEnum(flag);
|
||||
state ? flags |= ENUM_VALUE : flags &= ~ENUM_VALUE;
|
||||
|
||||
// If no other debug drawing state is active, turn active off. Otherwise, we maintain
|
||||
// the active state.
|
||||
flags == ACTIVE_FLAG ? flags = 0 : flags |= ACTIVE_FLAG;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -97,7 +106,7 @@ namespace SHADE
|
|||
if (EVENT_DATA->debugDrawState)
|
||||
{
|
||||
if (collidersToDraw.empty())
|
||||
SetFlagState(DebugDrawFlags::ACTIVE, true);
|
||||
flags |= ACTIVE_FLAG;
|
||||
|
||||
collidersToDraw.emplace(EVENT_DATA->entityID);
|
||||
}
|
||||
|
@ -105,8 +114,9 @@ namespace SHADE
|
|||
{
|
||||
collidersToDraw.erase(EVENT_DATA->entityID);
|
||||
|
||||
if (collidersToDraw.empty())
|
||||
SetFlagState(DebugDrawFlags::ACTIVE, false);
|
||||
// if no colliders queued for drawing and no other debug drawing is enabled, disable debug drawing
|
||||
if (collidersToDraw.empty() && flags == ACTIVE_FLAG)
|
||||
flags = 0;
|
||||
}
|
||||
|
||||
return onColliderDrawEvent.get()->handle;
|
||||
|
|
|
@ -35,11 +35,10 @@ namespace SHADE
|
|||
|
||||
enum class DebugDrawFlags : uint8_t
|
||||
{
|
||||
ACTIVE = 0x0001
|
||||
, COLLIDERS = 0x0002
|
||||
, CONTACTS = 0x0004
|
||||
, RAYCASTS = 0x0008
|
||||
, BROADPHASE = 0x0010
|
||||
COLLIDERS = 0x02
|
||||
, CONTACTS = 0x04
|
||||
, RAYCASTS = 0x08
|
||||
, BROADPHASE = 0x10
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -53,7 +52,8 @@ namespace SHADE
|
|||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
[[nodiscard]] bool GetFlagState (DebugDrawFlags flag) const noexcept;
|
||||
[[nodiscard]] bool IsDebugDrawActive () const noexcept;
|
||||
[[nodiscard]] bool GetFlagState (DebugDrawFlags flag) const noexcept;
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Setter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
@ -64,10 +64,10 @@ namespace SHADE
|
|||
/* Member Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
void Init () override;
|
||||
void Exit () override;
|
||||
void Init () override;
|
||||
void Exit () override;
|
||||
|
||||
void AddRaycast (const SHRay& ray, const SHPhysicsRaycastResult& result) noexcept;
|
||||
void AddRaycast (const SHRay& ray, const SHPhysicsRaycastResult& result) noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* System Routines */
|
||||
|
@ -123,6 +123,8 @@ namespace SHADE
|
|||
/* Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
static constexpr uint8_t ACTIVE_FLAG = 0x01;
|
||||
|
||||
static const SHColour DEBUG_DRAW_COLOURS[static_cast<int>(Colours::COUNT)];
|
||||
|
||||
// 0 0 0 drawBroadphase drawRaycasts drawContacts drawAllColliders debugDrawActive
|
||||
|
|
|
@ -52,8 +52,11 @@ namespace SHADE
|
|||
/* Getter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
[[nodiscard]] double GetFixedUpdateRate() const noexcept;
|
||||
[[nodiscard]] double GetFixedDT () const noexcept;
|
||||
[[nodiscard]] double GetFixedUpdateRate() const noexcept;
|
||||
[[nodiscard]] double GetFixedDT () const noexcept;
|
||||
|
||||
[[nodiscard]] const std::vector<SHTriggerEvent>& GetTriggerInfo () const noexcept;
|
||||
[[nodiscard]] const std::vector<SHCollisionEvent>& GetCollisionInfo () const noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Setter Functions */
|
||||
|
@ -62,9 +65,6 @@ namespace SHADE
|
|||
void SetFixedUpdateRate(double fixedUpdateRate) noexcept;
|
||||
void SetFixedDT(double fixedDt) noexcept;
|
||||
|
||||
const std::vector<SHTriggerEvent>& GetTriggerInfo () const noexcept;
|
||||
const std::vector<SHCollisionEvent>& GetCollisionInfo () const noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Member Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Reference in New Issue