Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ODE/src/world_entities/world_entity.h @ 10355

Last change on this file since 10355 was 10355, checked in by bottac, 17 years ago

Here comes the updated version.

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