Physics objects can be implicity static if only a collider was added.

Removed the need to create an extra body. Math is great.
This commit is contained in:
Diren D Bharwani 2023-01-23 00:56:46 +08:00
parent a0f6cd3ae7
commit 5730381302
4 changed files with 65 additions and 129 deletions

View File

@ -8,23 +8,6 @@
Rotate: {x: 0, y: 0, z: 0.436332315} Rotate: {x: 0, y: 0, z: 0.436332315}
Scale: {x: 4.61070776, y: 0.99999392, z: 0.999996722} Scale: {x: 4.61070776, y: 0.99999392, z: 0.999996722}
IsActive: true IsActive: true
RigidBody Component:
Type: Static
Auto Mass: false
Mass: .inf
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Gravity Scale: 1
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: true
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component: Collider Component:
DrawColliders: false DrawColliders: false
Colliders: Colliders:
@ -62,7 +45,7 @@
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component: Transform Component:
Translate: {x: -2, y: 7.5, z: 0} Translate: {x: 0, y: 7.5, z: 0}
Rotate: {x: -0, y: 0, z: 0.785398185} Rotate: {x: -0, y: 0, z: 0.785398185}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
@ -77,7 +60,7 @@
Interpolate: true Interpolate: true
Sleeping Enabled: true Sleeping Enabled: true
Freeze Position X: false Freeze Position X: false
Freeze Position Y: true Freeze Position Y: false
Freeze Position Z: false Freeze Position Z: false
Freeze Rotation X: false Freeze Rotation X: false
Freeze Rotation Y: false Freeze Rotation Y: false
@ -107,23 +90,6 @@
Rotate: {x: -0, y: 0, z: -0.436332315} Rotate: {x: -0, y: 0, z: -0.436332315}
Scale: {x: 4.61071014, y: 0.999995887, z: 1} Scale: {x: 4.61071014, y: 0.999995887, z: 1}
IsActive: true IsActive: true
RigidBody Component:
Type: Static
Auto Mass: false
Mass: .inf
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Gravity Scale: 1
Interpolate: true
Sleeping Enabled: true
Freeze Position X: true
Freeze Position Y: true
Freeze Position Z: true
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component: Collider Component:
DrawColliders: false DrawColliders: false
Colliders: Colliders:
@ -148,23 +114,6 @@
Rotate: {x: -0, y: 0, z: -0} Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 10, y: 3, z: 10} Scale: {x: 10, y: 3, z: 10}
IsActive: true IsActive: true
RigidBody Component:
Type: Static
Auto Mass: false
Mass: .inf
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Gravity Scale: 1
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: true
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component: Collider Component:
DrawColliders: false DrawColliders: false
Colliders: Colliders:
@ -189,23 +138,6 @@
Rotate: {x: -0, y: 0, z: 1.57079601} Rotate: {x: -0, y: 0, z: 1.57079601}
Scale: {x: 9.99975109, y: 0.499992192, z: 10} Scale: {x: 9.99975109, y: 0.499992192, z: 10}
IsActive: true IsActive: true
RigidBody Component:
Type: Static
Auto Mass: false
Mass: .inf
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Gravity Scale: 1
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: true
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component: Collider Component:
DrawColliders: false DrawColliders: false
Colliders: Colliders:
@ -230,23 +162,6 @@
Rotate: {x: -0, y: 0, z: 1.57079601} Rotate: {x: -0, y: 0, z: 1.57079601}
Scale: {x: 9.99975109, y: 0.499992192, z: 10} Scale: {x: 9.99975109, y: 0.499992192, z: 10}
IsActive: true IsActive: true
RigidBody Component:
Type: Static
Auto Mass: false
Mass: .inf
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Gravity Scale: 1
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: true
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component: Collider Component:
DrawColliders: false DrawColliders: false
Colliders: Colliders:
@ -267,7 +182,7 @@
NumberOfChildren: 0 NumberOfChildren: 0
Components: Components:
Transform Component: Transform Component:
Translate: {x: 0, y: 7, z: 0} Translate: {x: 0, y: 2, z: 3}
Rotate: {x: 0, y: 0.785398185, z: 0} Rotate: {x: 0, y: 0.785398185, z: 0}
Scale: {x: 0.999990404, y: 0.999994457, z: 0.999985337} Scale: {x: 0.999990404, y: 0.999994457, z: 0.999985337}
IsActive: true IsActive: true
@ -316,23 +231,6 @@
Rotate: {x: -0, y: 0, z: -0} Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1} Scale: {x: 1, y: 1, z: 1}
IsActive: true IsActive: true
RigidBody Component:
Type: Static
Auto Mass: false
Mass: .inf
Drag: 0.00999999978
Angular Drag: 0.00999999978
Use Gravity: true
Gravity Scale: 1
Interpolate: true
Sleeping Enabled: true
Freeze Position X: false
Freeze Position Y: true
Freeze Position Z: false
Freeze Rotation X: false
Freeze Rotation Y: false
Freeze Rotation Z: false
IsActive: true
Collider Component: Collider Component:
DrawColliders: false DrawColliders: false
Colliders: Colliders:

View File

@ -33,6 +33,12 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SHVelocityState (const SHRigidBody* rigidBody) noexcept SHVelocityState (const SHRigidBody* rigidBody) noexcept
: LinearVelocity { SHVec3::Zero }
, AngularVelocity { SHVec3::Zero }
, LinearLockFactor { SHVec3::Zero }
, AngularLockFactor { SHVec3::Zero }
{
if (rigidBody)
{ {
LinearVelocity = rigidBody->GetLinearVelocity(); LinearVelocity = rigidBody->GetLinearVelocity();
AngularVelocity = rigidBody->GetAngularVelocity(); AngularVelocity = rigidBody->GetAngularVelocity();
@ -51,6 +57,7 @@ namespace SHADE
, rigidBody->GetFreezeRotationZ() ? 0.0f : 1.0f , rigidBody->GetFreezeRotationZ() ? 0.0f : 1.0f
}; };
} }
}
}; };
} // namespace SHADE } // namespace SHADE

View File

@ -200,12 +200,18 @@ namespace SHADE
const auto& STATE_A = VELOCITY_STATES.find(key.GetEntityA())->second; const auto& STATE_A = VELOCITY_STATES.find(key.GetEntityA())->second;
const auto& STATE_B = VELOCITY_STATES.find(key.GetEntityB())->second; const auto& STATE_B = VELOCITY_STATES.find(key.GetEntityB())->second;
if (bodyA)
{
bodyA->SetLinearVelocity(STATE_A.LinearVelocity); bodyA->SetLinearVelocity(STATE_A.LinearVelocity);
bodyB->SetLinearVelocity(STATE_B.LinearVelocity);
bodyA->SetAngularVelocity(STATE_A.AngularVelocity); bodyA->SetAngularVelocity(STATE_A.AngularVelocity);
}
if (bodyB)
{
bodyB->SetLinearVelocity(STATE_B.LinearVelocity);
bodyB->SetAngularVelocity(STATE_B.AngularVelocity); bodyB->SetAngularVelocity(STATE_B.AngularVelocity);
} }
}
contactSolver.Reset(); contactSolver.Reset();
} }

View File

@ -63,13 +63,38 @@ namespace SHADE
// Mass data // Mass data
// Account for implicity-static bodies
if (BODY_A)
{
newConstraint.invMassA = BODY_A->invMass; newConstraint.invMassA = BODY_A->invMass;
newConstraint.invInertiaA = BODY_A->worldInvInertia;
newConstraint.centerOfMassA = BODY_A->worldCentroid; newConstraint.centerOfMassA = BODY_A->worldCentroid;
newConstraint.invInertiaA = BODY_A->worldInvInertia;
}
else
{
newConstraint.invMassA = 0.0f;
newConstraint.centerOfMassA = SHVec3::Zero;
// Matrix needs to maintain its homogenous structure
newConstraint.invInertiaA = SHMatrix::Zero;
newConstraint.invInertiaA.m[3][3] = 1.0f;
}
if (BODY_B)
{
newConstraint.invMassB = BODY_B->invMass; newConstraint.invMassB = BODY_B->invMass;
newConstraint.invInertiaB = BODY_B->worldInvInertia;
newConstraint.centerOfMassB = BODY_B->worldCentroid; newConstraint.centerOfMassB = BODY_B->worldCentroid;
newConstraint.invInertiaB = BODY_B->worldInvInertia;
}
else
{
newConstraint.invMassB = 0.0f;
newConstraint.centerOfMassB = SHVec3::Zero;
// Matrix needs to maintain its homogenous structure
newConstraint.invInertiaB = SHMatrix::Zero;
newConstraint.invInertiaB.m[3][3] = 1.0f;
}
// Collision data // Collision data