Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

removed some comilation problems.

File size: 9.5 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"
[9896]14#include "collision_filter.h"
[6142]15#include "object_manager.h"
[5511]16#include "glincl.h"
[5995]17#include <vector>
[5511]18
[8724]19#include "aabb_tree_node.h"
20
[8190]21#include "physics_interface.h"
[7927]22
23
[8190]24
[4885]25// FORWARD DECLARATION
[7460]26namespace OrxSound { class SoundBuffer; class SoundSource; }
[8974]27namespace OrxGui { class GLGuiWidget; class GLGuiBar; class GLGuiEnergyWidget; };
[9896]28namespace CoRe { class Collision; }
[7779]29
[5143]30class BVTree;
[8190]31class BoundingVolume;
[8724]32class AABBTreeNode;
[5511]33class Model;
[6440]34
[7927]35
[4885]36//! Basis-class all interactive stuff in the world is derived from
[6498]37class WorldEntity : public PNode
[4680]38{
[9869]39  ObjectListDeclaration(WorldEntity);
[9890]40
[6430]41public:
42  WorldEntity();
[3221]43  virtual ~WorldEntity ();
[3365]44
[6512]45  virtual void loadParams(const TiXmlElement* root);
[5994]46
[7711]47  void loadModel(const std::string& fileName, float scaling = 1.0f, unsigned int modelNumber = 0, unsigned int obbTreeDepth = 4);
[9235]48  void loadModel2(const std::string& fileN, float scal = 1.0f){this->loadModel(fileN,scal,0,4);}
[5994]49  void setModel(Model* model, unsigned int modelNumber = 0);
[9890]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
[9869]73  /** @returns a reference to the obb tree of this worldentity */
[7711]74  inline BVTree* getOBBTree() const { return this->obbTree; };
[9235]75  inline void setOBBTree(OBBTree* tree) { /*if( this->obbTree != NULL) delete this->obbTree;*/ this->obbTree = (BVTree*)tree; }
[7711]76  void drawBVTree(int depth, int drawMode) const;
[9235]77  inline AABB* getModelAABB() const { return (this->aabbNode)?this->aabbNode->getAABB():NULL;}
[5501]78
[9896]79  virtual void hit(float damage, WorldEntity* killer);
[9888]80
[9896]81
[7927]82  /* --- Collision Reaction Block --- */
[9892]83  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1);
84  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2);
85  void subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3);
[6424]86
[9892]87  void unsubscribeReaction(CoRe::CREngine::ReactionType type);
[9896]88  void unsubscribeReactions();
[6424]89
[9939]90  inline bool isSubscribed(CoRe::CREngine::ReactionType type) const { return this->_collisionFilter.isSubscribed( type); }
91
[8190]92  /** @return true if there is at least on collision reaction subscribed */
93  inline bool isReactive() const { return this->bReactive; }
[9939]94  inline bool isReactive( const WorldEntity& worldEntity) const { return this->isReactive() || (this->_collisionFilter(worldEntity)); }
[8190]95
[9939]96  const CoRe::CollisionFilter& getCollisionFilter(CoRe::CREngine::ReactionType type) const { return this->_collisionFilter; }
[8190]97
[9003]98  /** @returns true if this entity is standing on ground (BSP model) */
99  bool isOnGround() const { return this->bOnGround; }
100  /** @param flag: marks if this entity is standing on ground */
101  void setOnGround(bool flag) { this->bOnGround = flag; }
102
[9235]103  virtual void destroy( WorldEntity* killer );
[8190]104
[8724]105
[5510]106  /* @returns the Count of Faces on this WorldEntity */
107  //unsigned int getFaceCount () const { return (this->model != NULL)?this->model->getFaceCount():0; };
108  //  void addAbility(Ability* ability);
109  //  void removeAbility(Ability* ability);
110  //  void setCharacterAttributes(CharacterAttributes* charAttr);
111  //  CharacterAttributes* getCharacterAttributes();
[4680]112
[7927]113  /* --- Object Manager Block --- */
[6142]114  void toList(OM_LIST list);
[9656]115  void toListS(const std::string& listName);
[8037]116
117  void toReflectionList();
118  void removeFromReflectionList();
119
[6142]120  /** @returns a Reference to the objectListNumber to set. */
121  OM_LIST& getOMListNumber() { return this->objectListNumber; }
122  /** @returns a Reference to the Iterator */
[7370]123  ObjectManager::EntityList::iterator& getEntityIterator() { return this->objectListIterator; }
[6222]124
[8894]125  void hide() { if( this->objectListNumber != OM_DEAD) this->lastObjectListNumber = this->objectListNumber; this->toList(OM_DEAD); }
[9890]126  void unhide() { if( this->objectListNumber != this->lastObjectListNumber) this->toList(this->lastObjectListNumber); }
[8894]127
128
[7927]129  /* --- Character Attribute Block --- */
[9298]130  /** @returns the scaling of the model */
[9890]131  float getScaling(){return this->scaling;}
[8190]132  /** @returns the damage dealt by this world entity */
133  float getDamage() const { return this->damage; }
134  /** sets the damage dealt to @param damage damage per second */
135  void setDamage(float damage) { this->damage = damage; }
[6430]136  /** @returns the Energy of the entity */
[6700]137  float getHealth() const { return this->health; };
[6430]138  /** @returns the Maximum energy this entity can be charged with */
[6700]139  float getHealthMax() const { return this->healthMax; }
140  float increaseHealth(float health);
141  float decreaseHealth(float health);
142  void increaseHealthMax(float increaseHealth);
[7779]143  OrxGui::GLGuiWidget* getHealthWidget();
[7064]144  bool hasHealthWidget() const { return this->healthWidget; };
[8190]145
[7954]146  virtual void varChangeHandler( std::list<int> & id );
[6430]147
[8190]148
149  //FIXME: the PhysicsInterface and the whole PEngine should probably be reviewed. Here its just used to store the vars
150  /* --- Physics Interface --- */
151  inline PhysicsInterface getPhysicsInterface() const { return this->physicsInterface; }
152  inline float getMass() const { return this->physicsInterface.getMass(); }
153  inline float getTotalMass() const { return this->physicsInterface.getTotalMass(); }
[8490]154  inline void setVelocity(const Vector& vel) { this->velocity = vel; }
[8190]155
156
[7927]157  /* --- Misc Stuff Block --- */
158  void debugWE() { this->debugEntity(); }
159  ;  ///FIXME
160  void debugEntity() const;
161
162
[6430]163protected:
[7095]164  void setHealth(float health) { this->health = health; this->updateHealthWidget();};
[6700]165  void setHealthWidgetVisibilit(bool visibility);
166  void setHealthMax(float healthMax);
167  void createHealthWidget();
[9890]168    //  CharacterAttributes*    charAttr;         //!< the character attributes of a world_entity
[7711]169
[9890]170
[6430]171private:
[6700]172  void updateHealthWidget();
[5994]173
[9890]174
[6430]175private:
176  /// TODO maybe we will move the following three entries and the corresponding functions to Playable AND NPC
[8190]177  float                   damage;             //!< the damage dealt to other objects by colliding.
[6700]178  float                   health;             //!< The Energy of this Entity, if the Entity has any energy at all.
179  float                   healthMax;          //!< The Maximal energy this entity can take.
[8974]180  OrxGui::GLGuiEnergyWidget* healthWidget;    //!< The Slider (if wanted).
[6341]181
[6142]182  std::vector<Model*>     models;             //!< The model that should be loaded for this entity.
[7221]183  std::string             md2TextureFileName; //!< the file name of the md2 model texture, only if this
184  std::string             modelLODName;       //!< the name of the model lod file
[6142]185  BVTree*                 obbTree;            //!< this is the obb tree reference needed for collision detection
[8724]186  AABBTreeNode*           aabbNode;           //!< the tree node of the first level of a axis aligned bounding boxes tree: model dimension
[4680]187
[6142]188  bool                    bCollide;           //!< If it should be considered for the collisiontest.
189  bool                    bVisible;           //!< If it should be visible.
190
[8190]191  OM_LIST                 objectListNumber;                //!< The ObjectList from ObjectManager this Entity is in.
192  ObjectManager::EntityList::iterator objectListIterator;  //!< The iterator position of this Entity in the given list of the ObjectManager.
[8894]193  OM_LIST                 lastObjectListNumber;            //!< the last ObjectList from the ObjectManager this Entity was is in
[6142]194
[9890]195  /* collision reaction stuff */
[9939]196  CoRe::CollisionFilter   _collisionFilter;                //!< filter for collision event filtering (not every entity listens to all collisions)
[9896]197  bool                    bReactive;                       //!< true if there is at least one collision reaction subscibed
[6341]198
199
[9890]200  PhysicsInterface        physicsInterface;                //!< the physics object of the WorldEntity
201  bool                    bOnGround;                       //!< true if this entity is standing on the ground
202
203  /* network help structures */
[8190]204  float                   scaling;                         //!< model's scaling factor
205  int                     scaling_handle;                  //!< handle for syncing var
206
207  std::string             modelFileName;                   //!< model's file name
208  int                     modelFileName_handle;            //!< handle for syncing var
209
[9008]210  int                     list_write;                      //!< entity's list
211  int                     list_handle;                     //!< handle for list changes
[9235]212
[9110]213  float                   health_write;
214  int                     health_handle;
[9235]215
[9110]216  float                   healthMax_write;
217  int                     healthMax_handle;
[9008]218
[8190]219
[9889]220
[9869]221protected:
[8490]222  Vector                  velocity;                        //!< speed of the entity
223
[2036]224};
225
[3224]226#endif /* _WORLD_ENTITY_H */
Note: See TracBrowser for help on using the repository browser.