Merge branch 'main' into Fix-SetMesh
This commit is contained in:
commit
d7429c4627
|
@ -33,18 +33,18 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<SHComponentRemovedEvent> eventVec;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < componentSet.Size(); ++i)
|
for (uint32_t i = 0; i < componentSet.Size(); ++i)
|
||||||
{
|
{
|
||||||
SHComponent* comp = (SHComponent*) componentSet.GetElement(i, EntityHandleGenerator::GetIndex(entityID));
|
SHComponent* comp = (SHComponent*) componentSet.GetElement(i, EntityHandleGenerator::GetIndex(entityID));
|
||||||
if (comp)
|
if (comp)
|
||||||
{
|
{
|
||||||
comp->OnDestroy();
|
comp->OnDestroy();
|
||||||
|
|
||||||
SHComponentRemovedEvent eventData;
|
SHComponentRemovedEvent eventData;
|
||||||
eventData.eid = entityID;
|
eventData.eid = entityID;
|
||||||
eventData.removedComponentType = i;
|
eventData.removedComponentType = i;
|
||||||
|
eventVec.push_back(eventData);
|
||||||
SHEventManager::BroadcastEvent<SHComponentRemovedEvent>(eventData, SH_COMPONENT_REMOVED_EVENT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,12 @@ namespace SHADE
|
||||||
|
|
||||||
componentSet.RemoveElements(EntityHandleGenerator::GetIndex(entityID));
|
componentSet.RemoveElements(EntityHandleGenerator::GetIndex(entityID));
|
||||||
|
|
||||||
|
for (auto& eventData : eventVec)
|
||||||
|
{
|
||||||
|
SHEventManager::BroadcastEvent<SHComponentRemovedEvent>(eventData, SH_COMPONENT_REMOVED_EVENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//entityHandle.RemoveHandle(entityID);
|
//entityHandle.RemoveHandle(entityID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
// Project Headers
|
// Project Headers
|
||||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||||
|
#include "Math/SHMathHelpers.h"
|
||||||
#include "Physics/SHPhysicsSystem.h"
|
#include "Physics/SHPhysicsSystem.h"
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
|
@ -28,21 +29,9 @@ namespace SHADE
|
||||||
|
|
||||||
SHRigidBodyComponent::SHRigidBodyComponent() noexcept
|
SHRigidBodyComponent::SHRigidBodyComponent() noexcept
|
||||||
: type { Type::DYNAMIC }
|
: type { Type::DYNAMIC }
|
||||||
, flags { 0 }
|
|
||||||
, dirtyFlags { 0 }
|
|
||||||
, interpolate { true }
|
, interpolate { true }
|
||||||
, rp3dBody { nullptr }
|
, rp3dBody { nullptr }
|
||||||
, mass { 1.0f }
|
{}
|
||||||
, drag { 0.01f }
|
|
||||||
, angularDrag { 0.01f }
|
|
||||||
{
|
|
||||||
// Set default flags: Gravity & Sleeping enabled
|
|
||||||
flags |= 1U << 0;
|
|
||||||
flags |= 1U << 1;
|
|
||||||
|
|
||||||
// Set all dirty flags to true
|
|
||||||
dirtyFlags = 1023;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Getter Function Definitions */
|
/* Getter Function Definitions */
|
||||||
|
@ -50,12 +39,24 @@ namespace SHADE
|
||||||
|
|
||||||
bool SHRigidBodyComponent::IsGravityEnabled() const noexcept
|
bool SHRigidBodyComponent::IsGravityEnabled() const noexcept
|
||||||
{
|
{
|
||||||
return flags & (1U << 0);
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp3dBody->isGravityEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHRigidBodyComponent::IsAllowedToSleep() const noexcept
|
bool SHRigidBodyComponent::IsAllowedToSleep() const noexcept
|
||||||
{
|
{
|
||||||
return flags & (1U << 1);
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp3dBody->isAllowedToSleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHRigidBodyComponent::IsInterpolating() const noexcept
|
bool SHRigidBodyComponent::IsInterpolating() const noexcept
|
||||||
|
@ -70,67 +71,151 @@ namespace SHADE
|
||||||
|
|
||||||
float SHRigidBodyComponent::GetMass() const noexcept
|
float SHRigidBodyComponent::GetMass() const noexcept
|
||||||
{
|
{
|
||||||
return mass;
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp3dBody->getMass();
|
||||||
}
|
}
|
||||||
|
|
||||||
float SHRigidBodyComponent::GetDrag() const noexcept
|
float SHRigidBodyComponent::GetDrag() const noexcept
|
||||||
{
|
{
|
||||||
return drag;
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp3dBody->getLinearDamping();
|
||||||
}
|
}
|
||||||
|
|
||||||
float SHRigidBodyComponent::GetAngularDrag() const noexcept
|
float SHRigidBodyComponent::GetAngularDrag() const noexcept
|
||||||
{
|
{
|
||||||
return angularDrag;
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp3dBody->getAngularDamping();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHRigidBodyComponent::GetFreezePositionX() const noexcept
|
bool SHRigidBodyComponent::GetFreezePositionX() const noexcept
|
||||||
{
|
{
|
||||||
return flags & (1U << 2);
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& LINEAR_CONSTRAINTS = rp3dBody->getLinearLockAxisFactor();
|
||||||
|
return SHMath::CompareFloat(LINEAR_CONSTRAINTS.x, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHRigidBodyComponent::GetFreezePositionY() const noexcept
|
bool SHRigidBodyComponent::GetFreezePositionY() const noexcept
|
||||||
{
|
{
|
||||||
return flags & (1U << 3);
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& LINEAR_CONSTRAINTS = rp3dBody->getLinearLockAxisFactor();
|
||||||
|
return SHMath::CompareFloat(LINEAR_CONSTRAINTS.y, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHRigidBodyComponent::GetFreezePositionZ() const noexcept
|
bool SHRigidBodyComponent::GetFreezePositionZ() const noexcept
|
||||||
{
|
{
|
||||||
return flags & (1U << 4);
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& LINEAR_CONSTRAINTS = rp3dBody->getLinearLockAxisFactor();
|
||||||
|
return SHMath::CompareFloat(LINEAR_CONSTRAINTS.z, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHRigidBodyComponent::GetFreezeRotationX() const noexcept
|
bool SHRigidBodyComponent::GetFreezeRotationX() const noexcept
|
||||||
{
|
{
|
||||||
return flags & (1U << 5);
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& ANGULAR_CONSTRAINTS = rp3dBody->getAngularLockAxisFactor();
|
||||||
|
return SHMath::CompareFloat(ANGULAR_CONSTRAINTS.x, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHRigidBodyComponent::GetFreezeRotationY() const noexcept
|
bool SHRigidBodyComponent::GetFreezeRotationY() const noexcept
|
||||||
{
|
{
|
||||||
return flags & (1U << 6);
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& ANGULAR_CONSTRAINTS = rp3dBody->getAngularLockAxisFactor();
|
||||||
|
return SHMath::CompareFloat(ANGULAR_CONSTRAINTS.y, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHRigidBodyComponent::GetFreezeRotationZ() const noexcept
|
bool SHRigidBodyComponent::GetFreezeRotationZ() const noexcept
|
||||||
{
|
{
|
||||||
return flags & (1U << 7);
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& ANGULAR_CONSTRAINTS = rp3dBody->getAngularLockAxisFactor();
|
||||||
|
return SHMath::CompareFloat(ANGULAR_CONSTRAINTS.z, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHVec3& SHRigidBodyComponent::GetForce() const noexcept
|
SHVec3 SHRigidBodyComponent::GetForce() const noexcept
|
||||||
{
|
{
|
||||||
return force;
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp3dBody->getForce();
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHVec3& SHRigidBodyComponent::GetTorque() const noexcept
|
SHVec3 SHRigidBodyComponent::GetTorque() const noexcept
|
||||||
{
|
{
|
||||||
return torque;
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return SHVec3::Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp3dBody->getTorque();
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHVec3& SHRigidBodyComponent::GetLinearVelocity() const noexcept
|
SHVec3 SHRigidBodyComponent::GetLinearVelocity() const noexcept
|
||||||
{
|
{
|
||||||
return linearVelocity;
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return SHVec3::Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp3dBody->getLinearVelocity();
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHVec3& SHRigidBodyComponent::GetAngularVelocity() const noexcept
|
SHVec3 SHRigidBodyComponent::GetAngularVelocity() const noexcept
|
||||||
{
|
{
|
||||||
return angularVelocity;
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return SHVec3::Zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rp3dBody->getAngularVelocity();
|
||||||
}
|
}
|
||||||
|
|
||||||
const SHVec3& SHRigidBodyComponent::GetPosition() const noexcept
|
const SHVec3& SHRigidBodyComponent::GetPosition() const noexcept
|
||||||
|
@ -157,8 +242,15 @@ namespace SHADE
|
||||||
if (type == newType)
|
if (type == newType)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dirtyFlags |= 1U << 4;
|
|
||||||
type = newType;
|
type = newType;
|
||||||
|
|
||||||
|
if (rp3dBody == nullptr)
|
||||||
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp3dBody->setType(static_cast<rp3d::BodyType>(type));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetGravityEnabled(bool enableGravity) noexcept
|
void SHRigidBodyComponent::SetGravityEnabled(bool enableGravity) noexcept
|
||||||
|
@ -171,8 +263,13 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << FLAG_POS;
|
if (rp3dBody == nullptr)
|
||||||
enableGravity ? flags |= (1U << FLAG_POS) : flags &= ~(1U << FLAG_POS);
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp3dBody->enableGravity(enableGravity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetIsAllowedToSleep(bool isAllowedToSleep) noexcept
|
void SHRigidBodyComponent::SetIsAllowedToSleep(bool isAllowedToSleep) noexcept
|
||||||
|
@ -185,92 +282,127 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 1;
|
if (rp3dBody == nullptr)
|
||||||
isAllowedToSleep ? flags |= (1U << FLAG_POS) : flags &= ~(1U << FLAG_POS);
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp3dBody->setIsAllowedToSleep(isAllowedToSleep);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetFreezePositionX(bool freezePositionX) noexcept
|
void SHRigidBodyComponent::SetFreezePositionX(bool freezePositionX) noexcept
|
||||||
{
|
{
|
||||||
static constexpr int FLAG_POS = 2;
|
|
||||||
|
|
||||||
if (type == Type::STATIC)
|
if (type == Type::STATIC)
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Cannot set linear constraints of a static object {}", GetEID())
|
SHLOG_WARNING("Cannot set linear constraints of a static object {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 2;
|
if (rp3dBody == nullptr)
|
||||||
freezePositionX ? flags |= (1U << FLAG_POS) : flags &= ~(1U << FLAG_POS);
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto linearConstraints = rp3dBody->getLinearLockAxisFactor();
|
||||||
|
linearConstraints.x = freezePositionX ? 0.0f : 1.0f;
|
||||||
|
rp3dBody->setLinearLockAxisFactor(linearConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetFreezePositionY(bool freezePositionY) noexcept
|
void SHRigidBodyComponent::SetFreezePositionY(bool freezePositionY) noexcept
|
||||||
{
|
{
|
||||||
static constexpr int FLAG_POS = 3;
|
|
||||||
|
|
||||||
if (type == Type::STATIC)
|
if (type == Type::STATIC)
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Cannot set linear constraints of a static object {}", GetEID())
|
SHLOG_WARNING("Cannot set linear constraints of a static object {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 2;
|
if (rp3dBody == nullptr)
|
||||||
freezePositionY ? flags |= (1U << FLAG_POS) : flags &= ~(1U << FLAG_POS);
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto linearConstraints = rp3dBody->getLinearLockAxisFactor();
|
||||||
|
linearConstraints.y = freezePositionY ? 0.0f : 1.0f;
|
||||||
|
rp3dBody->setLinearLockAxisFactor(linearConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetFreezePositionZ(bool freezePositionZ) noexcept
|
void SHRigidBodyComponent::SetFreezePositionZ(bool freezePositionZ) noexcept
|
||||||
{
|
{
|
||||||
static constexpr int FLAG_POS = 4;
|
|
||||||
|
|
||||||
if (type == Type::STATIC)
|
if (type == Type::STATIC)
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Cannot set linear constraints of a static object {}", GetEID())
|
SHLOG_WARNING("Cannot set linear constraints of a static object {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 2;
|
if (rp3dBody == nullptr)
|
||||||
freezePositionZ ? flags |= (1U << FLAG_POS) : flags &= ~(1U << FLAG_POS);
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto linearConstraints = rp3dBody->getLinearLockAxisFactor();
|
||||||
|
linearConstraints.z = freezePositionZ ? 0.0f : 1.0f;
|
||||||
|
rp3dBody->setLinearLockAxisFactor(linearConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetFreezeRotationX(bool freezeRotationX) noexcept
|
void SHRigidBodyComponent::SetFreezeRotationX(bool freezeRotationX) noexcept
|
||||||
{
|
{
|
||||||
static constexpr int FLAG_POS = 5;
|
|
||||||
|
|
||||||
if (type == Type::STATIC)
|
if (type == Type::STATIC)
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Cannot set angular constraints of a static object {}", GetEID())
|
SHLOG_WARNING("Cannot set angular constraints of a static object {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 3;
|
if (rp3dBody == nullptr)
|
||||||
freezeRotationX ? flags |= (1U << FLAG_POS) : flags &= ~(1U << FLAG_POS);
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto angularConstraints = rp3dBody->getAngularLockAxisFactor();
|
||||||
|
angularConstraints.x = freezeRotationX ? 0.0f : 1.0f;
|
||||||
|
rp3dBody->setAngularLockAxisFactor(angularConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetFreezeRotationY(bool freezeRotationY) noexcept
|
void SHRigidBodyComponent::SetFreezeRotationY(bool freezeRotationY) noexcept
|
||||||
{
|
{
|
||||||
static constexpr int FLAG_POS = 6;
|
|
||||||
|
|
||||||
if (type == Type::STATIC)
|
if (type == Type::STATIC)
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Cannot set angular constraints of a static object {}", GetEID())
|
SHLOG_WARNING("Cannot set angular constraints of a static object {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 3;
|
if (rp3dBody == nullptr)
|
||||||
freezeRotationY ? flags |= (1U << FLAG_POS) : flags &= ~(1U << FLAG_POS);
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto angularConstraints = rp3dBody->getAngularLockAxisFactor();
|
||||||
|
angularConstraints.y = freezeRotationY ? 0.0f : 1.0f;
|
||||||
|
rp3dBody->setAngularLockAxisFactor(angularConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetFreezeRotationZ(bool freezeRotationZ) noexcept
|
void SHRigidBodyComponent::SetFreezeRotationZ(bool freezeRotationZ) noexcept
|
||||||
{
|
{
|
||||||
static constexpr int FLAG_POS = 7;
|
|
||||||
|
|
||||||
if (type == Type::STATIC)
|
if (type == Type::STATIC)
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Cannot set angular constraints of a static object {}", GetEID())
|
SHLOG_WARNING("Cannot set angular constraints of a static object {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 3;
|
if (rp3dBody == nullptr)
|
||||||
freezeRotationZ ? flags |= (1U << FLAG_POS) : flags &= ~(1U << FLAG_POS);
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto angularConstraints = rp3dBody->getAngularLockAxisFactor();
|
||||||
|
angularConstraints.z = freezeRotationZ ? 0.0f : 1.0f;
|
||||||
|
rp3dBody->setAngularLockAxisFactor(angularConstraints);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetInterpolate(bool allowInterpolation) noexcept
|
void SHRigidBodyComponent::SetInterpolate(bool allowInterpolation) noexcept
|
||||||
|
@ -283,11 +415,16 @@ namespace SHADE
|
||||||
if (type != Type::DYNAMIC)
|
if (type != Type::DYNAMIC)
|
||||||
{
|
{
|
||||||
SHLOG_WARNING("Cannot set mass of a non-dynamic object {}", GetEID())
|
SHLOG_WARNING("Cannot set mass of a non-dynamic object {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 5;
|
if (rp3dBody == nullptr)
|
||||||
mass = newMass;
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp3dBody->setMass(newMass);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetDrag(float newDrag) noexcept
|
void SHRigidBodyComponent::SetDrag(float newDrag) noexcept
|
||||||
|
@ -298,8 +435,13 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 6;
|
if (rp3dBody == nullptr)
|
||||||
drag = newDrag;
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp3dBody->setLinearDamping(newDrag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetAngularDrag(float newAngularDrag) noexcept
|
void SHRigidBodyComponent::SetAngularDrag(float newAngularDrag) noexcept
|
||||||
|
@ -310,8 +452,13 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 7;
|
if (rp3dBody == nullptr)
|
||||||
angularDrag = newAngularDrag;
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp3dBody->setLinearDamping(newAngularDrag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetLinearVelocity(const SHVec3& newLinearVelocity) noexcept
|
void SHRigidBodyComponent::SetLinearVelocity(const SHVec3& newLinearVelocity) noexcept
|
||||||
|
@ -322,8 +469,13 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 8;
|
if (rp3dBody == nullptr)
|
||||||
linearVelocity = newLinearVelocity;
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp3dBody->setLinearVelocity(newLinearVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHRigidBodyComponent::SetAngularVelocity(const SHVec3& newAngularVelocity) noexcept
|
void SHRigidBodyComponent::SetAngularVelocity(const SHVec3& newAngularVelocity) noexcept
|
||||||
|
@ -334,8 +486,13 @@ namespace SHADE
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dirtyFlags |= 1U << 9;
|
if (rp3dBody == nullptr)
|
||||||
angularVelocity = newAngularVelocity;
|
{
|
||||||
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp3dBody->setAngularVelocity(newAngularVelocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
@ -346,7 +503,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
if (rp3dBody == nullptr)
|
if (rp3dBody == nullptr)
|
||||||
{
|
{
|
||||||
SHLOGV_ERROR("Entity {} is missing an rp3dBody!", GetEID())
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +514,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
if (rp3dBody == nullptr)
|
if (rp3dBody == nullptr)
|
||||||
{
|
{
|
||||||
SHLOGV_ERROR("Entity {} is missing an rp3dBody!", GetEID())
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +525,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
if (rp3dBody == nullptr)
|
if (rp3dBody == nullptr)
|
||||||
{
|
{
|
||||||
SHLOGV_ERROR("Entity {} is missing an rp3dBody!", GetEID())
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +536,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
if (rp3dBody == nullptr)
|
if (rp3dBody == nullptr)
|
||||||
{
|
{
|
||||||
SHLOGV_ERROR("Entity {} is missing an rp3dBody!", GetEID())
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,7 +547,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
if (rp3dBody == nullptr)
|
if (rp3dBody == nullptr)
|
||||||
{
|
{
|
||||||
SHLOGV_ERROR("Entity {} is missing an rp3dBody!", GetEID())
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +558,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
if (rp3dBody == nullptr)
|
if (rp3dBody == nullptr)
|
||||||
{
|
{
|
||||||
SHLOGV_ERROR("Entity {} is missing an rp3dBody!", GetEID())
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +569,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
if (rp3dBody == nullptr)
|
if (rp3dBody == nullptr)
|
||||||
{
|
{
|
||||||
SHLOGV_ERROR("Entity {} is missing an rp3dBody!", GetEID())
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,7 +580,7 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
if (rp3dBody == nullptr)
|
if (rp3dBody == nullptr)
|
||||||
{
|
{
|
||||||
SHLOGV_ERROR("Entity {} is missing an rp3dBody!", GetEID())
|
SHLOG_ERROR("Missing rp3dBody from Entity {}", GetEID())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,10 +94,10 @@ namespace SHADE
|
||||||
[[nodiscard]] bool GetFreezeRotationY () const noexcept;
|
[[nodiscard]] bool GetFreezeRotationY () const noexcept;
|
||||||
[[nodiscard]] bool GetFreezeRotationZ () const noexcept;
|
[[nodiscard]] bool GetFreezeRotationZ () const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] const SHVec3& GetForce () const noexcept;
|
[[nodiscard]] SHVec3 GetForce () const noexcept;
|
||||||
[[nodiscard]] const SHVec3& GetTorque () const noexcept;
|
[[nodiscard]] SHVec3 GetTorque () const noexcept;
|
||||||
[[nodiscard]] const SHVec3& GetLinearVelocity () const noexcept;
|
[[nodiscard]] SHVec3 GetLinearVelocity () const noexcept;
|
||||||
[[nodiscard]] const SHVec3& GetAngularVelocity () const noexcept;
|
[[nodiscard]] SHVec3 GetAngularVelocity () const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] const SHVec3& GetPosition () const noexcept;
|
[[nodiscard]] const SHVec3& GetPosition () const noexcept;
|
||||||
[[nodiscard]] const SHQuaternion& GetOrientation () const noexcept;
|
[[nodiscard]] const SHQuaternion& GetOrientation () const noexcept;
|
||||||
|
@ -149,28 +149,13 @@ namespace SHADE
|
||||||
static constexpr size_t NUM_FLAGS = 8;
|
static constexpr size_t NUM_FLAGS = 8;
|
||||||
static constexpr size_t NUM_DIRTY_FLAGS = 16;
|
static constexpr size_t NUM_DIRTY_FLAGS = 16;
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
|
bool interpolate;
|
||||||
// rX rY rZ pX pY pZ slp g
|
|
||||||
uint8_t flags;
|
|
||||||
// 0 0 0 0 0 0 aV lV aD d m t ag lc slp g
|
|
||||||
uint16_t dirtyFlags;
|
|
||||||
bool interpolate;
|
|
||||||
|
|
||||||
reactphysics3d::RigidBody* rp3dBody;
|
reactphysics3d::RigidBody* rp3dBody;
|
||||||
|
|
||||||
float mass;
|
SHVec3 position;
|
||||||
float drag;
|
SHQuaternion orientation;
|
||||||
float angularDrag;
|
|
||||||
|
|
||||||
SHVec3 force;
|
|
||||||
SHVec3 linearVelocity;
|
|
||||||
|
|
||||||
SHVec3 torque;
|
|
||||||
SHVec3 angularVelocity;
|
|
||||||
|
|
||||||
SHVec3 position;
|
|
||||||
SHQuaternion orientation;
|
|
||||||
|
|
||||||
RTTR_ENABLE()
|
RTTR_ENABLE()
|
||||||
};
|
};
|
||||||
|
|
|
@ -168,100 +168,6 @@ namespace SHADE
|
||||||
rp3dBody->removeCollider(collider);
|
rp3dBody->removeCollider(collider);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SHPhysicsObject::SyncRigidBody(SHRigidBodyComponent* rb) const noexcept
|
|
||||||
{
|
|
||||||
SHASSERT(rp3dBody != nullptr, "ReactPhysics body does not exist!")
|
|
||||||
|
|
||||||
auto* rigidBody = reinterpret_cast<rp3d::RigidBody*>(rp3dBody);
|
|
||||||
if (rb->dirtyFlags != 0)
|
|
||||||
{
|
|
||||||
const uint16_t RB_FLAGS = rb->dirtyFlags;
|
|
||||||
for (size_t i = 0; i < SHRigidBodyComponent::NUM_DIRTY_FLAGS; ++i)
|
|
||||||
{
|
|
||||||
// Check if current dirty flag has been set to true
|
|
||||||
if (RB_FLAGS & 1U << i)
|
|
||||||
{
|
|
||||||
switch (i)
|
|
||||||
{
|
|
||||||
case 0: // Gravity
|
|
||||||
{
|
|
||||||
rigidBody->enableGravity(rb->IsGravityEnabled());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 1: // Sleeping
|
|
||||||
{
|
|
||||||
rigidBody->setIsAllowedToSleep(rb->IsAllowedToSleep());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 2: // Linear Constraints
|
|
||||||
{
|
|
||||||
const rp3d::Vector3 CONSTRAINTS
|
|
||||||
{
|
|
||||||
rb->flags & 1U << 2 ? 0.0f : 1.0f,
|
|
||||||
rb->flags & 1U << 3 ? 0.0f : 1.0f,
|
|
||||||
rb->flags & 1U << 4 ? 0.0f : 1.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
rigidBody->setLinearLockAxisFactor(CONSTRAINTS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 3: // Angular Constraints
|
|
||||||
{
|
|
||||||
const rp3d::Vector3 CONSTRAINTS
|
|
||||||
{
|
|
||||||
rb->flags & 1U << 5 ? 0.0f : 1.0f,
|
|
||||||
rb->flags & 1U << 6 ? 0.0f : 1.0f,
|
|
||||||
rb->flags & 1U << 7 ? 0.0f : 1.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
rigidBody->setAngularLockAxisFactor(CONSTRAINTS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 4: // Type
|
|
||||||
{
|
|
||||||
rigidBody->setType(static_cast<rp3d::BodyType>(rb->GetType()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 5: // Mass
|
|
||||||
{
|
|
||||||
rigidBody->setMass(rb->GetMass());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 6: // Drag
|
|
||||||
{
|
|
||||||
rigidBody->setLinearDamping(rb->GetDrag());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 7: // Angular Drag
|
|
||||||
{
|
|
||||||
rigidBody->setAngularDamping(rb->GetAngularDrag());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 8: // Linear Velocity
|
|
||||||
{
|
|
||||||
rigidBody->setLinearVelocity(rb->GetLinearVelocity());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 9: // Angular Velocity
|
|
||||||
{
|
|
||||||
rigidBody->setAngularVelocity(rb->GetAngularVelocity());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rb->dirtyFlags = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rb->linearVelocity = rigidBody->getLinearVelocity();
|
|
||||||
rb->angularVelocity = rigidBody->getAngularVelocity();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SHPhysicsObject::SyncColliders(SHColliderComponent* c) const noexcept
|
void SHPhysicsObject::SyncColliders(SHColliderComponent* c) const noexcept
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
|
@ -72,7 +72,6 @@ namespace SHADE
|
||||||
int AddCollider (SHCollider* collider);
|
int AddCollider (SHCollider* collider);
|
||||||
void RemoveCollider (int index);
|
void RemoveCollider (int index);
|
||||||
|
|
||||||
void SyncRigidBody (SHRigidBodyComponent* rb) const noexcept;
|
|
||||||
void SyncColliders (SHColliderComponent* c) const noexcept;
|
void SyncColliders (SHColliderComponent* c) const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -305,8 +305,6 @@ namespace SHADE
|
||||||
|
|
||||||
if (!COMPONENT_ACTIVE)
|
if (!COMPONENT_ACTIVE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
physicsObject.SyncRigidBody(rigidBodyComponent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync colliders
|
// Sync colliders
|
||||||
|
|
|
@ -28,11 +28,6 @@
|
||||||
|
|
||||||
namespace SHADE
|
namespace SHADE
|
||||||
{
|
{
|
||||||
/*-----------------------------------------------------------------------------------*/
|
|
||||||
/* Concepts */
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
/* Type Definitions */
|
/* Type Definitions */
|
||||||
|
|
|
@ -42,6 +42,9 @@ namespace SHADE
|
||||||
|
|
||||||
SHCollisionEvent cInfo;
|
SHCollisionEvent cInfo;
|
||||||
|
|
||||||
|
// Update collision state
|
||||||
|
cInfo.collisionState = static_cast<SHCollisionEvent::State>(cp.getEventType());
|
||||||
|
|
||||||
// Match body and collider for collision event
|
// Match body and collider for collision event
|
||||||
const rp3d::Entity body1 = cp.getBody1()->getEntity();
|
const rp3d::Entity body1 = cp.getBody1()->getEntity();
|
||||||
const rp3d::Entity body2 = cp.getBody2()->getEntity();
|
const rp3d::Entity body2 = cp.getBody2()->getEntity();
|
||||||
|
@ -76,9 +79,6 @@ namespace SHADE
|
||||||
return cInfo;
|
return cInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update collision state
|
|
||||||
cInfo.collisionState = static_cast<SHCollisionEvent::State>(cp.getEventType());
|
|
||||||
|
|
||||||
return cInfo;
|
return cInfo;
|
||||||
}
|
}
|
||||||
} // namespace SHADE
|
} // namespace SHADE
|
Loading…
Reference in New Issue