Added ICustombody event subscription
ICustomBody::EventAction_Move if an object have moved, an event can now be subscribed. External Impact: ICustomBody SimpleBodyDescription SphericalBodyDescription
This commit is contained in:
parent
a8c87273e2
commit
0b8ecd740a
|
@ -22,7 +22,7 @@ namespace
|
||||||
Float4 worldPointOfContact;
|
Float4 worldPointOfContact;
|
||||||
if( proto->Intersects(*deuter, worldPointOfContact) )
|
if( proto->Intersects(*deuter, worldPointOfContact) )
|
||||||
{
|
{
|
||||||
switch( proto->CallSubscription(proto, deuter) )
|
switch( proto->CallSubscription_Collision(deuter) )
|
||||||
{
|
{
|
||||||
case ICustomBody::SubscriptMessage_ignore_collision_response:
|
case ICustomBody::SubscriptMessage_ignore_collision_response:
|
||||||
break;
|
break;
|
||||||
|
@ -209,6 +209,7 @@ void API_Impl::Update()
|
||||||
{
|
{
|
||||||
case UpdateState_altered:
|
case UpdateState_altered:
|
||||||
this->worldScene.SetAsAltered( this->worldScene.GetTemporaryReferenceOf(*proto) );
|
this->worldScene.SetAsAltered( this->worldScene.GetTemporaryReferenceOf(*proto) );
|
||||||
|
(*proto)->CallSubscription_Move();
|
||||||
case UpdateState_resting: default:
|
case UpdateState_resting: default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -374,5 +375,8 @@ namespace Oyster { namespace Physics
|
||||||
{ /* 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_Move( const ::Oyster::Physics::ICustomBody *object )
|
||||||
|
{ /* Do nothing. */ }
|
||||||
}
|
}
|
||||||
} }
|
} }
|
|
@ -60,6 +60,7 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
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_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter );
|
||||||
|
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +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->collisionAction = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_Collision;
|
||||||
|
this->onMovement = Default::EventAction_Move;
|
||||||
this->ignoreGravity = this->isForwarded = false;
|
this->ignoreGravity = this->isForwarded = false;
|
||||||
this->scene = nullptr;
|
this->scene = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -63,13 +64,22 @@ SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
|
||||||
|
|
||||||
this->gravityNormal = Float3::null;
|
this->gravityNormal = Float3::null;
|
||||||
|
|
||||||
if( desc.subscription )
|
if( desc.subscription_onCollision )
|
||||||
{
|
{
|
||||||
this->collisionAction = desc.subscription;
|
this->onCollision = desc.subscription_onCollision;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->collisionAction = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_Collision;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( desc.subscription_onMovement )
|
||||||
|
{
|
||||||
|
this->onMovement= desc.subscription_onMovement;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->onMovement = Default::EventAction_Move;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->ignoreGravity = desc.ignoreGravity;
|
this->ignoreGravity = desc.ignoreGravity;
|
||||||
|
@ -138,9 +148,14 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter )
|
ICustomBody::SubscriptMessage SimpleRigidBody::CallSubscription_Collision( const ICustomBody *deuter )
|
||||||
{
|
{
|
||||||
return this->collisionAction( proto, deuter );
|
return this->onCollision( this, deuter );
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleRigidBody::CallSubscription_Move()
|
||||||
|
{
|
||||||
|
this->onMovement( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SimpleRigidBody::IsAffectedByGravity() const
|
bool SimpleRigidBody::IsAffectedByGravity() const
|
||||||
|
@ -282,11 +297,23 @@ void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functi
|
||||||
{
|
{
|
||||||
if( functionPointer )
|
if( functionPointer )
|
||||||
{
|
{
|
||||||
this->collisionAction = functionPointer;
|
this->onCollision = functionPointer;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->collisionAction = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_Collision;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Move functionPointer )
|
||||||
|
{
|
||||||
|
if( functionPointer )
|
||||||
|
{
|
||||||
|
this->onMovement = functionPointer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->onMovement = Default::EventAction_Move;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,9 @@ 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( const ICustomBody *proto, const ICustomBody *deuter );
|
SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter );
|
||||||
|
void CallSubscription_Move();
|
||||||
|
|
||||||
bool IsAffectedByGravity() const;
|
bool IsAffectedByGravity() const;
|
||||||
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const;
|
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const;
|
||||||
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape, ::Oyster::Math::Float4 &worldPointOfContact ) const;
|
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape, ::Oyster::Math::Float4 &worldPointOfContact ) const;
|
||||||
|
@ -39,7 +41,10 @@ namespace Oyster { namespace Physics
|
||||||
void Predict( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster::Math::Float4 &outDeltaAxis, const ::Oyster::Math::Float4 &actingLinearImpulse, const ::Oyster::Math::Float4 &actingAngularImpulse, ::Oyster::Math::Float deltaTime );
|
void Predict( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster::Math::Float4 &outDeltaAxis, const ::Oyster::Math::Float4 &actingLinearImpulse, const ::Oyster::Math::Float4 &actingAngularImpulse, ::Oyster::Math::Float deltaTime );
|
||||||
|
|
||||||
void SetScene( void *scene );
|
void SetScene( void *scene );
|
||||||
|
|
||||||
void SetSubscription( EventAction_Collision functionPointer );
|
void SetSubscription( EventAction_Collision functionPointer );
|
||||||
|
void SetSubscription( EventAction_Move functionPointer );
|
||||||
|
|
||||||
void SetGravity( bool ignore);
|
void SetGravity( bool ignore);
|
||||||
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
|
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
|
||||||
//void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
|
//void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
|
||||||
|
@ -56,7 +61,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 collisionAction;
|
EventAction_Collision onCollision;
|
||||||
|
EventAction_Move onMovement;
|
||||||
Octree *scene;
|
Octree *scene;
|
||||||
bool ignoreGravity, isForwarded;
|
bool ignoreGravity, isForwarded;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +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->collisionAction = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_Collision;
|
||||||
|
this->onMovement = Default::EventAction_Move;
|
||||||
this->ignoreGravity = this->isForwarded = false;
|
this->ignoreGravity = this->isForwarded = false;
|
||||||
this->scene = nullptr;
|
this->scene = nullptr;
|
||||||
this->body = Sphere( Float3::null, 0.5f );
|
this->body = Sphere( Float3::null, 0.5f );
|
||||||
|
@ -32,13 +33,22 @@ SphericalRigidBody::SphericalRigidBody( const API::SphericalBodyDescription &des
|
||||||
|
|
||||||
this->gravityNormal = Float3::null;
|
this->gravityNormal = Float3::null;
|
||||||
|
|
||||||
if( desc.subscription )
|
if( desc.subscription_onCollision )
|
||||||
{
|
{
|
||||||
this->collisionAction = desc.subscription;
|
this->onCollision = desc.subscription_onCollision;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->collisionAction = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_Collision;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( desc.subscription_onMovement )
|
||||||
|
{
|
||||||
|
this->onMovement= desc.subscription_onMovement;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->onMovement = Default::EventAction_Move;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->ignoreGravity = desc.ignoreGravity;
|
this->ignoreGravity = desc.ignoreGravity;
|
||||||
|
@ -108,9 +118,14 @@ void SphericalRigidBody::SetState( const SphericalRigidBody::State &state )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription( const ICustomBody *proto, const ICustomBody *deuter )
|
ICustomBody::SubscriptMessage SphericalRigidBody::CallSubscription_Collision( const ICustomBody *deuter )
|
||||||
{
|
{
|
||||||
return this->collisionAction( proto, deuter );
|
return this->onCollision( this, deuter );
|
||||||
|
}
|
||||||
|
|
||||||
|
void SphericalRigidBody::CallSubscription_Move()
|
||||||
|
{
|
||||||
|
this->onMovement( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SphericalRigidBody::IsAffectedByGravity() const
|
bool SphericalRigidBody::IsAffectedByGravity() const
|
||||||
|
@ -207,11 +222,23 @@ void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision fun
|
||||||
{
|
{
|
||||||
if( functionPointer )
|
if( functionPointer )
|
||||||
{
|
{
|
||||||
this->collisionAction = functionPointer;
|
this->onCollision = functionPointer;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this->collisionAction = Default::EventAction_Collision;
|
this->onCollision = Default::EventAction_Collision;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Move functionPointer )
|
||||||
|
{
|
||||||
|
if( functionPointer )
|
||||||
|
{
|
||||||
|
this->onMovement = functionPointer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->onMovement = Default::EventAction_Move;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,9 @@ 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( const ICustomBody *proto, const ICustomBody *deuter );
|
SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter );
|
||||||
|
void CallSubscription_Move();
|
||||||
|
|
||||||
bool IsAffectedByGravity() const;
|
bool IsAffectedByGravity() const;
|
||||||
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const;
|
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const;
|
||||||
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape, ::Oyster::Math::Float4 &worldPointOfContact ) const;
|
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape, ::Oyster::Math::Float4 &worldPointOfContact ) const;
|
||||||
|
@ -40,7 +42,10 @@ namespace Oyster { namespace Physics
|
||||||
void Predict( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster::Math::Float4 &outDeltaAxis, const ::Oyster::Math::Float4 &actingLinearImpulse, const ::Oyster::Math::Float4 &actingAngularImpulse, ::Oyster::Math::Float deltaTime );
|
void Predict( ::Oyster::Math::Float4 &outDeltaPos, ::Oyster::Math::Float4 &outDeltaAxis, const ::Oyster::Math::Float4 &actingLinearImpulse, const ::Oyster::Math::Float4 &actingAngularImpulse, ::Oyster::Math::Float deltaTime );
|
||||||
|
|
||||||
void SetScene( void *scene );
|
void SetScene( void *scene );
|
||||||
|
|
||||||
void SetSubscription( EventAction_Collision functionPointer );
|
void SetSubscription( EventAction_Collision functionPointer );
|
||||||
|
void SetSubscription( EventAction_Move functionPointer );
|
||||||
|
|
||||||
void SetGravity( bool ignore);
|
void SetGravity( bool ignore);
|
||||||
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
|
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
|
||||||
//void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
|
//void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
|
||||||
|
@ -57,7 +62,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 collisionAction;
|
EventAction_Collision onCollision;
|
||||||
|
EventAction_Move onMovement;
|
||||||
bool ignoreGravity, isForwarded;
|
bool ignoreGravity, isForwarded;
|
||||||
Octree *scene;
|
Octree *scene;
|
||||||
::Oyster::Collision3D::Sphere body;
|
::Oyster::Collision3D::Sphere body;
|
||||||
|
|
|
@ -235,6 +235,7 @@ namespace Oyster
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
|
typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
|
||||||
|
typedef void (*EventAction_Move)( const ICustomBody *object );
|
||||||
typedef Struct::SimpleBodyDescription SimpleBodyDescription;
|
typedef Struct::SimpleBodyDescription SimpleBodyDescription;
|
||||||
typedef Struct::SphericalBodyDescription SphericalBodyDescription;
|
typedef Struct::SphericalBodyDescription SphericalBodyDescription;
|
||||||
typedef Struct::CustomBodyState State;
|
typedef Struct::CustomBodyState State;
|
||||||
|
@ -250,7 +251,12 @@ namespace Oyster
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* @todo TODO: need doc
|
* @todo TODO: need doc
|
||||||
********************************************************/
|
********************************************************/
|
||||||
virtual SubscriptMessage CallSubscription( const ICustomBody *proto, const ICustomBody *deuter ) = 0;
|
virtual SubscriptMessage CallSubscription_Collision( const ICustomBody *deuter ) = 0;
|
||||||
|
|
||||||
|
/********************************************************
|
||||||
|
* @todo TODO: need doc
|
||||||
|
********************************************************/
|
||||||
|
virtual void CallSubscription_Move() = 0;
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* @todo TODO: need doc
|
* @todo TODO: need doc
|
||||||
|
@ -371,6 +377,13 @@ namespace Oyster
|
||||||
********************************************************/
|
********************************************************/
|
||||||
virtual void SetSubscription( EventAction_Collision functionPointer ) = 0;
|
virtual void SetSubscription( EventAction_Collision functionPointer ) = 0;
|
||||||
|
|
||||||
|
/********************************************************
|
||||||
|
* Sets the function that will be called by the engine
|
||||||
|
* whenever an object have moved.
|
||||||
|
* @param functionPointer: If NULL, an empty default function will be set.
|
||||||
|
********************************************************/
|
||||||
|
virtual void SetSubscription( EventAction_Move functionPointer ) = 0;
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* @param ignore: True if Engine should not apply Gravity.
|
* @param ignore: True if Engine should not apply Gravity.
|
||||||
********************************************************/
|
********************************************************/
|
||||||
|
|
|
@ -17,7 +17,8 @@ namespace Oyster
|
||||||
this->size = ::Oyster::Math::Float4( 1.0f );
|
this->size = ::Oyster::Math::Float4( 1.0f );
|
||||||
this->mass = 12.0f;
|
this->mass = 12.0f;
|
||||||
this->inertiaTensor = ::Oyster::Math::Float4x4::identity;
|
this->inertiaTensor = ::Oyster::Math::Float4x4::identity;
|
||||||
this->subscription = NULL;
|
this->subscription_onCollision = NULL;
|
||||||
|
this->subscription_onMovement = NULL;
|
||||||
this->ignoreGravity = false;
|
this->ignoreGravity = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +28,8 @@ namespace Oyster
|
||||||
this->centerPosition = ::Oyster::Math::Float4::standard_unit_w;
|
this->centerPosition = ::Oyster::Math::Float4::standard_unit_w;
|
||||||
this->radius = 0.5f;
|
this->radius = 0.5f;
|
||||||
this->mass = 10.0f;
|
this->mass = 10.0f;
|
||||||
this->subscription = NULL;
|
this->subscription_onCollision = NULL;
|
||||||
|
this->subscription_onMovement = NULL;
|
||||||
this->ignoreGravity = false;
|
this->ignoreGravity = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@ namespace Oyster { namespace Physics
|
||||||
::Oyster::Math::Float4 size;
|
::Oyster::Math::Float4 size;
|
||||||
::Oyster::Math::Float mass;
|
::Oyster::Math::Float mass;
|
||||||
::Oyster::Math::Float4x4 inertiaTensor;
|
::Oyster::Math::Float4x4 inertiaTensor;
|
||||||
::Oyster::Physics::ICustomBody::EventAction_Collision subscription;
|
::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
|
||||||
|
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
|
||||||
bool ignoreGravity;
|
bool ignoreGravity;
|
||||||
|
|
||||||
SimpleBodyDescription();
|
SimpleBodyDescription();
|
||||||
|
@ -27,7 +28,8 @@ namespace Oyster { namespace Physics
|
||||||
::Oyster::Math::Float4 centerPosition;
|
::Oyster::Math::Float4 centerPosition;
|
||||||
::Oyster::Math::Float radius;
|
::Oyster::Math::Float radius;
|
||||||
::Oyster::Math::Float mass;
|
::Oyster::Math::Float mass;
|
||||||
::Oyster::Physics::ICustomBody::EventAction_Collision subscription;
|
::Oyster::Physics::ICustomBody::EventAction_Collision subscription_onCollision;
|
||||||
|
::Oyster::Physics::ICustomBody::EventAction_Move subscription_onMovement;
|
||||||
bool ignoreGravity;
|
bool ignoreGravity;
|
||||||
|
|
||||||
SphericalBodyDescription();
|
SphericalBodyDescription();
|
||||||
|
|
Loading…
Reference in New Issue