Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/world_entity.h @ 8724

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

merged the bsp-model-stuff back here

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