- Timestamp:
- Dec 4, 2006, 6:42:46 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 30 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/README
r9406 r10013 1 1 2 2 3 This is the offical README file for the game project -
trunk/src/lib/collision_detection/aabb_tree_node.cc
r9869 r10013 17 17 #include "aabb_tree_node.h" 18 18 #include "aabb.h" 19 20 19 #include "bv_tree.h" 20 21 #include "collision_tube.h" 21 22 22 23 #include "matrix.h" … … 532 533 (treeNode->nodeRight == NULL && treeNode->nodeLeft == NULL)) ) 533 534 { 534 nodeA->registerCollision(nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);535 CoRe::CollisionTube::getInstance()->registerCollisionEvent( nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement); 535 536 } 536 537 -
trunk/src/lib/collision_detection/obb_tree_node.cc
r9869 r10013 18 18 #include "obb_tree.h" 19 19 #include "obb.h" 20 21 #include "collision_tube.h" 20 22 21 23 #include "matrix.h" … … 477 479 return; 478 480 481 #warning this should be done 482 // if( !CoRe::CollisionTube::getInstance()->isReactive( *nodeA, *nodeB) ) 483 // return; 484 479 485 // float distanceMax = this->bvElement->radius + ((OBBTreeNode*)treeNode)->bvElement->radius; 480 486 // float distance = fabs((nodeA->getAbsCoor() - nodeB->getAbsCoor()).len()); … … 566 572 (treeNode->nodeRight == NULL && treeNode->nodeLeft == NULL)) ) 567 573 { 568 //PRINTF(0)("----------------------------------------------\n\n\n\n\n\n--------------------------------\n\n\n");569 nodeA->registerCollision(nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement);574 //PRINTF(0)("----------------------------------------------\n\n\n\n\n\n--------------------------------\n\n\n"); 575 CoRe::CollisionTube::getInstance()->registerCollisionEvent( nodeA, nodeB, (BoundingVolume*)this->bvElement, (BoundingVolume*)treeNode->bvElement); 570 576 } 571 577 -
trunk/src/lib/collision_reaction/Makefile.am
r9235 r10013 5 5 6 6 libORXcr_a_SOURCES = cr_engine.cc \ 7 collision_tube.cc \ 7 8 collision.cc \ 8 9 collision_event.cc \ 9 collision_ handle.cc \10 collision_filter.cc \ 10 11 collision_reaction.cc \ 11 12 cr_object_damage.cc \ … … 16 17 17 18 noinst_HEADERS = cr_engine.h \ 19 collision_tube.h \ 18 20 collision.h \ 19 21 collision_event.h \ 20 collision_ handle.h \22 collision_filter.h \ 21 23 cr_defs.h \ 22 24 collision_reaction.h \ -
trunk/src/lib/collision_reaction/collision.cc
r9869 r10013 19 19 #include "debug.h" 20 20 21 /** 22 * standard constructor 23 */ 24 Collision::Collision () 21 namespace CoRe 25 22 { 26 this->flushCollisionEvents(); 27 } 23 24 /** 25 * standard constructor 26 */ 27 Collision::Collision () 28 { 29 this->reset(); 30 } 28 31 29 32 30 /** 31 * standard deconstructor 32 */ 33 Collision::~Collision () 34 { 35 } 33 /** 34 * standard deconstructor 35 */ 36 Collision::~Collision () 37 {} 36 38 37 39 38 /**39 * flushes the CollisionEvent list40 */41 void Collision::flushCollisionEvents()42 {43 this->entityA = NULL;44 this->entityB = NULL;40 /** 41 * resets all variable states to initial values 42 */ 43 void Collision::reset() 44 { 45 this->_entityA = NULL; 46 this->_entityB = NULL; 45 47 46 this->entityACollide = false;47 this->entityBCollide = false;48 this->_entityACollide = false; 49 this->_entityBCollide = false; 48 50 49 this->bDispatched = true; 51 this->_collisionEvents.clear(); 52 } 50 53 51 this->collisionEvents.clear();52 54 } 53 -
trunk/src/lib/collision_reaction/collision.h
r9869 r10013 1 1 /*! 2 2 * @file collision.h 3 * Definition of a collision as a two WE hit each other3 * Definition of a collision relation of two WorldEntities 4 4 * 5 * A is shared between two WorldEntity's CollisionHandles if both are subscribed to this event. In this case only one5 * Is shared between two WorldEntity's CollisionHandles if both are subscribed to this event. In this case only one 6 6 * of the two CollisionHandles will calculate the CollisionReaction and the bDispatched flag will be set afterwards 7 7 * to signal that it's already cared about and should be ignored. 8 * 9 * The collisions itself are saved in this container (CollisionEvent). Since there can be multiple collision events 10 * for one collision. Imagine: two objects are intersecting (this throws a Collision): many collision boxes will fire 11 * each of this boxes will "create" a CollisionEvent. 8 12 */ 9 13 … … 14 18 #include <vector> 15 19 20 21 16 22 class WorldEntity; 17 23 class BoundingVolume; 18 class CollisionEvent;19 24 20 //! A class representing a simple collision 21 class Collision 25 namespace CoRe 22 26 { 27 28 class CollisionEvent; 29 30 //! A class representing a simple collision 31 class Collision 32 { 33 34 typedef std::vector<CollisionEvent*> CollisionVector; //!< the vector containing all collision events 35 typedef std::vector<CollisionEvent*>::iterator Iterator; //!< iterator definition 36 typedef std::vector<CollisionEvent*>::const_iterator ConstIterator; //!< constant iterator definition 37 38 23 39 public: 40 24 41 Collision(); 25 42 virtual ~Collision(); 26 43 27 44 /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */ 28 inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this-> entityA = entityA; this->entityB = entityB; this->bDispatched = false; }45 inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->_entityA = entityA; this->_entityB = entityB; } 29 46 30 47 31 /** @return Collision WorldEntity A */ 32 inline WorldEntity* getEntityA() const { return this->entityA; } 33 /** @return Collision WorldEntity B */ 34 inline WorldEntity* getEntityB() const { return this->entityB; } 35 /** @return true if Entity A collides */ 36 inline bool isEntityACollide() const { return this->entityACollide; } 37 /** sets the flag if it reacts @param flag true if it should react on entityA*/ 38 inline void setEntityACollide(bool flag) { this->entityACollide = flag; } 39 /** @return true if Entity B collides */ 40 inline bool isEntityBCollide() const { return this->entityBCollide; } 41 /** sets the flag if it reacts @param flag true if it should react on entityB*/ 42 inline void setEntityBCollide(bool flag) { this->entityACollide = flag; } 48 /* list stuff */ 49 public: 50 51 /** registers a @param event CollisionEvent to take place */ 52 inline void registerCollisionEvent(CollisionEvent* event) { this->_collisionEvents.push_back(event); } 53 54 void reset(); 43 55 44 56 45 /** @returns true if this Collision has already been dispatched */ 46 inline bool isDispatched() { return this->bDispatched; } 47 /** sets the dispatched flag to true */ 48 inline void dispatched() { this->bDispatched = true; } 49 50 /** registers a @param event CollisionEvent to take place */ 51 inline void registerCollisionEvent(CollisionEvent* event) { this->collisionEvents.push_back(event); this->bDispatched = false;} 52 /** @returns a vector of collision events */ 53 inline const std::vector<CollisionEvent*>& getCollisionEvents() const { return this->collisionEvents; } 57 /** @returns iterator pointing to the beginning of the collision event vector */ 58 inline Iterator begin() { return this->_collisionEvents.begin(); } 59 /** @returns const iterator pointing to the beginning of the collision event vector */ 60 inline ConstIterator begin() const { return this->_collisionEvents.begin(); } 61 /** @returns iterator pointing to the end of the collision event vector */ 62 inline Iterator end() { return this->_collisionEvents.end(); } 63 /** @returns const iterator pointing to the end of the collision event vector */ 64 inline ConstIterator end() const { return this->_collisionEvents.end(); } 54 65 55 66 56 void flushCollisionEvents(); 67 /* misc interface functions */ 68 public: 69 /** @return Collision WorldEntity A */ 70 inline WorldEntity* getEntityA() const { return this->_entityA; } 71 /** @return Collision WorldEntity B */ 72 inline WorldEntity* getEntityB() const { return this->_entityB; } 73 inline bool same(const WorldEntity& entityA, WorldEntity& entityB) const { 74 return ((this->_entityA == &entityA && this->_entityB == &entityB) || (this->_entityA == &entityB && this->_entityB == &entityA)); } 75 76 /** @return true if Entity A collides */ 77 inline bool isEntityACollide() const { return this->_entityACollide; } 78 /** sets the flag if it reacts @param flag true if it should react on entityA*/ 79 inline void setEntityACollide(bool flag) { this->_entityACollide = flag; } 80 /** @return true if Entity B collides */ 81 inline bool isEntityBCollide() const { return this->_entityBCollide; } 82 /** sets the flag if it reacts @param flag true if it should react on entityB*/ 83 inline void setEntityBCollide(bool flag) { this->_entityBCollide = flag; } 57 84 58 85 59 86 private: 60 WorldEntity* entityA; //!< the collision body A61 WorldEntity* entityB; //!< the collision body B62 bool entityACollide; //!< true if entity A is subscribed for collision reaction63 bool entityBCollide; //!< true if entity B is subscribed for collision reaction87 WorldEntity* _entityA; //!< the collision body A 88 WorldEntity* _entityB; //!< the collision body B 89 bool _entityACollide; //!< true if entity A is subscribed for collision reaction 90 bool _entityBCollide; //!< true if entity B is subscribed for collision reaction 64 91 65 bool bDispatched; //!< true if this collision has already been dispatched92 CollisionVector _collisionEvents; //!< the collision event list 66 93 67 std::vector<CollisionEvent*> collisionEvents; //!< the collision event list68 } ;94 }; 95 } 69 96 70 97 #endif /* _COLLISION_H */ -
trunk/src/lib/collision_reaction/collision_event.cc
r9869 r10013 19 19 #include "debug.h" 20 20 21 /** 22 * standard constructor 23 */ 24 CollisionEvent::CollisionEvent () 21 namespace CoRe 25 22 { 26 this->entityA = NULL; 27 this->entityB = NULL; 28 this->bvA = NULL; 29 this->bvB = NULL; 23 24 /** 25 * standard constructor 26 */ 27 CollisionEvent::CollisionEvent () 28 { 29 this->entityA = NULL; 30 this->entityB = NULL; 31 this->bvA = NULL; 32 this->bvB = NULL; 33 } 34 35 36 /** 37 * standard deconstructor 38 */ 39 CollisionEvent::~CollisionEvent () 40 {} 41 30 42 } 31 43 32 33 /**34 * standard deconstructor35 */36 CollisionEvent::~CollisionEvent ()37 {38 }39 40 41 -
trunk/src/lib/collision_reaction/collision_event.h
r9869 r10013 2 2 * @file collision_event.h 3 3 * Definition of a collision event 4 * 5 * A collision event represents a collision of two bouning boxes. Every CollisionEvent belongs to a Collision object that 6 * represents the collision of two WorldEntities. 7 * 8 * There are different types of collisions: obb collisions and bsp collisions. Both collision types use different techniques 9 * to represent collisions. This is why this class saves bounding boxes from the OBB as well as the planes from BSP. 4 10 */ 5 11 … … 8 14 9 15 #include "vector.h" 16 #include "cr_engine.h" 10 17 11 18 #include "cr_defs.h" … … 16 23 class Plane; 17 24 25 namespace CoRe 26 { 27 28 //! A class representing a simple collision 29 class CollisionEvent 30 { 31 public: 32 CollisionEvent(); 33 virtual ~CollisionEvent(); 34 35 /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */ 36 inline void collide(CREngine::CollisionType type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) 37 { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; } 38 /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */ 39 inline void collide(CREngine::CollisionType type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall) 40 { 41 this->collisionType = type; 42 this->entityA = entity; 43 this->entityB = groundEntity; 44 this->groundNormal = normal; 45 this->position = position; 46 this->bInWall = bInWall; 47 } 18 48 19 49 20 //! A class representing a simple collision 21 class CollisionEvent { 22 public: 23 CollisionEvent(); 24 virtual ~CollisionEvent(); 50 /** @return CollisionEvent WorldEntity A */ 51 inline const WorldEntity* getEntityA() const { return this->entityA; } 52 /** @return CollisionEvent WorldEntity B */ 53 inline const WorldEntity* getEntityB() const { return this->entityB; } 54 /** @return Bounding Volume from EntityA */ 55 inline const BoundingVolume* getBVA() const { return this->bvA; } 56 /** @return Bounding Volume from EntityB */ 57 inline const BoundingVolume* getBVB() const { return this->bvB; } 25 58 26 /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */ 27 inline void collide(int type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) 28 { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; } 29 /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */ 30 inline void collide(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall) 31 { this->collisionType = type; this->entityA = entity; this->entityB = groundEntity, this->groundNormal = normal; this->position = position; this->bInWall = bInWall; } 59 /** @return ground plane if collided with bsp model */ 60 inline const Vector& getGroundNormal() const { return this->groundNormal; } 61 62 /** @return position of the position, only accurate if this is a collision with the ground!!! */ 63 inline const Vector& getCollisionPosition() const { return this->position; } 64 65 /** @return the type of the collision */ 66 inline int getType() const { return this->collisionType; } 67 68 /** @return true if the entity is in the wall */ 69 inline bool isInWall() const { return this->bInWall; } 32 70 33 71 34 /** @return CollisionEvent WorldEntity A */ 35 inline WorldEntity* getEntityA() const { return this->entityA; } 36 /** @return CollisionEvent WorldEntity B */ 37 inline WorldEntity* getEntityB() const { return this->entityB; } 38 /** @return Bounding Volume from EntityA */ 39 inline BoundingVolume* getBVA() const { return this->bvA; } 40 /** @return Bounding Volume from EntityB */ 41 inline BoundingVolume* getBVB() const { return this->bvB; } 72 private: 73 WorldEntity* entityA; //!< the collision body A 74 WorldEntity* entityB; //!< the collision body B 42 75 43 /** @return ground plane if collided with bsp model */44 inline Vector getGroundNormal() { return this->groundNormal; }76 BoundingVolume* bvA; //!< reference to the bounding volume A 77 BoundingVolume* bvB; //!< reference to the bounding volume B 45 78 46 /** @return position of the position, only accurate if this is a collision with the ground!!! */47 inline Vector getCollisionPosition() { return this->position; }79 Vector groundNormal; //!< the ground plane with which it collides (only for bsp-model collisions 80 Vector position; //!< position of the collision on the ground plane 48 81 49 /** @return the type of the collision */ 50 inline int getType() { return this->collisionType; } 82 bool bInWall; //!< true if is in wall 83 int collisionType; //!< collision type 84 }; 51 85 52 /** @return true if the entity is in the wall */ 53 inline bool isInWall() { return this->bInWall; } 54 55 56 private: 57 WorldEntity* entityA; //!< the collision body A 58 WorldEntity* entityB; //!< the collision body B 59 60 BoundingVolume* bvA; //!< reference to the bounding volume A 61 BoundingVolume* bvB; //!< reference to the bounding volume B 62 63 Vector groundNormal; //!< the ground plane with which it collides (only for bsp-model collisions 64 Vector position; //!< position of the collision on the ground plane 65 66 bool bInWall; //!< true if is in wall 67 int collisionType; //!< collision type 68 }; 69 86 } 70 87 #endif /* _COLLISION_EVENT_H */ -
trunk/src/lib/collision_reaction/collision_reaction.cc
r9869 r10013 11 11 ### File Specific: 12 12 main-programmer: Patrick Boenzli 13 co-programmer: ...14 13 */ 15 14 … … 18 17 #include "collision_reaction.h" 19 18 19 namespace CoRe 20 { 21 22 ObjectListDefinition(CollisionReaction); 23 24 /** 25 * standard constructor 26 */ 27 CollisionReaction::CollisionReaction () 28 : BaseObject() 29 { 30 this->registerObject(this, CollisionReaction::_objectList); 31 } 20 32 21 33 22 ObjectListDefinition(CollisionReaction); 34 /** 35 * standard deconstructor 36 */ 37 CollisionReaction::~CollisionReaction () 38 {} 23 39 24 /**25 * standard constructor26 */27 CollisionReaction::CollisionReaction ()28 : BaseObject()29 {30 this->registerObject(this, CollisionReaction::_objectList);31 40 } 32 33 34 /**35 * standard deconstructor36 */37 CollisionReaction::~CollisionReaction ()38 {39 }40 -
trunk/src/lib/collision_reaction/collision_reaction.h
r9869 r10013 9 9 #include "base_object.h" 10 10 11 12 13 class Collision;14 11 class WorldEntity; 15 12 13 namespace CoRe 14 { 16 15 17 //! A class representing a simple collision 18 class CollisionReaction : public BaseObject 19 { 20 ObjectListDeclaration(CollisionReaction); 16 class Collision; 17 18 //! A class representing a simple collision 19 class CollisionReaction : public BaseObject 20 { 21 ObjectListDeclaration(CollisionReaction); 21 22 public: 22 23 CollisionReaction(); … … 25 26 virtual void reactToCollision(Collision* collision) = 0; 26 27 27 virtual void update(WorldEntity* owner) {}28 29 28 /** use this to do some collision offline calculations, only called for bContinuousPoll == true */ 30 29 inline bool isContinuousPoll() const { return this->bContinuousPoll; } … … 32 31 private: 33 32 bool bContinuousPoll; //!< if true the collision rection function is also called, if there was no collision 34 };33 }; 35 34 35 } 36 36 #endif /* _COLLISION_REACTION_H */ -
trunk/src/lib/collision_reaction/cr_defs.h
r9062 r10013 28 28 29 29 30 //!< the collision axis x collision event31 #define COLLISION_TYPE_AXIS_X 132 #define COLLISION_TYPE_AXIS_X_NEG 233 //!< the collision axis y collision event34 #define COLLISION_TYPE_AXIS_Y 335 #define COLLISION_TYPE_AXIS_Y_NEG 436 //!< the collision axis z collision event37 #define COLLISION_TYPE_AXIS_Z 538 #define COLLISION_TYPE_AXIS_Z_NEG 639 //!< the collision is a obb collision40 #define COLLISION_TYPE_OBB 841 30 42 43 #endif /* _NETWORK_MANAGER */ 31 #endif /* _CR_DEFS_H */ -
trunk/src/lib/collision_reaction/cr_engine.cc
r9869 r10013 17 17 18 18 19 #include "cr_object_damage.h" 20 #include "cr_physics_full_walk.h" 21 #include "cr_physics_ground_walk.h" 19 22 20 23 #include "collision.h" 21 24 #include "collision_event.h" 22 #include "collision_handle.h" 25 #include "collision_filter.h" 26 #include "collision_tube.h" 23 27 #include "cr_defs.h" 24 28 … … 27 31 #include "debug.h" 28 32 29 30 31 ObjectListDefinition(CREngine); 32 /** 33 * standard constructor 34 */ 35 CREngine::CREngine () 36 : BaseObject() 33 namespace CoRe 37 34 { 38 this->registerObject(this, CREngine::_objectList); 39 this->setName("CREngine"); 40 41 this->init(); 35 36 ObjectListDefinition(CREngine); 37 38 39 /** 40 * standard constructor 41 */ 42 CREngine::CREngine () 43 : BaseObject() 44 { 45 this->registerObject(this, CREngine::_objectList); 46 this->setName("CREngine"); 47 48 this->init(); 49 } 50 51 /** 52 * the singleton reference to this class 53 */ 54 CREngine* CREngine::singletonRef = NULL; 55 56 /** 57 @brief standard deconstructor 58 */ 59 CREngine::~CREngine () 60 { 61 CREngine::singletonRef = NULL; 62 63 if( this->collisionsUnused.size() != CR_MAX_COLLISIONS) 64 PRINTF(0)("CollisionReaction Error: Collision cache size missmatch: %i of %i\n", this->collisionsUnused.size(), CR_MAX_COLLISIONS); 65 if( this->collisionEventsUnused.size() != CR_MAX_COLLISION_EVENTS) 66 PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS); 67 68 this->reset(); 69 70 CollisionIterator it1 = this->collisionsUnused.begin(); 71 for(; it1 < this->collisionsUnused.end(); it1++) 72 delete *it1; 73 CollisionEventIterator it2 = this->collisionEventsUnused.begin(); 74 for(; it2 < this->collisionEventsUnused.end(); it2++) 75 delete *it2; 76 77 this->collisionsUnused.clear(); 78 this->collisionEventsUnused.clear(); 79 } 80 81 82 /** 83 * inits the CREngine to a working state 84 */ 85 void CREngine::init() 86 { 87 // precaching: 88 // create a list of Collisions and CollisionEvents for fast object recycling purposes 89 for( int i = 0; i < CR_MAX_COLLISIONS; i++) 90 this->collisionsUnused.push_back(new Collision()); 91 for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++) 92 this->collisionEventsUnused.push_back(new CollisionEvent()); 93 94 95 // push the collision reaction object on the list in the right order 96 97 // physical reactions 98 this->_reactionList[CREngine::CR_PHYSICS_MOMENTUM] = NULL; 99 this->_reactionList[CREngine::CR_PHYSICS_STEP_BACK] = NULL; 100 this->_reactionList[CREngine::CR_PHYSICS_GROUND_WALK] = new CRPhysicsGroundWalk(); 101 this->_reactionList[CREngine::CR_PHYSICS_FULL_WALK] = new CRPhysicsFullWalk(); 102 this->_reactionList[CREngine::CR_PHYSICS_DAMAGE] = NULL; 103 // object based reactions 104 this->_reactionList[CREngine::CR_OBJECT_DAMAGE] = new CRObjectDamage(); 105 this->_reactionList[CREngine::CR_OBJECT_PICKUP] = NULL; 106 // misc reactions 107 this->_reactionList[CREngine::CR_VERTEX_TRAFO] = NULL; 108 this->_reactionList[CREngine::CR_SPECIAL_CALLBACK] = NULL; 109 } 110 111 112 /** 113 * @returns an instance to a collision object. instead of creating new object this ones can be resycled 114 */ 115 Collision* CREngine::popCollisionObject() 116 { 117 if( !this->collisionsUnused.empty()) 118 { 119 this->collisionsUsed.push_back(this->collisionsUnused.back()); 120 this->collisionsUnused.pop_back(); 121 return this->collisionsUsed.back(); 122 } 123 else 124 { 125 PRINTF(0)("There is no Collision Object left in the precache table, fatal error will cause segfault, change CR_MAX_COLLISIONS\n"); 126 assert(false); 127 return NULL; 128 } 129 } 130 131 132 /** 133 * @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled 134 */ 135 CollisionEvent* CREngine::popCollisionEventObject() 136 { 137 if( !this->collisionEventsUnused.empty()) 138 { 139 this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); 140 this->collisionEventsUnused.pop_back(); 141 return this->collisionEventsUsed.back(); 142 } 143 else 144 { 145 PRINTF(0)("There is no Collision Object left in the precache table, fatal error will cause segfault, change CR_MAX_COLLISION_EVENTS\n"); 146 assert(false); 147 return NULL; 148 } 149 } 150 151 152 /** 153 * handles all collisions in registered in this tube 154 */ 155 void CREngine::handleCollisions() 156 { 157 // for all collisions: 158 CollisionIterator ci = CollisionTube::getInstance()->begin(); 159 for(; ci < CollisionTube::getInstance()->end(); ci++) 160 { 161 for( int i = CREngine::CR_PHYSICS_MOMENTUM; i < CREngine::CR_NUMBER; i++) 162 { 163 if( _reactionList[i] == NULL) 164 continue; 165 166 // PRINTF(0)("CR CHECK: collision between: %s, %s\n", (*ci)->getEntityA()->getClassName().c_str(), (*ci)->getEntityB()->getClassName().c_str()); 167 168 // check if entity A or B is subscibed for this event 169 bool aReact = (*ci)->getEntityA()->isReactive(*(*ci)->getEntityB(), (CREngine::ReactionType)i); 170 bool bReact = (*ci)->getEntityB()->isReactive(*(*ci)->getEntityA(), (CREngine::ReactionType)i); 171 172 // store this information 173 (*ci)->setEntityACollide(aReact); 174 (*ci)->setEntityBCollide(bReact); 175 176 // and execute the reaction 177 if( aReact || bReact) 178 { 179 this->_reactionList[i]->reactToCollision(*ci); 180 //PRINTF(0)("executing reaction: %s, between %s - %s\n", this->_reactionList[i]->getClassName().c_str(), (*ci)->getEntityA()->getClassName().c_str(), (*ci)->getEntityB()->getClassName().c_str()); 181 } 182 } 183 (*ci)->reset(); 184 } 185 186 this->reset(); 187 } 188 189 190 /** 191 * flushes all the collision lists and puts them to their initial state 192 */ 193 void CREngine::reset() 194 { 195 CollisionIterator it1 = this->collisionsUsed.begin(); 196 for(; it1 < this->collisionsUsed.end(); it1++) 197 this->collisionsUnused.push_back(*it1); 198 199 CollisionEventIterator it2 = this->collisionEventsUsed.begin(); 200 for(; it2 < this->collisionEventsUsed.end(); it2++) 201 this->collisionEventsUnused.push_back(*it2); 202 203 this->collisionsUsed.clear(); 204 this->collisionEventsUsed.clear(); 205 206 CollisionTube::getInstance()->reset(); 207 } 208 209 210 void CREngine::debug() 211 { 212 } 213 42 214 } 43 44 /**45 * the singleton reference to this class46 */47 CREngine* CREngine::singletonRef = NULL;48 49 /**50 @brief standard deconstructor51 */52 CREngine::~CREngine ()53 {54 CREngine::singletonRef = NULL;55 56 if( this->collisionsUnused.size() != CR_MAX_COLLISIONS)57 PRINTF(0)("CollisionReaction Error: Collision cache size missmatch: %i of %i\n", this->collisionsUnused.size(), CR_MAX_COLLISIONS);58 if( this->collisionEventsUnused.size() != CR_MAX_COLLISION_EVENTS)59 PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS);60 61 this->reset();62 63 std::vector<Collision*>::iterator it1 = this->collisionsUnused.begin();64 for(; it1 < this->collisionsUnused.end(); it1++)65 delete *it1;66 std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUnused.begin();67 for(; it2 < this->collisionEventsUnused.end(); it2++)68 delete *it2;69 70 this->collisionsUnused.clear();71 this->collisionEventsUnused.clear();72 }73 74 /**75 * inits the CREngine to a working state76 */77 void CREngine::init()78 {79 // create a list of Collision events (precaching)80 for( int i = 0; i < CR_MAX_COLLISIONS; i++)81 this->collisionsUnused.push_back(new Collision());82 for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++)83 this->collisionEventsUnused.push_back(new CollisionEvent());84 }85 86 87 /**88 * flushes the CollisionHandles and restores the CREngine to the initial state89 */90 void CREngine::reset()91 {92 // first clear all CollisionHandles93 94 std::vector<CollisionHandle*>::iterator it = this->collisionHandles.begin();95 for(; it < this->collisionHandles.end(); it++)96 {97 (*it)->reset();98 delete *it;99 }100 101 this->collisionHandles.clear();102 }103 104 105 /**106 * subscribes a WorldEntity for a CollisionReaction107 * @param owner: the WE to subscribe108 * @param type: the type of collision reaction to perform109 * @return the newly created CollisionHandle110 */111 CollisionHandle* CREngine::subscribeReaction(WorldEntity* owner, CRType type)112 {113 CollisionHandle* ch = new CollisionHandle(owner, type);114 this->collisionHandles.push_back(ch);115 116 return ch;117 }118 119 120 /**121 * unsubscribe reaction from the reaction list122 * @param collisionHandle the CollisionHandle to remove123 * @param returns true if worked collrectly124 */125 bool CREngine::unsubscribeReaction(CollisionHandle* collisionHandle)126 {127 std::vector<CollisionHandle*>::iterator it;128 for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++) {129 if( *it == collisionHandle) {130 this->collisionHandles.erase(it);131 delete collisionHandle;132 return true;133 }134 }135 return false;136 }137 138 139 /**140 * processes the collisions by calling the EventHandlers141 */142 void CREngine::handleCollisions()143 {144 std::vector<CollisionHandle*>::iterator it;145 for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++)146 {147 if( !(*it)->isDispatched() || (*it)->isContinuousPoll()) //does it have any collisions to report at all148 {149 (*it)->handleCollisions();150 }151 }152 this->flushCollisions();153 }154 155 156 /**157 * flushes all the collision lists and puts them to their initial state158 */159 void CREngine::flushCollisions()160 {161 std::vector<Collision*>::iterator it1 = this->collisionsUsed.begin();162 for(; it1 < this->collisionsUsed.end(); it1++)163 this->collisionsUnused.push_back(*it1);164 165 std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUsed.begin();166 for(; it2 < this->collisionEventsUsed.end(); it2++)167 this->collisionEventsUnused.push_back(*it2);168 169 this->collisionsUsed.clear();170 this->collisionEventsUsed.clear();171 }172 173 174 void CREngine::debug()175 {176 177 }178 -
trunk/src/lib/collision_reaction/cr_engine.h
r9869 r10013 16 16 #include <vector> 17 17 18 // FORWARD DECLARATION19 class CollisionHandle;20 class Collision;21 class CollisionEvent;22 18 class WorldEntity; 23 19 24 //! A default singleton class. 25 class CREngine : public BaseObject 20 21 namespace CoRe 26 22 { 27 ObjectListDeclaration(CREngine); 23 class Collision; 24 class CollisionEvent; 25 class CollisionReaction; 26 27 28 //! A default singleton class. 29 class CREngine : public BaseObject 30 { 31 ObjectListDeclaration(CREngine); 32 33 typedef std::vector<CollisionEvent*> CollisionEventVector; 34 typedef std::vector<Collision*> CollisionVector; 35 typedef std::vector<Collision*>::iterator CollisionIterator; 36 typedef std::vector<CollisionEvent*>::iterator CollisionEventIterator; 37 28 38 29 39 public: 30 typedef enum CRType {31 CR_PHYSICS_MOMENTUM = 0,//!< physical reaction: conservervation of momentum32 CR_PHYSICS_STEP_BACK,//!< physical reaction: just go to the last position without collisions33 CR_PHYSICS_GROUND_WALK, //!< physical reaction: stand on the ground, no movement: simulatingsimple normal force away from the gravity force34 CR_PHYSICS_FULL_WALK,//!< physical reaction: walking on the ground (inkl. hills etc)35 CR_PHYSICS_DAMAGE,//!< physical reaction: daling damage according to the object energy and their structural stability40 typedef enum ReactionType { 41 CR_PHYSICS_MOMENTUM = 0, //!< physical reaction: conservervation of momentum 42 CR_PHYSICS_STEP_BACK, //!< physical reaction: just go to the last position without collisions 43 CR_PHYSICS_GROUND_WALK, //!< physical reaction: stand on the ground, no movement: simple normal force away from the gravity force 44 CR_PHYSICS_FULL_WALK, //!< physical reaction: walking on the ground (inkl. hills etc) 45 CR_PHYSICS_DAMAGE, //!< physical reaction: daling damage according to the object energy and their structural stability 36 46 37 CR_OBJECT_DAMAGE,//!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.)38 CR_OBJECT_PICKUP,//!< object rection: calling the objects pickup functions, let them handle the collision (once!)47 CR_OBJECT_DAMAGE, //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.) 48 CR_OBJECT_PICKUP, //!< object rection: calling the objects pickup functions, let them handle the collision (once!) 39 49 40 CR_VERTEX_TRAFO,//!< vertex trafo: transforming the vertex according to the damage50 CR_VERTEX_TRAFO, //!< vertex trafo: transforming the vertex according to the damage 41 51 42 CR_SPECIAL_CALLBACK,//!< special: call a callback function52 CR_SPECIAL_CALLBACK, //!< special: call a callback function 43 53 44 CR_NUMBER 54 CR_NUMBER 55 }; 56 57 typedef enum CollisionType { 58 CR_COLLISION_TYPE_AXIS_X = 0, //!< collision on x axis 59 CR_COLLISION_TYPE_AXIS_X_NEG, //!< collision on negative x axis 60 CR_COLLISION_TYPE_AXIS_Y, //!< collision on y axis 61 CR_COLLISION_TYPE_AXIS_Y_NEG, //!< collision on negative y axis 62 CR_COLLISION_TYPE_AXIS_Z, //!< collision on z axis 63 CR_COLLISION_TYPE_AXIS_Z_NEG, //!< collision on negative z axis 64 CR_COLLISION_TYPE_OBB, //!< object aligned bounding box collide 65 66 CR_COLLISION_TYPE_NUMBER 67 }; 68 69 70 virtual ~CREngine(void); 71 72 /** @returns a Pointer to the only object of this Class */ 73 inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; 74 75 Collision* popCollisionObject(); 76 CollisionEvent* popCollisionEventObject(); 77 78 void handleCollisions(); 79 80 void debug(); 81 82 83 private: 84 CREngine(); 85 void init(); 86 87 void reset(); 88 89 90 private: 91 static CREngine* singletonRef; //!< the reference to the CREngine object (singleton) 92 93 CollisionVector collisionsUsed; //!< a list of used, cached collisions 94 CollisionVector collisionsUnused; //!< a list of unused, cached collisions 95 96 CollisionEventVector collisionEventsUsed; //!< a list of used, cached collision events 97 CollisionEventVector collisionEventsUnused; //!< a list of unused, cached collision events 98 99 CollisionReaction* _reactionList[CREngine::CR_NUMBER]; //!< the collision reaction list containing all reactions types 100 101 45 102 }; 46 103 47 virtual ~CREngine(void); 48 49 /** @returns a Pointer to the only object of this Class */ 50 inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; 51 52 void reset(); 53 54 55 CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type); 56 57 bool unsubscribeReaction(CollisionHandle* collisionHandle); 58 59 void handleCollisions(); 60 61 /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */ 62 inline Collision* popCollisionObject() { 63 if( !this->collisionsUnused.empty()) { 64 this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back(); } else return NULL; } 65 66 67 /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */ 68 inline CollisionEvent* popCollisionEventObject() { 69 if( !this->collisionEventsUnused.empty()) { 70 this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back(); } else return NULL; } 71 72 void debug(); 73 74 75 private: 76 CREngine(); 77 void init(); 78 79 void flushCollisions(); 80 81 82 private: 83 std::vector<CollisionHandle*> collisionHandles; //!< list with the collision handles 84 85 std::vector<Collision*> collisionsUsed; //!< a list of used, cached collisions 86 std::vector<Collision*> collisionsUnused; //!< a list of unused, cached collisions 87 88 std::vector<CollisionEvent*> collisionEventsUsed; //!< a list of used, cached collision events 89 std::vector<CollisionEvent*> collisionEventsUnused; //!< a list of unused, cached collision events 90 91 static CREngine* singletonRef; //!< the reference to the CREngine object (singleton) 92 }; 93 104 } 94 105 #endif /* _CR_ENGINE_ */ -
trunk/src/lib/collision_reaction/cr_object_damage.cc
r9869 r10013 26 26 #include "debug.h" 27 27 28 namespace CoRe 29 { 30 31 ObjectListDefinition(CRObjectDamage); 32 /** 33 * standard constructor 34 */ 35 CRObjectDamage::CRObjectDamage () 36 : CollisionReaction() 37 { 38 this->registerObject(this, CRObjectDamage::_objectList); 39 } 28 40 29 41 30 ObjectListDefinition(CRObjectDamage); 31 /** 32 * standard constructor 33 */ 34 CRObjectDamage::CRObjectDamage () 35 : CollisionReaction() 36 { 37 this->registerObject(this, CRObjectDamage::_objectList); 38 } 42 /** 43 * standard deconstructor 44 */ 45 CRObjectDamage::~CRObjectDamage () 46 {} 39 47 40 48 41 /** 42 * standard deconstructor 43 */ 44 CRObjectDamage::~CRObjectDamage () 45 { 46 } 49 /** 50 * caluculates and applys the reaction to a specific collision 51 * @param collision the collision 52 */ 53 void CRObjectDamage::reactToCollision(Collision* collision) 54 { 55 float damage = 0.0f; 47 56 57 PRINTF(0)("Dealing damage - Handling collision: %s vs %s\n", 58 collision->getEntityA()->getClassCName(), 59 collision->getEntityB()->getClassCName()); 48 60 49 /** 50 * caluculates and applys the reaction to a specific collision51 * @param collision the collision52 */53 void CRObjectDamage::reactToCollision(Collision* collision) 54 { 55 float damage = 0.0f;61 // the collision damage been dealed by the entity 62 if( collision->isEntityACollide()) 63 { 64 damage = collision->getEntityB()->getDamage(); 65 collision->getEntityA()->hit(damage, collision->getEntityB()); 66 PRINTF(0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassCName()); 67 } 56 68 57 PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n", 58 collision->getEntityA()->getClassCName(), 59 collision->getEntityB()->getClassCName()); 69 if( collision->isEntityBCollide()) 70 { 71 damage = collision->getEntityA()->getDamage(); 72 collision->getEntityB()->hit(damage, collision->getEntityA()); 73 PRINTF(0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassCName()); 74 } 60 75 61 // the collision damage been dealed by the entity 62 if( collision->isEntityACollide()) { 63 damage = collision->getEntityB()->getDamage(); 64 collision->getEntityA()->hit(damage, collision->getEntityB()); 65 PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassCName()); 76 // const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); 77 // std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); 78 // for(; it != collisionEvents->end(); it++) 79 // { 80 // // go through the collisions and try to estimate the damage 81 // mass = (*it)->getEntityA()->getMass(); 82 // } 83 66 84 } 67 85 68 if( collision->isEntityBCollide()) {69 damage = collision->getEntityA()->getDamage();70 collision->getEntityB()->hit(damage, collision->getEntityA());71 PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassCName());72 }73 74 collision->flushCollisionEvents();75 collision->dispatched();76 77 // const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());78 // std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();79 // for(; it != collisionEvents->end(); it++)80 // {81 // // go through the collisions and try to estimate the damage82 // mass = (*it)->getEntityA()->getMass();83 // }84 85 86 } 86 -
trunk/src/lib/collision_reaction/cr_object_damage.h
r9869 r10013 7 7 #define _CR_OBJECT_DAMAGE_H 8 8 9 9 10 #include "collision_reaction.h" 10 11 11 12 12 class Collision; 13 namespace CoRe 14 { 13 15 14 //! A class representing a reaction to a collision: dealing damage to an object 15 class CRObjectDamage : public CollisionReaction 16 { 17 ObjectListDeclaration(CRObjectDamage); 16 class Collision; 17 18 //! A class representing a reaction to a collision: dealing damage to an object 19 class CRObjectDamage : public CollisionReaction 20 { 21 ObjectListDeclaration(CRObjectDamage); 18 22 public: 19 23 CRObjectDamage(); … … 22 26 virtual void reactToCollision(Collision* collision); 23 27 24 private: 25 26 }; 28 }; 29 } 27 30 28 31 #endif /* _CR_OBJECT_DAMAGE_H */ -
trunk/src/lib/collision_reaction/cr_physics_full_walk.cc
r9869 r10013 33 33 #include "cr_defs.h" 34 34 35 36 37 ObjectListDefinition(CRPhysicsFullWalk); 38 /** 39 * standard constructor 40 */ 41 CRPhysicsFullWalk::CRPhysicsFullWalk () 42 : CollisionReaction() 35 namespace CoRe 43 36 { 44 this->registerObject(this, CRPhysicsFullWalk::_objectList); 37 38 ObjectListDefinition(CRPhysicsFullWalk); 39 /** 40 * standard constructor 41 */ 42 CRPhysicsFullWalk::CRPhysicsFullWalk () 43 : CollisionReaction() 44 { 45 this->registerObject(this, CRPhysicsFullWalk::_objectList); 46 } 47 48 49 /** 50 * standard deconstructor 51 */ 52 CRPhysicsFullWalk::~CRPhysicsFullWalk () 53 {} 54 55 56 /** 57 * caluculates and applys the reaction to a specific collision 58 * @param collision the collision 59 */ 60 void CRPhysicsFullWalk::reactToCollision(Collision* collision) 61 { 62 63 AABB* box = collision->getEntityA()->getModelAABB(); 64 WorldEntity* entity = collision->getEntityA(); 65 66 if( box == NULL) 67 { 68 PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n"); 69 return; 70 } 71 72 73 float CR_MAX_WALK_HEIGHT = 15.0f; 74 // float CR_THRESHOLD = 0.2f; 75 76 float height = 0.0f; 77 float front = 0.0f; 78 float back = 0.0f; 79 float right = 0.0f; 80 float left = 0.0f; 81 82 83 std::vector<CollisionEvent*>::const_iterator it = collision->begin(); 84 for(; it != collision->end(); it++) 85 { 86 87 CollisionEvent* ce = (*it); 88 Vector normal = ce->getGroundNormal(); 89 90 // calculate the collision position 91 Vector collPos = collision->getEntityA()->getAbsCoor() + box->center - ce->getCollisionPosition(); 92 93 // test the 3 axis differently 94 switch( ce->getType()) 95 { 96 /* collision in the X-AXIS */ 97 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X: 98 front = collPos.len() - box->halfLength[0]; 99 100 // object is beneath the plane (ground) 101 if( front <= 0.0f ) 102 { 103 Vector dirX = entity->getAbsDirX(); 104 dirX.y = 0.0f; 105 dirX.normalize(); 106 Vector backoff = dirX * front; 107 108 entity->shiftCoor(backoff); 109 } 110 else if( ce->isInWall()) 111 { 112 // object is already in the wall 113 entity->setAbsCoor(entity->getLastAbsCoor()); 114 } 115 break; 116 117 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG: 118 back = collPos.len() - box->halfLength[0]; 119 120 // object is beneath the plane (ground) 121 if( back <= 0.0f) 122 { 123 Vector dirX = entity->getAbsDirX(); 124 dirX.y = 0.0f; 125 dirX.normalize(); 126 Vector backoff = dirX * back * -1.0f; 127 128 entity->shiftCoor(backoff); 129 } 130 else if( ce->isInWall()) 131 { 132 // object is already in the wall 133 entity->setAbsCoor(entity->getLastAbsCoor()); 134 } 135 break; 136 137 138 /* collision in the Y-AXIS */ 139 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG: 140 // calulate the height above ground 141 height = collPos.len() - box->halfLength[1]; 142 143 144 // object is beneath the plane (ground) 145 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing 146 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) 147 { 148 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); 149 entity->setOnGround(true); 150 } 151 // object is already in the wall 152 else if( ce->isInWall()) 153 { 154 entity->setAbsCoor(entity->getLastAbsCoor()); 155 PRINTF(0)("ground collision: reset pos\n"); 156 } 157 else 158 { 159 // entity is not on ground 160 entity->setOnGround(false); 161 } 162 break; 163 164 165 /* collision in the Z-AXIS */ 166 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z: 167 168 right = collPos.len() - box->halfLength[2]; 169 170 // object is beneath the plane (ground) 171 if( right <= 0.0f ) 172 { 173 Vector dirZ = entity->getAbsDirZ(); 174 dirZ.y = 0.0f; 175 dirZ.normalize(); 176 Vector backoff = dirZ * right; 177 entity->shiftCoor(backoff); 178 } 179 else if( ce->isInWall()) 180 { 181 // object is already in the wall 182 entity->setAbsCoor(entity->getLastAbsCoor()); 183 } 184 break; 185 186 187 // collision in the z-axis 188 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG: 189 190 left = collPos.len() - box->halfLength[2]; 191 192 // object is beneath the plane (ground) 193 if( left <= 0.0f ) 194 { 195 Vector dirZ = entity->getAbsDirZ(); 196 dirZ.y = 0.0f; 197 dirZ.normalize(); 198 Vector backoff = dirZ * left*-1.0f; 199 entity->shiftCoor(backoff); 200 } 201 // object is already in the wall 202 else if( ce->isInWall()) 203 { 204 entity->setAbsCoor(entity->getLastAbsCoor()); 205 } 206 break; 207 } 208 } 209 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side); 210 } 211 212 213 214 45 215 } 46 216 47 48 /**49 * standard deconstructor50 */51 CRPhysicsFullWalk::~CRPhysicsFullWalk ()52 {}53 54 55 /**56 * caluculates and applys the reaction to a specific collision57 * @param collision the collision58 */59 void CRPhysicsFullWalk::reactToCollision(Collision* collision)60 {61 62 AABB* box = collision->getEntityB()->getModelAABB();63 WorldEntity* entity = collision->getEntityB();64 65 if( box == NULL)66 {67 PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n");68 return;69 }70 71 72 float CR_MAX_WALK_HEIGHT = 15.0f;73 float CR_THRESHOLD = 0.2f;74 75 float height = 0.0f;76 float front = 0.0f;77 float back = 0.0f;78 float right = 0.0f;79 float left = 0.0f;80 81 82 const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents());83 std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin();84 for(; it != collisionEvents->end(); it++)85 {86 87 CollisionEvent* ce = (*it);88 Vector normal = ce->getGroundNormal();89 90 // calculate the collision position91 Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition();92 93 // test the 3 axis differently94 switch( ce->getType())95 {96 /* collision in the X-AXIS */97 case COLLISION_TYPE_AXIS_X:98 front = collPos.len() - box->halfLength[0];99 100 // object is beneath the plane (ground)101 if( front <= 0.0f )102 {103 Vector dirX = entity->getAbsDirX();104 dirX.y = 0.0f;105 dirX.normalize();106 Vector backoff = dirX * front;107 108 entity->shiftCoor(backoff);109 }110 else if( ce->isInWall())111 {112 // object is already in the wall113 entity->setAbsCoor(entity->getLastAbsCoor());114 }115 break;116 117 case COLLISION_TYPE_AXIS_X_NEG:118 back = collPos.len() - box->halfLength[0];119 120 // object is beneath the plane (ground)121 if( back <= 0.0f)122 {123 Vector dirX = entity->getAbsDirX();124 dirX.y = 0.0f;125 dirX.normalize();126 Vector backoff = dirX * back * -1.0f;127 128 entity->shiftCoor(backoff);129 }130 else if( ce->isInWall())131 {132 // object is already in the wall133 entity->setAbsCoor(entity->getLastAbsCoor());134 }135 break;136 137 138 /* collision in the Y-AXIS */139 case COLLISION_TYPE_AXIS_Y_NEG:140 // calulate the height above ground141 height = collPos.len() - box->halfLength[1];142 143 144 // object is beneath the plane (ground)145 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing146 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT)147 {148 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f));149 entity->setOnGround(true);150 }151 // object is already in the wall152 else if( ce->isInWall())153 {154 entity->setAbsCoor(entity->getLastAbsCoor());155 PRINTF(0)("ground collision: reset pos\n");156 }157 else158 {159 // entity is not on ground160 entity->setOnGround(false);161 }162 break;163 164 165 /* collision in the Z-AXIS */166 case COLLISION_TYPE_AXIS_Z:167 168 right = collPos.len() - box->halfLength[2];169 170 // object is beneath the plane (ground)171 if( right <= 0.0f )172 {173 Vector dirZ = entity->getAbsDirZ();174 dirZ.y = 0.0f;175 dirZ.normalize();176 Vector backoff = dirZ * right;177 entity->shiftCoor(backoff);178 }179 else if( ce->isInWall())180 {181 // object is already in the wall182 entity->setAbsCoor(entity->getLastAbsCoor());183 }184 break;185 186 187 // collision in the z-axis188 case COLLISION_TYPE_AXIS_Z_NEG:189 190 left = collPos.len() - box->halfLength[2];191 192 // object is beneath the plane (ground)193 if( left <= 0.0f )194 {195 Vector dirZ = entity->getAbsDirZ();196 dirZ.y = 0.0f;197 dirZ.normalize();198 Vector backoff = dirZ * left*-1.0f;199 entity->shiftCoor(backoff);200 }201 // object is already in the wall202 else if( ce->isInWall())203 {204 entity->setAbsCoor(entity->getLastAbsCoor());205 }206 break;207 }208 }209 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);210 211 212 213 214 215 216 217 }218 219 220 221 222 /**223 * use this to do some collision offline calculations, only called for bContinuousPoll == true224 */225 void CRPhysicsFullWalk::update(WorldEntity* owner)226 {}227 228 -
trunk/src/lib/collision_reaction/cr_physics_full_walk.h
r9869 r10013 9 9 #include "collision_reaction.h" 10 10 11 namespace CoRe 12 { 11 13 12 class Collision;14 class Collision; 13 15 14 //! A class representing a reaction to a collision: dealing damage to an object15 class CRPhysicsFullWalk : public CollisionReaction16 {17 ObjectListDeclaration(CRPhysicsFullWalk);16 //! A class representing a reaction to a collision: dealing damage to an object 17 class CRPhysicsFullWalk : public CollisionReaction 18 { 19 ObjectListDeclaration(CRPhysicsFullWalk); 18 20 public: 19 21 CRPhysicsFullWalk(); … … 21 23 22 24 virtual void reactToCollision(Collision* collision); 23 24 virtual void update(WorldEntity* entity); 25 26 27 private: 28 float downspeed; 29 }; 30 25 }; 26 } 31 27 #endif /* _CR_PHYSICS_FULL_WALK_H */ -
trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc
r9869 r10013 34 34 35 35 36 namespace CoRe 37 { 36 38 37 ObjectListDefinition(CRPhysicsGroundWalk); 38 /** 39 * standard constructor 40 */ 41 CRPhysicsGroundWalk::CRPhysicsGroundWalk () 42 : CollisionReaction() 43 { 44 this->registerObject(this, CRPhysicsGroundWalk::_objectList); 45 } 39 ObjectListDefinition(CRPhysicsGroundWalk); 46 40 47 41 48 /** 49 * standard deconstructor 50 */ 51 CRPhysicsGroundWalk::~CRPhysicsGroundWalk () 52 {} 53 54 55 /** 56 * caluculates and applys the reaction to a specific collision 57 * @param collision the collision 58 */ 59 void CRPhysicsGroundWalk::reactToCollision(Collision* collision) 60 { 61 62 AABB* box = collision->getEntityB()->getModelAABB(); 63 WorldEntity* entity = collision->getEntityB(); 64 65 if( box == NULL) 42 /** 43 * standard constructor 44 */ 45 CRPhysicsGroundWalk::CRPhysicsGroundWalk () 46 : CollisionReaction() 66 47 { 67 PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n"); 68 return; 48 this->registerObject(this, CRPhysicsGroundWalk::_objectList); 69 49 } 70 50 71 51 72 float CR_MAX_WALK_HEIGHT = 15.0f; 73 74 float height = 0.0f; 52 /** 53 * standard deconstructor 54 */ 55 CRPhysicsGroundWalk::~CRPhysicsGroundWalk () 56 {} 75 57 76 58 77 const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); 78 std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); 79 for(; it != collisionEvents->end(); it++) 59 /** 60 * caluculates and applys the reaction to a specific collision 61 * @param collision the collision 62 */ 63 void CRPhysicsGroundWalk::reactToCollision(Collision* collision) 80 64 { 81 65 82 CollisionEvent* ce = (*it);83 Vector normal = ce->getGroundNormal();66 AABB* box = collision->getEntityA()->getModelAABB(); 67 WorldEntity* entity = collision->getEntityA(); 84 68 85 // calculate the collision position 86 Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition(); 87 88 // test the 3 axis differently 89 switch( ce->getType()) 69 if( box == NULL) 90 70 { 91 /* collision in the Y-AXIS */ 92 case COLLISION_TYPE_AXIS_Y_NEG: 93 // calulate the height above ground 94 height = collPos.len() - box->halfLength[1]; 71 PRINTF(2)("this model has no aabb box so there is no correct collision reaction implemented. skipping\n"); 72 return; 73 } 95 74 96 75 97 // object is beneath the plane (ground) 98 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing 99 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) 100 { 101 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); 102 entity->setOnGround(true); 103 } 104 // object is already in the wall 105 else if( ce->isInWall()) 106 { 107 entity->setAbsCoor(entity->getLastAbsCoor()); 108 } 109 else 110 { 111 // entity is not on ground 112 entity->setOnGround(false); 113 } 114 break; 76 float CR_MAX_WALK_HEIGHT = 15.0f; 77 78 float height = 0.0f; 115 79 116 80 81 std::vector<CollisionEvent*>::const_iterator it = collision->begin(); 82 for(; it != collision->end(); it++) 83 { 84 85 CollisionEvent* ce = (*it); 86 Vector normal = ce->getGroundNormal(); 87 88 // calculate the collision position 89 Vector collPos = collision->getEntityA()->getAbsCoor() + box->center - ce->getCollisionPosition(); 90 91 // test the 3 axis differently 92 switch( ce->getType()) 93 { 94 /* collision in the Y-AXIS */ 95 case CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG: 96 // calulate the height above ground 97 height = collPos.len() - box->halfLength[1]; 98 99 100 // object is beneath the plane (ground) 101 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing 102 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) 103 { 104 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); 105 entity->setOnGround(true); 106 } 107 // object is already in the wall 108 else if( ce->isInWall()) 109 { 110 entity->setAbsCoor(entity->getLastAbsCoor()); 111 } 112 else 113 { 114 // entity is not on ground 115 entity->setOnGround(false); 116 } 117 break; 118 119 120 } 117 121 } 122 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side); 123 118 124 } 119 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);120 121 }122 125 123 126 124 127 125 126 /** 127 * use this to do some collision offline calculations, only called for bContinuousPoll == true 128 */ 129 void CRPhysicsGroundWalk::update(WorldEntity* owner) 130 {} 131 132 128 } -
trunk/src/lib/collision_reaction/cr_physics_ground_walk.h
r9869 r10013 9 9 #include "collision_reaction.h" 10 10 11 namespace CoRe 12 { 11 13 12 class Collision;14 class Collision; 13 15 14 //! A class representing a reaction to a collision: dealing damage to an object15 class CRPhysicsGroundWalk : public CollisionReaction16 {17 ObjectListDeclaration(CRPhysicsGroundWalk);16 //! A class representing a reaction to a collision: dealing damage to an object 17 class CRPhysicsGroundWalk : public CollisionReaction 18 { 19 ObjectListDeclaration(CRPhysicsGroundWalk); 18 20 public: 19 21 CRPhysicsGroundWalk(); … … 22 24 virtual void reactToCollision(Collision* collision); 23 25 24 virtual void update(WorldEntity* entity);26 }; 25 27 26 27 private: 28 float downspeed; 29 }; 30 28 } 31 29 #endif /* _CR_PHYSICS_GROUND_WALK_H */ -
trunk/src/lib/graphics/importer/bsp_manager.cc
r9869 r10013 46 46 47 47 #include "aabb.h" 48 #include "cr_defs.h" 48 #include "cr_engine.h" 49 #include "collision_tube.h" 49 50 50 51 … … 1215 1216 if( xCollisionForward) 1216 1217 { 1217 entity->registerCollision(COLLISION_TYPE_AXIS_X ,1218 this->parent, entity,1218 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X , 1219 entity, this->parent, 1219 1220 Vector(testPlane->x, testPlane->y, testPlane->z), 1220 1221 collPos, … … 1254 1255 if( xCollisionBackward) 1255 1256 { 1256 entity->registerCollision(COLLISION_TYPE_AXIS_X_NEG,1257 this->parent, entity,1257 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_X_NEG, 1258 entity, this->parent, 1258 1259 Vector(testPlane->x, testPlane->y, testPlane->z), 1259 1260 collPos, … … 1350 1351 if( yCollisionUp) 1351 1352 { 1352 entity->registerCollision(COLLISION_TYPE_AXIS_Y , this->parent,1353 entity, 1353 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y, 1354 entity, this->parent, 1354 1355 Vector(testPlane->x, testPlane->y, testPlane->z), 1355 1356 collPos, SolidFlag); … … 1403 1404 if( yCollisionDown) 1404 1405 { 1405 entity->registerCollision(COLLISION_TYPE_AXIS_Y_NEG , this->parent,1406 entity, 1406 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Y_NEG , 1407 entity, this->parent, 1407 1408 Vector(testPlane->x, testPlane->y, testPlane->z), 1408 1409 collPos, SolidFlag); 1409 1410 } 1410 1411 1412 1411 } 1413 1412 … … 1484 1483 1485 1484 if( zCollisionRight) { 1486 entity->registerCollision(COLLISION_TYPE_AXIS_Z , this->parent,1487 entity, 1485 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z , 1486 entity, this->parent, 1488 1487 Vector(testPlane->x, testPlane->y, testPlane->z), 1489 1488 collPos , SolidFlag); … … 1523 1522 1524 1523 if( zCollisionLeft) { 1525 entity->registerCollision(COLLISION_TYPE_AXIS_Z_NEG , this->parent,1526 entity,1527 Vector(testPlane->x, testPlane->y, testPlane->z),1528 collPos , SolidFlag);1524 CoRe::CollisionTube::getInstance()->registerCollisionEvent( CoRe::CREngine::CR_COLLISION_TYPE_AXIS_Z_NEG , 1525 entity, this->parent, 1526 Vector(testPlane->x, testPlane->y, testPlane->z), 1527 collPos , SolidFlag); 1529 1528 } 1530 1529 -
trunk/src/story_entities/game_world.cc
r9869 r10013 136 136 AnimationPlayer::getInstance(); 137 137 PhysicsEngine::getInstance(); 138 C REngine::getInstance();138 CoRe::CREngine::getInstance(); 139 139 140 140 State::setScriptManager(&this->scriptManager); … … 219 219 delete AnimationPlayer::getInstance(); 220 220 delete PhysicsEngine::getInstance(); 221 delete C REngine::getInstance();221 delete CoRe::CREngine::getInstance(); 222 222 223 223 State::setCurrentStoryEntity(NULL); … … 494 494 void GameWorld::collisionReaction() 495 495 { 496 C REngine::getInstance()->handleCollisions();496 CoRe::CREngine::getInstance()->handleCollisions(); 497 497 } 498 498 -
trunk/src/story_entities/game_world_data.cc
r9869 r10013 232 232 State::setPlayer(this->localPlayer); 233 233 234 Playable* playable;235 234 if (!Playable::objectList().empty()) 236 235 { -
trunk/src/world_entities/creatures/fps_player.cc
r9869 r10013 167 167 168 168 //subscribe to collision reaction 169 this->subscribeReaction(C REngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID());169 this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_FULL_WALK, BspEntity::staticClassID()); 170 170 171 171 this->initWeapon = false; -
trunk/src/world_entities/npcs/attractor_mine.cc
r9869 r10013 62 62 63 63 this->setDamage(30.0f); 64 this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Playable::staticClassID()); 64 65 65 66 -
trunk/src/world_entities/npcs/generic_npc.cc
r9869 r10013 96 96 97 97 // collision reaction registration 98 this->subscribeReaction(C REngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID());98 this->subscribeReaction(CoRe::CREngine::CR_PHYSICS_GROUND_WALK, BspEntity::staticClassID()); 99 99 } 100 100 -
trunk/src/world_entities/projectiles/projectile.cc
r9869 r10013 23 23 #include "model.h" 24 24 #include "sound/resource_sound_buffer.h" 25 #include "playable.h" 25 26 26 27 #include "debug.h" … … 43 44 this->setHealth(1.0f); 44 45 this->setDamage(1.0f); // default damage of a projectile set to 100.0 damage points 46 this->subscribeReaction( CoRe::CREngine::CR_PHYSICS_FULL_WALK, Playable::staticClassID()); 45 47 46 48 //this->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); -
trunk/src/world_entities/space_ships/spacecraft_2d.cc
r9869 r10013 221 221 registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); 222 222 223 223 this->setDamage( 1000.0f); 224 this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID()); 224 225 225 226 } -
trunk/src/world_entities/weapons/aiming_system.cc
r9869 r10013 61 61 62 62 // registering default reactions: 63 this->unsubscribeReaction(C REngine::CR_OBJECT_DAMAGE);64 this->subscribeReaction(C REngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID());63 this->unsubscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE); 64 this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, WorldEntity::staticClassID()); 65 65 66 66 this->range = 1000.0f; -
trunk/src/world_entities/world_entity.cc
r9869 r10013 35 35 #include "camera.h" 36 36 37 #include "collision_ handle.h"37 #include "collision_filter.h" 38 38 #include "collision_event.h" 39 39 #include "game_rules.h" … … 58 58 */ 59 59 WorldEntity::WorldEntity() 60 : Synchronizeable()60 : Synchronizeable(), _collisionFilter(this) 61 61 { 62 62 this->registerObject(this, WorldEntity::_objectList); … … 77 77 this->lastObjectListNumber = OM_INIT; 78 78 79 // reset all collision handles to NULL == unsubscribed state 80 for(int i = 0; i < CREngine::CR_NUMBER; ++i) 81 this->collisionHandles[i] = NULL; 82 this->bReactive = false; 83 this->bOnGround = false; 79 this->_bOnGround = false; 84 80 85 81 // registering default reactions: 86 this->subscribeReaction(C REngine::CR_OBJECT_DAMAGE, /* WorldEntity::staticClassID(), */Projectile::staticClassID());82 this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID()); 87 83 88 84 this->toList(OM_NULL); 89 85 90 registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );91 modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );92 scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );93 list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );94 95 health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );96 healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );86 this->registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) ); 87 this->modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) ); 88 this->scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) ); 89 this->list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) ); 90 91 this->health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) ); 92 this->healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) ); 97 93 } 98 94 … … 115 111 delete this->healthWidget; 116 112 117 this->unsubscribeReaction ();113 this->unsubscribeReactions(); 118 114 } 119 115 … … 302 298 * @param target1 a filter target (classID) 303 299 */ 304 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1) 305 { 306 this->subscribeReaction(type); 307 308 // add the target filter 309 this->collisionHandles[type]->addTarget(target1); 300 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1) 301 { 302 this->_collisionFilter.subscribeReaction(type, target1); 310 303 } 311 304 … … 316 309 * @param target1 a filter target (classID) 317 310 */ 318 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2) 319 { 320 this->subscribeReaction(type); 321 322 // add the target filter 323 this->collisionHandles[type]->addTarget(target1); 324 this->collisionHandles[type]->addTarget(target2); 311 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2) 312 { 313 this->_collisionFilter.subscribeReaction(type, target1, target2); 325 314 } 326 315 … … 331 320 * @param target1 a filter target (classID) 332 321 */ 333 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3) 334 { 335 this->subscribeReaction(type); 336 337 // add the target filter 338 this->collisionHandles[type]->addTarget(target1); 339 this->collisionHandles[type]->addTarget(target2); 340 this->collisionHandles[type]->addTarget(target3); 341 } 342 343 344 /** 345 * subscribes this world entity to a collision reaction 346 * @param type the type of reaction to subscribe to 347 * @param target1 a filter target (classID) 348 */ 349 void WorldEntity::subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3, const ClassID& target4) 350 { 351 this->subscribeReaction(type); 352 353 // add the target filter 354 this->collisionHandles[type]->addTarget(target1); 355 this->collisionHandles[type]->addTarget(target2); 356 this->collisionHandles[type]->addTarget(target3); 357 this->collisionHandles[type]->addTarget(target4); 358 } 359 360 361 /** 362 * subscribes this world entity to a collision reaction 363 * @param type the type of reaction to subscribe to 364 * @param nrOfTargets number of target filters 365 * @param ... the targets as classIDs 366 */ 367 void WorldEntity::subscribeReaction(CREngine::CRType type) 368 { 369 if( this->collisionHandles[type] != NULL) 370 { 371 PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n"); 372 return; 373 } 374 375 this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type); 376 377 // now there is at least one collision reaction subscribed 378 this->bReactive = true; 322 void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3) 323 { 324 this->_collisionFilter.subscribeReaction(type, target1, target2, target3); 379 325 } 380 326 … … 384 330 * @param type the reaction to unsubscribe 385 331 */ 386 void WorldEntity::unsubscribeReaction(CREngine::CRType type) 387 { 388 if( this->collisionHandles[type] == NULL) 389 return; 390 391 CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]); 392 this->collisionHandles[type] = NULL; 393 394 // check if there is still any handler registered 395 for(int i = 0; i < CREngine::CR_NUMBER; ++i) 396 { 397 if( this->collisionHandles[i] != NULL) 398 { 399 this->bReactive = true; 400 return; 401 } 402 } 403 this->bReactive = false; 332 void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type) 333 { 334 this->_collisionFilter.unsubscribeReaction(type); 404 335 } 405 336 … … 408 339 * unsubscribes all collision reactions 409 340 */ 410 void WorldEntity::unsubscribeReaction() 411 { 412 for( int i = 0; i < CREngine::CR_NUMBER; i++) 413 this->unsubscribeReaction((CREngine::CRType)i); 414 415 // there are no reactions subscribed from now on 416 this->bReactive = false; 417 } 418 419 420 /** 421 * registers a new collision event to this world entity 422 * @param entityA entity of the collision 423 * @param entityB entity of the collision 424 * @param bvA colliding bounding volume of entityA 425 * @param bvB colliding bounding volume of entityA 426 */ 427 bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) 428 { 429 PRINTF(5)("registering collision of type: %s vs %s\n", entityA->getClassCName(), entityB->getClassCName()); 430 // is there any handler listening? 431 if( !this->bReactive) 432 return false; 433 434 // get a collision event 435 CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject(); 436 assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h 437 c->collide(COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB); 438 439 for( int i = 0; i < CREngine::CR_NUMBER; ++i) 440 if( this->collisionHandles[i] != NULL) 441 this->collisionHandles[i]->registerCollisionEvent(c); 442 return true; 443 } 444 445 446 /** 447 * registers a new collision event to this woeld entity 448 * @param entity the entity that collides 449 * @param plane it stands on 450 * @param position it collides on the plane 451 */ 452 bool WorldEntity::registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall) 453 { 454 // is there any handler listening? 455 if( !this->bReactive) 456 return false; 457 458 // get a collision event 459 CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject(); 460 assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h 461 c->collide(type, entity, groundEntity, normal, position, bInWall); 462 463 for( int i = 0; i < CREngine::CR_NUMBER; ++i) 464 if( this->collisionHandles[i] != NULL) 465 this->collisionHandles[i]->registerCollisionEvent(c); 466 return true; 341 void WorldEntity::unsubscribeReactions() 342 { 343 this->_collisionFilter.unsubscribeReactions(); 467 344 } 468 345 -
trunk/src/world_entities/world_entity.h
r9869 r10013 12 12 13 13 #include "cr_engine.h" 14 #include "collision_filter.h" 14 15 #include "object_manager.h" 15 16 #include "glincl.h" … … 25 26 namespace OrxSound { class SoundBuffer; class SoundSource; } 26 27 namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; }; 28 namespace CoRe { class Collision; } 27 29 28 30 class BVTree; … … 30 32 class AABBTreeNode; 31 33 class Model; 32 class CollisionHandle;33 class Collision;34 35 36 //class CharacterAttributes;37 38 34 39 35 … … 42 38 { 43 39 ObjectListDeclaration(WorldEntity); 40 44 41 public: 45 42 WorldEntity(); … … 51 48 void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);} 52 49 void setModel(Model* model, unsigned int modelNumber = 0); 53 Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };50 Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; }; 54 51 55 52 inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; } … … 74 71 virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2); 75 72 76 77 73 /** @returns a reference to the obb tree of this worldentity */ 78 74 inline BVTree* getOBBTree() const { return this->obbTree; }; … … 81 77 inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;} 82 78 79 virtual void hit(float damage, WorldEntity* killer); 80 81 83 82 /* --- Collision Reaction Block --- */ 84 void subscribeReaction(CREngine::CRType type); 85 void subscribeReaction(CREngine::CRType type, const ClassID& target1); 86 void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2); 87 void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3); 88 void subscribeReaction(CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3, const ClassID& target4); 89 90 void unsubscribeReaction(CREngine::CRType type); 91 void unsubscribeReaction(); 92 93 bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB); 94 bool registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall = false); 83 void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1); 84 void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2); 85 void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3); 86 87 void unsubscribeReaction(CoRe::CREngine::ReactionType type); 88 void unsubscribeReactions(); 89 95 90 /** @return true if there is at least on collision reaction subscribed */ 96 inline bool isReactive() const { return this->bReactive; } 97 98 CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; } 91 inline bool isReactive() const { return this->_collisionFilter.isReactive(); } 92 93 /** @param worldEntity the world entity to be checked @returns true if there is a collisionreaction registered for the worldEntity */ 94 inline bool isReactive( const WorldEntity& worldEntity) const { return this->_collisionFilter(worldEntity); } 95 /** @param worldEntity the world entity to be checked @param type special reaction type @returns true if collision reaction reg. */ 96 inline bool isReactive( const WorldEntity& worldEntity, const CoRe::CREngine::ReactionType& type) const 97 { return this->_collisionFilter(worldEntity, type); } 98 99 100 const CoRe::CollisionFilter& getCollisionFilter(CoRe::CREngine::ReactionType type) const { return this->_collisionFilter; } 99 101 100 102 /** @returns true if this entity is standing on ground (BSP model) */ 101 bool isOnGround() const { return this-> bOnGround; }103 bool isOnGround() const { return this->_bOnGround; } 102 104 /** @param flag: marks if this entity is standing on ground */ 103 void setOnGround(bool flag) { this->bOnGround = flag; } 104 105 virtual void hit(float damage, WorldEntity* killer); 105 void setOnGround(bool flag) { this->_bOnGround = flag; } 106 106 107 107 virtual void destroy( WorldEntity* killer ); … … 128 128 129 129 void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); } 130 void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }130 void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); } 131 131 132 132 133 133 /* --- Character Attribute Block --- */ 134 134 /** @returns the scaling of the model */ 135 float getScaling(){return this->scaling;}135 float getScaling(){return this->scaling;} 136 136 /** @returns the damage dealt by this world entity */ 137 137 float getDamage() const { return this->damage; } … … 170 170 void setHealthMax(float healthMax); 171 171 void createHealthWidget(); 172 173 // CharacterAttributes* charAttr; //!< the character attributes of a world_entity 172 // CharacterAttributes* charAttr; //!< the character attributes of a world_entity 173 174 174 175 private: 175 176 void updateHealthWidget(); 177 176 178 177 179 private: … … 195 197 OM_LIST lastObjectListNumber; //!< the last ObjectList from the ObjectManager this Entity was is in 196 198 197 198 199 /* collision reaction stuff */ 200 CoRe::CollisionFilter _collisionFilter; //!< filter for collision event filtering (not every entity listens to all collisions) 201 bool _bOnGround; //!< flag true if the object is on the ground 202 203 PhysicsInterface physicsInterface; //!< the physics object of the WorldEntity 204 205 /* network help structures */ 199 206 float scaling; //!< model's scaling factor 200 207 int scaling_handle; //!< handle for syncing var … … 212 219 int healthMax_handle; 213 220 214 CollisionHandle* collisionHandles[CREngine::CR_NUMBER]; //!< the list of the collision reactions 215 bool bReactive; //!< true if there is at least one collision reaction subscibed 216 217 PhysicsInterface physicsInterface; //!< the physics object of the WorldEntity 218 bool bOnGround; //!< true if this entity is standing on the ground 221 219 222 220 223 protected:
Note: See TracChangeset
for help on using the changeset viewer.