Added epsilon value for testing

This commit is contained in:
Robin Engman 2014-01-29 12:22:18 +01:00
parent 1d3b073e7f
commit aa99742894
3 changed files with 29 additions and 2 deletions

View File

@ -99,6 +99,7 @@ API & API::Instance()
API_Impl::API_Impl() API_Impl::API_Impl()
{ {
this->gravityConstant = Constant::gravity_constant; this->gravityConstant = Constant::gravity_constant;
this->epsilon = Constant::epsilon;
this->updateFrameLength = 1.0f / 120.0f; this->updateFrameLength = 1.0f / 120.0f;
this->destructionAction = Default::EventAction_Destruction; this->destructionAction = Default::EventAction_Destruction;
this->gravity = ::std::vector<Gravity>(); this->gravity = ::std::vector<Gravity>();
@ -125,6 +126,11 @@ void API_Impl::SetGravityConstant( float g )
this->gravityConstant = g; this->gravityConstant = g;
} }
void API_Impl::SetEpsilon( float e )
{
this->epsilon = e;
}
void API_Impl::SetSubscription( API::EventAction_Destruction functionPointer ) void API_Impl::SetSubscription( API::EventAction_Destruction functionPointer )
{ {
if( functionPointer ) if( functionPointer )
@ -192,12 +198,31 @@ void API_Impl::Update()
proto = updateList.begin(); proto = updateList.begin();
for( ; proto != updateList.end(); ++proto ) 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) ) switch( (*proto)->Update(this->updateFrameLength) )
{ {
case UpdateState_altered: case UpdateState_altered:
this->worldScene.SetAsAltered( this->worldScene.GetTemporaryReferenceOf(*proto) ); this->worldScene.SetAsAltered( this->worldScene.GetTemporaryReferenceOf(*proto) );
(*proto)->CallSubscription_Move(); (*proto)->CallSubscription_Move();
case UpdateState_resting: default: case UpdateState_resting:
default:
break; break;
} }
} }

View File

@ -18,6 +18,7 @@ namespace Oyster
void SetFrameTimeLength( float deltaTime ); void SetFrameTimeLength( float deltaTime );
void SetGravityConstant( float g ); void SetGravityConstant( float g );
void SetEpsilon( float e );
void SetSubscription( EventAction_Destruction functionPointer ); void SetSubscription( EventAction_Destruction functionPointer );
float GetFrameTimeLength() const; float GetFrameTimeLength() const;
@ -52,7 +53,7 @@ namespace Oyster
::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateRigidBody( const SphericalBodyDescription &desc ) const; ::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateRigidBody( const SphericalBodyDescription &desc ) const;
private: private:
::Oyster::Math::Float gravityConstant, updateFrameLength; ::Oyster::Math::Float gravityConstant, updateFrameLength, epsilon;
EventAction_Destruction destructionAction; EventAction_Destruction destructionAction;
::std::vector<API::Gravity> gravity; ::std::vector<API::Gravity> gravity;
Octree worldScene; Octree worldScene;

View File

@ -34,6 +34,7 @@ namespace Oyster
namespace Constant namespace Constant
{ {
const float gravity_constant = (const float)6.67284e-11; //!< The _big_G_! ( N(m/kg)^2 ) Used in real gravityforcefields. 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 class PHYSICS_DLL_USAGE API