diff --git a/asteroids/AsteroidEntity.cc b/asteroids/AsteroidEntity.cc index 09937ad..fbf2cce 100644 --- a/asteroids/AsteroidEntity.cc +++ b/asteroids/AsteroidEntity.cc @@ -11,7 +11,7 @@ namespace asteroids { -bool AsteroidEntity::CollisionEvent (Engine::EntityBase* entity_state) { +bool AsteroidEntity::CollisionEvent (Engine::EntityBase* entity_state, vector3d point, vector3d normal) { GameEntityType other_type = (GameEntityType) entity_state->mType; if (other_type == GameEntityTypeRocket) { diff --git a/asteroids/AsteroidEntity.h b/asteroids/AsteroidEntity.h index 126e6f9..4104627 100644 --- a/asteroids/AsteroidEntity.h +++ b/asteroids/AsteroidEntity.h @@ -23,7 +23,7 @@ struct AsteroidEntity: public Engine::EntityBase { mSubAsteroidsCount = 4; } - virtual bool CollisionEvent (Engine::EntityBase *entity); + virtual bool CollisionEvent (Engine::EntityBase *entity, vector3d point, vector3d normal); int mSubAsteroidsCount; }; diff --git a/asteroids/RocketEntity.h b/asteroids/RocketEntity.h index 00571a6..a8c8d1f 100644 --- a/asteroids/RocketEntity.h +++ b/asteroids/RocketEntity.h @@ -26,7 +26,7 @@ struct RocketEntity: public Engine::EntityBase { virtual ~RocketEntity() {}; virtual void Update (float delta_sec); - virtual bool CollisionEvent (Engine::EntityBase *entity) { + virtual bool CollisionEvent (Engine::EntityBase *entity, vector3d point, vector3d normal) { return false; } diff --git a/asteroids/ShipEntity.cc b/asteroids/ShipEntity.cc index 3bfa139..391038b 100644 --- a/asteroids/ShipEntity.cc +++ b/asteroids/ShipEntity.cc @@ -56,7 +56,7 @@ void ShipEntity::Update (float delta_sec) { mAttackTimer -= delta_sec; } -bool ShipEntity::CollisionEvent (Engine::EntityBase* entity) { +bool ShipEntity::CollisionEvent (Engine::EntityBase* entity, vector3d point, vector3d normal) { GameEntityType other_type = (GameEntityType) entity->mType; if (other_type == GameEntityTypeAsteroid) { @@ -68,6 +68,7 @@ bool ShipEntity::CollisionEvent (Engine::EntityBase* entity) { Engine::EventBasePtr explode_event (new Engine::EventBase()); explode_event->mEventType = EventShipExplode; explode_event->mEventUnsignedInt = mId; + explode_event->mVector3d = normal; QueueEvent (explode_event); return true; @@ -80,6 +81,7 @@ bool ShipEntity::CollisionEvent (Engine::EntityBase* entity) { Engine::EventBasePtr explode_event (new Engine::EventBase()); explode_event->mEventType = EventShipExplode; explode_event->mEventUnsignedInt = mId; + explode_event->mVector3d = normal; QueueEvent (explode_event); return true; diff --git a/asteroids/ShipEntity.h b/asteroids/ShipEntity.h index 0ed1f31..b9a5e5f 100644 --- a/asteroids/ShipEntity.h +++ b/asteroids/ShipEntity.h @@ -46,7 +46,7 @@ struct ShipEntity: public Engine::EntityBase { virtual void Attack (); virtual void Update (float delta_sec); - virtual bool CollisionEvent (Engine::EntityBase *entity); + virtual bool CollisionEvent (Engine::EntityBase *entity, vector3d point, vector3d normal); bool mAlive; float mFadeTimer; diff --git a/data/levels/level1.txt b/data/levels/level1.txt index c673d2a..86e84ac 100644 --- a/data/levels/level1.txt +++ b/data/levels/level1.txt @@ -2,4 +2,4 @@ # GameEntityTypeShip 1 0 0 0 0 90 0 0 0 0 0 GameEntityTypeAsteroid 0 5 0 -2 0 0 0 -0.2 0 -0.1 -10 -GameEntityTypeAsteroid 0 -2 0 2 0 0 0 0.3 0 0.1 5 +GameEntityTypeAsteroid 0 -2 0 2 0 0 0 0.3 0 -0.4 5 diff --git a/engine/EntityBase.h b/engine/EntityBase.h index a9ce23f..e911ef5 100644 --- a/engine/EntityBase.h +++ b/engine/EntityBase.h @@ -144,7 +144,7 @@ struct EntityBase { * \returns true if it was able to react for this type of entity, false * false otherwise */ - virtual bool CollisionEvent (EntityBase* entity_state) { + virtual bool CollisionEvent (EntityBase* entity_state, vector3d point, vector3d normal) { return false; } }; diff --git a/engine/EventBase.h b/engine/EventBase.h index dc2916f..0ffd897 100644 --- a/engine/EventBase.h +++ b/engine/EventBase.h @@ -5,15 +5,10 @@ #include -#include -#include -#include -#include +#include "mathlib.h" namespace Engine { -class Module; - /** \brief Contains all information relevant to the Event */ struct EventBase { int mEventType; @@ -23,6 +18,8 @@ struct EventBase { float mEventFloat; int mEventInt; unsigned int mEventUnsignedInt; + vector3d mVector3d; + }; typedef boost::shared_ptr EventBasePtr; diff --git a/engine/ModelBase.cc b/engine/ModelBase.cc index edc0b66..d3f3f0b 100644 --- a/engine/ModelBase.cc +++ b/engine/ModelBase.cc @@ -215,7 +215,7 @@ void ModelBase::SetPlayerEntityId(unsigned int entity_id) { * \param collision_time The time when the collision occured relative to the start of the simulation frame */ void ModelBase::SendEntityCollisionEvent (const unsigned int reference_entity_id, - const unsigned int incidence_entity_id, float collision_time, vector3d normal) { + const unsigned int incidence_entity_id, float collision_time, vector3d point, vector3d normal) { // Check whether we report the same contact over and over static unsigned int last_reference_entity_id = 0; static unsigned int last_incidence_entity_id = 0; @@ -248,10 +248,10 @@ void ModelBase::SendEntityCollisionEvent (const unsigned int reference_entity_id // If the incidence entity accepted the collision we can return, otherwise // we perform the symmetric collision event. - if (incidence_entity->CollisionEvent (reference_entity)) + if (incidence_entity->CollisionEvent (reference_entity, point, normal)) return; - reference_entity->CollisionEvent (incidence_entity); + reference_entity->CollisionEvent (incidence_entity, point, normal * -1.); } /* diff --git a/engine/ModelBase.h b/engine/ModelBase.h index 3ef92fd..7427ac6 100644 --- a/engine/ModelBase.h +++ b/engine/ModelBase.h @@ -83,7 +83,7 @@ class ModelBase : public Module { /** Notifies the gamelogic of a collision event */ void SendEntityCollisionEvent (const unsigned int reference_entity_id, - const unsigned int incidence_entity_id, float collision_time, vector3d normal); + const unsigned int incidence_entity_id, float collision_time, vector3d point, vector3d normal); virtual void SetGameState (const unsigned int &state) { mLastGameState = mGameState; diff --git a/engine/PhysicsBase.cc b/engine/PhysicsBase.cc index 28faac0..fc86f04 100644 --- a/engine/PhysicsBase.cc +++ b/engine/PhysicsBase.cc @@ -100,7 +100,7 @@ int PhysicsBase::Simulate (float msec, ModelBase* model) { ResolveCollision (0., entity_a_id, entity_b_id, info); // Send the collision event to the Model (if we have one) if (model) { - model->SendEntityCollisionEvent (entity_a_id, entity_b_id, info.time, info.normal); + model->SendEntityCollisionEvent (entity_a_id, entity_b_id, info.time, info.point, info.normal); } // collision_remaining_step -= 1.0e-4; } else { @@ -109,7 +109,7 @@ int PhysicsBase::Simulate (float msec, ModelBase* model) { ResolveCollision (info.time * (1 - alpha), entity_a_id, entity_b_id, info); // Send the collision event to the Model (if we have one) if (model) { - model->SendEntityCollisionEvent (entity_a_id, entity_b_id, info.time, info.normal); + model->SendEntityCollisionEvent (entity_a_id, entity_b_id, info.time, info.point, info.normal); } collision_remaining_step -= info.time * (1 - alpha); }