Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file was 10013, checked in by patrick, 18 years ago

merged the collision reaction branche back to trunk

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