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

This commit is contained in:
lindaandersson 2014-02-04 10:39:09 +01:00
commit 07e8624807
2 changed files with 20 additions and 14 deletions

View File

@ -66,6 +66,9 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
this->rigid.SetRotation( desc.rotation ); this->rigid.SetRotation( desc.rotation );
this->rigid.centerPos = desc.centerPosition; this->rigid.centerPos = desc.centerPosition;
this->rigid.SetSize( desc.size ); this->rigid.SetSize( desc.size );
this->rigid.restitutionCoeff = desc.restitutionCoeff;
this->rigid.frictionCoeff_Static = desc.frictionCoeff_Static;
this->rigid.frictionCoeff_Kinetic = desc.frictionCoeff_Dynamic;
this->rigid.SetMass_KeepMomentum( desc.mass ); this->rigid.SetMass_KeepMomentum( desc.mass );
this->rigid.SetMomentOfInertia_KeepMomentum( desc.inertiaTensor ); this->rigid.SetMomentOfInertia_KeepMomentum( desc.inertiaTensor );
this->deltaPos = Float4::null; this->deltaPos = Float4::null;
@ -333,23 +336,23 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
// this->isForwarded = false; // this->isForwarded = false;
//} //}
this->rigid.Update_LeapFrog( timeStepLength );
{ // Rebound if needed { // Rebound if needed
if( this->collisionRebound.timeOfContact < 1.0f ) if( this->collisionRebound.timeOfContact < 1.0f )
{ {
this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact );
this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) );
this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact );
this->collisionRebound.timeOfContact = 1.0f;
} }
// Update rebound data // Update rebound data
this->collisionRebound.previousSpatial.center = this->rigid.centerPos; this->collisionRebound.previousSpatial.center = this->rigid.centerPos;
this->collisionRebound.previousSpatial.axis = this->rigid.axis; this->collisionRebound.previousSpatial.axis = this->rigid.axis;
this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach;
this->collisionRebound.timeOfContact = 1.0f;
} }
this->rigid.Update_LeapFrog( timeStepLength );
{ // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) { // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too)
Float3 n; Float3 n;
::std::modf( this->rigid.axis * (0.5f / pi), n ); ::std::modf( this->rigid.axis * (0.5f / pi), n );

View File

@ -33,6 +33,9 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des
this->rigid.SetRotation( desc.rotation ); this->rigid.SetRotation( desc.rotation );
this->rigid.centerPos = desc.centerPosition; this->rigid.centerPos = desc.centerPosition;
this->rigid.boundingReach = Float4( desc.radius, desc.radius, desc.radius, 0.0f ); this->rigid.boundingReach = Float4( desc.radius, desc.radius, desc.radius, 0.0f );
this->rigid.restitutionCoeff = desc.restitutionCoeff;
this->rigid.frictionCoeff_Static = desc.frictionCoeff_Static;
this->rigid.frictionCoeff_Kinetic = desc.frictionCoeff_Dynamic;
this->rigid.SetMass_KeepMomentum( desc.mass ); this->rigid.SetMass_KeepMomentum( desc.mass );
this->rigid.SetMomentOfInertia_KeepMomentum( MomentOfInertia::Sphere(desc.mass, desc.radius) ); this->rigid.SetMomentOfInertia_KeepMomentum( MomentOfInertia::Sphere(desc.mass, desc.radius) );
this->deltaPos = Float4::null; this->deltaPos = Float4::null;
@ -254,23 +257,23 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength )
// this->isForwarded = false; // this->isForwarded = false;
//} //}
this->rigid.Update_LeapFrog( timeStepLength );
{ // Rebound if needed { // Rebound if needed
if( this->collisionRebound.timeOfContact < 1.0f ) if( this->collisionRebound.timeOfContact < 1.0f )
{ {
this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact );
this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) );
this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact );
this->collisionRebound.timeOfContact = 1.0f;
} }
// Update rebound data // Update rebound data
this->collisionRebound.previousSpatial.center = this->rigid.centerPos; this->collisionRebound.previousSpatial.center = this->rigid.centerPos;
this->collisionRebound.previousSpatial.axis = this->rigid.axis; this->collisionRebound.previousSpatial.axis = this->rigid.axis;
this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach;
this->collisionRebound.timeOfContact = 1.0f;
} }
this->rigid.Update_LeapFrog( timeStepLength );
{ // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) { // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too)
Float3 n; Float3 n;
::std::modf( this->rigid.axis * (0.5f / pi), n ); ::std::modf( this->rigid.axis * (0.5f / pi), n );