Added physics constants

This commit is contained in:
Diren D Bharwani 2023-03-06 18:17:13 +08:00
parent 8506298fd3
commit e89f5df35f
8 changed files with 54 additions and 33 deletions

View File

@ -11,7 +11,7 @@
#include <SHpch.h> #include <SHpch.h>
// Primary Header // Primary Header
#include "SHPhysicsWorld.h" #include "SHPhysicsWorldState.h"
namespace SHADE namespace SHADE
{ {

View File

@ -1,7 +1,7 @@
/**************************************************************************************** /****************************************************************************************
* \file SHPhysicsWorld.h * \file SHPhysicsWorldState.h
* \author Diren D Bharwani, diren.dbharwani, 390002520 * \author Diren D Bharwani, diren.dbharwani, 390002520
* \brief Interface for a Physics World. * \brief Interface for a Physics World State.
* *
* \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or * \copyright Copyright (C) 2022 DigiPen Institute of Technology. Reproduction or
* disclosure of this file or its contents without the prior written consent * disclosure of this file or its contents without the prior written consent
@ -14,6 +14,7 @@
// Project Headers // Project Headers
#include "Math/Vector/SHVec3.h" #include "Math/Vector/SHVec3.h"
#include "Physics/SHPhysicsConstants.h"
namespace SHADE namespace SHADE
{ {
@ -37,8 +38,8 @@ namespace SHADE
/*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/
SHVec3 gravity = SHVec3{ 0.0f, -9.81f, 0.0f }; SHVec3 gravity = SHVec3{ 0.0f, -9.81f, 0.0f };
uint16_t numVelocitySolverIterations = 10; uint16_t numVelocitySolverIterations = SHPhysicsConstants::DEFAULT_VELOCITY_ITERATIONS;
uint16_t numPositionSolverIterations = 5; uint16_t numPositionSolverIterations = SHPhysicsConstants::DEFAULT_POSITION_ITERATIONS;
bool sleepingEnabled = true; bool sleepingEnabled = true;
}; };

View File

@ -0,0 +1,25 @@
/****************************************************************************************
* \file SHPhysicsConstants.h
* \author Diren D Bharwani, diren.dbharwani, 390002520
* \brief Declaration of Constants used for physics simulations
*
* \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
// Project Headers
#include "Math/Vector/SHVec3.h"
namespace SHADE
{
struct SHPhysicsConstants
{
static constexpr double DEFAULT_FIXED_DT = 1.0 / 60.0;
static constexpr int DEFAULT_VELOCITY_ITERATIONS = 10;
static constexpr int DEFAULT_POSITION_ITERATIONS = 5;
};
}

View File

@ -34,7 +34,7 @@ namespace SHADE
SHPhysicsSystem::SHPhysicsSystem() noexcept SHPhysicsSystem::SHPhysicsSystem() noexcept
: worldUpdated { false } : worldUpdated { false }
, interpolationFactor { 0.0 } , interpolationFactor { 0.0 }
, fixedDT { DEFAULT_FIXED_STEP } , fixedDT { SHPhysicsConstants::DEFAULT_FIXED_DT }
{ {
// Add more events here to register them // Add more events here to register them
@ -63,11 +63,6 @@ namespace SHADE
return fixedDT; return fixedDT;
} }
double SHPhysicsSystem::GetDefaultFixedDT() const noexcept
{
return DEFAULT_FIXED_STEP;
}
const std::vector<SHCollisionInfo>& SHPhysicsSystem::GetAllCollisionInfo() const noexcept const std::vector<SHCollisionInfo>& SHPhysicsSystem::GetAllCollisionInfo() const noexcept
{ {
return collisionListener.GetCollisionInfoContainer(); return collisionListener.GetCollisionInfoContainer();

View File

@ -21,7 +21,7 @@
#include "Math/Geometry/SHAABB.h" #include "Math/Geometry/SHAABB.h"
#include "Physics/Collision/SHCollisionInfo.h" #include "Physics/Collision/SHCollisionInfo.h"
#include "Physics/Interface/PhysicsObject/SHPhysicsObjectManager.h" #include "Physics/Interface/PhysicsObject/SHPhysicsObjectManager.h"
#include "Physics/RP3DWrapper/SHPhysicsWorld.h" #include "Physics/RP3DWrapper/SHPhysicsWorldState.h"
#include "Physics/RP3DWrapper/SHCollisionListener.h" #include "Physics/RP3DWrapper/SHCollisionListener.h"
#include "Physics/RP3DWrapper/SHRaycaster.h" #include "Physics/RP3DWrapper/SHRaycaster.h"
#include "Scene/SHSceneGraph.h" #include "Scene/SHSceneGraph.h"
@ -59,7 +59,6 @@ namespace SHADE
[[nodiscard]] double GetFixedUpdateRate () const noexcept; [[nodiscard]] double GetFixedUpdateRate () const noexcept;
[[nodiscard]] double GetFixedDT () const noexcept; [[nodiscard]] double GetFixedDT () const noexcept;
[[nodiscard]] double GetDefaultFixedDT () const noexcept;
[[nodiscard]] const std::vector<SHCollisionInfo>& GetAllTriggerInfo () const noexcept; [[nodiscard]] const std::vector<SHCollisionInfo>& GetAllTriggerInfo () const noexcept;
[[nodiscard]] const std::vector<SHCollisionInfo>& GetAllCollisionInfo () const noexcept; [[nodiscard]] const std::vector<SHCollisionInfo>& GetAllCollisionInfo () const noexcept;
@ -70,6 +69,7 @@ namespace SHADE
void SetFixedUpdateRate (double fixedUpdateRate) noexcept; void SetFixedUpdateRate (double fixedUpdateRate) noexcept;
void SetFixedDT (double fixedDt) noexcept; void SetFixedDT (double fixedDt) noexcept;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Function Members */ /* Function Members */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -60,21 +60,11 @@ namespace SHADE
return 0.0; return 0.0;
} }
double SHPhysicsSystemInterface::GetDeafultFixedDT() noexcept void SHPhysicsSystemInterface::SetFixedDT(double fixedDT) noexcept
{ {
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>(); auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
if (physicsSystem) if (physicsSystem)
return physicsSystem->GetDefaultFixedDT(); physicsSystem->SetFixedDT(fixedDT);
SHLOGV_WARNING("Failed to get defualt fixed delta time. 0.0 returned instead.");
return 0.0;
}
void SHPhysicsSystemInterface::SetFixedDT(double value) noexcept
{
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
if (physicsSystem)
physicsSystem->SetFixedDT(value);
SHLOGV_WARNING("Failed to set fixed delta time."); SHLOGV_WARNING("Failed to set fixed delta time.");
} }
@ -89,6 +79,16 @@ namespace SHADE
return 0.0; return 0.0;
} }
void SHPhysicsSystemInterface::SetFixedUpdateRate(double fixedUpdateRate) noexcept
{
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
if (physicsSystem)
return physicsSystem->SetFixedUpdateRate(fixedUpdateRate);
SHLOGV_WARNING("Failed to set fixed update rate.");
}
const std::vector<SHPhysicsRaycastResult>& SHPhysicsSystemInterface::Raycast(const RaycastInfo& info) noexcept const std::vector<SHPhysicsRaycastResult>& SHPhysicsSystemInterface::Raycast(const RaycastInfo& info) noexcept
{ {
static std::vector<SHPhysicsRaycastResult> emptyVec; static std::vector<SHPhysicsRaycastResult> emptyVec;

View File

@ -93,9 +93,9 @@ namespace SHADE
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetCollisionInfo () noexcept; [[nodiscard]] static const std::vector<SHCollisionInfo>& GetCollisionInfo () noexcept;
[[nodiscard]] static const std::vector<SHCollisionInfo>& GetTriggerInfo () noexcept; [[nodiscard]] static const std::vector<SHCollisionInfo>& GetTriggerInfo () noexcept;
[[nodiscard]] static double GetFixedDT () noexcept; [[nodiscard]] static double GetFixedDT () noexcept;
[[nodiscard]] static void SetFixedDT (double value) noexcept; [[nodiscard]] static void SetFixedDT (double fixedDT) noexcept;
[[nodiscard]] static double GetDeafultFixedDT () noexcept;
[[nodiscard]] static int GetFixedUpdateRate () 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<SHPhysicsRaycastResult>& Raycast (const RaycastInfo& info) noexcept;
}; };

View File

@ -17,6 +17,7 @@ of DigiPen Institute of Technology is prohibited.
// External Dependencies // External Dependencies
#include "FRC/SHFramerateController.h" #include "FRC/SHFramerateController.h"
#include "Physics/System/SHPhysicsSystemInterface.h" #include "Physics/System/SHPhysicsSystemInterface.h"
#include "Physics/SHPhysicsConstants.h"
// Primary Header // Primary Header
#include "Time.hxx" #include "Time.hxx"
@ -47,7 +48,6 @@ namespace SHADE
double Time::DefaultFixDeltaTime::get() double Time::DefaultFixDeltaTime::get()
{ {
return SHPhysicsSystemInterface::GetDeafultFixedDT(); return SHPhysicsConstants::DEFAULT_FIXED_DT;
} }
} }