Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/mount_points/src/world_entities/world_entity.cc @ 10201

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

tracing a bug within the mp structure

File size: 22.3 KB
Line 
1
2
3/*
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, Benjamin Grauer
15   co-programmer: Christian Meier
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
18
19#include "world_entity.h"
20#include "shell_command.h"
21
22#include "util/loading/resource_manager.h"
23#include "resource_obj.h"
24#include "md2/md2Model.h"
25#include "md3/md3_model.h"
26
27#include "oif/object_information_file.h"
28#include "mount_point.h"
29
30#include "aabb_tree_node.h"
31
32#include "util/loading/load_param.h"
33#include "obb_tree.h"
34
35#include "elements/glgui_energywidget.h"
36
37#include "state.h"
38#include "camera.h"
39
40#include "collision_filter.h"
41#include "collision_event.h"
42#include "game_rules.h"
43#include "kill.h"
44#include "debug.h"
45
46#include "projectiles/projectile.h"
47
48SHELL_COMMAND(model, WorldEntity, loadModel)
49->describe("sets the Model of the WorldEntity")
50->defaultValues("models/ships/fighter.obj", 1.0f);
51
52SHELL_COMMAND(debugEntity, WorldEntity, debugWE);
53
54
55ObjectListDefinition(WorldEntity);
56/**
57 *  Loads the WordEntity-specific Part of any derived Class
58 *
59 * @param root: Normally NULL, as the Derived Entities define a loadParams Function themeselves,
60 *              that can calls WorldEntities loadParams for itself.
61 */
62WorldEntity::WorldEntity()
63  : Synchronizeable(), _collisionFilter(this)
64{
65  this->registerObject(this, WorldEntity::_objectList);
66
67  this->obbTree = NULL;
68  this->aabbNode = NULL;
69  this->healthWidget = NULL;
70  this->healthMax = 1.0f;
71  this->health = 1.0f;
72  this->damage = 0.0f; // no damage dealt by a default entity
73  this->scaling = 1.0f;
74  this->oiFile = NULL;
75
76  /* OSOLETE */
77  this->bVisible = true;
78  this->bCollide = true;
79
80  this->objectListNumber = OM_INIT;
81  this->lastObjectListNumber = OM_INIT;
82
83  this->_bOnGround = false;
84
85  // registering default reactions:
86  this->subscribeReaction(CoRe::CREngine::CR_OBJECT_DAMAGE, Projectile::staticClassID());
87
88  this->toList(OM_NULL);
89
90  this->registerVar( new SynchronizeableString( &this->md2TextureFileName, &this->md2TextureFileName, "md2TextureFileName", PERMISSION_MASTER_SERVER ) );
91  this->modelFileName_handle = registerVarId( new SynchronizeableString( &modelFileName, &modelFileName, "modelFileName", PERMISSION_MASTER_SERVER ) );
92  this->scaling_handle = registerVarId( new SynchronizeableFloat( &scaling, &scaling, "scaling", PERMISSION_MASTER_SERVER ) );
93  this->list_handle = registerVarId( new SynchronizeableInt( (int*)&objectListNumber, &list_write, "list", PERMISSION_MASTER_SERVER ) );
94
95  this->health_handle = registerVarId( new SynchronizeableFloat( &this->health, &this->health_write, "health", PERMISSION_MASTER_SERVER ) );
96  this->healthMax_handle = registerVarId( new SynchronizeableFloat( &this->healthMax, &this->healthMax_write, "maxHealth", PERMISSION_MASTER_SERVER ) );
97}
98
99/**
100 *  standard destructor
101*/
102WorldEntity::~WorldEntity ()
103{
104  State::getObjectManager()->toList(this, OM_INIT);
105
106  // Delete the model (unregister it with the ResourceManager)
107  for (unsigned int i = 0; i < this->models.size(); i++)
108    this->setModel(NULL, i);
109
110  // remove the object information file
111  if( this->oiFile)
112    delete this->oiFile;
113  // and clear all monut points
114  this->mountPoints.clear();
115
116  // Delete the obbTree
117  if( this->obbTree != NULL)
118    delete this->obbTree;
119
120  if (this->healthWidget != NULL)
121    delete this->healthWidget;
122
123  this->unsubscribeReactions();
124}
125
126/**
127 * loads the WorldEntity Specific Parameters.
128 * @param root: the XML-Element to load the Data From
129 */
130void WorldEntity::loadParams(const TiXmlElement* root)
131{
132  // Do the PNode loading stuff
133  PNode::loadParams(root);
134
135  LoadParam(root, "md2texture", this, WorldEntity, loadMD2Texture)
136  .describe("the fileName of the texture, that should be loaded onto this world-entity. (must be relative to the data-dir)")
137  .defaultValues("");
138
139  // Model Loading
140  LoadParam(root, "model", this, WorldEntity, loadModel)
141  .describe("the fileName of the model, that should be loaded onto this world-entity. (must be relative to the data-dir)")
142  .defaultValues("", 1.0f, 0);
143
144  LoadParam(root, "maxHealth", this, WorldEntity, setHealthMax)
145  .describe("The Maximum health that can be loaded onto this entity")
146  .defaultValues(1.0f);
147
148  LoadParam(root, "health", this, WorldEntity, setHealth)
149  .describe("The Health the WorldEntity has at this moment")
150  .defaultValues(1.0f);
151
152  LoadParam(root, "list", this, WorldEntity, toListS);
153}
154
155
156/**
157 * loads a Model onto a WorldEntity
158 * @param fileName the name of the model to load
159 * @param scaling the Scaling of the model
160 *
161 * FIXME
162 * @todo: separate the obb tree generation from the model
163 */
164void WorldEntity::loadModel(const std::string& fileName, float scaling, unsigned int modelNumber, unsigned int obbTreeDepth)
165{
166  this->modelLODName = fileName;
167  this->scaling = scaling;
168
169  std::string name = fileName;
170
171  if (  name.find( Resources::ResourceManager::getInstance()->mainGlobalPath().name() ) == 0 )
172  {
173    name.erase(Resources::ResourceManager::getInstance()->mainGlobalPath().name().size());
174  }
175
176  this->modelFileName = name;
177
178  if (!fileName.empty())
179  {
180    // search for the special character # in the LoadParam
181    if (fileName.find('#') != std::string::npos)
182    {
183      PRINTF(4)("Found # in %s... searching for LOD's\n", fileName.c_str());
184      std::string lodFile = fileName;
185      unsigned int offset = lodFile.find('#');
186      for (unsigned int i = 0; i < 3; i++)
187      {
188        lodFile[offset] = 48+(int)i;
189        if (Resources::ResourceManager::getInstance()->checkFileInMainPath( lodFile))
190          this->loadModel(lodFile, scaling, i);
191      }
192      return;
193    }
194    if (this->scaling <= 0.0)
195    {
196      PRINTF(1)("YOU GAVE ME A CRAPY SCALE resetting to 1.0\n");
197      this->scaling = 1.0;
198    }
199    /// LOADING AN OBJ FILE
200    if(fileName.find(".obj") != std::string::npos)
201    {
202      PRINTF(4)("fetching OBJ file: %s\n", fileName.c_str());
203      // creating the model and loading it
204      StaticModel* model = new StaticModel();
205      *model = ResourceOBJ(fileName, this->scaling);
206
207      // check if ther is a valid model and load other stuff
208      if (model->getVertexCount() > 0)
209      {
210        this->setModel(model, modelNumber);
211        PRINTF(0)("model number: %i\n", modelNumber);
212
213        if( modelNumber == 0)
214        {
215          this->buildObbTree(obbTreeDepth);
216
217          // now get the object information file for this model, if any
218          std::string oifName = fileName.substr(0, fileName.length() - 4) + ".oif";
219          this->loadMountPoints( oifName);
220        }
221      }
222      else
223        delete model;
224    }
225    /// LOADING AN MD2-model
226    else if(fileName.find(".md2") != std::string::npos)
227    {
228      PRINTF(4)("fetching MD2 file: %s\n", fileName.c_str());
229      Model* m = new MD2Model(fileName, this->md2TextureFileName, this->scaling);
230      //this->setModel((Model*)ResourceManager::getInstance()->load(fileName, MD2, RP_CAMPAIGN), 0);
231      this->setModel(m, 0);
232
233      if( m != NULL)
234        this->buildObbTree(obbTreeDepth);
235    }
236    /// LOADING AN MD3-MODEL.
237    else if(fileName.find(".md3") != std::string::npos)
238    {
239      PRINTF(4)("fetching MD3 file: %s\n", fileName.c_str());
240//      Model* m = new md3::MD3Model(fileName, this->scaling);
241//      this->setModel(m, 0);
242
243      //       if( m != NULL)
244      //         this->buildObbTree(obbTreeDepth);
245    }
246  }
247  else
248  {
249    this->setModel(NULL);
250  }
251}
252
253/**
254 * sets a specific Model for the Object.
255 * @param model The Model to set
256 * @param modelNumber the n'th model in the List to get.
257 */
258void WorldEntity::setModel(Model* model, unsigned int modelNumber)
259{
260  if (this->models.size() <= modelNumber)
261    this->models.resize(modelNumber+1, NULL);
262
263  if (this->models[modelNumber] != NULL)
264  {
265    delete this->models[modelNumber];
266  }
267
268  this->models[modelNumber] = model;
269}
270
271
272
273/**
274 * loads the object information file for this model
275 * @param fileName the name of the file
276 */
277void WorldEntity::loadMountPoints(const std::string& fileName)
278{
279  PRINTF(0)("loading the oif File: %s\n", fileName.c_str());
280
281
282  // first get all mount points from the model
283  std::list<mountPointSkeleton> mpList = this->getModel()->getMountPoints();
284  // for each skeleton create a mounting point world entity
285  std::list<mountPointSkeleton>::const_iterator it = mpList.begin();
286
287  PRINTF(0)("->>>> size: %i\n", mpList.size());
288
289  for( ; it != mpList.end(); it++)
290  {
291    MountPoint* mp = new MountPoint( (*it).up, (*it).forward, (*it).center, (*it).name);
292
293    std::string nrStr = (*it).name.substr(1, 2);
294
295    PRINTF(0)("got mp nr: %s\n", nrStr.c_str());
296
297    this->addMountPoint(mp);
298  }
299
300  // now load the object information file
301  this->oiFile = new ObjectInformationFile(fileName);
302
303  PRINTF(0)("\n");
304
305
306
307}
308
309
310/**
311 * builds the obb-tree
312 * @param depth the depth to calculate
313 */
314bool WorldEntity::buildObbTree(int depth)
315{
316  if( this->obbTree != NULL)
317  {
318    delete this->obbTree;
319    this->obbTree = NULL;
320  }
321
322  if (this->models[0] != NULL)
323    this->obbTree = new OBBTree(depth, models[0]->getModelInfo(), this);
324  else
325  {
326    PRINTF(1)("could not create obb-tree, because no model was loaded yet\n");
327    this->obbTree = NULL;
328    return false;
329  }
330
331
332  // create the axis aligned bounding box
333  if( this->aabbNode != NULL)
334  {
335    delete this->aabbNode;
336    this->aabbNode = NULL;
337  }
338
339  if( this->models[0] != NULL)
340  {
341    this->aabbNode = new AABBTreeNode();
342    this->aabbNode->spawnBVTree(this->models[0]);
343  }
344  else
345  {
346    PRINTF(1)("could not create aabb bounding box, because no model was loaded yet\n");
347    this->aabbNode = NULL;
348    return false;
349  }
350  return true;
351}
352
353
354/**
355 * adds a mount point to the end of the list
356 * @param mountPoint point to be added
357 */
358void WorldEntity::addMountPoint(MountPoint* mountPoint)
359{
360  // add the mount point at the last position
361  this->mountPoints.push_back(mountPoint);
362}
363
364/**
365 * adds a mount point to a world entity
366 * @param mountPoint point to be added
367 */
368void WorldEntity::addMountPoint(int slot, MountPoint* mountPoint)
369{
370  if( this->mountPoints[slot] != NULL)
371  {
372    PRINTF(0)("adding a mount point to a slot, that already exists! ignoring - maybe some object do not get connected well (object: %s)\n", this->getClassCName());
373  }
374
375  // just connect the mount point
376  this->mountPoints[slot] = mountPoint;
377}
378
379
380/**
381 * mounts a world entity on a specified mount point (~socket)
382 * @param entity entity to be connected
383 */
384void WorldEntity::mount(int slot, WorldEntity* entity)
385{
386  if( this->mountPoints[slot] == NULL)
387  {
388    PRINTF(0)("you tried to add an entity to a mount point that doesn't exist (slot %i)\n", slot);
389    return;
390  }
391
392  // mount the entity
393  this->mountPoints[slot]->mount(entity);
394}
395
396
397/**
398 * removes a mount point from a specified mount point
399 * @param mountPoint entity to be unconnected
400 */
401void WorldEntity::unmount(int slot)
402{
403    if( this->mountPoints[slot] == NULL)
404  {
405    PRINTF(0)("you tried to remove an entity from a mount point that doesn't exist (slot %i)\n", slot);
406    return;
407  }
408
409  // unmount the entity
410  this->mountPoints[slot]->unmount();
411}
412
413
414/**
415 * subscribes this world entity to a collision reaction
416 *  @param type the type of reaction to subscribe to
417 *  @param target1 a filter target (classID)
418 */
419void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1)
420{
421  this->_collisionFilter.subscribeReaction(type, target1);
422}
423
424
425/**
426 * subscribes this world entity to a collision reaction
427 *  @param type the type of reaction to subscribe to
428 *  @param target1 a filter target (classID)
429 */
430void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2)
431{
432  this->_collisionFilter.subscribeReaction(type, target1, target2);
433}
434
435
436/**
437 * subscribes this world entity to a collision reaction
438 *  @param type the type of reaction to subscribe to
439 *  @param target1 a filter target (classID)
440 */
441void WorldEntity::subscribeReaction(CoRe::CREngine::ReactionType type, const ClassID& target1, const ClassID& target2, const ClassID& target3)
442{
443  this->_collisionFilter.subscribeReaction(type, target1, target2, target3);
444}
445
446
447/**
448 * unsubscribes a specific reaction from the worldentity
449 *  @param type the reaction to unsubscribe
450 */
451void WorldEntity::unsubscribeReaction(CoRe::CREngine::ReactionType type)
452{
453  this->_collisionFilter.unsubscribeReaction(type);
454}
455
456
457/**
458 * unsubscribes all collision reactions
459 */
460void WorldEntity::unsubscribeReactions()
461{
462  this->_collisionFilter.unsubscribeReactions();
463}
464
465
466/**
467 * @brief moves this entity to the List OM_List
468 * @param list the list to set this Entity to.
469 *
470 * this is the same as a call to State::getObjectManager()->toList(entity , list);
471 * directly, but with an easier interface.
472 *
473 * @todo inline this (peut etre)
474 */
475void WorldEntity::toList(OM_LIST list)
476{
477  State::getObjectManager()->toList(this, list);
478}
479
480void WorldEntity::toListS(const std::string& listName)
481{
482  OM_LIST id = ObjectManager::StringToOMList(listName);
483  if (id != OM_NULL)
484    this->toList(id);
485  else
486    PRINTF(2)("List %s not found\n", listName.c_str());
487}
488
489
490void WorldEntity::toReflectionList()
491{
492  State::getObjectManager()->toReflectionList( this );
493}
494
495void removeFromReflectionList()
496{
497  /// TODO
498  ///  State::getObject
499}
500
501/**
502 * sets the character attributes of a worldentity
503 * @param character attributes
504 *
505 * these attributes don't have to be set, only use them, if you need them
506*/
507//void WorldEntity::setCharacterAttributes(CharacterAttributes* charAttr)
508//{}
509
510
511/**
512 *  this function is called, when two entities collide
513 * @param entity: the world entity with whom it collides
514 *
515 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
516 */
517void WorldEntity::collidesWith(WorldEntity* entity, const Vector& location)
518{
519  /**
520   * THIS IS A DEFAULT COLLISION-Effect.
521   * IF YOU WANT TO CREATE A SPECIFIC COLLISION ON EACH OBJECT
522   * USE::
523   * if (entity->isA(CL_WHAT_YOU_ARE_LOOKING_FOR)) { printf "dothings"; };
524   *
525   * You can always define a default Action.... don't be affraid just test it :)
526   */
527  //  PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassCName(), entity->getClassCName(), location.x, location.y, location.z);
528}
529
530
531/**
532 *  this function is called, when two entities collide
533 * @param entity: the world entity with whom it collides
534 *
535 * Implement behaviour like damage application or other miscellaneous collision stuff in this function
536 */
537void WorldEntity::collidesWithGround(const Vector& location)
538{
539  PRINTF(0)("BSP_GROUND: %s collides \n", this->getClassCName() );
540}
541
542void WorldEntity::collidesWithGround(const Vector& feet, const Vector& ray_1, const Vector& ray_2)
543{
544
545  // PRINTF(0)("BSP_GROUND: Player collides \n", this->getClassCName() );
546
547  Vector v = this->getAbsDirX();
548  v.x *= 10.1;
549  v.y *= 10.1;
550  v.z *= 10.1;
551  Vector u = Vector(0.0,-20.0,0.0);
552
553
554  if(!(this->getAbsCoor().x == ray_2.x && this->getAbsCoor().y == ray_2.y && this->getAbsCoor().z == ray_2.z) )
555  {
556
557    this->setAbsCoor(ray_2 - v);
558
559  }
560  else
561  {
562    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)
563    {
564      this->setAbsCoor(feet -u );
565    }
566
567    this->setAbsCoor(ray_2 - v);
568
569  }
570
571
572}
573
574/**
575 *  this is called immediately after the Entity has been constructed, initialized and then Spawned into the World
576 *
577 */
578void WorldEntity::postSpawn ()
579{}
580
581
582/**
583 *  this method is called by the world if the WorldEntity leaves the game
584 */
585void WorldEntity::leaveWorld ()
586{}
587
588
589/**
590 * resets the WorldEntity to its initial values. eg. used for multiplayer games: respawning
591 */
592void WorldEntity::reset()
593{
594  this->setHealth( this->getHealthMax() );
595}
596
597/**
598 *  this method is called every frame
599 * @param time: the time in seconds that has passed since the last tick
600 *
601 * Handle all stuff that should update with time inside this method (movement, animation, etc.)
602*/
603void WorldEntity::tick(float time)
604{}
605
606
607/**
608 *  the entity is drawn onto the screen with this function
609 *
610 * This is a central function of an entity: call it to let the entity painted to the screen.
611 * Just override this function with whatever you want to be drawn.
612*/
613void WorldEntity::draw() const
614{
615  //PRINTF(0)("(%s::%s)\n", this->getClassCName(), this->getName());
616  //  assert(!unlikely(this->models.empty()));
617  {
618    glMatrixMode(GL_MODELVIEW);
619    glPushMatrix();
620
621    /* translate */
622    glTranslatef (this->getAbsCoor ().x,
623                  this->getAbsCoor ().y,
624                  this->getAbsCoor ().z);
625    Vector tmpRot = this->getAbsDir().getSpacialAxis();
626    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
627
628
629    // This Draws the LOD's
630    float cameraDistance = State::getCamera()->distance(this);
631    if (cameraDistance > 30 && this->models.size() >= 3 && this->models[2] != NULL)
632    {
633      this->models[2]->draw();
634    }
635    else if (cameraDistance > 10 && this->models.size() >= 2 && this->models[1] != NULL)
636    {
637      this->models[1]->draw();
638    }
639    else if (this->models.size() >= 1 && this->models[0] != NULL)
640    {
641      this->models[0]->draw();
642    }
643
644    //     if( this->aabbNode != NULL)
645    //       this->aabbNode->drawBV(0, DRAW_BV_POLYGON, Vector(1, 0.6, 0.2), true);
646
647    glPopMatrix();
648  }
649}
650
651/**
652 * @param health the Health to add.
653 * @returns the health left (this->healthMax - health+this->health)
654 */
655float WorldEntity::increaseHealth(float health)
656{
657  this->health += health;
658  if (this->health > this->healthMax)
659  {
660    float retHealth = this->healthMax - this->health;
661    this->health = this->healthMax;
662    this->updateHealthWidget();
663    return retHealth;
664  }
665  this->updateHealthWidget();
666  return 0.0;
667}
668
669/**
670 * @param health the Health to be removed
671 * @returns 0.0 or the rest, that was not substracted (bellow 0.0)
672 */
673float WorldEntity::decreaseHealth(float health)
674{
675  this->health -= health;
676
677  if (this->health < 0)
678  {
679    float retHealth = -this->health;
680    this->health = 0.0f;
681    this->updateHealthWidget();
682    return retHealth;
683  }
684  this->updateHealthWidget();
685  return 0.0;
686
687}
688
689/**
690 * @param maxHealth the maximal health that can be loaded onto the entity.
691 */
692void WorldEntity::setHealthMax(float healthMax)
693{
694  this->healthMax = healthMax;
695  if (this->health > this->healthMax)
696  {
697    PRINTF(3)("new maxHealth is bigger as the old health. Did you really intend to do this for (%s::%s)\n", this->getClassCName(), this->getCName());
698    this->health = this->healthMax;
699  }
700  this->updateHealthWidget();
701}
702
703/**
704 * @brief creates the HealthWidget
705 *
706 * since not all entities need an HealthWidget, it is only created on request.
707 */
708void WorldEntity::createHealthWidget()
709{
710  if (this->healthWidget == NULL)
711  {
712    this->healthWidget = new OrxGui::GLGuiEnergyWidget();
713    this->healthWidget->setDisplayedName(std::string(this->getClassName()) + " Energy:");
714    this->healthWidget->setSize2D(30,400);
715    this->healthWidget->setAbsCoor2D(10,100);
716
717    this->updateHealthWidget();
718  }
719  else
720    PRINTF(3)("Allready created the HealthWidget for %s::%s\n", this->getClassCName(), this->getCName());
721}
722
723void WorldEntity::increaseHealthMax(float increaseHealth)
724{
725  this->healthMax += increaseHealth;
726  this->updateHealthWidget();
727}
728
729
730OrxGui::GLGuiWidget* WorldEntity::getHealthWidget()
731{
732  this->createHealthWidget();
733  return this->healthWidget;
734}
735
736/**
737 * @param visibility shows or hides the health-bar
738 * (creates the widget if needed)
739 */
740void WorldEntity::setHealthWidgetVisibilit(bool visibility)
741{
742  if (visibility)
743  {
744    if (this->healthWidget != NULL)
745      this->healthWidget->show();
746    else
747    {
748      this->createHealthWidget();
749      this->updateHealthWidget();
750      this->healthWidget->show();
751    }
752  }
753  else if (this->healthWidget != NULL)
754    this->healthWidget->hide();
755}
756
757
758/**
759 * hit the world entity with
760 *  @param damage damage to be dealt
761 */
762void WorldEntity::hit(float damage, WorldEntity* killer)
763{
764  this->decreaseHealth(damage);
765
766  PRINTF(5)("Hit me: %s::%s now only %f/%f health\n", this->getClassCName(), this->getCName(), this->getHealth(), this->getHealthMax());
767
768  if( this->getHealth() > 0)
769  {
770    // any small explosion animaitions
771  }
772  else
773  {
774    this->destroy( killer );
775  }
776}
777
778
779/**
780 * destoys the world entity
781 */
782void WorldEntity::destroy(WorldEntity* killer)
783{
784  this->toList(OM_DEAD);
785}
786
787
788/**
789 * @brief updates the HealthWidget
790 */
791void WorldEntity::updateHealthWidget()
792{
793  if (this->healthWidget != NULL)
794  {
795    this->healthWidget->setMaximum(this->healthMax);
796    this->healthWidget->setValue(this->health);
797  }
798}
799
800
801/**
802 * DEBUG-DRAW OF THE BV-Tree.
803 * @param depth What depth to draw
804 * @param drawMode the mode to draw this entity under
805 */
806void WorldEntity::drawBVTree(int depth, int drawMode) const
807{
808  glMatrixMode(GL_MODELVIEW);
809  glPushMatrix();
810  /* translate */
811  glTranslatef (this->getAbsCoor ().x,
812                this->getAbsCoor ().y,
813                this->getAbsCoor ().z);
814  /* rotate */
815  Vector tmpRot = this->getAbsDir().getSpacialAxis();
816  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
817
818
819  if (this->obbTree)
820    this->obbTree->drawBV(depth, drawMode);
821
822
823  glPopMatrix();
824}
825
826
827/**
828 * Debug the WorldEntity
829 */
830void WorldEntity::debugEntity() const
831{
832  PRINT(0)("WorldEntity %s::%s  (DEBUG)\n", this->getClassCName(), this->getCName());
833  this->debugNode();
834  PRINT(0)("List: %s ; ModelCount %d - ", ObjectManager::OMListToString(this->objectListNumber).c_str(), this->models.size());
835  for (unsigned int i = 0; i < this->models.size(); i++)
836  {
837    if (models[i] != NULL)
838      PRINT(0)(" : %d:%s", i, this->models[i]->getCName());
839  }
840  PRINT(0)("\n");
841
842}
843
844
845/**
846 * handler for changes on registred vars
847 * @param id id's which changed
848 */
849void WorldEntity::varChangeHandler( std::list< int > & id )
850{
851  if ( std::find( id.begin(), id.end(), modelFileName_handle ) != id.end() ||
852       std::find( id.begin(), id.end(), scaling_handle ) != id.end()
853     )
854  {
855    loadModel( modelFileName, scaling );
856  }
857
858  if ( std::find( id.begin(), id.end(), list_handle ) != id.end() )
859  {
860    this->toList( (OM_LIST)list_write );
861  }
862
863  if ( std::find( id.begin(), id.end(), health_handle ) != id.end() )
864  {
865    this->setHealth( health_write );
866  }
867
868  if ( std::find( id.begin(), id.end(), healthMax_handle ) != id.end() )
869  {
870    this->setHealthMax( healthMax_write );
871  }
872
873  PNode::varChangeHandler( id );
874}
875
Note: See TracBrowser for help on using the repository browser.