Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cr/src/world_entities/world_entity.h @ 8204

Last change on this file since 8204 was 8182, checked in by patrick, 19 years ago

cr: extended the collisionevent and added the interface to the WE

File size: 7.0 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 "physics_interface.h"
19
20
21
22// FORWARD DECLARATION
23namespace OrxSound { class SoundBuffer; class SoundSource; }
24namespace OrxGui { class GLGuiWidget; class GLGuiBar; };
25
26class BVTree;
27class BoundingVolume;
28class Model;
29class CollisionHandle;
30class Collision;
31class Plane;
32
33
34//class CharacterAttributes;
35
36
37//! Basis-class all interactive stuff in the world is derived from
38class WorldEntity : public PNode
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 setModel(Model* model, unsigned int modelNumber = 0);
48  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
49
50  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
51
52  /** @param visibility if the Entity should be visible (been draw) */
53  void setVisibiliy (bool visibility) { this->bVisible = visibility; };
54  /** @returns true if the entity is visible, false otherwise */
55  inline bool isVisible() const { return this->bVisible; };
56
57  virtual void reset();
58
59  virtual void postSpawn ();
60  virtual void leaveWorld ();
61  virtual void destroy() {};
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  /** @returns a reference to the obb tree of this worldentity */
70  inline BVTree* getOBBTree() const { return this->obbTree; };
71  void drawBVTree(int depth, int drawMode) const;
72
73  /* --- Collision Reaction Block --- */
74  void subscribeReaction(CREngine::CRType type);
75  void subscribeReaction(CREngine::CRType type, long target1);
76  void subscribeReaction(CREngine::CRType type, long target1, long target2);
77  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3);
78  void subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4);
79
80  void unsubscribeReaction(CREngine::CRType type);
81  void unsubscribeReaction();
82
83  bool registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
84  bool registerCollision(WorldEntity* entity, Plane* plane, Vector position);
85  /** @return true if there is at least on collision reaction subscribed */
86  inline bool isReactive() const { return this->bReactive; }
87
88  CollisionHandle* getCollisionHandle(CREngine::CRType type) const { return this->collisionHandles[type]; }
89
90
91  /* @returns the Count of Faces on this WorldEntity */
92  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
93  //  void addAbility(Ability* ability);
94  //  void removeAbility(Ability* ability);
95  //  void setCharacterAttributes(CharacterAttributes* charAttr);
96  //  CharacterAttributes* getCharacterAttributes();
97
98  /* --- Object Manager Block --- */
99  void toList(OM_LIST list);
100  /** @returns a Reference to the objectListNumber to set. */
101  OM_LIST& getOMListNumber() { return this->objectListNumber; }
102  /** @returns a Reference to the Iterator */
103  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
104
105  /* --- Network Block --- */
106  int       writeState(const byte* data, int length, int sender);
107  int       readState(byte* data, int maxLength );
108
109  /* --- Character Attribute Block --- */
110  /** @returns the damage dealt by this world entity */
111  float getDamage() const { return this->damage; }
112  /** sets the damage dealt to @param damage damage per second */
113  void setDamage(float damage) { this->damage = damage; }
114  /** @returns the Energy of the entity */
115  float getHealth() const { return this->health; };
116  /** @returns the Maximum energy this entity can be charged with */
117  float getHealthMax() const { return this->healthMax; }
118  float increaseHealth(float health);
119  float decreaseHealth(float health);
120  void increaseHealthMax(float increaseHealth);
121  OrxGui::GLGuiWidget* getHealthWidget();
122  bool hasHealthWidget() const { return this->healthWidget; };
123
124
125  //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars
126  /* --- Physics Interface --- */
127  inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; }
128  inline float getMass() const { return this->physicsInterface.getMass(); }
129  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
130
131
132  /* --- Misc Stuff Block --- */
133  void debugWE() { this->debugEntity(); }
134  ;  ///FIXME
135  void debugEntity() const;
136
137
138protected:
139  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
140  void setHealthWidgetVisibilit(bool visibility);
141  void setHealthMax(float healthMax);
142  void createHealthWidget();
143
144  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
145private:
146  void updateHealthWidget();
147
148private:
149  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
150  float                   damage;             //!< the damage dealt to other objects by colliding.
151  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
152  float                   healthMax;          //!< The Maximal energy this entity can take.
153  OrxGui::GLGuiBar*       healthWidget;       //!< The Slider (if wanted).
154
155  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
156  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
157  std::string             modelLODName;       //!< the name of the model lod file
158  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
159
160  bool                    bCollide;           //!< If it should be considered for the collisiontest.
161  bool                    bVisible;           //!< If it should be visible.
162
163  OM_LIST                           objectListNumber;             //!< The ObjectList from ObjectManager this Entity is in.
164  ObjectManager::EntityList::iterator objectListIterator;         //!< The iterator position of this Entity in the given list of the ObjectManager.
165
166  float                   scaling;                                //!< the scaling of the model
167  CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
168  bool                    bReactive;                              //!< true if there is at least one collision reaction subscibed
169
170  PhysicsInterface        physicsInterface;  //!< the physics object of the WorldEntity
171
172};
173
174#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.