Created function for friction
This commit is contained in:
parent
9cee69edd6
commit
59d5a3dc1e
|
@ -7,6 +7,7 @@ using namespace ::Oyster::Physics;
|
||||||
using namespace ::Oyster::Math;
|
using namespace ::Oyster::Math;
|
||||||
using namespace ::Oyster::Collision3D;
|
using namespace ::Oyster::Collision3D;
|
||||||
using namespace ::Utility::DynamicMemory;
|
using namespace ::Utility::DynamicMemory;
|
||||||
|
using namespace ::Utility::Value;
|
||||||
|
|
||||||
API_Impl API_instance;
|
API_Impl API_instance;
|
||||||
|
|
||||||
|
@ -43,32 +44,10 @@ namespace
|
||||||
protoState.GetMass(), protoG_Magnitude );;
|
protoState.GetMass(), protoG_Magnitude );;
|
||||||
Float4 sumJ = normal*impulse;
|
Float4 sumJ = normal*impulse;
|
||||||
|
|
||||||
// FRICTION
|
sumJ -= Formula::CollisionResponse::Friction( impulse, normal, protoState.GetLinearMomentum(),
|
||||||
// Relative momentum after normal impulse
|
protoState.GetFrictionCoeff(), 0.2f, protoState.GetMass(),
|
||||||
Float4 relativeMomentum = deuterState.GetLinearMomentum() - protoState.GetLinearMomentum();
|
deuterState.GetLinearMomentum(), deuterState.GetFrictionCoeff(),
|
||||||
|
0.2f, deuterState.GetMass());
|
||||||
Float4 tanFriction = relativeMomentum - relativeMomentum.Dot(normal)*normal;
|
|
||||||
tanFriction.Normalize();
|
|
||||||
|
|
||||||
Float magnitudeFriction = -relativeMomentum.Dot(tanFriction);
|
|
||||||
magnitudeFriction = magnitudeFriction/( 1/protoState.GetMass() + 1/deuterState.GetMass() );
|
|
||||||
|
|
||||||
float mu = 0.5f;
|
|
||||||
|
|
||||||
Float4 frictionImpulse;
|
|
||||||
if( abs(magnitudeFriction) < impulse*mu )
|
|
||||||
{
|
|
||||||
frictionImpulse = magnitudeFriction*tanFriction;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Float dynamicFriction = 0.5f;
|
|
||||||
frictionImpulse = -impulse*tanFriction*dynamicFriction;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply
|
|
||||||
sumJ -= ( 1 / protoState.GetMass() )*frictionImpulse;
|
|
||||||
// FRICTION END
|
|
||||||
|
|
||||||
// calc from perspective of proto
|
// calc from perspective of proto
|
||||||
proto->GetNormalAt( worldPointOfContact, normal );
|
proto->GetNormalAt( worldPointOfContact, normal );
|
||||||
|
|
|
@ -40,6 +40,34 @@ namespace Oyster { namespace Physics { namespace Formula
|
||||||
{
|
{
|
||||||
return (e + 1) * (mB*gA - mA*gB) / (mA + mB);
|
return (e + 1) * (mB*gA - mA*gB) / (mA + mB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline ::Oyster::Math::Float4 Friction( ::Oyster::Math::Float i, ::Oyster::Math::Float4 iN, ::Oyster::Math::Float4 momA, ::Oyster::Math::Float sFA, ::Oyster::Math::Float dFA, ::Oyster::Math::Float mA, ::Oyster::Math::Float4 momB, ::Oyster::Math::Float sFB, ::Oyster::Math::Float dFB, ::Oyster::Math::Float mB )
|
||||||
|
{
|
||||||
|
// FRICTION
|
||||||
|
// Relative momentum after normal impulse
|
||||||
|
::Oyster::Math::Float4 relativeMomentum = momB - momA;
|
||||||
|
|
||||||
|
::Oyster::Math::Float4 tanFriction = relativeMomentum - relativeMomentum.Dot( iN )*iN;
|
||||||
|
tanFriction.Normalize();
|
||||||
|
|
||||||
|
::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;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
::Oyster::Math::Float dynamicFriction = 0.5f*( dFA + dFB );
|
||||||
|
frictionImpulse = -i*tanFriction*dynamicFriction;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( 1 / mA )*frictionImpulse;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} } }
|
} } }
|
||||||
|
|
|
@ -20,6 +20,13 @@ namespace Oyster { namespace Physics { namespace Formula
|
||||||
::Oyster::Math::Float Impulse( ::Oyster::Math::Float coeffOfRestitution,
|
::Oyster::Math::Float Impulse( ::Oyster::Math::Float coeffOfRestitution,
|
||||||
::Oyster::Math::Float massA, ::Oyster::Math::Float momentumA,
|
::Oyster::Math::Float massA, ::Oyster::Math::Float momentumA,
|
||||||
::Oyster::Math::Float massB, ::Oyster::Math::Float momentumB );
|
::Oyster::Math::Float massB, ::Oyster::Math::Float momentumB );
|
||||||
|
|
||||||
|
::Oyster::Math::Float4 Friction( ::Oyster::Math::Float impulse, ::Oyster::Math::Float4 impulseNormal,
|
||||||
|
::Oyster::Math::Float4 momentumA, ::Oyster::Math::Float staticFrictionA,
|
||||||
|
::Oyster::Math::Float dynamicFrictionA, ::Oyster::Math::Float massA,
|
||||||
|
::Oyster::Math::Float4 momentumB, ::Oyster::Math::Float staticFrictionB,
|
||||||
|
::Oyster::Math::Float dynamicFrictionB, ::Oyster::Math::Float massB );
|
||||||
|
|
||||||
}
|
}
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue