From 66e93fbdae53c53f1a778a734e7099e12134510d Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Fri, 20 Dec 2013 11:36:39 +0100 Subject: [PATCH] SimpleRigid functions mirrored in SphericalRigid The functions added to SimpleRigidBody has been added to SphericalRigidBody too. --- .../Implementation/SphericalRigidBody.cpp | 24 ++++++++++++++++++- .../Implementation/SphericalRigidBody.h | 4 +++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index d0bebedf..4b37b2b9 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -14,7 +14,7 @@ SphericalRigidBody::SphericalRigidBody() this->rigid.SetMass_KeepMomentum( 10.0f ); this->gravityNormal = Float3::null; this->collisionAction = Default::EventAction_Collision; - this->ignoreGravity = false; + this->ignoreGravity = this->isForwarded = false; this->scene = nullptr; this->body = Sphere( Float3::null, 0.5f ); } @@ -27,6 +27,8 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des this->rigid.boundingReach = Float4( desc.radius, desc.radius, desc.radius, 0.0f ); this->rigid.SetMass_KeepMomentum( desc.mass ); this->rigid.SetMomentOfInertia_KeepMomentum( Formula::MomentOfInertia::CreateSphereMatrix( desc.mass, desc.radius ) ); + this->deltaPos = Float4::null; + this->deltaAxis = Float4::null; this->gravityNormal = Float3::null; @@ -82,6 +84,13 @@ void SphericalRigidBody::SetState( const SphericalRigidBody::State &state ) this->rigid.frictionCoeff_Static = state.GetFrictionCoeff_Static(); this->rigid.frictionCoeff_Kinetic = state.GetFrictionCoeff_Kinetic(); + if( state.IsForwarded() ) + { + this->deltaPos += state.GetForward_DeltaPos(); + this->deltaAxis += state.GetForward_DeltaAxis(); + this->isForwarded = false; + } + if( this->scene ) { if( state.IsSpatiallyAltered() ) @@ -171,6 +180,14 @@ Float3 SphericalRigidBody::GetRigidLinearVelocity() const UpdateState SphericalRigidBody::Update( Float timeStepLength ) { + if( this->isForwarded ) + { + this->rigid.Move( this->deltaPos, this->deltaAxis ); + this->deltaPos = Float4::null; + this->deltaAxis = Float4::null; + this->isForwarded = false; + } + this->rigid.Update_LeapFrog( timeStepLength ); this->body.center = this->rigid.centerPos; @@ -179,6 +196,11 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength ) return UpdateState_altered; } +void SphericalRigidBody::Predict( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster::Math::Float4 &outDeltaAxis, const ::Oyster::Math::Float4 &actingLinearImpulse, const ::Oyster::Math::Float4 &actingAngularImpulse, ::Oyster::Math::Float deltaTime ) +{ + this->rigid.Predict_LeapFrog( outDeltaPos, outDeltaAxis, actingLinearImpulse, actingAngularImpulse, deltaTime ); +} + void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer ) { if( functionPointer ) diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.h b/Code/GamePhysics/Implementation/SphericalRigidBody.h index 4c2d74e5..3a76715f 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.h +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.h @@ -37,6 +37,7 @@ namespace Oyster { namespace Physics //::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; UpdateState Update( ::Oyster::Math::Float timeStepLength ); + void Predict( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster::Math::Float4 &outDeltaAxis, const ::Oyster::Math::Float4 &actingLinearImpulse, const ::Oyster::Math::Float4 &actingAngularImpulse, ::Oyster::Math::Float deltaTime ); void SetScene( void *scene ); void SetSubscription( EventAction_Collision functionPointer ); @@ -54,9 +55,10 @@ namespace Oyster { namespace Physics private: ::Oyster::Physics3D::RigidBody rigid; + ::Oyster::Math::Float4 deltaPos, deltaAxis; ::Oyster::Math::Float3 gravityNormal; EventAction_Collision collisionAction; - bool ignoreGravity; + bool ignoreGravity, isForwarded; Octree *scene; ::Oyster::Collision3D::Sphere body; };