Merge remote-tracking branch 'origin/Physics' into GameLogic
This commit is contained in:
commit
3a9c47722a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -22,92 +22,71 @@ namespace
|
||||||
Float4 worldPointOfContact;
|
Float4 worldPointOfContact;
|
||||||
if( proto->Intersects(*deuter, worldPointOfContact) )
|
if( proto->Intersects(*deuter, worldPointOfContact) )
|
||||||
{
|
{
|
||||||
switch( proto->CallSubscription_Collision(deuter) )
|
// Apply CollisionResponse in pure gather pattern
|
||||||
{
|
ICustomBody::State protoState; proto->GetState( protoState );
|
||||||
case ICustomBody::SubscriptMessage_ignore_collision_response:
|
ICustomBody::State deuterState; deuter->GetState( deuterState );
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{ // Apply CollisionResponse in pure gather pattern
|
|
||||||
ICustomBody::State protoState; proto->GetState( protoState );
|
|
||||||
ICustomBody::State deuterState; deuter->GetState( deuterState );
|
|
||||||
|
|
||||||
Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ),
|
Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ),
|
||||||
deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz );
|
deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz );
|
||||||
|
|
||||||
// calc from perspective of deuter
|
// calc from perspective of deuter
|
||||||
Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal );
|
Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal );
|
||||||
Float protoG_Magnitude = protoG.Dot( normal ),
|
Float protoG_Magnitude = protoG.Dot( normal ),
|
||||||
deuterG_Magnitude = deuterG.Dot( normal );
|
|
||||||
|
|
||||||
// if they are not relatively moving towards eachother, there is no collision
|
|
||||||
Float deltaPos = normal.Dot( Float4(deuterState.GetCenterPosition(), 1) - Float4(protoState.GetCenterPosition(), 1) );
|
|
||||||
if( deltaPos < 0.0f )
|
|
||||||
{
|
|
||||||
if( protoG_Magnitude >= deuterG_Magnitude )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if( deltaPos > 0.0f )
|
|
||||||
{
|
|
||||||
if( protoG_Magnitude <= deuterG_Magnitude )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// bounce
|
|
||||||
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());
|
|
||||||
|
|
||||||
// calc from perspective of proto
|
|
||||||
proto->GetNormalAt( worldPointOfContact, normal );
|
|
||||||
protoG_Magnitude = protoG.Dot( normal ),
|
|
||||||
deuterG_Magnitude = deuterG.Dot( normal );
|
deuterG_Magnitude = deuterG.Dot( normal );
|
||||||
|
|
||||||
// bounce
|
// if they are not relatively moving towards eachother, there is no collision
|
||||||
Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(),
|
Float deltaPos = normal.Dot( Float4(deuterState.GetCenterPosition(), 1) - Float4(protoState.GetCenterPosition(), 1) );
|
||||||
protoState.GetMass(), protoG_Magnitude,
|
if( deltaPos < 0.0f )
|
||||||
deuterState.GetMass(), deuterG_Magnitude );
|
{
|
||||||
|
if( protoG_Magnitude >= deuterG_Magnitude )
|
||||||
Float4 bounce = Average( bounceD, bounceP );
|
{
|
||||||
//Float4 bounce = bounceD + bounceP;
|
return;
|
||||||
|
|
||||||
// FRICTION
|
|
||||||
// Apply
|
|
||||||
//sumJ += ( 1 / deuterState.GetMass() )*frictionImpulse;
|
|
||||||
// FRICTION END
|
|
||||||
|
|
||||||
// Float4 forwardedDeltaPos, forwardedDeltaAxis;
|
|
||||||
// { // @todo TODO: is this right?
|
|
||||||
// Float4 bounceAngularImpulse = ::Oyster::Math::Float4( (worldPointOfContact - protoState.GetCenterPosition()).xyz.Cross(bounce.xyz), 0.0f ),
|
|
||||||
// bounceLinearImpulse = bounce - bounceAngularImpulse;
|
|
||||||
// proto->Predict( forwardedDeltaPos, forwardedDeltaAxis, bounceLinearImpulse, bounceAngularImpulse, API_instance.GetFrameTimeLength() );
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
Float kineticEnergyPBefore = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), protoState.GetLinearMomentum()/protoState.GetMass() );
|
|
||||||
|
|
||||||
// protoState.ApplyForwarding( forwardedDeltaPos, forwardedDeltaAxis );
|
|
||||||
protoState.ApplyImpulse( bounce.xyz, worldPointOfContact.xyz, normal.xyz );
|
|
||||||
proto->SetState( protoState );
|
|
||||||
|
|
||||||
Float kineticEnergyPAFter = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), (protoState.GetLinearMomentum() + protoState.GetLinearImpulse())/protoState.GetMass() );
|
|
||||||
|
|
||||||
proto->CallSubscription_CollisionResponse( deuter, kineticEnergyPBefore - kineticEnergyPAFter );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else if( deltaPos > 0.0f )
|
||||||
|
{
|
||||||
|
if( protoG_Magnitude <= deuterG_Magnitude )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( proto->CallSubscription_BeforeCollisionResponse(proto) == ICustomBody::SubscriptMessage_ignore_collision_response )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// bounce
|
||||||
|
Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(),
|
||||||
|
deuterState.GetMass(), deuterG_Magnitude,
|
||||||
|
protoState.GetMass(), protoG_Magnitude );
|
||||||
|
|
||||||
|
|
||||||
|
// calc from perspective of proto
|
||||||
|
proto->GetNormalAt( worldPointOfContact, normal );
|
||||||
|
protoG_Magnitude = protoG.Dot( normal ),
|
||||||
|
deuterG_Magnitude = deuterG.Dot( normal );
|
||||||
|
|
||||||
|
// bounce
|
||||||
|
Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(),
|
||||||
|
protoState.GetMass(), protoG_Magnitude,
|
||||||
|
deuterState.GetMass(), deuterG_Magnitude );
|
||||||
|
|
||||||
|
Float4 bounce = Average( bounceD, bounceP );
|
||||||
|
|
||||||
|
Float kineticEnergyPBefore = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), protoState.GetLinearMomentum()/protoState.GetMass() );
|
||||||
|
|
||||||
|
protoState.ApplyImpulse( bounce.xyz, worldPointOfContact.xyz, normal.xyz );
|
||||||
|
proto->SetState( protoState );
|
||||||
|
|
||||||
|
Float kineticEnergyPAFter = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), (protoState.GetLinearMomentum() + protoState.GetLinearImpulse())/protoState.GetMass() );
|
||||||
|
|
||||||
|
proto->CallSubscription_AfterCollisionResponse( deuter, kineticEnergyPBefore - kineticEnergyPAFter );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,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>();
|
||||||
|
@ -146,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 )
|
||||||
|
@ -213,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,12 +388,12 @@ namespace Oyster { namespace Physics
|
||||||
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto )
|
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto )
|
||||||
{ /* Do nothing except allowing the proto uniquePointer destroy itself. */ }
|
{ /* Do nothing except allowing the proto uniquePointer destroy itself. */ }
|
||||||
|
|
||||||
::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter )
|
::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_BeforeCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter )
|
||||||
{ /* Do nothing except returning business as usual. */
|
{ /* Do nothing except returning business as usual. */
|
||||||
return ::Oyster::Physics::ICustomBody::SubscriptMessage_none;
|
return ::Oyster::Physics::ICustomBody::SubscriptMessage_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventAction_CollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss )
|
void EventAction_AfterCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss )
|
||||||
{ /* Do nothing except returning business as usual. */
|
{ /* Do nothing except returning business as usual. */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -61,8 +62,8 @@ namespace Oyster
|
||||||
namespace Default
|
namespace Default
|
||||||
{
|
{
|
||||||
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto );
|
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto );
|
||||||
::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter );
|
::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_BeforeCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter );
|
||||||
void EventAction_CollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
void EventAction_AfterCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
||||||
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object );
|
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ SimpleRigidBody::SimpleRigidBody()
|
||||||
this->rigid = RigidBody();
|
this->rigid = RigidBody();
|
||||||
this->rigid.SetMass_KeepMomentum( 16.0f );
|
this->rigid.SetMass_KeepMomentum( 16.0f );
|
||||||
this->gravityNormal = Float3::null;
|
this->gravityNormal = Float3::null;
|
||||||
this->onCollision = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_BeforeCollisionResponse;
|
||||||
this->onCollisionResponse = Default::EventAction_CollisionResponse;
|
this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
|
||||||
this->onMovement = Default::EventAction_Move;
|
this->onMovement = Default::EventAction_Move;
|
||||||
this->scene = nullptr;
|
this->scene = nullptr;
|
||||||
this->customTag = nullptr;
|
this->customTag = nullptr;
|
||||||
|
@ -72,7 +72,7 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->onCollision = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_BeforeCollisionResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( desc.subscription_onCollisionResponse )
|
if( desc.subscription_onCollisionResponse )
|
||||||
|
@ -81,7 +81,7 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->onCollisionResponse = Default::EventAction_CollisionResponse;
|
this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( desc.subscription_onMovement )
|
if( desc.subscription_onMovement )
|
||||||
|
@ -163,12 +163,12 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription_Collision( const ICustomBody *deuter )
|
ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter )
|
||||||
{
|
{
|
||||||
return this->onCollision( this, deuter );
|
return this->onCollision( this, deuter );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleRigidBody::CallSubscription_CollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss )
|
void SimpleRigidBody::CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss )
|
||||||
{
|
{
|
||||||
return this->onCollisionResponse( this, deuter, kineticEnergyLoss );
|
return this->onCollisionResponse( this, deuter, kineticEnergyLoss );
|
||||||
}
|
}
|
||||||
|
@ -318,7 +318,7 @@ void SimpleRigidBody::SetScene( void *scene )
|
||||||
this->scene = (Octree*)scene;
|
this->scene = (Octree*)scene;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
|
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_BeforeCollisionResponse functionPointer )
|
||||||
{
|
{
|
||||||
if( functionPointer )
|
if( functionPointer )
|
||||||
{
|
{
|
||||||
|
@ -326,11 +326,11 @@ void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functi
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->onCollision = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_BeforeCollisionResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_CollisionResponse functionPointer )
|
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_AfterCollisionResponse functionPointer )
|
||||||
{
|
{
|
||||||
if( functionPointer )
|
if( functionPointer )
|
||||||
{
|
{
|
||||||
|
@ -338,7 +338,7 @@ void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_CollisionRespons
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->onCollisionResponse = Default::EventAction_CollisionResponse;
|
this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ namespace Oyster { namespace Physics
|
||||||
void SetState( const State &state );
|
void SetState( const State &state );
|
||||||
//::Oyster::Math::Float3 GetRigidLinearVelocity() const;
|
//::Oyster::Math::Float3 GetRigidLinearVelocity() const;
|
||||||
|
|
||||||
SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter );
|
SubscriptMessage CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter );
|
||||||
void CallSubscription_CollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
void CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
||||||
void CallSubscription_Move();
|
void CallSubscription_Move();
|
||||||
|
|
||||||
bool IsAffectedByGravity() const;
|
bool IsAffectedByGravity() const;
|
||||||
|
@ -44,8 +44,8 @@ namespace Oyster { namespace Physics
|
||||||
|
|
||||||
void SetScene( void *scene );
|
void SetScene( void *scene );
|
||||||
|
|
||||||
void SetSubscription( EventAction_Collision functionPointer );
|
void SetSubscription( EventAction_BeforeCollisionResponse functionPointer );
|
||||||
void SetSubscription( EventAction_CollisionResponse functionPointer );
|
void SetSubscription( EventAction_AfterCollisionResponse functionPointer );
|
||||||
void SetSubscription( EventAction_Move functionPointer );
|
void SetSubscription( EventAction_Move functionPointer );
|
||||||
|
|
||||||
void SetGravity( bool ignore);
|
void SetGravity( bool ignore);
|
||||||
|
@ -65,8 +65,8 @@ namespace Oyster { namespace Physics
|
||||||
::Oyster::Physics3D::RigidBody rigid;
|
::Oyster::Physics3D::RigidBody rigid;
|
||||||
::Oyster::Math::Float4 deltaPos, deltaAxis;
|
::Oyster::Math::Float4 deltaPos, deltaAxis;
|
||||||
::Oyster::Math::Float3 gravityNormal;
|
::Oyster::Math::Float3 gravityNormal;
|
||||||
EventAction_Collision onCollision;
|
EventAction_BeforeCollisionResponse onCollision;
|
||||||
EventAction_CollisionResponse onCollisionResponse;
|
EventAction_AfterCollisionResponse onCollisionResponse;
|
||||||
EventAction_Move onMovement;
|
EventAction_Move onMovement;
|
||||||
Octree *scene;
|
Octree *scene;
|
||||||
void *customTag;
|
void *customTag;
|
||||||
|
|
|
@ -13,8 +13,8 @@ SphericalRigidBody::SphericalRigidBody()
|
||||||
this->rigid = RigidBody();
|
this->rigid = RigidBody();
|
||||||
this->rigid.SetMass_KeepMomentum( 10.0f );
|
this->rigid.SetMass_KeepMomentum( 10.0f );
|
||||||
this->gravityNormal = Float3::null;
|
this->gravityNormal = Float3::null;
|
||||||
this->onCollision = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_BeforeCollisionResponse;
|
||||||
this->onCollisionResponse = Default::EventAction_CollisionResponse;
|
this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
|
||||||
this->onMovement = Default::EventAction_Move;
|
this->onMovement = Default::EventAction_Move;
|
||||||
this->scene = nullptr;
|
this->scene = nullptr;
|
||||||
this->customTag = nullptr;
|
this->customTag = nullptr;
|
||||||
|
@ -40,7 +40,7 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->onCollision = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_BeforeCollisionResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( desc.subscription_onCollisionResponse )
|
if( desc.subscription_onCollisionResponse )
|
||||||
|
@ -49,7 +49,7 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->onCollisionResponse = Default::EventAction_CollisionResponse;
|
this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( desc.subscription_onMovement )
|
if( desc.subscription_onMovement )
|
||||||
|
@ -128,12 +128,12 @@ void SphericalRigidBody::SetState( const SphericalRigidBody::State &state )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription_Collision( const ICustomBody *deuter )
|
ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter )
|
||||||
{
|
{
|
||||||
return this->onCollision( this, deuter );
|
return this->onCollision( this, deuter );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::CallSubscription_CollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss )
|
void SphericalRigidBody::CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss )
|
||||||
{
|
{
|
||||||
this->onCollisionResponse( this, deuter, kineticEnergyLoss);
|
this->onCollisionResponse( this, deuter, kineticEnergyLoss);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
|
||||||
|
|
||||||
Float4 & SphericalRigidBody::GetNormalAt( const Float4 &worldPos, Float4 &targetMem ) const
|
Float4 & SphericalRigidBody::GetNormalAt( const Float4 &worldPos, Float4 &targetMem ) const
|
||||||
{
|
{
|
||||||
targetMem = worldPos.xyz - this->rigid.centerPos;
|
targetMem = Float4( worldPos.xyz - this->rigid.centerPos, 0);
|
||||||
Float magnitude = targetMem.GetMagnitude();
|
Float magnitude = targetMem.GetMagnitude();
|
||||||
if( magnitude != 0.0f )
|
if( magnitude != 0.0f )
|
||||||
{ // sanity check
|
{ // sanity check
|
||||||
|
@ -238,7 +238,7 @@ void SphericalRigidBody::Predict( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster:
|
||||||
this->rigid.Predict_LeapFrog( outDeltaPos.xyz, outDeltaAxis.xyz, actingLinearImpulse.xyz, actingAngularImpulse.xyz, deltaTime );
|
this->rigid.Predict_LeapFrog( outDeltaPos.xyz, outDeltaAxis.xyz, actingLinearImpulse.xyz, actingAngularImpulse.xyz, deltaTime );
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
|
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_BeforeCollisionResponse functionPointer )
|
||||||
{
|
{
|
||||||
if( functionPointer )
|
if( functionPointer )
|
||||||
{
|
{
|
||||||
|
@ -246,11 +246,11 @@ void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision fun
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->onCollision = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_BeforeCollisionResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_CollisionResponse functionPointer )
|
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_AfterCollisionResponse functionPointer )
|
||||||
{
|
{
|
||||||
if( functionPointer )
|
if( functionPointer )
|
||||||
{
|
{
|
||||||
|
@ -258,7 +258,7 @@ void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_CollisionResp
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->onCollisionResponse = Default::EventAction_CollisionResponse;
|
this->onCollisionResponse = Default::EventAction_AfterCollisionResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace Oyster { namespace Physics
|
||||||
void SetState( const State &state );
|
void SetState( const State &state );
|
||||||
//::Oyster::Math::Float3 GetRigidLinearVelocity() const;
|
//::Oyster::Math::Float3 GetRigidLinearVelocity() const;
|
||||||
|
|
||||||
SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter );
|
SubscriptMessage CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter );
|
||||||
void CallSubscription_CollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
void CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
||||||
void CallSubscription_Move();
|
void CallSubscription_Move();
|
||||||
|
|
||||||
bool IsAffectedByGravity() const;
|
bool IsAffectedByGravity() const;
|
||||||
|
@ -45,8 +45,8 @@ namespace Oyster { namespace Physics
|
||||||
|
|
||||||
void SetScene( void *scene );
|
void SetScene( void *scene );
|
||||||
|
|
||||||
void SetSubscription( EventAction_Collision functionPointer );
|
void SetSubscription( EventAction_BeforeCollisionResponse functionPointer );
|
||||||
void SetSubscription( EventAction_CollisionResponse functionPointer );
|
void SetSubscription( EventAction_AfterCollisionResponse functionPointer );
|
||||||
void SetSubscription( EventAction_Move functionPointer );
|
void SetSubscription( EventAction_Move functionPointer );
|
||||||
|
|
||||||
void SetGravity( bool ignore);
|
void SetGravity( bool ignore);
|
||||||
|
@ -66,8 +66,8 @@ namespace Oyster { namespace Physics
|
||||||
::Oyster::Physics3D::RigidBody rigid;
|
::Oyster::Physics3D::RigidBody rigid;
|
||||||
::Oyster::Math::Float4 deltaPos, deltaAxis;
|
::Oyster::Math::Float4 deltaPos, deltaAxis;
|
||||||
::Oyster::Math::Float3 gravityNormal;
|
::Oyster::Math::Float3 gravityNormal;
|
||||||
EventAction_Collision onCollision;
|
EventAction_BeforeCollisionResponse onCollision;
|
||||||
EventAction_CollisionResponse onCollisionResponse;
|
EventAction_AfterCollisionResponse onCollisionResponse;
|
||||||
EventAction_Move onMovement;
|
EventAction_Move onMovement;
|
||||||
Octree *scene;
|
Octree *scene;
|
||||||
void *customTag;
|
void *customTag;
|
||||||
|
|
|
@ -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
|
||||||
|
@ -244,8 +245,8 @@ namespace Oyster
|
||||||
SubscriptMessage_ignore_collision_response
|
SubscriptMessage_ignore_collision_response
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
|
typedef SubscriptMessage (*EventAction_BeforeCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter );
|
||||||
typedef void (*EventAction_CollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
typedef void (*EventAction_AfterCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
||||||
typedef void (*EventAction_Move)( const ICustomBody *object );
|
typedef void (*EventAction_Move)( const ICustomBody *object );
|
||||||
typedef Struct::SimpleBodyDescription SimpleBodyDescription;
|
typedef Struct::SimpleBodyDescription SimpleBodyDescription;
|
||||||
typedef Struct::SphericalBodyDescription SphericalBodyDescription;
|
typedef Struct::SphericalBodyDescription SphericalBodyDescription;
|
||||||
|
@ -262,12 +263,12 @@ namespace Oyster
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* @todo TODO: need doc
|
* @todo TODO: need doc
|
||||||
********************************************************/
|
********************************************************/
|
||||||
virtual SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter ) = 0;
|
virtual SubscriptMessage CallSubscription_BeforeCollisionResponse( const ICustomBody *deuter ) = 0;
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* @todo TODO: need doc
|
* @todo TODO: need doc
|
||||||
********************************************************/
|
********************************************************/
|
||||||
virtual void CallSubscription_CollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ) = 0;
|
virtual void CallSubscription_AfterCollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ) = 0;
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* @todo TODO: need doc
|
* @todo TODO: need doc
|
||||||
|
@ -397,14 +398,14 @@ namespace Oyster
|
||||||
* whenever a collision occurs.
|
* whenever a collision occurs.
|
||||||
* @param functionPointer: If NULL, an empty default function will be set.
|
* @param functionPointer: If NULL, an empty default function will be set.
|
||||||
********************************************************/
|
********************************************************/
|
||||||
virtual void SetSubscription( EventAction_Collision functionPointer ) = 0;
|
virtual void SetSubscription( EventAction_BeforeCollisionResponse functionPointer ) = 0;
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* Sets the function that will be called by the engine
|
* Sets the function that will be called by the engine
|
||||||
* whenever a collision has finished.
|
* whenever a collision has finished.
|
||||||
* @param functionPointer: If NULL, an empty default function will be set.
|
* @param functionPointer: If NULL, an empty default function will be set.
|
||||||
********************************************************/
|
********************************************************/
|
||||||
virtual void SetSubscription( EventAction_CollisionResponse functionPointer ) = 0;
|
virtual void SetSubscription( EventAction_AfterCollisionResponse functionPointer ) = 0;
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* Sets the function that will be called by the engine
|
* Sets the function that will be called by the engine
|
||||||
|
|
|
@ -19,8 +19,8 @@ namespace Oyster { namespace Physics
|
||||||
::Oyster::Math::Float frictionCoeff_Static;
|
::Oyster::Math::Float frictionCoeff_Static;
|
||||||
::Oyster::Math::Float frictionCoeff_Dynamic;
|
::Oyster::Math::Float frictionCoeff_Dynamic;
|
||||||
::Oyster::Physics3D::MomentOfInertia inertiaTensor;
|
::Oyster::Physics3D::MomentOfInertia inertiaTensor;
|
||||||
::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
|
::Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse subscription_onCollision;
|
||||||
::Oyster::Physics::ICustomBody::EventAction_CollisionResponse subscription_onCollisionResponse;
|
::Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse subscription_onCollisionResponse;
|
||||||
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
|
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
|
||||||
bool ignoreGravity;
|
bool ignoreGravity;
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ namespace Oyster { namespace Physics
|
||||||
::Oyster::Math::Float restitutionCoeff;
|
::Oyster::Math::Float restitutionCoeff;
|
||||||
::Oyster::Math::Float frictionCoeff_Static;
|
::Oyster::Math::Float frictionCoeff_Static;
|
||||||
::Oyster::Math::Float frictionCoeff_Dynamic;
|
::Oyster::Math::Float frictionCoeff_Dynamic;
|
||||||
::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
|
::Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse subscription_onCollision;
|
||||||
::Oyster::Physics::ICustomBody::EventAction_CollisionResponse subscription_onCollisionResponse;
|
::Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse subscription_onCollisionResponse;
|
||||||
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
|
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
|
||||||
bool ignoreGravity;
|
bool ignoreGravity;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue