Added new onCollisionResponse handle

This commit is contained in:
Robin Engman 2014-01-22 13:50:54 +01:00
parent 0cae6261e9
commit 53961f0e88
8 changed files with 87 additions and 0 deletions

View File

@ -94,9 +94,14 @@ namespace
// proto->Predict( forwardedDeltaPos, forwardedDeltaAxis, bounceLinearImpulse, bounceAngularImpulse, API_instance.GetFrameTimeLength() );
// }
// protoState.ApplyForwarding( forwardedDeltaPos, forwardedDeltaAxis );
protoState.ApplyImpulse( bounce, worldPointOfContact, normal );
proto->SetState( protoState );
proto->CallSubscription_CollisionResponse( deuter, protoState.GetLinearMomentum().GetMagnitude()/(protoState.GetMass() + protoState.GetLinearMomentum().GetMagnitude()));
}
break;
}
@ -381,6 +386,11 @@ namespace Oyster { namespace Physics
return ::Oyster::Physics::ICustomBody::SubscriptMessage_none;
}
void EventAction_CollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss )
{ /* Do nothing except returning business as usual. */
}
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object )
{ /* Do nothing. */ }
}

View File

@ -62,6 +62,7 @@ namespace Oyster
{
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 );
void EventAction_CollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object );
}
}

View File

