From aa99742894f92e2dd2c882a3674525f460575f9b Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 29 Jan 2014 12:22:18 +0100 Subject: [PATCH] Added epsilon value for testing --- .../Implementation/PhysicsAPI_Impl.cpp | 27 ++++++++++++++++++- .../Implementation/PhysicsAPI_Impl.h | 3 ++- Code/GamePhysics/PhysicsAPI.h | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 5ca06fce..6f164810 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -99,6 +99,7 @@ API & API::Instance() API_Impl::API_Impl() { this->gravityConstant = Constant::gravity_constant; + this->epsilon = Constant::epsilon; this->updateFrameLength = 1.0f / 120.0f; this->destructionAction = Default::EventAction_Destruction; this->gravity = ::std::vector(); @@ -125,6 +126,11 @@ void API_Impl::SetGravityConstant( float g ) this->gravityConstant = g; } +void API_Impl::SetEpsilon( float e ) +{ + this->epsilon = e; +} + void API_Impl::SetSubscription( API::EventAction_Destruction functionPointer ) { if( functionPointer ) @@ -192,12 +198,31 @@ void API_Impl::Update() proto = updateList.begin(); for( ; proto != updateList.end(); ++proto ) { + Float3 lM = state.GetLinearMomentum() + state.GetLinearImpulse(); + + if( lM.x < this->epsilon ) + { + state.SetLinearMomentum( Float3(0, lM.y, lM.z) ); + state.SetLinearImpulse( Float3(0, lM.y, lM.z) ); + } + if( lM.y < this->epsilon ) + { + state.SetLinearMomentum( Float3(lM.x, 0, lM.z) ); + state.SetLinearImpulse( Float3(lM.x, 0, lM.z) ); + } + if( lM.z < this->epsilon ) + { + state.SetLinearMomentum( Float3(lM.x, lM.y, 0) ); + state.SetLinearImpulse( Float3(lM.x, lM.y, 0) ); + } + switch( (*proto)->Update(this->updateFrameLength) ) { case UpdateState_altered: this->worldScene.SetAsAltered( this->worldScene.GetTemporaryReferenceOf(*proto) ); (*proto)->CallSubscription_Move(); - case UpdateState_resting: default: + case UpdateState_resting: + default: break; } } diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h index 9ea9a6fc..21460944 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -18,6 +18,7 @@ namespace Oyster void SetFrameTimeLength( float deltaTime ); void SetGravityConstant( float g ); + void SetEpsilon( float e ); void SetSubscription( EventAction_Destruction functionPointer ); float GetFrameTimeLength() const; @@ -52,7 +53,7 @@ namespace Oyster ::Utility::DynamicMemory::UniquePointer CreateRigidBody( const SphericalBodyDescription &desc ) const; private: - ::Oyster::Math::Float gravityConstant, updateFrameLength; + ::Oyster::Math::Float gravityConstant, updateFrameLength, epsilon; EventAction_Destruction destructionAction; ::std::vector gravity; Octree worldScene; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 353756eb..78b65f5e 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -34,6 +34,7 @@ namespace Oyster namespace Constant { const float gravity_constant = (const float)6.67284e-11; //!< The _big_G_! ( N(m/kg)^2 ) Used in real gravityforcefields. + const float epsilon = (const float)1.0e-7; } class PHYSICS_DLL_USAGE API