Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/coll_rect/src/world_entities/world_entity.h @ 9890

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

intruducing new container collision_tube. which serves as a central collision registration tube.

File size: 9.5 KB
Line 
1/*!
2 * @file world_entity.h
3 * Definition of the basic WorldEntity
4 */
5
6#ifndef _WORLD_ENTITY_H
7#define _WORLD_ENTITY_H
8
9#include "p_node.h"
10#include "synchronizeable.h"
11#include "model.h"
12
13#include "cr_engine.h"
14#include "object_manager.h"
15#include "glincl.h"
16#include <vector>
17
18#include "aabb_tree_node.h"
19
20#include "physics_interface.h"
21
22
23
24// FORWARD DECLARATION
25namespace OrxSound { class SoundBuffer; class SoundSource; }
26namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; };
27namespace CoRe { class CollisionHandle; class Collision; }
28
29class BVTree;
30class BoundingVolume;
31class AABBTreeNode;
32class Model;
33
34
35//! Basis-class all interactive stuff in the world is derived from
36class WorldEntity : public PNode
37{
38  ObjectListDeclaration(WorldEntity);
39
40public:
41  WorldEntity();
42  virtual ~WorldEntity ();
43
44  virtual void loadParams(const TiXmlElement* root);
45
46  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
47  void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);}
48  void setModel(Model* model, unsigned int modelNumber = 0);
49  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
50
51  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
52
53  /** @param visibility if the Entity should be visible (been draw) */
54  void setVisibiliy (bool visibility) { this->bVisible = visibility; };
55  /** @returns true if the entity is visible, false otherwise */
56  inline bool isVisible() const { return this->bVisible; };
57
58  virtual void reset();
59
60  virtual void postSpawn ();
61  virtual void leaveWorld ();
62
63  virtual void tick (float time);
64  virtual void draw () const;
65
66  /* --- Collision Detection Block  --- */
67  bool buildObbTree(int depth);
68  virtual void collidesWith (WorldEntity* entity, const Vector& location);
69  virtual void collidesWithGround(const Vector& location);
70  virtual void collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2);
71
72  /** @returns a reference to the obb tree of this worldentity */
73  inline BVTree* getOBBTree() const { return this->obbTree; };
74  inline void setOBBTree(OBBTree* tree) { /*if( this->obbTree != NULL) delete this->obbTree;*/ this->obbTree = (BVTree*)tree; }
75  void drawBVTree(int depth, int drawMode) const;
76  inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
77
78
79  /* --- Collision Reaction Block --- */
80  void subscribeReaction(CoRe::CREngine::CRType type);
81  void subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1);
82  void subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2);
83  void subscribeReaction(CoRe::CREngine::CRType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
84
85  void unsubscribeReaction(CoRe::CREngine::CRType type);
86  void unsubscribeReaction();
87
88  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
89  bool registerCollision(int type, WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position, bool bInWall = false);
90  /** @return true if there is at least on collision reaction subscribed */
91  inline bool isReactive() const { return this->bReactive; }
92
93  CoRe::CollisionHandle* getCollisionHandle(CoRe::CREngine::CRType type) const { return this->collisionHandles[type]; }
94
95  /** @returns true if this entity is standing on ground (BSP model) */
96  bool isOnGround() const { return this->bOnGround; }
97  /** @param flag: marks if this entity is standing on ground */
98  void setOnGround(bool flag) { this->bOnGround = flag; }
99
100  virtual void hit(float damage, WorldEntity* killer);
101
102  virtual void destroy( WorldEntity* killer );
103
104
105  /* @returns the Count of Faces on this WorldEntity */
106  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
107  //  void addAbility(Ability* ability);
108  //  void removeAbility(Ability* ability);
109  //  void setCharacterAttributes(CharacterAttributes* charAttr);
110  //  CharacterAttributes* getCharacterAttributes();
111
112  /* --- Object Manager Block --- */
113  void toList(OM_LIST list);
114  void toListS(const std::string& listName);
115
116  void toReflectionList();
117  void removeFromReflectionList();
118
119  /** @returns a Reference to the objectListNumber to set. */
120  OM_LIST& getOMListNumber() { return this->objectListNumber; }
121  /** @returns a Reference to the Iterator */
122  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
123
124  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
125  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
126
127
128  /* --- Character Attribute Block --- */
129  /** @returns the scaling of the model */
130  float getScaling(){return this->scaling;}
131  /** @returns the damage dealt by this world entity */
132  float getDamage() const { return this->damage; }
133  /** sets the damage dealt to @param damage damage per second */
134  void setDamage(float damage) { this->damage = damage; }
135  /** @returns the Energy of the entity */
136  float getHealth() const { return this->health; };
137  /** @returns the Maximum energy this entity can be charged with */
138  float getHealthMax() const { return this->healthMax; }
139  float increaseHealth(float health);
140  float decreaseHealth(float health);
141  void increaseHealthMax(float increaseHealth);
142  OrxGui::GLGuiWidget* getHealthWidget();
143  bool hasHealthWidget() const { return this->healthWidget; };
144
145  virtual void varChangeHandler( std::list<int> & id );
146
147
148  //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars
149  /* --- Physics Interface --- */
150  inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; }
151  inline float getMass() const { return this->physicsInterface.getMass(); }
152  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
153  inline void setVelocity(const Vector& vel) { this->velocity = vel; }
154
155
156  /* --- Misc Stuff Block --- */
157  void debugWE() { this->debugEntity(); }
158  ;  ///FIXME
159  void debugEntity() const;
160
161
162protected:
163  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
164  void setHealthWidgetVisibilit(bool visibility);
165  void setHealthMax(float healthMax);
166  void createHealthWidget();
167    //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
168
169
170private:
171  void updateHealthWidget();
172
173
174private:
175  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
176  float                   damage;             //!< the damage dealt to other objects by colliding.
177  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
178  float                   healthMax;          //!< The Maximal energy this entity can take.
179  OrxGui::GLGuiEnergyWidget* healthWidget;    //!< The Slider (if wanted).
180
181  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
182  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
183  std::string             modelLODName;       //!< the name of the model lod file
184  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
185  AABBTreeNode*           aabbNode;           //!< the tree node of the first level of a axis aligned bounding boxes tree: model dimension
186
187  bool                    bCollide;           //!< If it should be considered for the collisiontest.
188  bool                    bVisible;           //!< If it should be visible.
189
190  OM_LIST                 objectListNumber;                //!< The ObjectList from ObjectManager this Entity is in.
191  ObjectManager::EntityList::iterator objectListIterator;  //!< The iterator position of this Entity in the given list of the ObjectManager.
192  OM_LIST                 lastObjectListNumber;            //!< the last ObjectList from the ObjectManager this Entity was is in
193
194  /* collision reaction stuff */
195  CoRe::CollisionHandle*  collisionHandles[CoRe::CREngine::CR_NUMBER];  //!< the list of the collision reactions
196  bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
197
198
199  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
200  bool                    bOnGround;                       //!< true if this entity is standing on the ground
201
202  /* network help structures */
203  float                   scaling;                         //!< model's scaling factor
204  int                     scaling_handle;                  //!< handle for syncing var
205
206  std::string             modelFileName;                   //!< model's file name
207  int                     modelFileName_handle;            //!< handle for syncing var
208
209  int                     list_write;                      //!< entity's list
210  int                     list_handle;                     //!< handle for list changes
211
212  float                   health_write;
213  int                     health_handle;
214
215  float                   healthMax_write;
216  int                     healthMax_handle;
217
218
219
220protected:
221  Vector                  velocity;                        //!< speed of the entity
222
223};
224
225#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.