From 9cee69edd63146e7f86a6311976b53dd2874874d Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Thu, 19 Dec 2013 10:03:56 +0100 Subject: [PATCH] Extended friction content of the ICustomBody::State struct --- .../Implementation/SimpleRigidBody.cpp | 12 +++++----- .../Implementation/SphericalRigidBody.cpp | 6 +++-- Code/GamePhysics/PhysicsStructs-Impl.h | 22 +++++++++++++------ Code/GamePhysics/PhysicsStructs.h | 10 +++++---- Code/OysterPhysics3D/RigidBody.cpp | 6 +++-- Code/OysterPhysics3D/RigidBody.h | 2 +- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index b0c8acce..16d7113d 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -44,7 +44,8 @@ UniquePointer SimpleRigidBody::Clone() const SimpleRigidBody::State SimpleRigidBody::GetState() const { - return State( this->rigid.GetMass(), this->rigid.restitutionCoeff, this->rigid.frictionCoeff, + return State( this->rigid.GetMass(), this->rigid.restitutionCoeff, + this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic, this->rigid.GetMomentOfInertia(), this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation), Float4(this->rigid.linearMomentum, 0.0f), Float4(this->rigid.angularMomentum, 0.0f) ); @@ -52,10 +53,11 @@ SimpleRigidBody::State SimpleRigidBody::GetState() const SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targetMem ) const { - return targetMem = State( this->rigid.GetMass(), this->rigid.restitutionCoeff, this->rigid.frictionCoeff, - this->rigid.GetMomentOfInertia(), this->rigid.box.boundingOffset, - this->rigid.box.center, AngularAxis(this->rigid.box.rotation), - Float4(this->rigid.linearMomentum, 0.0f), Float4(this->rigid.angularMomentum, 0.0f) ); + return targetMem = State( this->rigid.GetMass(), this->rigid.restitutionCoeff, + this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic, + this->rigid.GetMomentOfInertia(), this->rigid.box.boundingOffset, + this->rigid.box.center, AngularAxis(this->rigid.box.rotation), + Float4(this->rigid.linearMomentum, 0.0f), Float4(this->rigid.angularMomentum, 0.0f) ); } void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index d7154f2f..a3ccfa77 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -46,7 +46,8 @@ UniquePointer SphericalRigidBody::Clone() const SphericalRigidBody::State SphericalRigidBody::GetState() const { - return State( this->rigid.GetMass(), this->rigid.restitutionCoeff, this->rigid.frictionCoeff, + return State( this->rigid.GetMass(), this->rigid.restitutionCoeff, + this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic, this->rigid.GetMomentOfInertia(), this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation), Float4(this->rigid.linearMomentum, 0.0f), Float4(this->rigid.angularMomentum, 0.0f) ); @@ -54,7 +55,8 @@ SphericalRigidBody::State SphericalRigidBody::GetState() const SphericalRigidBody::State & SphericalRigidBody::GetState( SphericalRigidBody::State &targetMem ) const { - return targetMem = State( this->rigid.GetMass(), this->rigid.restitutionCoeff, this->rigid.frictionCoeff, + return targetMem = State( this->rigid.GetMass(), this->rigid.restitutionCoeff, + this->rigid.frictionCoeff_Static, this->rigid.frictionCoeff_Kinetic, this->rigid.GetMomentOfInertia(), this->rigid.box.boundingOffset, this->rigid.box.center, AngularAxis(this->rigid.box.rotation), Float4(this->rigid.linearMomentum, 0.0f), Float4(this->rigid.angularMomentum, 0.0f) ); diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index d13fdd80..8a75b0bf 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -28,11 +28,12 @@ namespace Oyster { namespace Physics this->ignoreGravity = false; } - inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float frictionCoeff, const ::Oyster::Math::Float4x4 &inertiaTensor, const ::Oyster::Math::Float4 &reach, const ::Oyster::Math::Float4 ¢erPos, const ::Oyster::Math::Float4 &rotation, const ::Oyster::Math::Float4 &linearMomentum, const ::Oyster::Math::Float4 &angularMomentum ) + inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float kineticFrictionCoeff, const ::Oyster::Math::Float4x4 &inertiaTensor, const ::Oyster::Math::Float4 &reach, const ::Oyster::Math::Float4 ¢erPos, const ::Oyster::Math::Float4 &rotation, const ::Oyster::Math::Float4 &linearMomentum, const ::Oyster::Math::Float4 &angularMomentum ) { this->mass = mass; this->restitutionCoeff = restitutionCoeff; - this->frictionCoeff = frictionCoeff; + this->staticFrictionCoeff = staticFrictionCoeff; + this->kineticFrictionCoeff = kineticFrictionCoeff; this->inertiaTensor = inertiaTensor; this->reach = ::Oyster::Math::Float4( reach.xyz, 0.0f ); this->centerPos = ::Oyster::Math::Float4( centerPos.xyz, 1.0f ); @@ -47,7 +48,8 @@ namespace Oyster { namespace Physics { this->mass = state.mass; this->restitutionCoeff = state.restitutionCoeff; - this->frictionCoeff = state.frictionCoeff; + this->staticFrictionCoeff = state.staticFrictionCoeff; + this->kineticFrictionCoeff = state.kineticFrictionCoeff; this->inertiaTensor = state.inertiaTensor; this->reach = state.reach; this->centerPos = state.centerPos; @@ -71,9 +73,14 @@ namespace Oyster { namespace Physics return this->restitutionCoeff; } - inline const ::Oyster::Math::Float CustomBodyState::GetFrictionCoeff() const + inline const ::Oyster::Math::Float CustomBodyState::GetFrictionCoeff_Static() const { - return this->frictionCoeff; + return this->staticFrictionCoeff; + } + + inline const ::Oyster::Math::Float CustomBodyState::GetFrictionCoeff_Kinetic() const + { + return this->kineticFrictionCoeff; } inline const ::Oyster::Math::Float4x4 & CustomBodyState::GetMomentOfInertia() const @@ -163,9 +170,10 @@ namespace Oyster { namespace Physics this->restitutionCoeff = e; } - inline void CustomBodyState::SetFrictionCoeff( ::Oyster::Math::Float u ) + inline void CustomBodyState::SetFrictionCoeff( ::Oyster::Math::Float staticU, ::Oyster::Math::Float kineticU ) { - this->frictionCoeff = u; + this->staticFrictionCoeff = staticU; + this->kineticFrictionCoeff = kineticU; } inline void CustomBodyState::SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &tensor ) diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index ce2b40cb..96ec1f14 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -38,7 +38,8 @@ namespace Oyster { namespace Physics public: CustomBodyState( ::Oyster::Math::Float mass = 1.0f, ::Oyster::Math::Float restitutionCoeff = 1.0f, - ::Oyster::Math::Float frictionCoeff = 1.0f, + ::Oyster::Math::Float staticFrictionCoeff = 1.0f, + ::Oyster::Math::Float kineticFrictionCoeff = 1.0f, const ::Oyster::Math::Float4x4 &inertiaTensor = ::Oyster::Math::Float4x4::identity, const ::Oyster::Math::Float4 &reach = ::Oyster::Math::Float4::null, const ::Oyster::Math::Float4 ¢erPos = ::Oyster::Math::Float4::standard_unit_w, @@ -50,7 +51,8 @@ namespace Oyster { namespace Physics const ::Oyster::Math::Float GetMass() const; const ::Oyster::Math::Float GetRestitutionCoeff() const; - const ::Oyster::Math::Float GetFrictionCoeff() const; + const ::Oyster::Math::Float GetFrictionCoeff_Static() const; + const ::Oyster::Math::Float GetFrictionCoeff_Kinetic() const; const ::Oyster::Math::Float4x4 & GetMomentOfInertia() const; const ::Oyster::Math::Float4 & GetReach() const; ::Oyster::Math::Float4 GetSize() const; @@ -68,7 +70,7 @@ namespace Oyster { namespace Physics void SetMass_KeepMomentum( ::Oyster::Math::Float m ); void SetMass_KeepVelocity( ::Oyster::Math::Float m ); void SetRestitutionCoeff( ::Oyster::Math::Float e ); - void SetFrictionCoeff( ::Oyster::Math::Float u ); + void SetFrictionCoeff( ::Oyster::Math::Float staticU, ::Oyster::Math::Float kineticU ); void SetMomentOfInertia_KeepMomentum( const ::Oyster::Math::Float4x4 &tensor ); void SetMomentOfInertia_KeepVelocity( const ::Oyster::Math::Float4x4 &tensor ); void SetSize( const ::Oyster::Math::Float4 &size ); @@ -93,7 +95,7 @@ namespace Oyster { namespace Physics bool IsDisturbed() const; private: - ::Oyster::Math::Float mass, restitutionCoeff, frictionCoeff; + ::Oyster::Math::Float mass, restitutionCoeff, staticFrictionCoeff, kineticFrictionCoeff; ::Oyster::Math::Float4x4 inertiaTensor; ::Oyster::Math::Float4 reach, centerPos, angularAxis; ::Oyster::Math::Float4 linearMomentum, angularMomentum; diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index 538fb1e6..cebf3747 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -17,7 +17,8 @@ RigidBody::RigidBody( const Box &b, Float m, const Float4x4 &inertiaTensor ) this->impulseTorqueSum = Float3::null; this->impulseForceSum = Float3::null; this->restitutionCoeff = 1.0f; - this->frictionCoeff = 1.0f; + this->frictionCoeff_Static = 1.0f; + this->frictionCoeff_Kinetic = 1.0f; if( m != 0.0f ) { @@ -46,7 +47,8 @@ RigidBody & RigidBody::operator = ( const RigidBody &body ) this->impulseTorqueSum = body.impulseTorqueSum; this->impulseForceSum = body.impulseForceSum; this->restitutionCoeff = body.restitutionCoeff; - this->frictionCoeff = body.frictionCoeff; + this->frictionCoeff_Static = body.frictionCoeff_Static; + this->frictionCoeff_Kinetic = body.frictionCoeff_Kinetic; this->mass = body.mass; this->momentOfInertiaTensor = body.momentOfInertiaTensor; return *this; diff --git a/Code/OysterPhysics3D/RigidBody.h b/Code/OysterPhysics3D/RigidBody.h index 1ac632d7..fae7b842 100644 --- a/Code/OysterPhysics3D/RigidBody.h +++ b/Code/OysterPhysics3D/RigidBody.h @@ -19,7 +19,7 @@ namespace Oyster { namespace Physics3D linearMomentum, /** The linear momentum G (kg*m/s). (worldValue) */ impulseTorqueSum, /** The impulse torque T (Nm) that will be consumed each update. (worldValue) */ impulseForceSum; /** The impulse force F (N) that will be consumed each update. (worldValue) */ - ::Oyster::Math::Float restitutionCoeff, frictionCoeff; + ::Oyster::Math::Float restitutionCoeff, frictionCoeff_Static, frictionCoeff_Kinetic; RigidBody( const ::Oyster::Collision3D::Box &box = ::Oyster::Collision3D::Box(), ::Oyster::Math::Float mass = 12.0f,