Changeset 10010 in orxonox.OLD for branches/coll_rect.merge/src/lib/collision_reaction/cr_engine.h
- Timestamp:
- Dec 4, 2006, 4:39:45 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/coll_rect.merge/src/lib/collision_reaction/cr_engine.h
r9869 r10010 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_ */
Note: See TracChangeset
for help on using the changeset viewer.