diff --git a/Assets/Scenes/PhysicsSandbox.shade b/Assets/Scenes/PhysicsSandbox.shade index 44e5e03f..3b940bc1 100644 --- a/Assets/Scenes/PhysicsSandbox.shade +++ b/Assets/Scenes/PhysicsSandbox.shade @@ -8,23 +8,6 @@ Rotate: {x: 0, y: 0, z: 0.436332315} Scale: {x: 4.61070776, y: 0.99999392, z: 0.999996722} 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: DrawColliders: false Colliders: @@ -62,7 +45,7 @@ NumberOfChildren: 0 Components: 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} Scale: {x: 1, y: 1, z: 1} IsActive: true @@ -77,7 +60,7 @@ Interpolate: true Sleeping Enabled: true Freeze Position X: false - Freeze Position Y: true + Freeze Position Y: false Freeze Position Z: false Freeze Rotation X: false Freeze Rotation Y: false @@ -107,23 +90,6 @@ Rotate: {x: -0, y: 0, z: -0.436332315} Scale: {x: 4.61071014, y: 0.999995887, z: 1} 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: DrawColliders: false Colliders: @@ -148,23 +114,6 @@ Rotate: {x: -0, y: 0, z: -0} Scale: {x: 10, y: 3, z: 10} 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: DrawColliders: false Colliders: @@ -189,23 +138,6 @@ Rotate: {x: -0, y: 0, z: 1.57079601} Scale: {x: 9.99975109, y: 0.499992192, z: 10} 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: DrawColliders: false Colliders: @@ -230,23 +162,6 @@ Rotate: {x: -0, y: 0, z: 1.57079601} Scale: {x: 9.99975109, y: 0.499992192, z: 10} 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: DrawColliders: false Colliders: @@ -267,7 +182,7 @@ NumberOfChildren: 0 Components: Transform Component: - Translate: {x: 0, y: 7, z: 0} + Translate: {x: 0, y: 2, z: 3} Rotate: {x: 0, y: 0.785398185, z: 0} Scale: {x: 0.999990404, y: 0.999994457, z: 0.999985337} IsActive: true @@ -316,23 +231,6 @@ Rotate: {x: -0, y: 0, z: -0} Scale: {x: 1, y: 1, z: 1} 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: DrawColliders: false Colliders: diff --git a/SHADE_Engine/src/Physics/Dynamics/Constraints/SHVelocityState.h b/SHADE_Engine/src/Physics/Dynamics/Constraints/SHVelocityState.h index 6cbb6efb..7c9b6a10 100644 --- a/SHADE_Engine/src/Physics/Dynamics/Constraints/SHVelocityState.h +++ b/SHADE_Engine/src/Physics/Dynamics/Constraints/SHVelocityState.h @@ -33,23 +33,30 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ SHVelocityState (const SHRigidBody* rigidBody) noexcept + : LinearVelocity { SHVec3::Zero } + , AngularVelocity { SHVec3::Zero } + , LinearLockFactor { SHVec3::Zero } + , AngularLockFactor { SHVec3::Zero } { - LinearVelocity = rigidBody->GetLinearVelocity(); - AngularVelocity = rigidBody->GetAngularVelocity(); - - LinearLockFactor = SHVec3 + if (rigidBody) { - rigidBody->GetFreezePositionX() ? 0.0f : 1.0f - , rigidBody->GetFreezePositionY() ? 0.0f : 1.0f - , rigidBody->GetFreezePositionZ() ? 0.0f : 1.0f - }; + LinearVelocity = rigidBody->GetLinearVelocity(); + AngularVelocity = rigidBody->GetAngularVelocity(); - AngularLockFactor = SHVec3 - { - rigidBody->GetFreezeRotationX() ? 0.0f : 1.0f - , rigidBody->GetFreezeRotationY() ? 0.0f : 1.0f - , rigidBody->GetFreezeRotationZ() ? 0.0f : 1.0f - }; + LinearLockFactor = SHVec3 + { + rigidBody->GetFreezePositionX() ? 0.0f : 1.0f + , rigidBody->GetFreezePositionY() ? 0.0f : 1.0f + , rigidBody->GetFreezePositionZ() ? 0.0f : 1.0f + }; + + AngularLockFactor = SHVec3 + { + rigidBody->GetFreezeRotationX() ? 0.0f : 1.0f + , rigidBody->GetFreezeRotationY() ? 0.0f : 1.0f + , rigidBody->GetFreezeRotationZ() ? 0.0f : 1.0f + }; + } } }; diff --git a/SHADE_Engine/src/Physics/Dynamics/SHContactManager.cpp b/SHADE_Engine/src/Physics/Dynamics/SHContactManager.cpp index ade7b482..7434953e 100644 --- a/SHADE_Engine/src/Physics/Dynamics/SHContactManager.cpp +++ b/SHADE_Engine/src/Physics/Dynamics/SHContactManager.cpp @@ -200,11 +200,17 @@ namespace SHADE const auto& STATE_A = VELOCITY_STATES.find(key.GetEntityA())->second; const auto& STATE_B = VELOCITY_STATES.find(key.GetEntityB())->second; - bodyA->SetLinearVelocity(STATE_A.LinearVelocity); - bodyB->SetLinearVelocity(STATE_B.LinearVelocity); + if (bodyA) + { + bodyA->SetLinearVelocity(STATE_A.LinearVelocity); + bodyA->SetAngularVelocity(STATE_A.AngularVelocity); + } - bodyA->SetAngularVelocity(STATE_A.AngularVelocity); - bodyB->SetAngularVelocity(STATE_B.AngularVelocity); + if (bodyB) + { + bodyB->SetLinearVelocity(STATE_B.LinearVelocity); + bodyB->SetAngularVelocity(STATE_B.AngularVelocity); + } } contactSolver.Reset(); diff --git a/SHADE_Engine/src/Physics/Dynamics/SHContactSolver.cpp b/SHADE_Engine/src/Physics/Dynamics/SHContactSolver.cpp index 926e1fed..f16d7f1e 100644 --- a/SHADE_Engine/src/Physics/Dynamics/SHContactSolver.cpp +++ b/SHADE_Engine/src/Physics/Dynamics/SHContactSolver.cpp @@ -63,13 +63,38 @@ namespace SHADE // Mass data - newConstraint.invMassA = BODY_A->invMass; - newConstraint.invInertiaA = BODY_A->worldInvInertia; - newConstraint.centerOfMassA = BODY_A->worldCentroid; + // Account for implicity-static bodies + if (BODY_A) + { + newConstraint.invMassA = BODY_A->invMass; + newConstraint.centerOfMassA = BODY_A->worldCentroid; + newConstraint.invInertiaA = BODY_A->worldInvInertia; + } + else + { + newConstraint.invMassA = 0.0f; + newConstraint.centerOfMassA = SHVec3::Zero; - newConstraint.invMassB = BODY_B->invMass; - newConstraint.invInertiaB = BODY_B->worldInvInertia; - newConstraint.centerOfMassB = BODY_B->worldCentroid; + // 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.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