Fixed computation of global inverse inertia tensor

This commit is contained in:
Diren D Bharwani 2022-12-15 22:59:55 +08:00
parent 53edffebac
commit 27c7a17397
2 changed files with 8 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#include "Events/SHEvent.h" #include "Events/SHEvent.h"
#include "Math/SHMathHelpers.h" #include "Math/SHMathHelpers.h"
#include "Physics/SHPhysicsEvents.h" #include "Physics/SHPhysicsEvents.h"
#include "Physics/Dynamics/SHRigidBody.h"
namespace SHADE namespace SHADE
@ -277,6 +278,9 @@ namespace SHADE
SHEventManager::BroadcastEvent<SHPhysicsColliderAddedEvent>(EVENT_DATA, SH_PHYSICS_COLLIDER_ADDED_EVENT); SHEventManager::BroadcastEvent<SHPhysicsColliderAddedEvent>(EVENT_DATA, SH_PHYSICS_COLLIDER_ADDED_EVENT);
if (rigidBody)
rigidBody->ComputeMassData();
return static_cast<int>(shapes.size()); return static_cast<int>(shapes.size());
} }
@ -316,6 +320,9 @@ namespace SHADE
// Broadcast Event for removing a shape // Broadcast Event for removing a shape
SHEventManager::BroadcastEvent<SHPhysicsColliderRemovedEvent>(EVENT_DATA, SH_PHYSICS_COLLIDER_REMOVED_EVENT); SHEventManager::BroadcastEvent<SHPhysicsColliderRemovedEvent>(EVENT_DATA, SH_PHYSICS_COLLIDER_REMOVED_EVENT);
if (rigidBody)
rigidBody->ComputeMassData();
SHLOG_INFO_D("Removing Collision Shape {} from Entity {}", index, entityID) SHLOG_INFO_D("Removing Collision Shape {} from Entity {}", index, entityID)
} }

View File

@ -598,7 +598,7 @@ namespace SHADE
const SHMatrix ROTATION = SHMatrix::Rotate(motionState.orientation); const SHMatrix ROTATION = SHMatrix::Rotate(motionState.orientation);
// Compute world inertia // Compute world inertia
worldInvInertia = ROTATION * localInvInertia * SHMatrix::Transpose(ROTATION); worldInvInertia = SHMatrix::Transpose(ROTATION) * localInvInertia * ROTATION;
// Compute world centroid // Compute world centroid
worldCentroid = (ROTATION * localCentroid) + motionState.position; worldCentroid = (ROTATION * localCentroid) + motionState.position;