@ -47,6 +47,7 @@ SimpleRigidBody::SimpleRigidBody()
this->rigid.SetMass_KeepMomentum( 16.0f );
this->gravityNormal = Float3::null;
this->onCollision = Default::EventAction_Collision;
this->onCollisionResponse = Default::EventAction_CollisionResponse;
this->onMovement = Default::EventAction_Move;
this->scene = nullptr;
this->customTag = nullptr;
@ -74,6 +75,15 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
this->onCollision = Default::EventAction_Collision;
}
if( desc.subscription_onCollisionResponse )
{
this->onCollisionResponse = desc.subscription_onCollisionResponse;
}
else
{
this->onCollisionResponse = Default::EventAction_CollisionResponse;
}
if( desc.subscription_onMovement )
{
this->onMovement= desc.subscription_onMovement;
@ -158,6 +168,11 @@ ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription_Collision( const
return this->onCollision( this, deuter );
}
void SimpleRigidBody::CallSubscription_CollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss )
{
return this->onCollisionResponse( this, deuter, kineticEnergyLoss );
}
void SimpleRigidBody::CallSubscription_Move()
{
this->onMovement( this );
@ -315,6 +330,18 @@ void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functi
}
}
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_CollisionResponse functionPointer )
{
if( functionPointer )
{
this->onCollisionResponse = functionPointer;
}
else
{
this->onCollisionResponse = Default::EventAction_CollisionResponse;
}
}
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Move functionPointer )
{
if( functionPointer )

View File

@ -22,6 +22,7 @@ namespace Oyster { namespace Physics
//::Oyster::Math::Float3 GetRigidLinearVelocity() const;
SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter );
void CallSubscription_CollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
void CallSubscription_Move();
bool IsAffectedByGravity() const;
@ -44,6 +45,7 @@ namespace Oyster { namespace Physics
void SetScene( void *scene );
void SetSubscription( EventAction_Collision functionPointer );
void SetSubscription( EventAction_CollisionResponse functionPointer );
void SetSubscription( EventAction_Move functionPointer );
void SetGravity( bool ignore);
@ -64,6 +66,7 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float4 deltaPos, deltaAxis;
::Oyster::Math::Float3 gravityNormal;
EventAction_Collision onCollision;
EventAction_CollisionResponse onCollisionResponse;
EventAction_Move onMovement;
Octree *scene;
void *customTag;

View File

@ -14,6 +14,7 @@ SphericalRigidBody::SphericalRigidBody()
this->rigid.SetMass_KeepMomentum( 10.0f );
this->gravityNormal = Float3::null;
this->onCollision = Default::EventAction_Collision;
this->onCollisionResponse = Default::EventAction_CollisionResponse;
this->onMovement = Default::EventAction_Move;
this->scene = nullptr;
this->customTag = nullptr;
@ -42,6 +43,15 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des
this->onCollision = Default::EventAction_Collision;
}
if( desc.subscription_onCollisionResponse )
{
this->onCollisionResponse = desc.subscription_onCollisionResponse;
}
else
{
this->onCollisionResponse = Default::EventAction_CollisionResponse;
}
if( desc.subscription_onMovement )
{
this->onMovement= desc.subscription_onMovement;
@ -123,6 +133,12 @@ ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription_Collision( co
return this->onCollision( this, deuter );
}
void SphericalRigidBody::CallSubscription_CollisionResponse( const ICustomBody *deuter, Float kineticEnergyLoss )
{
this->onCollisionResponse( this, deuter, kineticEnergyLoss);
}
void SphericalRigidBody::CallSubscription_Move()
{
this->onMovement( this );
@ -234,6 +250,18 @@ void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision fun
}
}
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_CollisionResponse functionPointer )
{
if( functionPointer )
{
this->onCollisionResponse = functionPointer;
}
else
{
this->onCollisionResponse = Default::EventAction_CollisionResponse;
}
}
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Move functionPointer )
{
if( functionPointer )

View File

@ -23,6 +23,7 @@ namespace Oyster { namespace Physics
//::Oyster::Math::Float3 GetRigidLinearVelocity() const;
SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter );
void CallSubscription_CollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
void CallSubscription_Move();
bool IsAffectedByGravity() const;
@ -45,6 +46,7 @@ namespace Oyster { namespace Physics
void SetScene( void *scene );
void SetSubscription( EventAction_Collision functionPointer );
void SetSubscription( EventAction_CollisionResponse functionPointer );
void SetSubscription( EventAction_Move functionPointer );
void SetGravity( bool ignore);
@ -65,6 +67,7 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float4 deltaPos, deltaAxis;
::Oyster::Math::Float3 gravityNormal;
EventAction_Collision onCollision;
EventAction_CollisionResponse onCollisionResponse;
EventAction_Move onMovement;
Octree *scene;
void *customTag;

View File

@ -238,6 +238,7 @@ namespace Oyster
enum SubscriptMessage
{
SubscriptMessage_none,
SubscriptMessage_kineticLoss,
SubscriptMessage_ignore_collision_response
};
@ -261,6 +262,11 @@ namespace Oyster
********************************************************/
virtual SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter ) = 0;
/********************************************************
* @todo TODO: need doc
********************************************************/
virtual void CallSubscription_CollisionResponse( const ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss ) = 0;
/********************************************************
* @todo TODO: need doc
********************************************************/
@ -391,6 +397,13 @@ namespace Oyster
********************************************************/
virtual void SetSubscription( EventAction_Collision functionPointer ) = 0;
/********************************************************
* Sets the function that will be called by the engine
* whenever a collision has finished.
* @param functionPointer: If NULL, an empty default function will be set.
********************************************************/
virtual void SetSubscription( EventAction_CollisionResponse functionPointer ) = 0;
/********************************************************
* Sets the function that will be called by the engine
* whenever an object have moved.

View File

@ -19,6 +19,7 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float frictionCoeff_Dynamic;
::Oyster::Math::Float4x4 inertiaTensor;
::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
::Oyster::Physics::ICustomBody::EventAction_CollisionResponse subscription_onCollisionResponse;
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
bool ignoreGravity;
@ -35,6 +36,7 @@ namespace Oyster { namespace Physics
::Oyster::Math::Float frictionCoeff_Static;
::Oyster::Math::Float frictionCoeff_Dynamic;
::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
::Oyster::Physics::ICustomBody::EventAction_CollisionResponse subscription_onCollisionResponse;
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
bool ignoreGravity;