Changeset 9889 in orxonox.OLD for branches/coll_rect/src
- Timestamp:
- Oct 13, 2006, 3:57:44 PM (18 years ago)
- Location:
- branches/coll_rect/src
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/coll_rect/src/lib/collision_reaction/collision.cc
r9869 r9889 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->flushCollisionEvents(); 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 * flushes the CollisionEvent list 42 */ 43 void Collision::flushCollisionEvents() 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->bDispatched = true; 50 52 51 this->collisionEvents.clear(); 53 this->collisionEvents.clear(); 54 } 55 52 56 } 53 -
branches/coll_rect/src/lib/collision_reaction/collision.h
r9888 r9889 18 18 #include <vector> 19 19 20 21 20 22 class WorldEntity; 21 23 class BoundingVolume; 22 class CollisionEvent;23 24 24 //! A class representing a simple collision 25 class Collision 25 namespace CoRe 26 26 { 27 28 class CollisionEvent; 29 30 //! A class representing a simple collision 31 class Collision 32 { 27 33 public: 28 34 Collision(); … … 70 76 71 77 std::vector<CollisionEvent*> collisionEvents; //!< the collision event list 72 }; 78 }; 79 } 73 80 74 81 #endif /* _COLLISION_H */ -
branches/coll_rect/src/lib/collision_reaction/collision_event.cc
r9869 r9889 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 -
branches/coll_rect/src/lib/collision_reaction/collision_event.h
r9888 r9889 22 22 class Plane; 23 23 24 namespace CoRe 25 { 26 27 //! A class representing a simple collision 28 class CollisionEvent 29 { 30 public: 31 CollisionEvent(); 32 virtual ~CollisionEvent(); 33 34 /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */ 35 inline void collide(int type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) 36 { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; } 37 /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */ 38 inline void collide(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall) 39 { 40 this->collisionType = type; 41 this->entityA = entity; 42 this->entityB = groundEntity; 43 this->groundNormal = normal; 44 this->position = position; 45 this->bInWall = bInWall; 46 } 24 47 25 48 26 //! A class representing a simple collision 27 class CollisionEvent { 28 public: 29 CollisionEvent(); 30 virtual ~CollisionEvent(); 49 /** @return CollisionEvent WorldEntity A */ 50 inline WorldEntity* getEntityA() const 51 { 52 return this->entityA; 53 } 54 /** @return CollisionEvent WorldEntity B */ 55 inline WorldEntity* getEntityB() const 56 { 57 return this->entityB; 58 } 59 /** @return Bounding Volume from EntityA */ 60 inline BoundingVolume* getBVA() const 61 { 62 return this->bvA; 63 } 64 /** @return Bounding Volume from EntityB */ 65 inline BoundingVolume* getBVB() const 66 { 67 return this->bvB; 68 } 31 69 32 /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */ 33 inline void collide(int type, WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) 34 { this->collisionType = type; this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; } 35 /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */ 36 inline void collide(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall) 37 { this->collisionType = type; this->entityA = entity; this->entityB = groundEntity, this->groundNormal = normal; this->position = position; this->bInWall = bInWall; } 70 /** @return ground plane if collided with bsp model */ 71 inline Vector getGroundNormal() 72 { 73 return this->groundNormal; 74 } 75 76 /** @return position of the position, only accurate if this is a collision with the ground!!! */ 77 inline Vector getCollisionPosition() 78 { 79 return this->position; 80 } 81 82 /** @return the type of the collision */ 83 inline int getType() 84 { 85 return this->collisionType; 86 } 87 88 /** @return true if the entity is in the wall */ 89 inline bool isInWall() 90 { 91 return this->bInWall; 92 } 38 93 39 94 40 /** @return CollisionEvent WorldEntity A */ 41 inline WorldEntity* getEntityA() const { return this->entityA; } 42 /** @return CollisionEvent WorldEntity B */ 43 inline WorldEntity* getEntityB() const { return this->entityB; } 44 /** @return Bounding Volume from EntityA */ 45 inline BoundingVolume* getBVA() const { return this->bvA; } 46 /** @return Bounding Volume from EntityB */ 47 inline BoundingVolume* getBVB() const { return this->bvB; } 95 private: 96 WorldEntity* entityA; //!< the collision body A 97 WorldEntity* entityB; //!< the collision body B 48 98 49 /** @return ground plane if collided with bsp model */50 inline Vector getGroundNormal() { return this->groundNormal; }99 BoundingVolume* bvA; //!< reference to the bounding volume A 100 BoundingVolume* bvB; //!< reference to the bounding volume B 51 101 52 /** @return position of the position, only accurate if this is a collision with the ground!!! */53 inline Vector getCollisionPosition() { return this->position; }102 Vector groundNormal; //!< the ground plane with which it collides (only for bsp-model collisions 103 Vector position; //!< position of the collision on the ground plane 54 104 55 /** @return the type of the collision */ 56 inline int getType() { return this->collisionType; } 105 bool bInWall; //!< true if is in wall 106 int collisionType; //!< collision type 107 }; 57 108 58 /** @return true if the entity is in the wall */ 59 inline bool isInWall() { return this->bInWall; } 60 61 62 private: 63 WorldEntity* entityA; //!< the collision body A 64 WorldEntity* entityB; //!< the collision body B 65 66 BoundingVolume* bvA; //!< reference to the bounding volume A 67 BoundingVolume* bvB; //!< reference to the bounding volume B 68 69 Vector groundNormal; //!< the ground plane with which it collides (only for bsp-model collisions 70 Vector position; //!< position of the collision on the ground plane 71 72 bool bInWall; //!< true if is in wall 73 int collisionType; //!< collision type 74 }; 75 109 } 76 110 #endif /* _COLLISION_EVENT_H */ -
branches/coll_rect/src/lib/collision_reaction/collision_handle.cc
r9869 r9889 29 29 #include "debug.h" 30 30 31 32 ObjectListDefinition(CollisionHandle); 33 34 /** 35 * standard constructor 36 * @todo this constructor is not jet implemented - do it 37 */ 38 CollisionHandle::CollisionHandle (WorldEntity* owner, CREngine::CRType type) 31 namespace CoRe 39 32 { 40 this->registerObject(this, CollisionHandle::_objectList); 41 42 this->owner = owner; 43 this->type = type; 44 45 this->bCollided = false; 46 this->bDispatched = true; 47 48 this->collisionReaction = NULL; 49 this->bContinuousPoll = false; 50 this->bStopOnFirstCollision = false; 51 52 53 switch( type) 54 { 55 case CREngine::CR_PHYSICS_FULL_WALK: 56 this->collisionReaction = new CRPhysicsFullWalk(); 57 this->bContinuousPoll = true; 58 break; 59 case CREngine::CR_PHYSICS_GROUND_WALK: 60 this->collisionReaction = new CRPhysicsGroundWalk(); 61 this->bContinuousPoll = true; 62 break; 63 case CREngine::CR_OBJECT_DAMAGE: 64 this->collisionReaction = new CRObjectDamage(); 65 this->bStopOnFirstCollision = true; 66 break; 67 default: 68 break; 69 }; 33 34 ObjectListDefinition(CollisionHandle); 35 36 /** 37 * standard constructor 38 * @todo this constructor is not jet implemented - do it 39 */ 40 CollisionHandle::CollisionHandle (WorldEntity* owner, CREngine::CRType type) 41 { 42 this->registerObject(this, CollisionHandle::_objectList); 43 44 this->owner = owner; 45 this->type = type; 46 47 this->bCollided = false; 48 this->bDispatched = true; 49 50 this->collisionReaction = NULL; 51 this->bContinuousPoll = false; 52 this->bStopOnFirstCollision = false; 53 54 55 switch( type) 56 { 57 case CREngine::CR_PHYSICS_FULL_WALK: 58 this->collisionReaction = new CRPhysicsFullWalk(); 59 this->bContinuousPoll = true; 60 break; 61 case CREngine::CR_PHYSICS_GROUND_WALK: 62 this->collisionReaction = new CRPhysicsGroundWalk(); 63 this->bContinuousPoll = true; 64 break; 65 case CREngine::CR_OBJECT_DAMAGE: 66 this->collisionReaction = new CRObjectDamage(); 67 this->bStopOnFirstCollision = true; 68 break; 69 default: 70 break; 71 }; 72 } 73 74 75 /** 76 * standard deconstructor 77 */ 78 CollisionHandle::~CollisionHandle () 79 { 80 // delete what has to be deleted here 81 if( this->collisionReaction != NULL) 82 delete this->collisionReaction; 83 } 84 85 /** 86 * restores the CollisionHandle to its initial state 87 */ 88 void CollisionHandle::reset() 89 { 90 this->flushCollisions(); 91 } 92 93 94 /** 95 * add more filter targets to this collision handle 96 * @param classID the classid to look for 97 */ 98 void CollisionHandle::addTarget(const ClassID& target) 99 { 100 // make sure there is no dublicate 101 std::vector<ClassID>::iterator it = this->targetList.begin(); 102 for( ; it < this->targetList.end(); it++) 103 if( (*it) == target) 104 return; 105 106 107 // add element 108 this->targetList.push_back(target); 109 PRINTF(5)("addTarget: %i \n", target.id()); 110 } 111 112 113 /** 114 * registers a new Collision Object 115 * @param entityA WorldEntity A of the collision 116 * @param entityB WorldEntity B of the collision 117 * if a there is already a collision object with the same stats 118 * registration will be skipped and the last collision object is returned 119 */ 120 Collision* CollisionHandle::registerCollision(WorldEntity* entityA, WorldEntity* entityB) 121 { 122 //first get the collision object, multiple sources 123 Collision* c; 124 if( this->collisionList.empty() || 125 ((this->collisionList.back())->getEntityA() != entityA && (this->collisionList.back())->getEntityB() != entityB )) 126 { 127 c = CREngine::getInstance()->popCollisionObject(); 128 c->collide(entityA, entityB); 129 this->collisionList.push_back(c); 130 131 // now register it as a shared collision with the other collision entity 132 CollisionHandle* ch = entityB->getCollisionHandle(this->type); 133 if( ch != NULL) 134 ch->registerSharedCollision(c); 135 } 136 else 137 c = this->collisionList.back(); 138 139 return c; 140 } 141 142 143 /** 144 * register a Collision to the Collision handle. 145 * @param collision the collision object to register 146 * 147 * This is used for internal collision registration: sharing the collision objects between Collision Reactions 148 * Therefore dispatching it only once 149 */ 150 void CollisionHandle::registerSharedCollision(Collision* collision) 151 { 152 // fist check if we are listening for this Collision 153 if( !this->filterCollision(collision)) 154 return; 155 156 // set the state to not dispatched 157 this->bDispatched = false; 158 this->bCollided = true; 159 collision->setEntityBCollide(true); 160 161 this->collisionList.push_back(collision); 162 } 163 164 165 /** 166 * this is the function to be called on a collision event for this handle 167 * @param collision the collision objects containing all collision informations 168 */ 169 void CollisionHandle::registerCollisionEvent(CollisionEvent* collisionEvent) 170 { 171 if( !this->filterCollisionEvent(collisionEvent)) 172 return; 173 174 // set the state to not dispatched 175 this->bDispatched = false; 176 this->bCollided = true; 177 178 // checks if these WorldEntities have already collided or if its a new collision -> create a new Collision object 179 Collision* c = this->registerCollision(collisionEvent->getEntityA(), collisionEvent->getEntityB()); 180 c->setEntityACollide(true); 181 182 c->registerCollisionEvent(collisionEvent); 183 PRINTF(5)("Registering Collision Event: %s, %s\n", collisionEvent->getEntityA()->getClassCName(), collisionEvent->getEntityB()->getClassCName()); 184 } 185 186 187 /** 188 * flushes the collision list 189 */ 190 void CollisionHandle::flushCollisions() 191 { 192 this->collisionList.clear(); 193 } 194 195 196 /** 197 * handles the collisions and react according to algorithm 198 */ 199 void CollisionHandle::handleCollisions() 200 { 201 // if continuous poll poll the reaction 202 if( this->bContinuousPoll && !this->bCollided) 203 { 204 this->collisionReaction->update(this->owner); 205 return; 206 } 207 208 // collision reaction calculations (for every collision there will be a reaction) 209 std::vector<Collision*>::iterator it = this->collisionList.begin(); 210 for(; it < this->collisionList.end(); it++) 211 { 212 if( !(*it)->isDispatched()) 213 { 214 this->collisionReaction->reactToCollision(*it); 215 (*it)->flushCollisionEvents(); 216 } 217 } 218 219 // now set state to dispatched 220 this->bDispatched = true; 221 this->bCollided = false; 222 223 this->flushCollisions(); 224 } 225 226 227 /** 228 * filter out the CollisionEvents that are not wanted 229 * @param collisionEvent the collision event to filter 230 */ 231 bool CollisionHandle::filterCollisionEvent(CollisionEvent* collisionEvent) 232 { 233 std::vector<ClassID>::iterator it = this->targetList.begin(); 234 for(; it < this->targetList.end(); it++) 235 { 236 // if(collisionEvent->getEntityB()->isA(CL_AIMING_SYSTEM) || collisionEvent->getEntityA()->isA(CL_AIMING_SYSTEM)) 237 // { 238 // PRINTF(0)("I am: %s colliding with: %s\n", owner->getClassCName(), collisionEvent->getEntityB()->getClassCName(), *it); 239 // if( collisionEvent->getEntityA() == this->owner) { 240 // PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(), 241 // collisionEvent->getEntityB()->getClassCName(), *it); 242 // if( collisionEvent->getEntityB()->isA((ClassID)(*it))) { 243 // PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 244 // collisionEvent->getEntityB()->getClassCName(), *it); 245 // } 246 // } 247 // else { 248 // PRINTF(0)("I am not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(), 249 // collisionEvent->getEntityB()->getClassCName(), *it); 250 // if( collisionEvent->getEntityA()->isA((ClassID)(*it))) { 251 // PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 252 // collisionEvent->getEntityA()->getClassCName(), *it); 253 // } 254 // } 255 // 256 // } 257 258 if( collisionEvent->getEntityA() == this->owner) 259 { 260 if( collisionEvent->getEntityB()->isA((*it))) 261 { 262 PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 263 collisionEvent->getEntityB()->getClassCName(), (*it).id()); 264 return true; 265 } 266 } 267 else 268 { 269 if( collisionEvent->getEntityA()->isA((*it))) 270 { 271 PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 272 collisionEvent->getEntityA()->getClassCName(), (*it).id()); 273 return true; 274 } 275 } 276 } 277 278 return false; 279 } 280 281 282 /** 283 * filter Collisions that are not wanted to be reacted to 284 * @param collision the collision object to filter 285 */ 286 bool CollisionHandle::filterCollision(Collision* collision) 287 { 288 std::vector<ClassID>::iterator it = this->targetList.begin(); 289 for(; it < this->targetList.end(); it++) 290 { 291 292 // if(collision->getEntityB()->isA(CL_AIMING_SYSTEM) || collision->getEntityA()->isA(CL_AIMING_SYSTEM)) 293 // { 294 // PRINTF(0)("Shared!!! I am: %s colliding with: %s\n", owner->getClassCName(), collision->getEntityB()->getClassCName(), *it); 295 // if( collision->getEntityA() == this->owner) { 296 // PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(), 297 // collision->getEntityB()->getClassCName(), *it); 298 // if( collision->getEntityB()->isA((ClassID)(*it))) { 299 // PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 300 // collision->getEntityB()->getClassCName(), *it); 301 // } 302 // } 303 // else { 304 // PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(), 305 // collision->getEntityB()->getClassCName(), *it); 306 // if( collision->getEntityA()->isA((ClassID)(*it))) { 307 // PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 308 // collision->getEntityA()->getClassCName(), *it); 309 // } 310 // } 311 // } 312 313 if( collision->getEntityA() == this->owner) 314 { 315 if( collision->getEntityA()->isA(*it)) 316 return true; 317 } 318 else 319 { 320 if( collision->getEntityB()->isA(*it)) 321 return true; 322 } 323 } 324 325 return false; 326 } 327 328 329 70 330 } 71 331 72 332 73 /** 74 * standard deconstructor 75 */ 76 CollisionHandle::~CollisionHandle () 77 { 78 // delete what has to be deleted here 79 if( this->collisionReaction != NULL) 80 delete this->collisionReaction; 81 } 82 83 /** 84 * restores the CollisionHandle to its initial state 85 */ 86 void CollisionHandle::reset() 87 { 88 this->flushCollisions(); 89 } 90 91 92 /** 93 * add more filter targets to this collision handle 94 * @param classID the classid to look for 95 */ 96 void CollisionHandle::addTarget(const ClassID& target) 97 { 98 // make sure there is no dublicate 99 std::vector<ClassID>::iterator it = this->targetList.begin(); 100 for( ; it < this->targetList.end(); it++) 101 if( (*it) == target) 102 return; 103 104 105 // add element 106 this->targetList.push_back(target); 107 PRINTF(5)("addTarget: %i \n", target.id()); 108 } 109 110 111 /** 112 * registers a new Collision Object 113 * @param entityA WorldEntity A of the collision 114 * @param entityB WorldEntity B of the collision 115 * if a there is already a collision object with the same stats 116 * registration will be skipped and the last collision object is returned 117 */ 118 Collision* CollisionHandle::registerCollision(WorldEntity* entityA, WorldEntity* entityB) 119 { 120 //first get the collision object, multiple sources 121 Collision* c; 122 if( this->collisionList.empty() || 123 ((this->collisionList.back())->getEntityA() != entityA && (this->collisionList.back())->getEntityB() != entityB )) { 124 c = CREngine::getInstance()->popCollisionObject(); 125 c->collide(entityA, entityB); 126 this->collisionList.push_back(c); 127 128 // now register it as a shared collision with the other collision entity 129 CollisionHandle* ch = entityB->getCollisionHandle(this->type); 130 if( ch != NULL) 131 ch->registerSharedCollision(c); 132 } 133 else 134 c = this->collisionList.back(); 135 136 return c; 137 } 138 139 140 /** 141 * register a Collision to the Collision handle. 142 * @param collision the collision object to register 143 * 144 * This is used for internal collision registration: sharing the collision objects between Collision Reactions 145 * Therefore dispatching it only once 146 */ 147 void CollisionHandle::registerSharedCollision(Collision* collision) 148 { 149 // fist check if we are listening for this Collision 150 if( !this->filterCollision(collision)) 151 return; 152 153 // set the state to not dispatched 154 this->bDispatched = false; 155 this->bCollided = true; 156 collision->setEntityBCollide(true); 157 158 this->collisionList.push_back(collision); 159 } 160 161 162 /** 163 * this is the function to be called on a collision event for this handle 164 * @param collision the collision objects containing all collision informations 165 */ 166 void CollisionHandle::registerCollisionEvent(CollisionEvent* collisionEvent) 167 { 168 if( !this->filterCollisionEvent(collisionEvent)) 169 return; 170 171 // set the state to not dispatched 172 this->bDispatched = false; 173 this->bCollided = true; 174 175 // checks if these WorldEntities have already collided or if its a new collision -> create a new Collision object 176 Collision* c = this->registerCollision(collisionEvent->getEntityA(), collisionEvent->getEntityB()); 177 c->setEntityACollide(true); 178 179 c->registerCollisionEvent(collisionEvent); 180 PRINTF(5)("Registering Collision Event: %s, %s\n", collisionEvent->getEntityA()->getClassCName(), collisionEvent->getEntityB()->getClassCName()); 181 } 182 183 184 /** 185 * flushes the collision list 186 */ 187 void CollisionHandle::flushCollisions() 188 { 189 this->collisionList.clear(); 190 } 191 192 193 /** 194 * handles the collisions and react according to algorithm 195 */ 196 void CollisionHandle::handleCollisions() 197 { 198 // if continuous poll poll the reaction 199 if( this->bContinuousPoll && !this->bCollided) 200 { 201 this->collisionReaction->update(this->owner); 202 return; 203 } 204 205 // collision reaction calculations (for every collision there will be a reaction) 206 std::vector<Collision*>::iterator it = this->collisionList.begin(); 207 for(; it < this->collisionList.end(); it++) { 208 if( !(*it)->isDispatched()) 209 { 210 this->collisionReaction->reactToCollision(*it); 211 (*it)->flushCollisionEvents(); 212 } 213 } 214 215 // now set state to dispatched 216 this->bDispatched = true; 217 this->bCollided = false; 218 219 this->flushCollisions(); 220 } 221 222 223 /** 224 * filter out the CollisionEvents that are not wanted 225 * @param collisionEvent the collision event to filter 226 */ 227 bool CollisionHandle::filterCollisionEvent(CollisionEvent* collisionEvent) 228 { 229 std::vector<ClassID>::iterator it = this->targetList.begin(); 230 for(; it < this->targetList.end(); it++) 231 { 232 // if(collisionEvent->getEntityB()->isA(CL_AIMING_SYSTEM) || collisionEvent->getEntityA()->isA(CL_AIMING_SYSTEM)) 233 // { 234 // PRINTF(0)("I am: %s colliding with: %s\n", owner->getClassCName(), collisionEvent->getEntityB()->getClassCName(), *it); 235 // if( collisionEvent->getEntityA() == this->owner) { 236 // PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(), 237 // collisionEvent->getEntityB()->getClassCName(), *it); 238 // if( collisionEvent->getEntityB()->isA((ClassID)(*it))) { 239 // PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 240 // collisionEvent->getEntityB()->getClassCName(), *it); 241 // } 242 // } 243 // else { 244 // PRINTF(0)("I am not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(), 245 // collisionEvent->getEntityB()->getClassCName(), *it); 246 // if( collisionEvent->getEntityA()->isA((ClassID)(*it))) { 247 // PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 248 // collisionEvent->getEntityA()->getClassCName(), *it); 249 // } 250 // } 251 // 252 // } 253 254 if( collisionEvent->getEntityA() == this->owner) { 255 if( collisionEvent->getEntityB()->isA((*it))) { 256 PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 257 collisionEvent->getEntityB()->getClassCName(), (*it).id()); 258 return true; } 259 } 260 else { 261 if( collisionEvent->getEntityA()->isA((*it))) { 262 PRINTF(5)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 263 collisionEvent->getEntityA()->getClassCName(), (*it).id()); 264 return true; } 265 } 266 } 267 268 return false; 269 } 270 271 272 /** 273 * filter Collisions that are not wanted to be reacted to 274 * @param collision the collision object to filter 275 */ 276 bool CollisionHandle::filterCollision(Collision* collision) 277 { 278 std::vector<ClassID>::iterator it = this->targetList.begin(); 279 for(; it < this->targetList.end(); it++) 280 { 281 282 // if(collision->getEntityB()->isA(CL_AIMING_SYSTEM) || collision->getEntityA()->isA(CL_AIMING_SYSTEM)) 283 // { 284 // PRINTF(0)("Shared!!! I am: %s colliding with: %s\n", owner->getClassCName(), collision->getEntityB()->getClassCName(), *it); 285 // if( collision->getEntityA() == this->owner) { 286 // PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(), 287 // collision->getEntityB()->getClassCName(), *it); 288 // if( collision->getEntityB()->isA((ClassID)(*it))) { 289 // PRINTF(0)("I am owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 290 // collision->getEntityB()->getClassCName(), *it); 291 // } 292 // } 293 // else { 294 // PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter?\n", owner->getClassCName(), 295 // collision->getEntityB()->getClassCName(), *it); 296 // if( collision->getEntityA()->isA((ClassID)(*it))) { 297 // PRINTF(0)("I'm not owner -> I am: %s colliding with: %s is a %i filter ok\n", owner->getClassCName(), 298 // collision->getEntityA()->getClassCName(), *it); 299 // } 300 // } 301 // } 302 303 if( collision->getEntityA() == this->owner) { 304 if( collision->getEntityA()->isA(*it)) 305 return true; } 306 else { 307 if( collision->getEntityB()->isA(*it)) 308 return true; } 309 } 310 311 return false; 312 } 313 314 315 316 317 318 319 333 -
branches/coll_rect/src/lib/collision_reaction/collision_handle.h
r9888 r9889 16 16 class Collision; 17 17 class WorldEntity; 18 class CollisionReaction; 18 19 namespace CoRe 20 { 21 22 class CollisionReaction; 19 23 20 24 21 25 22 //! A class for defining collision reactions and storing events23 class CollisionHandle : public BaseObject24 {25 ObjectListDeclaration(CollisionHandle);26 //! A class for defining collision reactions and storing events 27 class CollisionHandle : public BaseObject 28 { 29 ObjectListDeclaration(CollisionHandle); 26 30 public: 27 31 CollisionHandle(WorldEntity* owner, CREngine::CRType type); … … 68 72 CollisionReaction* collisionReaction; //!< reference to the collision reaction object 69 73 70 };74 }; 71 75 76 } 72 77 #endif /* _COLLISION_HANDLE_H */ -
branches/coll_rect/src/lib/collision_reaction/collision_reaction.cc
r9888 r9889 17 17 #include "collision_reaction.h" 18 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 } 19 32 20 33 21 ObjectListDefinition(CollisionReaction); 34 /** 35 * standard deconstructor 36 */ 37 CollisionReaction::~CollisionReaction () 38 {} 22 39 23 /**24 * standard constructor25 */26 CollisionReaction::CollisionReaction ()27 : BaseObject()28 {29 this->registerObject(this, CollisionReaction::_objectList);30 40 } 31 32 33 /**34 * standard deconstructor35 */36 CollisionReaction::~CollisionReaction ()37 {38 }39 -
branches/coll_rect/src/lib/collision_reaction/collision_reaction.h
r9869 r9889 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(); … … 32 33 private: 33 34 bool bContinuousPoll; //!< if true the collision rection function is also called, if there was no collision 34 };35 }; 35 36 37 } 36 38 #endif /* _COLLISION_REACTION_H */ -
branches/coll_rect/src/lib/collision_reaction/cr_engine.cc
r9869 r9889 27 27 #include "debug.h" 28 28 29 namespace CoRe 30 { 31 32 ObjectListDefinition(CREngine); 33 /** 34 * standard constructor 35 */ 36 CREngine::CREngine () 37 : BaseObject() 38 { 39 this->registerObject(this, CREngine::_objectList); 40 this->setName("CREngine"); 41 42 this->init(); 43 } 44 45 /** 46 * the singleton reference to this class 47 */ 48 CREngine* CREngine::singletonRef = NULL; 49 50 /** 51 @brief standard deconstructor 52 */ 53 CREngine::~CREngine () 54 { 55 CREngine::singletonRef = NULL; 56 57 if( this->collisionsUnused.size() != CR_MAX_COLLISIONS) 58 PRINTF(0)("CollisionReaction Error: Collision cache size missmatch: %i of %i\n", this->collisionsUnused.size(), CR_MAX_COLLISIONS); 59 if( this->collisionEventsUnused.size() != CR_MAX_COLLISION_EVENTS) 60 PRINTF(0)("CollisionReaction Error: CollisionEvent cache size missmatch: %i of %i\n", this->collisionEventsUnused.size(), CR_MAX_COLLISION_EVENTS); 61 62 this->reset(); 63 64 std::vector<Collision*>::iterator it1 = this->collisionsUnused.begin(); 65 for(; it1 < this->collisionsUnused.end(); it1++) 66 delete *it1; 67 std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUnused.begin(); 68 for(; it2 < this->collisionEventsUnused.end(); it2++) 69 delete *it2; 70 71 this->collisionsUnused.clear(); 72 this->collisionEventsUnused.clear(); 73 } 74 75 /** 76 * inits the CREngine to a working state 77 */ 78 void CREngine::init() 79 { 80 // create a list of Collision events (precaching) 81 for( int i = 0; i < CR_MAX_COLLISIONS; i++) 82 this->collisionsUnused.push_back(new Collision()); 83 for( int i = 0; i < CR_MAX_COLLISION_EVENTS; i++) 84 this->collisionEventsUnused.push_back(new CollisionEvent()); 85 } 29 86 30 87 31 ObjectListDefinition(CREngine); 32 /** 33 * standard constructor 34 */ 35 CREngine::CREngine () 36 : BaseObject() 37 { 38 this->registerObject(this, CREngine::_objectList); 39 this->setName("CREngine"); 88 /** 89 * flushes the CollisionHandles and restores the CREngine to the initial state 90 */ 91 void CREngine::reset() 92 { 93 // first clear all CollisionHandles 40 94 41 this->init(); 42 } 95 std::vector<CollisionHandle*>::iterator it = this->collisionHandles.begin(); 96 for(; it < this->collisionHandles.end(); it++) 97 { 98 (*it)->reset(); 99 delete *it; 100 } 43 101 44 /** 45 * the singleton reference to this class 46 */ 47 CREngine* CREngine::singletonRef = NULL; 48 49 /** 50 @brief standard deconstructor 51 */ 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 state 76 */ 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 } 102 this->collisionHandles.clear(); 103 } 85 104 86 105 87 /** 88 * flushes the CollisionHandles and restores the CREngine to the initial state 89 */ 90 void CREngine::reset() 91 { 92 // first clear all CollisionHandles 106 /** 107 * subscribes a WorldEntity for a CollisionReaction 108 * @param owner: the WE to subscribe 109 * @param type: the type of collision reaction to perform 110 * @return the newly created CollisionHandle 111 */ 112 CollisionHandle* CREngine::subscribeReaction(WorldEntity* owner, CRType type) 113 { 114 CollisionHandle* ch = new CollisionHandle(owner, type); 115 this->collisionHandles.push_back(ch); 93 116 94 std::vector<CollisionHandle*>::iterator it = this->collisionHandles.begin(); 95 for(; it < this->collisionHandles.end(); it++) 96 { 97 (*it)->reset(); 98 delete *it; 117 return ch; 99 118 } 100 119 101 this->collisionHandles.clear(); 102 } 120 121 /** 122 * unsubscribe reaction from the reaction list 123 * @param collisionHandle the CollisionHandle to remove 124 * @param returns true if worked collrectly 125 */ 126 bool CREngine::unsubscribeReaction(CollisionHandle* collisionHandle) 127 { 128 std::vector<CollisionHandle*>::iterator it; 129 for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++) 130 { 131 if( *it == collisionHandle) 132 { 133 this->collisionHandles.erase(it); 134 delete collisionHandle; 135 return true; 136 } 137 } 138 return false; 139 } 103 140 104 141 105 /** 106 * subscribes a WorldEntity for a CollisionReaction 107 * @param owner: the WE to subscribe 108 * @param type: the type of collision reaction to perform 109 * @return the newly created CollisionHandle 110 */ 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 } 142 /** 143 * processes the collisions by calling the EventHandlers 144 */ 145 void CREngine::handleCollisions() 146 { 147 std::vector<CollisionHandle*>::iterator it; 148 for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++) 149 { 150 if( !(*it)->isDispatched() || (*it)->isContinuousPoll()) //does it have any collisions to report at all 151 { 152 (*it)->handleCollisions(); 153 } 154 } 155 this->flushCollisions(); 156 } 118 157 119 158 120 /** 121 * unsubscribe reaction from the reaction list 122 * @param collisionHandle the CollisionHandle to remove 123 * @param returns true if worked collrectly 124 */ 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 } 159 /** 160 * flushes all the collision lists and puts them to their initial state 161 */ 162 void CREngine::flushCollisions() 163 { 164 std::vector<Collision*>::iterator it1 = this->collisionsUsed.begin(); 165 for(; it1 < this->collisionsUsed.end(); it1++) 166 this->collisionsUnused.push_back(*it1); 167 168 std::vector<CollisionEvent*>::iterator it2 = this->collisionEventsUsed.begin(); 169 for(; it2 < this->collisionEventsUsed.end(); it2++) 170 this->collisionEventsUnused.push_back(*it2); 171 172 this->collisionsUsed.clear(); 173 this->collisionEventsUsed.clear(); 134 174 } 135 return false;136 }137 175 138 176 139 /** 140 * processes the collisions by calling the EventHandlers 141 */ 142 void CREngine::handleCollisions() 143 { 144 std::vector<CollisionHandle*>::iterator it; 145 for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++) 177 void CREngine::debug() 146 178 { 147 if( !(*it)->isDispatched() || (*it)->isContinuousPoll()) //does it have any collisions to report at all148 {149 (*it)->handleCollisions();150 }151 179 } 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 180 177 181 } 178 -
branches/coll_rect/src/lib/collision_reaction/cr_engine.h
r9869 r9889 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 CollisionHandle; 24 class Collision; 25 class CollisionEvent; 26 27 //! A default singleton class. 28 class CREngine : public BaseObject 29 { 30 ObjectListDeclaration(CREngine); 28 31 29 32 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: simulating simple 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 stability33 typedef enum CRType { 34 CR_PHYSICS_MOMENTUM = 0, //!< physical reaction: conservervation of momentum 35 CR_PHYSICS_STEP_BACK, //!< physical reaction: just go to the last position without collisions 36 CR_PHYSICS_GROUND_WALK, //!< physical reaction: stand on the ground, no movement: simulating simple normal force away from the gravity force 37 CR_PHYSICS_FULL_WALK, //!< physical reaction: walking on the ground (inkl. hills etc) 38 CR_PHYSICS_DAMAGE, //!< physical reaction: daling damage according to the object energy and their structural stability 36 39 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!)40 CR_OBJECT_DAMAGE, //!< object raction: deals damage according to the objects specific damage potential (like weapons, nukes, etc.) 41 CR_OBJECT_PICKUP, //!< object rection: calling the objects pickup functions, let them handle the collision (once!) 39 42 40 CR_VERTEX_TRAFO, //!< vertex trafo: transforming the vertex according to the damage43 CR_VERTEX_TRAFO, //!< vertex trafo: transforming the vertex according to the damage 41 44 42 CR_SPECIAL_CALLBACK, //!< special: call a callback function45 CR_SPECIAL_CALLBACK, //!< special: call a callback function 43 46 44 CR_NUMBER 47 CR_NUMBER 48 }; 49 50 virtual ~CREngine(void); 51 52 /** @returns a Pointer to the only object of this Class */ 53 inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine(); return singletonRef; }; 54 55 void reset(); 56 57 58 CollisionHandle* subscribeReaction(WorldEntity* worldEntity, CRType type); 59 60 bool unsubscribeReaction(CollisionHandle* collisionHandle); 61 62 void handleCollisions(); 63 64 /** @returns an instance to a collision object. instead of creating new object this ones can be resycled */ 65 inline Collision* popCollisionObject() 66 { 67 if( !this->collisionsUnused.empty()) 68 { 69 this->collisionsUsed.push_back(this->collisionsUnused.back()); this->collisionsUnused.pop_back(); return this->collisionsUsed.back(); 70 } 71 else return NULL; 72 } 73 74 75 /** @return an instanco of a CollisionEvent object. instead of creating a new object this ones can be used and resycled */ 76 inline CollisionEvent* popCollisionEventObject() 77 { 78 if( !this->collisionEventsUnused.empty()) 79 { 80 this->collisionEventsUsed.push_back(this->collisionEventsUnused.back()); this->collisionEventsUnused.pop_back(); return this->collisionEventsUsed.back(); 81 } 82 else return NULL; 83 } 84 85 void debug(); 86 87 88 private: 89 CREngine(); 90 void init(); 91 92 void flushCollisions(); 93 94 95 private: 96 std::vector<CollisionHandle*> collisionHandles; //!< list with the collision handles 97 98 std::vector<Collision*> collisionsUsed; //!< a list of used, cached collisions 99 std::vector<Collision*> collisionsUnused; //!< a list of unused, cached collisions 100 101 std::vector<CollisionEvent*> collisionEventsUsed; //!< a list of used, cached collision events 102 std::vector<CollisionEvent*> collisionEventsUnused; //!< a list of unused, cached collision events 103 104 static CREngine* singletonRef; //!< the reference to the CREngine object (singleton) 45 105 }; 46 106 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 107 } 94 108 #endif /* _CR_ENGINE_ */ -
branches/coll_rect/src/lib/collision_reaction/cr_object_damage.cc
r9869 r9889 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(4)("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(4)("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(4)("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 collision->flushCollisionEvents(); 77 collision->dispatched(); 78 79 // const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); 80 // std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); 81 // for(; it != collisionEvents->end(); it++) 82 // { 83 // // go through the collisions and try to estimate the damage 84 // mass = (*it)->getEntityA()->getMass(); 85 // } 86 66 87 } 67 88 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 89 } 86 -
branches/coll_rect/src/lib/collision_reaction/cr_object_damage.h
r9869 r9889 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(); … … 24 28 private: 25 29 26 }; 30 }; 31 } 27 32 28 33 #endif /* _CR_OBJECT_DAMAGE_H */ -
branches/coll_rect/src/lib/collision_reaction/cr_physics_full_walk.cc
r9869 r9889 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->getEntityB()->getModelAABB(); 64 WorldEntity* entity = collision->getEntityB(); 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 const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); 84 std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); 85 for(; it != collisionEvents->end(); it++) 86 { 87 88 CollisionEvent* ce = (*it); 89 Vector normal = ce->getGroundNormal(); 90 91 // calculate the collision position 92 Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition(); 93 94 // test the 3 axis differently 95 switch( ce->getType()) 96 { 97 /* collision in the X-AXIS */ 98 case COLLISION_TYPE_AXIS_X: 99 front = collPos.len() - box->halfLength[0]; 100 101 // object is beneath the plane (ground) 102 if( front <= 0.0f ) 103 { 104 Vector dirX = entity->getAbsDirX(); 105 dirX.y = 0.0f; 106 dirX.normalize(); 107 Vector backoff = dirX * front; 108 109 entity->shiftCoor(backoff); 110 } 111 else if( ce->isInWall()) 112 { 113 // object is already in the wall 114 entity->setAbsCoor(entity->getLastAbsCoor()); 115 } 116 break; 117 118 case COLLISION_TYPE_AXIS_X_NEG: 119 back = collPos.len() - box->halfLength[0]; 120 121 // object is beneath the plane (ground) 122 if( back <= 0.0f) 123 { 124 Vector dirX = entity->getAbsDirX(); 125 dirX.y = 0.0f; 126 dirX.normalize(); 127 Vector backoff = dirX * back * -1.0f; 128 129 entity->shiftCoor(backoff); 130 } 131 else if( ce->isInWall()) 132 { 133 // object is already in the wall 134 entity->setAbsCoor(entity->getLastAbsCoor()); 135 } 136 break; 137 138 139 /* collision in the Y-AXIS */ 140 case COLLISION_TYPE_AXIS_Y_NEG: 141 // calulate the height above ground 142 height = collPos.len() - box->halfLength[1]; 143 144 145 // object is beneath the plane (ground) 146 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing 147 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) 148 { 149 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); 150 entity->setOnGround(true); 151 } 152 // object is already in the wall 153 else if( ce->isInWall()) 154 { 155 entity->setAbsCoor(entity->getLastAbsCoor()); 156 PRINTF(0)("ground collision: reset pos\n"); 157 } 158 else 159 { 160 // entity is not on ground 161 entity->setOnGround(false); 162 } 163 break; 164 165 166 /* collision in the Z-AXIS */ 167 case COLLISION_TYPE_AXIS_Z: 168 169 right = collPos.len() - box->halfLength[2]; 170 171 // object is beneath the plane (ground) 172 if( right <= 0.0f ) 173 { 174 Vector dirZ = entity->getAbsDirZ(); 175 dirZ.y = 0.0f; 176 dirZ.normalize(); 177 Vector backoff = dirZ * right; 178 entity->shiftCoor(backoff); 179 } 180 else if( ce->isInWall()) 181 { 182 // object is already in the wall 183 entity->setAbsCoor(entity->getLastAbsCoor()); 184 } 185 break; 186 187 188 // collision in the z-axis 189 case COLLISION_TYPE_AXIS_Z_NEG: 190 191 left = collPos.len() - box->halfLength[2]; 192 193 // object is beneath the plane (ground) 194 if( left <= 0.0f ) 195 { 196 Vector dirZ = entity->getAbsDirZ(); 197 dirZ.y = 0.0f; 198 dirZ.normalize(); 199 Vector backoff = dirZ * left*-1.0f; 200 entity->shiftCoor(backoff); 201 } 202 // object is already in the wall 203 else if( ce->isInWall()) 204 { 205 entity->setAbsCoor(entity->getLastAbsCoor()); 206 } 207 break; 208 } 209 } 210 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side); 211 212 213 214 215 216 217 218 } 219 220 221 222 223 /** 224 * use this to do some collision offline calculations, only called for bContinuousPoll == true 225 */ 226 void CRPhysicsFullWalk::update(WorldEntity* owner) 227 {} 45 228 } 46 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 -
branches/coll_rect/src/lib/collision_reaction/cr_physics_full_walk.h
r9869 r9889 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(); … … 27 29 private: 28 30 float downspeed; 29 };30 31 }; 32 } 31 33 #endif /* _CR_PHYSICS_FULL_WALK_H */ -
branches/coll_rect/src/lib/collision_reaction/cr_physics_ground_walk.cc
r9869 r9889 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->getEntityB()->getModelAABB(); 67 WorldEntity* entity = collision->getEntityB(); 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 const std::vector<CollisionEvent*>* collisionEvents = &(collision->getCollisionEvents()); 82 std::vector<CollisionEvent*>::const_iterator it = collisionEvents->begin(); 83 for(; it != collisionEvents->end(); it++) 84 { 85 86 CollisionEvent* ce = (*it); 87 Vector normal = ce->getGroundNormal(); 88 89 // calculate the collision position 90 Vector collPos = collision->getEntityB()->getAbsCoor() + box->center - ce->getCollisionPosition(); 91 92 // test the 3 axis differently 93 switch( ce->getType()) 94 { 95 /* collision in the Y-AXIS */ 96 case COLLISION_TYPE_AXIS_Y_NEG: 97 // calulate the height above ground 98 height = collPos.len() - box->halfLength[1]; 99 100 101 // object is beneath the plane (ground) 102 // if(height >= 0.0f && height <= 0.0001f) break ;// Do nothing 103 if( height < 0.0f && -height < CR_MAX_WALK_HEIGHT) 104 { 105 entity->shiftCoor(Vector(0.0f, -height + 0.00001, 0.0f)); 106 entity->setOnGround(true); 107 } 108 // object is already in the wall 109 else if( ce->isInWall()) 110 { 111 entity->setAbsCoor(entity->getLastAbsCoor()); 112 } 113 else 114 { 115 // entity is not on ground 116 entity->setOnGround(false); 117 } 118 break; 119 120 121 } 117 122 } 123 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side); 124 118 125 } 119 //PRINTF(0)("collision distances: x: %f, y: %f, z: %f\n", front, height, side);120 121 }122 126 123 127 124 128 125 129 126 /**127 * use this to do some collision offline calculations, only called for bContinuousPoll == true128 */129 void CRPhysicsGroundWalk::update(WorldEntity* owner)130 {}130 /** 131 * use this to do some collision offline calculations, only called for bContinuousPoll == true 132 */ 133 void CRPhysicsGroundWalk::update(WorldEntity* owner) 134 {} 131 135 132 136 } -
branches/coll_rect/src/lib/collision_reaction/cr_physics_ground_walk.h
r9869 r9889 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(); … … 27 29 private: 28 30 float downspeed; 29 };31 }; 30 32 33 } 31 34 #endif /* _CR_PHYSICS_GROUND_WALK_H */ -
branches/coll_rect/src/story_entities/game_world.cc
r9869 r9889 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 -
branches/coll_rect/src/story_entities/game_world_data.cc
r9869 r9889 232 232 State::setPlayer(this->localPlayer); 233 233 234 Playable* playable;235 234 if (!Playable::objectList().empty()) 236 235 { -
branches/coll_rect/src/world_entities/creatures/fps_player.cc
r9869 r9889 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; -
branches/coll_rect/src/world_entities/npcs/generic_npc.cc
r9869 r9889 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 -
branches/coll_rect/src/world_entities/weapons/aiming_system.cc
r9869 r9889 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; -
branches/coll_rect/src/world_entities/world_entity.cc
r9869 r9889 78 78 79 79 // reset all collision handles to NULL == unsubscribed state 80 for(int i = 0; i < C REngine::CR_NUMBER; ++i)80 for(int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i) 81 81 this->collisionHandles[i] = NULL; 82 82 this->bReactive = false; … … 84 84 85 85 // registering default reactions: 86 this->subscribeReaction(C REngine::CR_OBJECT_DAMAGE, /* WorldEntity::staticClassID(), */ Projectile::staticClassID());86 this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, /* WorldEntity::staticClassID(), */ Projectile::staticClassID()); 87 87 88 88 this->toList(OM_NULL); … … 302 302 * @param target1 a filter target (classID) 303 303 */ 304 void WorldEntity::subscribeReaction(C REngine::CRType type, const ClassID& target1)304 void WorldEntity::subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1) 305 305 { 306 306 this->subscribeReaction(type); … … 316 316 * @param target1 a filter target (classID) 317 317 */ 318 void WorldEntity::subscribeReaction(C REngine::CRType type, const ClassID& target1, const ClassID& target2)318 void WorldEntity::subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2) 319 319 { 320 320 this->subscribeReaction(type); … … 331 331 * @param target1 a filter target (classID) 332 332 */ 333 void WorldEntity::subscribeReaction(C REngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)333 void WorldEntity::subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3) 334 334 { 335 335 this->subscribeReaction(type); … … 342 342 343 343 344 /**345 * subscribes this world entity to a collision reaction346 * @param type the type of reaction to subscribe to347 * @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 filter354 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 344 361 345 /** … … 365 349 * @param ... the targets as classIDs 366 350 */ 367 void WorldEntity::subscribeReaction(C REngine::CRType type)351 void WorldEntity::subscribeReaction(CoRe::CREngine::CRType type) 368 352 { 369 353 if( this->collisionHandles[type] != NULL) … … 373 357 } 374 358 375 this->collisionHandles[type] = C REngine::getInstance()->subscribeReaction(this, type);359 this->collisionHandles[type] = CoRe::CREngine::getInstance()->subscribeReaction(this, type); 376 360 377 361 // now there is at least one collision reaction subscribed … … 384 368 * @param type the reaction to unsubscribe 385 369 */ 386 void WorldEntity::unsubscribeReaction(C REngine::CRType type)370 void WorldEntity::unsubscribeReaction(CoRe::CREngine::CRType type) 387 371 { 388 372 if( this->collisionHandles[type] == NULL) 389 373 return; 390 374 391 C REngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);375 CoRe::CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]); 392 376 this->collisionHandles[type] = NULL; 393 377 394 378 // check if there is still any handler registered 395 for(int i = 0; i < C REngine::CR_NUMBER; ++i)379 for(int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i) 396 380 { 397 381 if( this->collisionHandles[i] != NULL) … … 410 394 void WorldEntity::unsubscribeReaction() 411 395 { 412 for( int i = 0; i < C REngine::CR_NUMBER; i++)413 this->unsubscribeReaction((C REngine::CRType)i);396 for( int i = 0; i < CoRe::CREngine::CR_NUMBER; i++) 397 this->unsubscribeReaction((CoRe::CREngine::CRType)i); 414 398 415 399 // there are no reactions subscribed from now on … … 433 417 434 418 // get a collision event 435 Co llisionEvent* c =CREngine::getInstance()->popCollisionEventObject();419 CoRe::CollisionEvent* c = CoRe::CREngine::getInstance()->popCollisionEventObject(); 436 420 assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h 437 421 c->collide(COLLISION_TYPE_OBB, entityA, entityB, bvA, bvB); 438 422 439 for( int i = 0; i < C REngine::CR_NUMBER; ++i)423 for( int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i) 440 424 if( this->collisionHandles[i] != NULL) 441 425 this->collisionHandles[i]->registerCollisionEvent(c); … … 457 441 458 442 // get a collision event 459 Co llisionEvent* c =CREngine::getInstance()->popCollisionEventObject();443 CoRe::CollisionEvent* c = CoRe::CREngine::getInstance()->popCollisionEventObject(); 460 444 assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h 461 445 c->collide(type, entity, groundEntity, normal, position, bInWall); 462 446 463 for( int i = 0; i < C REngine::CR_NUMBER; ++i)447 for( int i = 0; i < CoRe::CREngine::CR_NUMBER; ++i) 464 448 if( this->collisionHandles[i] != NULL) 465 449 this->collisionHandles[i]->registerCollisionEvent(c); -
branches/coll_rect/src/world_entities/world_entity.h
r9888 r9889 82 82 83 83 /* --- 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); 84 void subscribeReaction(CoRe::CREngine::CRType type); 85 void subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1); 86 void subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2); 87 void subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3); 88 89 void unsubscribeReaction(CoRe::CREngine::CRType type); 91 90 void unsubscribeReaction(); 92 91 … … 96 95 inline bool isReactive() const { return this->bReactive; } 97 96 98 Co llisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }97 CoRe::CollisionHandle* getCollisionHandle(CoRe::CREngine::CRType type) const { return this->collisionHandles[type]; } 99 98 100 99 /** @returns true if this entity is standing on ground (BSP model) */ … … 212 211 int healthMax_handle; 213 212 214 Co llisionHandle* collisionHandles[CREngine::CR_NUMBER]; //!< the list of the collision reactions213 CoRe::CollisionHandle* collisionHandles[CoRe::CREngine::CR_NUMBER]; //!< the list of the collision reactions 215 214 bool bReactive; //!< true if there is at least one collision reaction subscibed 215 216 216 217 217 PhysicsInterface physicsInterface; //!< the physics object of the WorldEntity
Note: See TracChangeset
for help on using the changeset viewer.