From d4bd72bb4a9210dd6349e31da11a072f6a7bcd1c Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 08:55:57 +0100 Subject: [PATCH] Friction fix special case; no movement special case; movement directly into surface .. dealt with --- Code/GamePhysics/PhysicsFormula-Impl.h | 36 +++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/Code/GamePhysics/PhysicsFormula-Impl.h b/Code/GamePhysics/PhysicsFormula-Impl.h index 323fd732..189691f6 100644 --- a/Code/GamePhysics/PhysicsFormula-Impl.h +++ b/Code/GamePhysics/PhysicsFormula-Impl.h @@ -48,26 +48,32 @@ namespace Oyster { namespace Physics { namespace Formula // Relative momentum after normal impulse ::Oyster::Math::Float4 relativeMomentum = momB - momA; - ::Oyster::Math::Float4 tanFriction = relativeMomentum - relativeMomentum.Dot( iN )*iN; - tanFriction.Normalize(); + ::Oyster::Math::Float4 tanFriction = relativeMomentum - relativeMomentum.Dot( iN ) * iN; - ::Oyster::Math::Float magnitudeFriction = -relativeMomentum.Dot( tanFriction ); - magnitudeFriction = magnitudeFriction*mA*mB/( mA + mB ); + if( tanFriction.Dot(tanFriction) > 0.0f ) + { // no friction if moving directly into surface, or not at all. + tanFriction.Normalize(); - ::Oyster::Math::Float mu = 0.5f*( sFA + sFB ); + ::Oyster::Math::Float magnitudeFriction = -relativeMomentum.Dot( tanFriction ); + magnitudeFriction = magnitudeFriction * mA * mB / ( mA + mB ); + + ::Oyster::Math::Float mu = 0.5f * ( sFA + sFB ); - ::Oyster::Math::Float4 frictionImpulse; - if( abs(magnitudeFriction) < i*mu ) - { - frictionImpulse = magnitudeFriction*tanFriction; + ::Oyster::Math::Float4 frictionImpulse; + if( abs(magnitudeFriction) < i * mu ) + { + frictionImpulse = magnitudeFriction * tanFriction; + } + else + { + ::Oyster::Math::Float dynamicFriction = 0.5f * ( dFA + dFB ); + frictionImpulse = ( -i * dynamicFriction ) * tanFriction; + } + + return ( 1 / mA ) * frictionImpulse; } else - { - ::Oyster::Math::Float dynamicFriction = 0.5f*( dFA + dFB ); - frictionImpulse = -i*tanFriction*dynamicFriction; - } - - return ( 1 / mA )*frictionImpulse; + return ::Oyster::Math::Float4::null; } }