Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/world_entity.cc @ 9064

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

merged the single_player branche to trunk

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