Added Capsule Collider, AABB Query & SimulateBody for Trajectory path prediction #402
|
@ -25,6 +25,7 @@
|
|||
#include "Serialization/SHSerialization.h"
|
||||
#include "Serialization/Configurations/SHConfigurationManager.h"
|
||||
#include "Editor/EditorWindow/SHEditorWindowManager.h"
|
||||
#include "Physics/System/SHPhysicsSystem.h"
|
||||
#include "Physics/System/SHPhysicsDebugDrawSystem.h"
|
||||
#include "Camera/SHCameraSystem.h"
|
||||
#include "Tools/Utilities/SHClipboardUtilities.h"
|
||||
|
@ -359,21 +360,63 @@ namespace SHADE
|
|||
{
|
||||
if (ImGui::BeginMenu("Physics Settings"))
|
||||
{
|
||||
if (auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>())
|
||||
{
|
||||
SHEditorWidgets::DragVec3
|
||||
(
|
||||
"Gravity", { "X", "Y", "Z" },
|
||||
[physicsSystem] {return physicsSystem->GetGravity(); },
|
||||
[physicsSystem](SHVec3 const& value) { physicsSystem->SetGravity(value); }
|
||||
, false, "Global Gravity", 0.1f, "%.3f", 0.0f, 0.0f
|
||||
);
|
||||
|
||||
SHEditorWidgets::SliderScalar<uint16_t>
|
||||
(
|
||||
"Velocity Iterations", ImGuiDataType_U16, (uint16_t)1, (uint16_t)32,
|
||||
[physicsSystem] { return physicsSystem->GetNumVelocityIterations(); },
|
||||
[physicsSystem](uint16_t value) { physicsSystem->SetNumVelocityIterations(value); },
|
||||
"Number of times velocity is solved per collision. Higher values increase precision at the cost of performance.",
|
||||
"%zu"
|
||||
);
|
||||
|
||||
SHEditorWidgets::SliderScalar<uint16_t>
|
||||
(
|
||||
"Position Iterations", ImGuiDataType_U16, (uint16_t)1, (uint16_t)32,
|
||||
[physicsSystem] { return physicsSystem->GetNumPositionIterations(); },
|
||||
[physicsSystem](uint16_t value) { physicsSystem->SetNumPositionIterations(value); },
|
||||
"Number of times position is solved per collision. Higher values increase precision at the cost of performance.",
|
||||
"%zu"
|
||||
);
|
||||
|
||||
SHEditorWidgets::CheckBox
|
||||
(
|
||||
"Sleeping Enabled",
|
||||
[physicsSystem] { return physicsSystem->IsSleepingEnabled(); },
|
||||
[physicsSystem](bool value) { physicsSystem->EnableSleeping(value); },
|
||||
"If bodies are allowed to sleep. Sleeping increases performance of the simulation and should be left enabled."
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
if(ImGui::CollapsingHeader("Debug Draw", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
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 drawContactPoints = physicsDebugDraw->GetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::CONTACTS);
|
||||
if (ImGui::Checkbox("Draw Contact Points", &drawContactPoints))
|
||||
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::CONTACTS, drawContactPoints);
|
||||
|
||||
bool drawRays = physicsDebugDraw->GetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::RAYCASTS);
|
||||
if (ImGui::Checkbox("Draw Rays", &drawRays))
|
||||
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::RAYCASTS, drawRays);
|
||||
bool drawRays = physicsDebugDraw->GetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::RAYCASTS);
|
||||
if (ImGui::Checkbox("Draw Rays", &drawRays))
|
||||
physicsDebugDraw->SetFlagState(SHPhysicsDebugDrawSystem::DebugDrawFlags::RAYCASTS, drawRays);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,26 @@ namespace SHADE
|
|||
return collisionListener.GetTriggerInfoContainer();
|
||||
}
|
||||
|
||||
const SHVec3& SHPhysicsSystem::GetGravity() const noexcept
|
||||
{
|
||||
return worldState.settings.gravity;
|
||||
}
|
||||
|
||||
uint16_t SHPhysicsSystem::GetNumVelocityIterations() const noexcept
|
||||
{
|
||||
return worldState.settings.numVelocitySolverIterations;
|
||||
}
|
||||
|
||||
uint16_t SHPhysicsSystem::GetNumPositionIterations() const noexcept
|
||||
{
|
||||
return worldState.settings.numPositionSolverIterations;
|
||||
}
|
||||
|
||||
bool SHPhysicsSystem::IsSleepingEnabled() const noexcept
|
||||
{
|
||||
return worldState.settings.sleepingEnabled;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Setter Function Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -112,6 +132,30 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::SetGravity(const SHVec3& gravity) noexcept
|
||||
{
|
||||
worldState.settings.gravity = gravity;
|
||||
worldState.UpdateSettings();
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::SetNumVelocityIterations(uint16_t value) noexcept
|
||||
{
|
||||
worldState.settings.numVelocitySolverIterations = value;
|
||||
worldState.UpdateSettings();
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::SetNumPositionIterations(uint16_t value) noexcept
|
||||
{
|
||||
worldState.settings.numPositionSolverIterations = value;
|
||||
worldState.UpdateSettings();
|
||||
}
|
||||
|
||||
void SHPhysicsSystem::EnableSleeping(bool sleepingAllowed) noexcept
|
||||
{
|
||||
worldState.settings.sleepingEnabled = sleepingAllowed;
|
||||
worldState.UpdateSettings();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Public Function Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -57,18 +57,29 @@ 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<SHCollisionInfo>& GetAllTriggerInfo () const noexcept;
|
||||
[[nodiscard]] const std::vector<SHCollisionInfo>& GetAllCollisionInfo () const noexcept;
|
||||
[[nodiscard]] const std::vector<SHCollisionInfo>& GetAllTriggerInfo () const noexcept;
|
||||
[[nodiscard]] const std::vector<SHCollisionInfo>& GetAllCollisionInfo () const noexcept;
|
||||
|
||||
// World Settings
|
||||
[[nodiscard]] const SHVec3& GetGravity () const noexcept;
|
||||
[[nodiscard]] uint16_t GetNumVelocityIterations () const noexcept;
|
||||
[[nodiscard]] uint16_t GetNumPositionIterations () const noexcept;
|
||||
[[nodiscard]] bool IsSleepingEnabled () const noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Setter Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
void SetFixedUpdateRate (double fixedUpdateRate) noexcept;
|
||||
void SetFixedDT (double fixedDt) noexcept;
|
||||
void SetFixedUpdateRate (double fixedUpdateRate) noexcept;
|
||||
void SetFixedDT (double fixedDt) noexcept;
|
||||
|
||||
void SetGravity (const SHVec3& gravity) noexcept;
|
||||
void SetNumVelocityIterations (uint16_t value) noexcept;
|
||||
void SetNumPositionIterations (uint16_t value) noexcept;
|
||||
void EnableSleeping (bool sleepingAllowed) noexcept;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Function Members */
|
||||
|
|
|
@ -60,14 +60,7 @@ namespace SHADE
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
void SHPhysicsSystemInterface::SetFixedDT(double fixedDT) noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
physicsSystem->SetFixedDT(fixedDT);
|
||||
|
||||
SHLOGV_WARNING("Failed to set fixed delta time.");
|
||||
}
|
||||
|
||||
int SHPhysicsSystemInterface::GetFixedUpdateRate() noexcept
|
||||
{
|
||||
|
@ -79,6 +72,55 @@ namespace SHADE
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
SHVec3 SHPhysicsSystemInterface::GetGravity() noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
return physicsSystem->GetGravity();
|
||||
|
||||
SHLOGV_WARNING("Failed to get gravity. Zero Vec3 returned instead.");
|
||||
return SHVec3::Zero;
|
||||
}
|
||||
|
||||
uint16_t SHPhysicsSystemInterface::GetNumVelocityIterations() noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
return physicsSystem->GetNumVelocityIterations();
|
||||
|
||||
SHLOGV_WARNING("Failed to get number of velocity iterations. 0 returned instead.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t SHPhysicsSystemInterface::GetNumPositionIterations() noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
return physicsSystem->GetNumPositionIterations();
|
||||
|
||||
SHLOGV_WARNING("Failed to get number of position iterations. 0 returned instead.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool SHPhysicsSystemInterface::IsSleepingEnabled() noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
return physicsSystem->IsSleepingEnabled();
|
||||
|
||||
SHLOGV_WARNING("Failed to check if sleeping is enabled. False returned instead.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void SHPhysicsSystemInterface::SetFixedDT(double fixedDT) noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
physicsSystem->SetFixedDT(fixedDT);
|
||||
|
||||
SHLOGV_WARNING("Failed to set fixed delta time.");
|
||||
}
|
||||
|
||||
void SHPhysicsSystemInterface::SetFixedUpdateRate(double fixedUpdateRate) noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
|
@ -88,6 +130,41 @@ namespace SHADE
|
|||
SHLOGV_WARNING("Failed to set fixed update rate.");
|
||||
}
|
||||
|
||||
void SHPhysicsSystemInterface::SetGravity(const SHVec3& gravity) noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
return physicsSystem->SetGravity(gravity);
|
||||
|
||||
SHLOGV_WARNING("Failed to set gravity.");
|
||||
}
|
||||
|
||||
void SHPhysicsSystemInterface::SetNumVelocityIterations(uint16_t value) noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
return physicsSystem->SetNumVelocityIterations(value);
|
||||
|
||||
SHLOGV_WARNING("Failed to set number of velocity iterations.");
|
||||
}
|
||||
|
||||
void SHPhysicsSystemInterface::SetNumPositionIterations(uint16_t value) noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
return physicsSystem->SetNumPositionIterations(value);
|
||||
|
||||
SHLOGV_WARNING("Failed to set number of position iterations.");
|
||||
}
|
||||
|
||||
void SHPhysicsSystemInterface::EnableSleeping(bool sleepingAllowed) noexcept
|
||||
{
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
if (physicsSystem)
|
||||
return physicsSystem->EnableSleeping(sleepingAllowed);
|
||||
|
||||
SHLOGV_WARNING("Failed to set global sleeping state.");
|
||||
}
|
||||
|
||||
const std::vector<SHPhysicsRaycastResult>& SHPhysicsSystemInterface::Raycast(const RaycastInfo& info) noexcept
|
||||
{
|
||||
|
|
|
@ -90,13 +90,23 @@ namespace SHADE
|
|||
/* Static Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetCollisionInfo () noexcept;
|
||||
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetTriggerInfo () noexcept;
|
||||
[[nodiscard]] static double GetFixedDT () noexcept;
|
||||
[[nodiscard]] static void SetFixedDT (double fixedDT) noexcept;
|
||||
[[nodiscard]] static int GetFixedUpdateRate () noexcept;
|
||||
[[nodiscard]] static void SetFixedUpdateRate (double fixedUpdateRate) noexcept;
|
||||
[[nodiscard]] static const std::vector<SHPhysicsRaycastResult>& Raycast (const RaycastInfo& info) noexcept;
|
||||
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetCollisionInfo () noexcept;
|
||||
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetTriggerInfo () noexcept;
|
||||
[[nodiscard]] static double GetFixedDT () noexcept;
|
||||
[[nodiscard]] static int GetFixedUpdateRate () noexcept;
|
||||
[[nodiscard]] static SHVec3 GetGravity () noexcept;
|
||||
[[nodiscard]] static uint16_t GetNumVelocityIterations () noexcept;
|
||||
[[nodiscard]] static uint16_t GetNumPositionIterations () noexcept;
|
||||
[[nodiscard]] static bool IsSleepingEnabled () noexcept;
|
||||
|
||||
static void SetFixedDT (double fixedDT) noexcept;
|
||||
static void SetFixedUpdateRate (double fixedUpdateRate) noexcept;
|
||||
static void SetGravity (const SHVec3& gravity) noexcept;
|
||||
static void SetNumVelocityIterations (uint16_t value) noexcept;
|
||||
static void SetNumPositionIterations (uint16_t value) noexcept;
|
||||
static void EnableSleeping (bool sleepingAllowed) noexcept;
|
||||
|
||||
[[nodiscard]] static const std::vector<SHPhysicsRaycastResult>& Raycast (const RaycastInfo& info) noexcept;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
@ -31,14 +31,42 @@ namespace SHADE
|
|||
|
||||
Vector3 Physics::Gravity::get()
|
||||
{
|
||||
// TODO(Diren)
|
||||
|
||||
return Vector3::Zero;
|
||||
return Convert::ToCLI(SHPhysicsSystemInterface::GetGravity());
|
||||
}
|
||||
|
||||
void Physics::Gravity::set(Vector3 value)
|
||||
{
|
||||
(void)value;
|
||||
SHPhysicsSystemInterface::SetGravity(Convert::ToNative(value));
|
||||
}
|
||||
|
||||
uint16_t Physics::VelocityIterations::get()
|
||||
{
|
||||
return SHPhysicsSystemInterface::GetNumVelocityIterations();
|
||||
}
|
||||
|
||||
void Physics::VelocityIterations::set(uint16_t value)
|
||||
{
|
||||
SHPhysicsSystemInterface::SetNumVelocityIterations(value);
|
||||
}
|
||||
|
||||
uint16_t Physics::PositionIterations::get()
|
||||
{
|
||||
return SHPhysicsSystemInterface::GetNumPositionIterations();
|
||||
}
|
||||
|
||||
void Physics::PositionIterations::set(uint16_t value)
|
||||
{
|
||||
SHPhysicsSystemInterface::SetNumPositionIterations(value);
|
||||
}
|
||||
|
||||
bool Physics::SleepingEnabled::get()
|
||||
{
|
||||
return SHPhysicsSystemInterface::IsSleepingEnabled();
|
||||
}
|
||||
|
||||
void Physics::SleepingEnabled::set(bool value)
|
||||
{
|
||||
SHPhysicsSystemInterface::EnableSleeping(value);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -33,7 +33,23 @@ namespace SHADE
|
|||
void set(Vector3 value);
|
||||
}
|
||||
|
||||
// TODO(Diren): Add more properties for physics system settings.
|
||||
static property uint16_t VelocityIterations
|
||||
{
|
||||
uint16_t get();
|
||||
void set(uint16_t value);
|
||||
}
|
||||
|
||||
static property uint16_t PositionIterations
|
||||
{
|
||||
uint16_t get();
|
||||
void set(uint16_t value);
|
||||
}
|
||||
|
||||
static property bool SleepingEnabled
|
||||
{
|
||||
bool get();
|
||||
void set(bool value);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Raycast Function Members */
|
||||
|
|
Loading…
Reference in New Issue