Merge branch 'Physics' of https://github.com/dean11/Danbias into GameLogic

This commit is contained in:
lindaandersson 2014-02-04 08:56:32 +01:00
commit 6e9423670f
1 changed files with 21 additions and 15 deletions

View File

@ -48,26 +48,32 @@ namespace Oyster { namespace Physics { namespace Formula
// Relative momentum after normal impulse // Relative momentum after normal impulse
::Oyster::Math::Float4 relativeMomentum = momB - momA; ::Oyster::Math::Float4 relativeMomentum = momB - momA;
::Oyster::Math::Float4 tanFriction = relativeMomentum - relativeMomentum.Dot( iN )*iN; ::Oyster::Math::Float4 tanFriction = relativeMomentum - relativeMomentum.Dot( iN ) * iN;
if( tanFriction.Dot(tanFriction) > 0.0f )
{ // no friction if moving directly into surface, or not at all.
tanFriction.Normalize(); tanFriction.Normalize();
::Oyster::Math::Float magnitudeFriction = -relativeMomentum.Dot( tanFriction ); ::Oyster::Math::Float magnitudeFriction = -relativeMomentum.Dot( tanFriction );
magnitudeFriction = magnitudeFriction*mA*mB/( mA + mB ); magnitudeFriction = magnitudeFriction * mA * mB / ( mA + mB );
::Oyster::Math::Float mu = 0.5f*( sFA + sFB ); ::Oyster::Math::Float mu = 0.5f * ( sFA + sFB );
::Oyster::Math::Float4 frictionImpulse; ::Oyster::Math::Float4 frictionImpulse;
if( abs(magnitudeFriction) < i*mu ) if( abs(magnitudeFriction) < i * mu )
{ {
frictionImpulse = magnitudeFriction*tanFriction; frictionImpulse = magnitudeFriction * tanFriction;
} }
else else
{ {
::Oyster::Math::Float dynamicFriction = 0.5f*( dFA + dFB ); ::Oyster::Math::Float dynamicFriction = 0.5f * ( dFA + dFB );
frictionImpulse = -i*tanFriction*dynamicFriction; frictionImpulse = ( -i * dynamicFriction ) * tanFriction;
} }
return ( 1 / mA )*frictionImpulse; return ( 1 / mA ) * frictionImpulse;
}
else
return ::Oyster::Math::Float4::null;
} }
} }