Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added namspacing to collision reaction. now comes the harder part :D

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