Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/world_entities/world_entity.cc @ 8929

Last change on this file since 8929 was 8929, checked in by ponder, 18 years ago
  • added a clipping plane for removing popping effects
  • put the update stuff from terrain::draw to terrain::tick.
File size: 20.5 KB
RevLine 
[2036]1
2
[4570]3/*
[2036]4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
[2190]15   co-programmer: Christian Meyer
[2036]16*/
[5300]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
[2036]18
19#include "world_entity.h"
[5208]20#include "shell_command.h"
[5143]21
[5511]22#include "model.h"
[8490]23#include "md2/md2Model.h"
24#include "md3/md3_model.h"
25
[7193]26#include "util/loading/resource_manager.h"
27#include "util/loading/load_param.h"
[3803]28#include "vector.h"
[4682]29#include "obb_tree.h"
[3608]30
[6430]31#include "glgui_bar.h"
32
[6002]33#include "state.h"
[7014]34#include "camera.h"
[6002]35
[7927]36#include "collision_handle.h"
[8190]37#include "collision_event.h"
[7927]38
[8190]39#include <stdarg.h>
[7927]40
[8190]41
[2036]42using namespace std;
43
[5208]44SHELL_COMMAND(model, WorldEntity, loadModel)
[6430]45->describe("sets the Model of the WorldEntity")
[7711]46->defaultValues("models/ships/fighter.obj", 1.0f);
[5208]47
[6424]48SHELL_COMMAND(debugEntity, WorldEntity, debugWE);
[5208]49
[2043]50/**
[4836]51 *  Loads the WordEntity-specific Part of any derived Class
[5498]52 *
53 * @param root: Normally NULL, as the Derived Entities define a loadParams Function themeselves,
54 *              that can calls WorldEntities loadParams for itself.
55 */
[6430]56WorldEntity::WorldEntity()
57    : Synchronizeable()
[2190]58{
[4320]59  this->setClassID(CL_WORLD_ENTITY, "WorldEntity");
[4597]60
[4682]61  this->obbTree = NULL;
[6700]62  this->healthWidget = NULL;
63  this->healthMax = 1.0f;
64  this->health = 1.0f;
[8190]65  this->damage = 0.0f; // no damage dealt by a default entity
[6695]66  this->scaling = 1.0f;
[4261]67
[6695]68  /* OSOLETE */
69  this->bVisible = true;
70  this->bCollide = true;
71
[6142]72  this->objectListNumber = OM_INIT;
73  this->objectListIterator = NULL;
74
[8190]75  // reset all collision handles to NULL == unsubscribed state
76  for(int i = 0; i < CREngine::CR_NUMBER; ++i)
77    this->collisionHandles[i] = NULL;
78  this->bReactive = false;
79
80  // registering default reactions:
[8490]81//   this->subscribeReaction(CREngine::CR_OBJECT_DAMAGE, CL_WORLD_ENTITY);
[8190]82
[6142]83  this->toList(OM_NULL);
[7927]84
[7954]85  modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName" ) );
86  scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling" ) );
[2190]87}
[2043]88
89/**
[4836]90 *  standard destructor
[2043]91*/
[2190]92WorldEntity::~WorldEntity ()
[2036]93{
[7125]94  State::getObjectManager()->toList(this, OM_INIT);
95
96  // Delete the model (unregister it with the ResourceManager)
97  for (unsigned int i = 0; i < this->models.size(); i++)
98    this->setModel(NULL, i);
99
[5498]100  // Delete the obbTree
[5302]101  if( this->obbTree != NULL)
[4814]102    delete this->obbTree;
[5994]103
[6700]104  if (this->healthWidget != NULL)
105    delete this->healthWidget;
[8190]106
107  this->unsubscribeReaction();
[3531]108}
109
[5498]110/**
111 * loads the WorldEntity Specific Parameters.
112 * @param root: the XML-Element to load the Data From
113 */
[4436]114void WorldEntity::loadParams(const TiXmlElement* root)
115{
[5498]116  // Do the PNode loading stuff
[6512]117  PNode::loadParams(root);
[5498]118
[6222]119  LoadParam(root, "md2texture", this, WorldEntity, loadMD2Texture)
[6430]120  .describe("the fileName of the texture, that should be loaded onto this world-entity. (must be relative to the data-dir)")
[7198]121  .defaultValues("");
[6222]122
[4436]123  // Model Loading
[5671]124  LoadParam(root, "model", this, WorldEntity, loadModel)
[6430]125  .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)")
[7198]126  .defaultValues("", 1.0f, 0);
[6430]127
[6700]128  LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax)
129  .describe("The Maximum health that can be loaded onto this entity")
[7198]130  .defaultValues(1.0f);
[6430]131
[6700]132  LoadParam(root, "health", this, WorldEntity, setHealth)
133  .describe("The Health the WorldEntity has at this moment")
[7198]134  .defaultValues(1.0f);
[4436]135}
136
[6222]137
[3531]138/**
[4885]139 * loads a Model onto a WorldEntity
[4836]140 * @param fileName the name of the model to load
[5057]141 * @param scaling the Scaling of the model
[7711]142 *
143 * FIXME
144 * @todo: separate the obb tree generation from the model
[7221]145 */
[7711]146void WorldEntity::loadModel(const std::string& fileName, float scaling, unsigned int modelNumber, unsigned int obbTreeDepth)
[4261]147{
[6695]148  this->modelLODName = fileName;
[6424]149  this->scaling = scaling;
[7954]150
151  std::string name = fileName;
152
153  if (  name.find( ResourceManager::getInstance()->getDataDir() ) == 0 )
154  {
155    name.erase(ResourceManager::getInstance()->getDataDir().size());
156  }
157
158  this->modelFileName = name;
159
[7221]160  if (!fileName.empty())
[6142]161  {
[6430]162    // search for the special character # in the LoadParam
[7221]163    if (fileName.find('#') != std::string::npos)
[6222]164    {
[7221]165      PRINTF(4)("Found # in %s... searching for LOD's\n", fileName.c_str());
166      std::string lodFile = fileName;
167      unsigned int offset = lodFile.find('#');
[6720]168      for (unsigned int i = 0; i < 3; i++)
[6005]169      {
[7221]170        lodFile[offset] = 48+(int)i;
[6222]171        if (ResourceManager::isInDataDir(lodFile))
172          this->loadModel(lodFile, scaling, i);
[6005]173      }
[6222]174      return;
175    }
[6720]176    if (this->scaling <= 0.0)
[6424]177    {
[7193]178      PRINTF(1)("YOU GAVE ME A CRAPY SCALE resetting to 1.0\n");
[6720]179      this->scaling = 1.0;
[6424]180    }
[7221]181    if(fileName.find(".obj") != std::string::npos)
[6222]182    {
[7221]183      PRINTF(4)("fetching OBJ file: %s\n", fileName.c_str());
[7193]184      BaseObject* loadedModel = ResourceManager::getInstance()->load(fileName, OBJ, RP_CAMPAIGN, this->scaling);
185      if (loadedModel != NULL)
186        this->setModel(dynamic_cast<Model*>(loadedModel), modelNumber);
[7221]187      else
188        PRINTF(1)("OBJ-File %s not found.\n", fileName.c_str());
[6222]189
190      if( modelNumber == 0)
[7711]191        this->buildObbTree(obbTreeDepth);
[6222]192    }
[7221]193    else if(fileName.find(".md2") != std::string::npos)
[6222]194    {
[7221]195      PRINTF(4)("fetching MD2 file: %s\n", fileName.c_str());
[7055]196      Model* m = new MD2Model(fileName, this->md2TextureFileName, this->scaling);
[6430]197      //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0);
[6222]198      this->setModel(m, 0);
[7068]199
200      if( m != NULL)
[7711]201        this->buildObbTree(obbTreeDepth);
[6222]202    }
[8490]203    else if(fileName.find(".md3") != std::string::npos)
204    {
205      PRINTF(4)("fetching MD3 file: %s\n", fileName.c_str());
206      Model* m = new md3::MD3Model(fileName, this->scaling);
207      this->setModel(m, 0);
208
209//       if( m != NULL)
210//         this->buildObbTree(obbTreeDepth);
211    }
[4732]212  }
213  else
[6341]214  {
[5995]215    this->setModel(NULL);
[6341]216  }
[4261]217}
218
[5061]219/**
[5994]220 * sets a specific Model for the Object.
221 * @param model The Model to set
222 * @param modelNumber the n'th model in the List to get.
223 */
224void WorldEntity::setModel(Model* model, unsigned int modelNumber)
225{
[5995]226  if (this->models.size() <= modelNumber)
227    this->models.resize(modelNumber+1, NULL);
228
229  if (this->models[modelNumber] != NULL)
[6004]230  {
[7193]231    Resource* resource = ResourceManager::getInstance()->locateResourceByPointer(dynamic_cast<BaseObject*>(this->models[modelNumber]));
[7123]232    if (resource != NULL)
233      ResourceManager::getInstance()->unload(resource, RP_LEVEL);
234    else
235    {
236      PRINTF(4)("Forcing model deletion\n");
237      delete this->models[modelNumber];
238    }
[5994]239  }
[6222]240
[5995]241  this->models[modelNumber] = model;
[5994]242
[6222]243
[6430]244  //   if (this->model != NULL)
245  //     this->buildObbTree(4);
[5994]246}
247
248
249/**
[5061]250 * builds the obb-tree
251 * @param depth the depth to calculate
252 */
[7711]253bool WorldEntity::buildObbTree(int depth)
[5061]254{
[5428]255  if (this->obbTree)
256    delete this->obbTree;
257
[5995]258  if (this->models[0] != NULL)
[5428]259  {
[7711]260    this->obbTree = new OBBTree(depth, models[0]->getModelInfo(), this);
[5428]261    return true;
262  }
263  else
264  {
[7711]265    PRINTF(1)("could not create obb-tree, because no model was loaded yet\n");
[5428]266    this->obbTree = NULL;
267    return false;
268  }
[5061]269}
[5057]270
[7927]271
[6142]272/**
[7927]273 * subscribes this world entity to a collision reaction
274 *  @param type the type of reaction to subscribe to
[8190]275 *  @param target1 a filter target (classID)
276 */
277void WorldEntity::subscribeReaction(CREngine::CRType type, long target1)
278{
279  this->subscribeReaction(type);
280
281  // add the target filter
282  this->collisionHandles[type]->addTarget(target1);
283}
284
285
286/**
287 * subscribes this world entity to a collision reaction
288 *  @param type the type of reaction to subscribe to
289 *  @param target1 a filter target (classID)
290 */
291void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2)
292{
293  this->subscribeReaction(type);
294
295  // add the target filter
296  this->collisionHandles[type]->addTarget(target1);
297  this->collisionHandles[type]->addTarget(target2);
298}
299
300
301/**
302 * subscribes this world entity to a collision reaction
303 *  @param type the type of reaction to subscribe to
304 *  @param target1 a filter target (classID)
305 */
306void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3)
307{
308  this->subscribeReaction(type);
309
310  // add the target filter
311  this->collisionHandles[type]->addTarget(target1);
312  this->collisionHandles[type]->addTarget(target2);
313  this->collisionHandles[type]->addTarget(target3);
314}
315
316
317/**
318 * subscribes this world entity to a collision reaction
319 *  @param type the type of reaction to subscribe to
320 *  @param target1 a filter target (classID)
321 */
322void WorldEntity::subscribeReaction(CREngine::CRType type, long target1, long target2, long target3, long target4)
323{
324  this->subscribeReaction(type);
325
326  // add the target filter
327  this->collisionHandles[type]->addTarget(target1);
328  this->collisionHandles[type]->addTarget(target2);
329  this->collisionHandles[type]->addTarget(target3);
330  this->collisionHandles[type]->addTarget(target4);
331}
332
333
334/**
335 * subscribes this world entity to a collision reaction
336 *  @param type the type of reaction to subscribe to
[7927]337 *  @param nrOfTargets number of target filters
338 *  @param ... the targets as classIDs
339 */
[8190]340void WorldEntity::subscribeReaction(CREngine::CRType type)
341{
342  if( this->collisionHandles[type] != NULL)  {
343    PRINTF(2)("Registering for a CollisionReaction already subscribed to! Skipping\n");
344    return;
345  }
[7927]346
[8190]347  this->collisionHandles[type] = CREngine::getInstance()->subscribeReaction(this, type);
[7927]348
[8190]349  // now there is at least one collision reaction subscribed
350  this->bReactive = true;
351}
352
353
[7927]354/**
[8190]355 * unsubscribes a specific reaction from the worldentity
356 *  @param type the reaction to unsubscribe
357 */
358void WorldEntity::unsubscribeReaction(CREngine::CRType type)
359{
360  if( this->collisionHandles[type] == NULL)
361    return;
362
363  CREngine::getInstance()->unsubscribeReaction(this->collisionHandles[type]);
364  this->collisionHandles[type] = NULL;
365
366  // check if there is still any handler registered
367  for(int i = 0; i < CREngine::CR_NUMBER; ++i)
368  {
369    if( this->collisionHandles[i] != NULL)
370    {
371      this->bReactive = true;
372      return;
373    }
374  }
375  this->bReactive = false;
376}
377
378
379/**
380 * unsubscribes all collision reactions
381 */
382void WorldEntity::unsubscribeReaction()
383{
384  for( int i = 0; i < CREngine::CR_NUMBER; i++)
385    this->unsubscribeReaction((CREngine::CRType)i);
386
387  // there are no reactions subscribed from now on
388  this->bReactive = false;
389}
390
391
392/**
393 * registers a new collision event to this world entity
394 *  @param entityA entity of the collision
395 *  @param entityB entity of the collision
396 *  @param bvA colliding bounding volume of entityA
397 *  @param bvB colliding bounding volume of entityA
398 */
399bool WorldEntity::registerCollision(WorldEntity* entityA, WorldEntity* entityB, BoundingVolume* bvA, BoundingVolume* bvB)
400{
401  // is there any handler listening?
402  if( !this->bReactive)
403    return false;
404
405  // get a collision event
406  CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
407  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
408  c->collide(entityA, entityB, bvA, bvB);
409
410  for( int i = 0; i < CREngine::CR_NUMBER; ++i)
411    if( this->collisionHandles[i] != NULL)
412      this->collisionHandles[i]->registerCollisionEvent(c);
[8316]413  return true;
[8190]414}
415
416
417/**
418 * registers a new collision event to this woeld entity
419 *  @param entity the entity that collides
420 *  @param plane it stands on
421 *  @param position it collides on the plane
422 */
[8490]423bool WorldEntity::registerCollision(WorldEntity* entity, WorldEntity* groundEntity, Vector normal, Vector position)
[8190]424{
425  // is there any handler listening?
426  if( !this->bReactive)
427    return false;
428
[8929]429
[8190]430  // get a collision event
431  CollisionEvent* c = CREngine::getInstance()->popCollisionEventObject();
432  assert(c != NULL); // if this should fail: we got not enough precached CollisionEvents: alter value in cr_defs.h
[8490]433  c->collide(entity, groundEntity, normal, position);
[8190]434
435  for( int i = 0; i < CREngine::CR_NUMBER; ++i)
436    if( this->collisionHandles[i] != NULL)
437      this->collisionHandles[i]->registerCollisionEvent(c);
[8316]438  return true;
[8190]439}
440
441
442/**
[6142]443 * @brief moves this entity to the List OM_List
444 * @param list the list to set this Entity to.
445 *
446 * this is the same as a call to State::getObjectManager()->toList(entity , list);
447 * directly, but with an easier interface.
448 *
449 * @todo inline this (peut etre)
450 */
451void WorldEntity::toList(OM_LIST list)
452{
453  State::getObjectManager()->toList(this, list);
454}
[5061]455
[8037]456void WorldEntity::toReflectionList()
457{
458  State::getObjectManager()->toReflectionList( this );
459}
[6142]460
[8037]461void removeFromReflectionList()
462{
463/// TODO
464///  State::getObject
465}
[6142]466
[4261]467/**
[4885]468 * sets the character attributes of a worldentity
[4836]469 * @param character attributes
[4885]470 *
471 * these attributes don't have to be set, only use them, if you need them
[2043]472*/
[5498]473//void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
474//{}
[2036]475
[3583]476
[2043]477/**
[5029]478 *  this function is called, when two entities collide
479 * @param entity: the world entity with whom it collides
480 *
481 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
482 */
483void WorldEntity::collidesWith(WorldEntity* entity, const Vector& location)
484{
[5498]485  /**
486   * THIS IS A DEFAULT COLLISION-Effect.
487   * IF YOU WANT TO CREATE A SPECIFIC COLLISION ON EACH OBJECT
488   * USE::
489   * if (entity->isA(CL_WHAT_YOU_ARE_LOOKING_FOR)) { printf "dothings"; };
490   *
491   * You can always define a default Action.... don't be affraid just test it :)
492   */
[6430]493  //  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassName(), entity->getClassName(), location.x, location.y, location.z);
[5029]494}
495
[2043]496
497/**
[8186]498 *  this function is called, when two entities collide
499 * @param entity: the world entity with whom it collides
500 *
501 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
502 */
503void WorldEntity::collidesWithGround(const Vector& location)
504{
505  PRINTF(0)("BSP_GROUND: %s collides \n", this->getClassName() );
506}
507
508void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2)
509{
[8190]510
[8186]511  // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassName() );
[8190]512
[8186]513  Vector v = this->getAbsDirX();
[8490]514  v.x *= 10.1;
515  v.y *= 10.1;
516  v.z *= 10.1;
517  Vector u = Vector(0.0,-20.0,0.0);
[8190]518
[8490]519
520  if(!(this->getAbsCoor().x == ray_2.x && this->getAbsCoor().y == ray_2.y && this->getAbsCoor().z == ray_2.z) )
[8186]521  {
[8190]522
[8186]523  this->setAbsCoor(ray_2 - v);
[8490]524
[8186]525  }
[8490]526    else
[8186]527  {
528    if(ray_1.x == this->getAbsCoor().x + v.x && ray_1.y == this->getAbsCoor().y + v.y + 0.1 && ray_1.z ==this->getAbsCoor().z + v.z)
529    {
[8190]530      this->setAbsCoor(feet -u );
[8186]531    }
[8190]532
533    this->setAbsCoor(ray_2 - v);
534
[8186]535  }
[8490]536
537
[8186]538}
539
540/**
[5498]541 *  this is called immediately after the Entity has been constructed, initialized and then Spawned into the World
[4885]542 *
[5498]543 */
[3229]544void WorldEntity::postSpawn ()
[6430]545{}
[2043]546
[3583]547
[2043]548/**
[6959]549 *  this method is called by the world if the WorldEntity leaves the game
[5498]550 */
[6959]551void WorldEntity::leaveWorld ()
[6430]552{}
[2043]553
[3583]554
[2190]555/**
[7085]556 * resets the WorldEntity to its initial values. eg. used for multiplayer games: respawning
557 */
558void WorldEntity::reset()
559{}
560
561/**
[4836]562 *  this method is called every frame
563 * @param time: the time in seconds that has passed since the last tick
[4885]564 *
565 * Handle all stuff that should update with time inside this method (movement, animation, etc.)
[2043]566*/
[4570]567void WorldEntity::tick(float time)
[6430]568{}
[3583]569
[5498]570
[3583]571/**
[4836]572 *  the entity is drawn onto the screen with this function
[4885]573 *
574 * This is a central function of an entity: call it to let the entity painted to the screen.
575 * Just override this function with whatever you want to be drawn.
[3365]576*/
[5500]577void WorldEntity::draw() const
[3803]578{
[6430]579  //PRINTF(0)("(%s::%s)\n", this->getClassName(), this->getName());
[6281]580  //  assert(!unlikely(this->models.empty()));
[6002]581  {
582    glMatrixMode(GL_MODELVIEW);
583    glPushMatrix();
[4570]584
[6002]585    /* translate */
586    glTranslatef (this->getAbsCoor ().x,
587                  this->getAbsCoor ().y,
588                  this->getAbsCoor ().z);
[6004]589    Vector tmpRot = this->getAbsDir().getSpacialAxis();
590    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[2043]591
[6004]592
593    // This Draws the LOD's
[7014]594    float cameraDistance = State::getCamera()->distance(this);
[6004]595    if (cameraDistance > 30 && this->models.size() >= 3 && this->models[2] != NULL)
[6002]596    {
[6222]597      this->models[2]->draw();
[6004]598    }
599    else if (cameraDistance > 10 && this->models.size() >= 2 && this->models[1] != NULL)
[6002]600    {
601      this->models[1]->draw();
[6004]602    }
603    else if (this->models.size() >= 1 && this->models[0] != NULL)
[6002]604    {
605      this->models[0]->draw();
606    }
607    glPopMatrix();
608  }
[3803]609}
[3583]610
[6430]611/**
[6700]612 * @param health the Health to add.
613 * @returns the health left (this->healthMax - health+this->health)
[6430]614 */
[6700]615float WorldEntity::increaseHealth(float health)
[6430]616{
[6700]617  this->health += health;
618  if (this->health > this->healthMax)
[6430]619  {
[6700]620    float retHealth = this->healthMax - this->health;
621    this->health = this->healthMax;
622    this->updateHealthWidget();
623    return retHealth;
[6430]624  }
[6700]625  this->updateHealthWidget();
[6430]626  return 0.0;
627}
[6281]628
[5498]629/**
[6700]630 * @param health the Health to be removed
[6430]631 * @returns 0.0 or the rest, that was not substracted (bellow 0.0)
632 */
[6700]633float WorldEntity::decreaseHealth(float health)
[6430]634{
[6700]635  this->health -= health;
[6430]636
[6700]637  if (this->health < 0)
[6430]638  {
[6700]639    float retHealth = -this->health;
640    this->health = 0.0f;
641    this->updateHealthWidget();
642    return retHealth;
[6430]643  }
[6700]644  this->updateHealthWidget();
[6430]645  return 0.0;
646
647}
648
649/**
[6700]650 * @param maxHealth the maximal health that can be loaded onto the entity.
[6430]651 */
[6700]652void WorldEntity::setHealthMax(float healthMax)
[6430]653{
[6700]654  this->healthMax = healthMax;
655  if (this->health > this->healthMax)
[6430]656  {
[6700]657    PRINTF(3)("new maxHealth is bigger as the old health. Did you really intend to do this for (%s::%s)\n", this->getClassName(), this->getName());
658    this->health = this->healthMax;
[6430]659  }
[6700]660  this->updateHealthWidget();
[6430]661}
662
[6431]663/**
[6700]664 * @brief creates the HealthWidget
[6431]665 *
[6700]666 * since not all entities need an HealthWidget, it is only created on request.
[6431]667 */
[6700]668void WorldEntity::createHealthWidget()
[6430]669{
[6700]670  if (this->healthWidget == NULL)
[6430]671  {
[7779]672    this->healthWidget = new OrxGui::GLGuiBar();
[6700]673    this->healthWidget->setSize2D(30,400);
674    this->healthWidget->setAbsCoor2D(10,100);
[6430]675
[6700]676    this->updateHealthWidget();
[6430]677  }
678  else
[6700]679    PRINTF(3)("Allready created the HealthWidget for %s::%s\n", this->getClassName(), this->getName());
[6430]680}
681
[6700]682void WorldEntity::increaseHealthMax(float increaseHealth)
[6440]683{
[6700]684  this->healthMax += increaseHealth;
685  this->updateHealthWidget();
[6440]686}
687
[6700]688
[7779]689OrxGui::GLGuiWidget* WorldEntity::getHealthWidget()
[6700]690{
691  this->createHealthWidget();
692  return this->healthWidget;
693}
694
[6431]695/**
[6700]696 * @param visibility shows or hides the health-bar
[6431]697 * (creates the widget if needed)
698 */
[6700]699void WorldEntity::setHealthWidgetVisibilit(bool visibility)
[6430]700{
[7198]701  if (visibility)
702  {
703    if (this->healthWidget != NULL)
704      this->healthWidget->show();
705    else
[6430]706    {
[7198]707      this->createHealthWidget();
708      this->updateHealthWidget();
709      this->healthWidget->show();
[6430]710    }
[7198]711  }
712  else if (this->healthWidget != NULL)
713    this->healthWidget->hide();
[6430]714}
715
[6431]716/**
[6700]717 * @brief updates the HealthWidget
[6431]718 */
[6700]719void WorldEntity::updateHealthWidget()
[6430]720{
[6700]721  if (this->healthWidget != NULL)
[6430]722  {
[6700]723    this->healthWidget->setMaximum(this->healthMax);
724    this->healthWidget->setValue(this->health);
[6430]725  }
726}
727
728
729/**
[5498]730 * DEBUG-DRAW OF THE BV-Tree.
731 * @param depth What depth to draw
732 * @param drawMode the mode to draw this entity under
733 */
[7711]734void WorldEntity::drawBVTree(int depth, int drawMode) const
[4684]735{
736  glMatrixMode(GL_MODELVIEW);
737  glPushMatrix();
738  /* translate */
739  glTranslatef (this->getAbsCoor ().x,
740                this->getAbsCoor ().y,
741                this->getAbsCoor ().z);
742  /* rotate */
[4998]743  Vector tmpRot = this->getAbsDir().getSpacialAxis();
744  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[4684]745
[7711]746
[4684]747  if (this->obbTree)
748    this->obbTree->drawBV(depth, drawMode);
[7711]749
750
[4684]751  glPopMatrix();
752}
[6341]753
[6424]754
[6341]755/**
[6424]756 * Debug the WorldEntity
757 */
758void WorldEntity::debugEntity() const
759{
760  PRINT(0)("WorldEntity %s::%s  (DEBUG)\n", this->getClassName(), this->getName());
761  this->debugNode();
762  PRINT(0)("List: %s ; ModelCount %d - ", ObjectManager::OMListToString(this->objectListNumber) , this->models.size());
763  for (unsigned int i = 0; i < this->models.size(); i++)
764  {
765    if (models[i] != NULL)
766      PRINT(0)(" : %d:%s", i, this->models[i]->getName());
767  }
768  PRINT(0)("\n");
769
770}
771
772
773/**
[7954]774 * handler for changes on registred vars
775 * @param id id's which changed
[6341]776 */
[7954]777void WorldEntity::varChangeHandler( std::list< int > & id )
[6341]778{
[7954]779  if ( std::find( id.begin(), id.end(), modelFileName_handle ) != id.end() ||
780       std::find( id.begin(), id.end(), scaling_handle ) != id.end()
781     )
[6341]782  {
[7954]783    loadModel( modelFileName, scaling );
[6341]784  }
785
[7954]786  PNode::varChangeHandler( id );
[6341]787}
788
Note: See TracBrowser for help on using the repository browser.