Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/collision_detection/cd_engine.h @ 8793

Last change on this file since 8793 was 8186, checked in by bensch, 18 years ago

trunk: merged the branche bsp_model back here

File size: 2.7 KB
Line 
1/*!
2 * @file cd_engine.h
3  *  Definition of the collision detection engine
4
5*/
6
7#ifndef _CD_ENGINE_H
8#define _CD_ENGINE_H
9
10#include "base_object.h"
11#include "collision_defs.h"
12#include "model.h"
13
14#include <list>
15
16class WorldEntity;
17class OBBTree;
18class Terrain;
19class BspManager;
20//class Player;
21
22
23//! featured state options, they are all additive
24typedef enum cdState
25  {
26    CD_DEBUG_DRAW_ALL = 1,
27    CD_DEBUG_DRAW_POLYGONS = 1<<1,
28    CD_DEBUG_DRAW_BLENDED = 1<<2,
29    CD_DEBUG_DRAW_HIT_BV = 1<<3,
30    CD_DEBUG_VERBOSE = 1<<4,
31
32    CD_STORE_VERTICES = 1<<5
33  };
34
35
36//! The class representing the collision detection system of orxonox
37class CDEngine : public BaseObject {
38
39  friend class WorldEntity;
40
41 public:
42  virtual ~CDEngine();
43  /** @returns a Pointer to the only object of this Class */
44  static CDEngine* getInstance() { if (!singletonRef) singletonRef = new CDEngine(); return singletonRef; }
45  void init();
46
47  inline void setState(const int newState) { this->state = newState; }
48  inline const int getState() const { return this->state; }
49  inline void enable(const int options) { this->state |= options; }
50  inline void disable(const int options) { int temp = this->state & options; this->state ^= temp; }
51
52  inline void setTerrain(Terrain* terrain) { this->terrain = terrain; }
53  inline void setBSPModel(BspManager* bspManager) { this->bspManager = bspManager; }
54
55  void checkCollisions(std::list<WorldEntity*>& list1, std::list<WorldEntity*>& list2);
56  void checkCollisionGround(std::list<WorldEntity*>& list1);
57
58  void drawBV(const std::list<WorldEntity*>& drawList, int level) const;
59  void debug();
60
61  /** @returns true if cd alg returns after detecting first error (default behavour) */
62  inline bool isAbordOnFirstCollision() const { return this->bAbordOnFirstCollision; }
63  /** sets @param flag true if the alg should return after detection of the first error */
64  inline void setAbordOnFirstCollision(bool flag) { this->bAbordOnFirstCollision = flag; }
65
66
67 private:
68  CDEngine();
69  static CDEngine* singletonRef;
70
71  void spawnBVTree(int depth = MAX_BV_TREE_DEPTH);
72
73  void checkCollisionObjects();
74
75
76  void debugSpawnTree(int depth, sVec3D* vertices, int numVertices);
77  void debugDraw(int depth, int drawMode);
78
79
80 private:
81  int                     state;                            //!< the current state of the cd engine
82  bool                    bAbordOnFirstCollision;           //!< abords the collision detection on first collision event => more speed but less accurate infomations
83  OBBTree*                rootTree;                         //!< for testing purposes a root tree
84
85  Terrain*                terrain;                          //!< this it a ref to the terrain, serving as a ground for all WE
86  BspManager*             bspManager;
87};
88
89#endif /* _CD_ENGINE_H */
Note: See TracBrowser for help on using the repository browser.