Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/lib/collision_reaction/cr_engine.h @ 9892

Last change on this file since 9892 was 9892, checked in by patrick, 18 years ago

new interface to collision registers, more transparent. some more functionality

File size: 4.2 KB
Line 
1/*!
2 * @file cr_engine.h
3 * @brief The collision reaction engine, defining generic collision reactions to collision events
4 *
5 * some parts of this module are tuned for efficiency. They are probably not self-explenatory anymore :D
6 *  - Collision/ CollisionEvent objects recycling: This class contains a class of precached objects of these types
7 *      they are used for fast registration of collision events: These objects can be get by the interface functions and
8 *      are returned after one cycle automaticly by reseting the cached lists to its initial state. So do not wonder :D
9 */
10
11#ifndef _CR_ENGINE_
12#define _CR_ENGINE_
13
14#include "base_object.h"
15
16#include <vector>
17
18class WorldEntity;
19
20
21namespace CoRe
22{
23  class CollisionHandle;
24  class Collision;
25  class CollisionEvent;
26
27  //! A default singleton class.
28  class CREngine : public BaseObject
29  {
30    ObjectListDeclaration(CREngine);
31
32  public:
33    typedef enum ReactionType {
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: 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
39
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!)
42
43      CR_VERTEX_TRAFO,                     //!< vertex trafo: transforming the vertex according to the damage
44
45      CR_SPECIAL_CALLBACK,                 //!< special: call a callback function
46
47      CR_NUMBER
48    };
49
50    typedef enum CollisionType {
51      CR_COLLISION_TYPE_AXIS_X       = 0,  //!< collision on x axis
52      CR_COLLISION_TYPE_AXIS_X_NEG,        //!< collision on negative x axis
53      CR_COLLISION_TYPE_AXIS_Y,            //!< collision on y axis
54      CR_COLLISION_TYPE_AXIS_Y_NEG,        //!< collision on negative y axis
55      CR_COLLISION_TYPE_AXIS_Z,            //!< collision on z axis
56      CR_COLLISION_TYPE_AXIS_Z_NEG,        //!< collision on negative z axis
57      CR_COLLISION_TYPE_OBB,               //!< object aligned bounding box collide
58
59      CR_COLLISION_TYPE_NUMBER
60    };
61
62
63#define COLLISION_TYPE_AXIS_X      1
64#define COLLISION_TYPE_AXIS_X_NEG  2
65//!< the collision axis y collision event
66#define COLLISION_TYPE_AXIS_Y      3
67#define COLLISION_TYPE_AXIS_Y_NEG  4
68//!< the collision axis z collision event
69#define COLLISION_TYPE_AXIS_Z      5
70#define COLLISION_TYPE_AXIS_Z_NEG  6
71//!< the collision is a obb collision
72#define COLLISION_TYPE_OBB         8
73
74    virtual ~CREngine(void);
75
76    /** @returns a Pointer to the only object of this Class */
77    inline static CREngine* getInstance() { if (!singletonRef) singletonRef = new CREngine();  return singletonRef; };
78
79    CollisionHandle* subscribeReaction(WorldEntity* worldEntity, ReactionType type);
80    bool unsubscribeReaction(CollisionHandle* collisionHandle);
81
82
83    Collision* popCollisionObject();
84    CollisionEvent* popCollisionEventObject();
85    void reset();
86
87    void handleCollisions();
88
89    void debug();
90
91
92  private:
93    CREngine();
94    void init();
95
96    void flushCollisions();
97
98
99  private:
100    std::vector<CollisionHandle*>       collisionHandles;         //!< list with the collision handles
101
102    std::vector<Collision*>             collisionsUsed;           //!< a list of used, cached collisions
103    std::vector<Collision*>             collisionsUnused;         //!< a list of unused, cached collisions
104
105    std::vector<CollisionEvent*>        collisionEventsUsed;      //!< a list of used, cached collision events
106    std::vector<CollisionEvent*>        collisionEventsUnused;    //!< a list of unused, cached collision events
107
108    static CREngine*                    singletonRef;             //!< the reference to the CREngine object (singleton)
109  };
110
111}
112#endif /* _CR_ENGINE_ */
Note: See TracBrowser for help on using the repository browser.