diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index cc3caf10..86e5038f 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -39,14 +39,13 @@ namespace deuterG_Magnitude = deuterG.Dot( normal ); // bounce - Float impulse = Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(), - deuterState.GetMass(), deuterG_Magnitude, - protoState.GetMass(), protoG_Magnitude );; - Float4 sumJ = normal*impulse; + Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(), + deuterState.GetMass(), deuterG_Magnitude, + protoState.GetMass(), protoG_Magnitude ); - sumJ -= Formula::CollisionResponse::Friction( impulse, normal, - protoState.GetLinearMomentum(), protoState.GetFrictionCoeff_Static(), protoState.GetFrictionCoeff_Kinetic(), protoState.GetMass(), - deuterState.GetLinearMomentum(), deuterState.GetFrictionCoeff_Static(), deuterState.GetFrictionCoeff_Kinetic(), deuterState.GetMass()); + //sumJ -= Formula::CollisionResponse::Friction( impulse, normal, + // protoState.GetLinearMomentum(), protoState.GetFrictionCoeff_Static(), protoState.GetFrictionCoeff_Kinetic(), protoState.GetMass(), + // deuterState.GetLinearMomentum(), deuterState.GetFrictionCoeff_Static(), deuterState.GetFrictionCoeff_Kinetic(), deuterState.GetMass()); // calc from perspective of proto proto->GetNormalAt( worldPointOfContact, normal ); @@ -54,18 +53,22 @@ namespace deuterG_Magnitude = deuterG.Dot( normal ); // bounce - sumJ -= normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(), - protoState.GetMass(), protoG_Magnitude, - deuterState.GetMass(), deuterG_Magnitude ); + Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(), + protoState.GetMass(), protoG_Magnitude, + deuterState.GetMass(), deuterG_Magnitude ); + + Float4 bounce = Average( bounceD, bounceP ); + //Float4 bounce = bounceD + bounceP; + // FRICTION // Apply //sumJ += ( 1 / deuterState.GetMass() )*frictionImpulse; // FRICTION END - protoState.ApplyImpulse( sumJ, worldPointOfContact, normal ); + protoState.ApplyImpulse( bounce, worldPointOfContact, normal ); proto->SetState( protoState ); } - break; + break; } } } diff --git a/Code/GamePhysics/PhysicsFormula-Impl.h b/Code/GamePhysics/PhysicsFormula-Impl.h index 6546a856..323fd732 100644 --- a/Code/GamePhysics/PhysicsFormula-Impl.h +++ b/Code/GamePhysics/PhysicsFormula-Impl.h @@ -38,7 +38,8 @@ namespace Oyster { namespace Physics { namespace Formula { inline ::Oyster::Math::Float Bounce( ::Oyster::Math::Float e, ::Oyster::Math::Float mA, ::Oyster::Math::Float gA, ::Oyster::Math::Float mB, ::Oyster::Math::Float gB ) { - return (e + 1) * (mB*gA - mA*gB) / (mA + mB); + //return (e + 1) * (mB*gA - mA*gB) / (mA + mB); + return (e + 1) * (mA*gB - mB*gA) / (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 ) diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index cebf3747..a71884f9 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -108,13 +108,13 @@ void RigidBody::Update_LeapFrog( Float deltaTime ) // updating the linear // dG = F * dt // ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G - Float3 linearImpulse = this->impulseForceSum * deltaTime; // aka deltaLinearMomentum + Float3 linearImpulse = this->impulseForceSum; // HACK: * deltaTime; // aka deltaLinearMomentum Float3 deltaPos = ( deltaTime / this->mass ) * ::Utility::Value::AverageWithDelta( this->linearMomentum, linearImpulse ); // updating the angular // dH = T * dt // dO = dt * Formula::AngularVelocity( (RI)^-1, avg_H ) = dt * (RI)^-1 * avg_H - Float3 angularImpulse = this->impulseTorqueSum * deltaTime; // aka deltaAngularMomentum + Float3 angularImpulse = this->impulseTorqueSum; // HACK: * deltaTime; // aka deltaAngularMomentum Float3 rotationAxis = Formula::AngularVelocity( wMomentOfInertiaTensor.GetInverse(), ::Utility::Value::AverageWithDelta(this->angularMomentum, angularImpulse) );