Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/mount_points/src/world_entities/world_entity.h @ 10184

Last change on this file since 10184 was 10184, checked in by patrick, 17 years ago

extended model again, added mounting point generation procedures now working on a nicer interface

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