reporting now collision normal and collision point when collisions occur
parent
7711142e4b
commit
4c1e016fc2
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
namespace asteroids {
|
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;
|
GameEntityType other_type = (GameEntityType) entity_state->mType;
|
||||||
|
|
||||||
if (other_type == GameEntityTypeRocket) {
|
if (other_type == GameEntityTypeRocket) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ struct AsteroidEntity: public Engine::EntityBase {
|
||||||
mSubAsteroidsCount = 4;
|
mSubAsteroidsCount = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool CollisionEvent (Engine::EntityBase *entity);
|
virtual bool CollisionEvent (Engine::EntityBase *entity, vector3d point, vector3d normal);
|
||||||
|
|
||||||
int mSubAsteroidsCount;
|
int mSubAsteroidsCount;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,7 @@ struct RocketEntity: public Engine::EntityBase {
|
||||||
virtual ~RocketEntity() {};
|
virtual ~RocketEntity() {};
|
||||||
|
|
||||||
virtual void Update (float delta_sec);
|
virtual void Update (float delta_sec);
|
||||||
virtual bool CollisionEvent (Engine::EntityBase *entity) {
|
virtual bool CollisionEvent (Engine::EntityBase *entity, vector3d point, vector3d normal) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ void ShipEntity::Update (float delta_sec) {
|
||||||
mAttackTimer -= 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;
|
GameEntityType other_type = (GameEntityType) entity->mType;
|
||||||
|
|
||||||
if (other_type == GameEntityTypeAsteroid) {
|
if (other_type == GameEntityTypeAsteroid) {
|
||||||
|
@ -68,6 +68,7 @@ bool ShipEntity::CollisionEvent (Engine::EntityBase* entity) {
|
||||||
Engine::EventBasePtr explode_event (new Engine::EventBase());
|
Engine::EventBasePtr explode_event (new Engine::EventBase());
|
||||||
explode_event->mEventType = EventShipExplode;
|
explode_event->mEventType = EventShipExplode;
|
||||||
explode_event->mEventUnsignedInt = mId;
|
explode_event->mEventUnsignedInt = mId;
|
||||||
|
explode_event->mVector3d = normal;
|
||||||
QueueEvent (explode_event);
|
QueueEvent (explode_event);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -80,6 +81,7 @@ bool ShipEntity::CollisionEvent (Engine::EntityBase* entity) {
|
||||||
Engine::EventBasePtr explode_event (new Engine::EventBase());
|
Engine::EventBasePtr explode_event (new Engine::EventBase());
|
||||||
explode_event->mEventType = EventShipExplode;
|
explode_event->mEventType = EventShipExplode;
|
||||||
explode_event->mEventUnsignedInt = mId;
|
explode_event->mEventUnsignedInt = mId;
|
||||||
|
explode_event->mVector3d = normal;
|
||||||
QueueEvent (explode_event);
|
QueueEvent (explode_event);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -46,7 +46,7 @@ struct ShipEntity: public Engine::EntityBase {
|
||||||
|
|
||||||
virtual void Attack ();
|
virtual void Attack ();
|
||||||
virtual void Update (float delta_sec);
|
virtual void Update (float delta_sec);
|
||||||
virtual bool CollisionEvent (Engine::EntityBase *entity);
|
virtual bool CollisionEvent (Engine::EntityBase *entity, vector3d point, vector3d normal);
|
||||||
|
|
||||||
bool mAlive;
|
bool mAlive;
|
||||||
float mFadeTimer;
|
float mFadeTimer;
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
# <Type> <player?> <xpos> <ypos> <zpos> <zrot> <yrot> <xrot> <xvel> <yvel> <zvel> <rotvel>
|
# <Type> <player?> <xpos> <ypos> <zpos> <zrot> <yrot> <xrot> <xvel> <yvel> <zvel> <rotvel>
|
||||||
GameEntityTypeShip 1 0 0 0 0 90 0 0 0 0 0
|
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 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
|
||||||
|
|
|
@ -144,7 +144,7 @@ struct EntityBase {
|
||||||
* \returns true if it was able to react for this type of entity, false
|
* \returns true if it was able to react for this type of entity, false
|
||||||
* false otherwise
|
* false otherwise
|
||||||
*/
|
*/
|
||||||
virtual bool CollisionEvent (EntityBase* entity_state) {
|
virtual bool CollisionEvent (EntityBase* entity_state, vector3d point, vector3d normal) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,15 +5,10 @@
|
||||||
|
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include "mathlib.h"
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <queue>
|
|
||||||
|
|
||||||
namespace Engine {
|
namespace Engine {
|
||||||
|
|
||||||
class Module;
|
|
||||||
|
|
||||||
/** \brief Contains all information relevant to the Event */
|
/** \brief Contains all information relevant to the Event */
|
||||||
struct EventBase {
|
struct EventBase {
|
||||||
int mEventType;
|
int mEventType;
|
||||||
|
@ -23,6 +18,8 @@ struct EventBase {
|
||||||
float mEventFloat;
|
float mEventFloat;
|
||||||
int mEventInt;
|
int mEventInt;
|
||||||
unsigned int mEventUnsignedInt;
|
unsigned int mEventUnsignedInt;
|
||||||
|
vector3d mVector3d;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef boost::shared_ptr<EventBase> EventBasePtr;
|
typedef boost::shared_ptr<EventBase> EventBasePtr;
|
||||||
|
|
|
@ -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
|
* \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,
|
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
|
// Check whether we report the same contact over and over
|
||||||
static unsigned int last_reference_entity_id = 0;
|
static unsigned int last_reference_entity_id = 0;
|
||||||
static unsigned int last_incidence_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
|
// If the incidence entity accepted the collision we can return, otherwise
|
||||||
// we perform the symmetric collision event.
|
// we perform the symmetric collision event.
|
||||||
if (incidence_entity->CollisionEvent (reference_entity))
|
if (incidence_entity->CollisionEvent (reference_entity, point, normal))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
reference_entity->CollisionEvent (incidence_entity);
|
reference_entity->CollisionEvent (incidence_entity, point, normal * -1.);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -83,7 +83,7 @@ class ModelBase : public Module {
|
||||||
|
|
||||||
/** Notifies the gamelogic of a collision event */
|
/** Notifies the gamelogic of a collision event */
|
||||||
void SendEntityCollisionEvent (const unsigned int reference_entity_id,
|
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) {
|
virtual void SetGameState (const unsigned int &state) {
|
||||||
mLastGameState = mGameState;
|
mLastGameState = mGameState;
|
||||||
|
|
|
@ -100,7 +100,7 @@ int PhysicsBase::Simulate (float msec, ModelBase* model) {
|
||||||
ResolveCollision (0., entity_a_id, entity_b_id, info);
|
ResolveCollision (0., entity_a_id, entity_b_id, info);
|
||||||
// Send the collision event to the Model (if we have one)
|
// Send the collision event to the Model (if we have one)
|
||||||
if (model) {
|
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;
|
// collision_remaining_step -= 1.0e-4;
|
||||||
} else {
|
} else {
|
||||||
|
@ -109,7 +109,7 @@ int PhysicsBase::Simulate (float msec, ModelBase* model) {
|
||||||
ResolveCollision (info.time * (1 - alpha), entity_a_id, entity_b_id, info);
|
ResolveCollision (info.time * (1 - alpha), entity_a_id, entity_b_id, info);
|
||||||
// Send the collision event to the Model (if we have one)
|
// Send the collision event to the Model (if we have one)
|
||||||
if (model) {
|
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);
|
collision_remaining_step -= info.time * (1 - alpha);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue