reporting now collision normal and collision point when collisions occur

main
Martin Felis (berta) 2010-12-01 10:18:45 +01:00
parent 7711142e4b
commit 4c1e016fc2
11 changed files with 18 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,4 +2,4 @@
# <Type> <player?> <xpos> <ypos> <zpos> <zrot> <yrot> <xrot> <xvel> <yvel> <zvel> <rotvel>
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

View File

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

View File

@ -5,15 +5,10 @@
#include <boost/shared_ptr.hpp>
#include <string>
#include <map>
#include <vector>
#include <queue>
#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<EventBase> EventBasePtr;

View File

@ -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.);
}
/*

View File

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

View File

@ -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);
}