Changeset 8490 in orxonox.OLD for trunk/src/lib/collision_reaction
- Timestamp:
- Jun 15, 2006, 9:34:48 PM (19 years ago)
- Location:
- trunk/src/lib/collision_reaction
- Files:
-
- 8 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/collision_reaction/Makefile.am
r8190 r8490 9 9 collision_handle.cc \ 10 10 collision_reaction.cc \ 11 cr_object_damage.cc 11 cr_object_damage.cc \ 12 cr_physics_ground_walk.cc 12 13 13 14 … … 19 20 cr_defs.h \ 20 21 collision_reaction.h \ 21 cr_object_damage.h 22 cr_object_damage.h \ 23 cr_physics_ground_walk.h 22 24 -
trunk/src/lib/collision_reaction/collision.h
r8190 r8490 27 27 28 28 /** collides two WorldEntities @param entityA world entity A, @param entityB world entity B, @param bvA volume A @param bvB volumeB */ 29 inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; }29 inline void collide(WorldEntity* entityA, WorldEntity* entityB) { this->entityA = entityA; this->entityB = entityB; this->bDispatched = false; } 30 30 31 31 … … 42 42 /** sets the flag if it reacts @param flag true if it should react on entityB*/ 43 43 inline void setEntityBCollide(bool flag) { this->entityACollide = flag; } 44 44 45 45 46 /** @returns true if this Collision has already been dispatched */ -
trunk/src/lib/collision_reaction/collision_event.h
r8190 r8490 25 25 { this->entityA = entityA; this->entityB = entityB; this->bvA = bvA; this->bvB = bvB; } 26 26 /** collides two WorldEntities @param entity world entity , @param ground ground plane, @param position position on the ground */ 27 inline void collide(WorldEntity* entity, Plane* ground, Vector position)28 { this->entityA = entity; this-> ground = ground; this->position = position; }27 inline void collide(WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position) 28 { this->entityA = entity; this->entityB = groundEntity, this->groundNormal = normal; this->position = position; } 29 29 30 30 … … 38 38 inline BoundingVolume* getBVB() const { return this->bvB; } 39 39 40 /** @return ground plane if collided with bsp model */ 41 inline Vector getGroundNormal() { return this->groundNormal; } 40 42 41 inline void operator()(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB) { this->collide(entityA, entityB, bvA, bvB); } 42 inline void operator()(WorldEntity* entity, Plane* ground, Vector position) { this->collide(entity, ground, position); } 43 43 /** @return position of the position, only accurate if this is a collision with the ground!!! */ 44 inline Vector getCollisionPosition() { return this->position; } 44 45 45 46 private: … … 50 51 BoundingVolume* bvB; //!< reference to the bounding volume B 51 52 52 Plane* ground;//!< the ground plane with which it collides (only for bsp-model collisions53 Vector groundNormal; //!< the ground plane with which it collides (only for bsp-model collisions 53 54 Vector position; //!< position of the collision on the ground plane 54 55 }; -
trunk/src/lib/collision_reaction/collision_handle.cc
r8362 r8490 24 24 25 25 #include "cr_object_damage.h" 26 #include "cr_physics_ground_walk.h" 26 27 27 28 #include "debug.h" … … 42 43 43 44 this->bCollided = false; 44 this->bDispatched = false; 45 46 if( this->type == CREngine::CR_PHYSICS_STEP_BACK) 47 this->bContinuousPoll = false; 48 else 49 this->bContinuousPoll = true; 50 51 if( this->type == CREngine::CR_OBJECT_DAMAGE) 52 this->bStopOnFirstCollision = true; 53 else 54 this->bStopOnFirstCollision = false; 45 this->bDispatched = true; 46 47 this->collisionReaction = NULL; 48 this->bContinuousPoll = false; 49 this->bStopOnFirstCollision = false; 50 55 51 56 52 switch( type) 57 53 { 54 case CREngine::CR_PHYSICS_STEP_BACK: 55 // this->collisionReaction = new CRPhysicsGroundWalk(); 56 this->bContinuousPoll = true; 57 break; 58 case CREngine::CR_PHYSICS_GROUND_WALK: 59 this->collisionReaction = new CRPhysicsGroundWalk(); 60 this->bContinuousPoll = true; 61 break; 58 62 case CREngine::CR_OBJECT_DAMAGE: 59 63 this->collisionReaction = new CRObjectDamage(); 64 this->bStopOnFirstCollision = true; 60 65 break; 61 66 default: … … 71 76 { 72 77 // delete what has to be deleted here 78 if( this->collisionReaction != NULL) 79 delete this->collisionReaction; 73 80 } 74 81 … … 169 176 170 177 c->registerCollisionEvent(collisionEvent); 178 PRINTF(0)("Registering Collision Event: %s, %s\n", collisionEvent->getEntityA()->getClassName(), collisionEvent->getEntityB()->getClassName()); 171 179 } 172 180 … … 186 194 void CollisionHandle::handleCollisions() 187 195 { 196 // if continuous poll poll the reaction 197 if( this->bContinuousPoll && !this->bCollided) 198 { 199 this->collisionReaction->update(this->owner); 200 return; 201 } 202 188 203 // collision reaction calculations (for every collision there will be a reaction) 189 204 vector<Collision*>::iterator it = this->collisionList.begin(); … … 214 229 { 215 230 if( collisionEvent->getEntityA() == this->owner) { 216 if( collisionEvent->getEntityA()->isA((ClassID)(*it))) 231 if( collisionEvent->getEntityB()->isA((ClassID)(*it))) { 232 PRINTF(0)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(), 233 collisionEvent->getEntityB()->getClassName(), *it); 217 234 return true; } 235 } 218 236 else { 219 if( collisionEvent->getEntityB()->isA((ClassID)(*it))) 220 return true; } 237 if( collisionEvent->getEntityA()->isA((ClassID)(*it))) { 238 PRINTF(0)("I am: %s colliding with: %s is a %i filter ok\n", owner->getClassName(), 239 collisionEvent->getEntityA()->getClassName(), *it); 240 return true; } 241 } 221 242 } 222 243 -
trunk/src/lib/collision_reaction/collision_handle.h
r8190 r8490 41 41 /** @returns true if this handle should be pulled also if there are no collisions */ 42 42 inline bool isContinuousPoll() const { return this->bContinuousPoll; } 43 /** @returns the type */ 44 inline CREngine::CRType getType() const { return this->type; } 43 45 44 46 void handleCollisions(); -
trunk/src/lib/collision_reaction/collision_reaction.h
r8190 r8490 12 12 13 13 class Collision; 14 class WorldEntity; 15 14 16 15 17 //! A class representing a simple collision … … 23 25 virtual void reactToCollision(Collision* collision) = 0; 24 26 27 virtual void update(WorldEntity* owner) {} 28 29 /** use this to do some collision offline calculations, only called for bContinuousPoll == true */ 25 30 inline bool isContinuousPoll() const { return this->bContinuousPoll; } 26 31 -
trunk/src/lib/collision_reaction/cr_engine.cc
r8362 r8490 126 126 { 127 127 std::vector<CollisionHandle*>::iterator it; 128 for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++) 129 { 130 if( *it == collisionHandle) 131 { 128 for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++) { 129 if( *it == collisionHandle) { 132 130 this->collisionHandles.erase(it); 133 131 delete collisionHandle; … … 147 145 for( it = this->collisionHandles.begin(); it != this->collisionHandles.end(); it++) 148 146 { 149 if( (*it)->isCollided() || (*it)->isContinuousPoll()) //does it have any collisions to report at all147 if( !(*it)->isDispatched() || (*it)->isContinuousPoll()) //does it have any collisions to report at all 150 148 { 151 149 (*it)->handleCollisions(); -
trunk/src/lib/collision_reaction/cr_object_damage.cc
r8362 r8490 54 54 void CRObjectDamage::reactToCollision(Collision* collision) 55 55 { 56 float damage ;56 float damage = 0.0f; 57 57 58 PRINTF( 0)("Dealing damage - Handling collision: %s vs %s\n",58 PRINTF(4)("Dealing damage - Handling collision: %s vs %s\n", 59 59 collision->getEntityA()->getClassName(), 60 60 collision->getEntityB()->getClassName()); … … 65 65 collision->getEntityA()->decreaseHealth(damage); 66 66 } 67 PRINTF( 0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName());67 PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityA()->getClassName()); 68 68 69 69 if( collision->isEntityBCollide()) { … … 71 71 collision->getEntityB()->decreaseHealth(damage); 72 72 } 73 PRINTF( 0)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName());73 PRINTF(4)("Dealing damage - %f damage to %s \n", damage, collision->getEntityB()->getClassName()); 74 74 75 75 collision->flushCollisionEvents(); -
trunk/src/lib/collision_reaction/cr_physics_ground_walk.cc
r8489 r8490 23 23 #include "world_entity.h" 24 24 #include "cr_physics_ground_walk.h" 25 26 #include "debug.h" 25 27 26 28 #include <vector>
Note: See TracChangeset
for help on using the changeset viewer.