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()
{
this->gravityConstant = Constant::gravity_constant;
this->epsilon = Constant::epsilon;
this->updateFrameLength = 1.0f / 120.0f;
this->destructionAction = Default::EventAction_Destruction;
this->gravity = ::std::vector<Gravity>();
@ -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;
}
}

View File

@ -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<ICustomBody> CreateRigidBody( const SphericalBodyDescription &desc ) const;
private:
::Oyster::Math::Float gravityConstant, updateFrameLength;
::Oyster::Math::Float gravityConstant, updateFrameLength, epsilon;
EventAction_Destruction destructionAction;
::std::vector<API::Gravity> gravity;
Octree worldScene;

View File

@ -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