Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

cr: collision registration work

File size: 5.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
19
20
21// FORWARD DECLARATION
22namespace OrxSound { class SoundBuffer; class SoundSource; }
23namespace OrxGui { class GLGuiWidget; class GLGuiBar; };
24
25class BVTree;
26class BoundingVolume;
27class Model;
28class CollisionHandle;
29class Collision;
30
31
32//class CharacterAttributes;
33
34
35//! Basis-class all interactive stuff in the world is derived from
36class WorldEntity : public PNode
37{
38public:
39  WorldEntity();
40  virtual ~WorldEntity ();
41
42  virtual void loadParams(const TiXmlElement* root);
43
44  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
45  void setModel(Model* model, unsigned int modelNumber = 0);
46  Model* getModel(unsigned int modelNumber = 0) const { return (this->models.size() > modelNumber)? this->models[modelNumber] : NULL; };
47
48  inline void loadMD2Texture(const std::string& fileName) { this->md2TextureFileName = fileName; }
49
50  /** @param visibility if the Entity should be visible (been draw) */
51  void setVisibiliy (bool visibility) { this->bVisible = visibility; };
52  /** @returns true if the entity is visible, false otherwise */
53  inline bool isVisible() const { return this->bVisible; };
54
55  virtual void reset();
56
57  virtual void postSpawn ();
58  virtual void leaveWorld ();
59  virtual void destroy() {};
60
61  virtual void tick (float time);
62  virtual void draw () const;
63
64  /* --- Collision Detection Block  --- */
65  bool buildObbTree(int depth);
66  virtual void collidesWith (WorldEntity* entity, const Vector& location);
67  /** @returns a reference to the obb tree of this worldentity */
68  inline BVTree* getOBBTree() const { return this->obbTree; };
69  void drawBVTree(int depth, int drawMode) const;
70
71  /* --- Collision Reaction Block --- */
72  void subscribeReaction(CREngine::CRType type, int nrOfTargets, long target, ...);
73  void registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB);
74
75
76  /* @returns the Count of Faces on this WorldEntity */
77  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
78  //  void addAbility(Ability* ability);
79  //  void removeAbility(Ability* ability);
80  //  void setCharacterAttributes(CharacterAttributes* charAttr);
81  //  CharacterAttributes* getCharacterAttributes();
82
83  /* --- Object Manager Block --- */
84  void toList(OM_LIST list);
85  /** @returns a Reference to the objectListNumber to set. */
86  OM_LIST& getOMListNumber() { return this->objectListNumber; }
87  /** @returns a Reference to the Iterator */
88  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
89
90  /* --- Network Block --- */
91  int       writeState(const byte* data, int length, int sender);
92  int       readState(byte* data, int maxLength );
93
94  /* --- Character Attribute Block --- */
95  /** @returns the Energy of the entity */
96  float getHealth() const { return this->health; };
97  /** @returns the Maximum energy this entity can be charged with */
98  float getHealthMax() const { return this->healthMax; }
99  float increaseHealth(float health);
100  float decreaseHealth(float health);
101  void increaseHealthMax(float increaseHealth);
102  OrxGui::GLGuiWidget* getHealthWidget();
103  bool hasHealthWidget() const { return this->healthWidget; };
104
105  /* --- Misc Stuff Block --- */
106  void debugWE() { this->debugEntity(); }
107  ;  ///FIXME
108  void debugEntity() const;
109
110
111protected:
112  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
113  void setHealthWidgetVisibilit(bool visibility);
114  void setHealthMax(float healthMax);
115  void createHealthWidget();
116
117  //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
118private:
119  void updateHealthWidget();
120
121private:
122  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
123  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
124  float                   healthMax;          //!< The Maximal energy this entity can take.
125  OrxGui::GLGuiBar*       healthWidget;       //!< The Slider (if wanted).
126
127  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
128  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
129  std::string             modelLODName;       //!< the name of the model lod file
130  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
131
132  bool                    bCollide;           //!< If it should be considered for the collisiontest.
133  bool                    bVisible;           //!< If it should be visible.
134
135  OM_LIST                           objectListNumber;             //!< The ObjectList from ObjectManager this Entity is in.
136  ObjectManager::EntityList::iterator objectListIterator;         //!< The iterator position of this Entity in the given list of the ObjectManager.
137
138  float                   scaling;                                //!< the scaling of the model
139  CollisionHandle*        collisionHandles[CREngine::CR_NUMBER];  //!< the list of the collision reactions
140
141
142};
143
144#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.