Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/coord/p_node.cc @ 5770

Last change on this file since 5770 was 5770, checked in by bensch, 18 years ago

orxonox/trunk: PNode is now std::list-conform

File size: 24.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: Benjamin Grauer
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_PNODE
17
18#include "p_node.h"
19#include "null_parent.h"
20
21#include "load_param.h"
22#include "class_list.h"
23
24#include "stdincl.h"
25#include "compiler.h"
26#include "error.h"
27#include "debug.h"
28#include "list.h"
29#include "vector.h"
30
31#include "color.h"
32
33using namespace std;
34
35
36/**
37 *  standard constructor
38 */
39PNode::PNode ()
40{
41  init(NULL);
42
43  NullParent::getInstance()->addChild(this);
44}
45
46/**
47 * @param root the load-Element for the PNode
48 */
49PNode::PNode(const TiXmlElement* root)
50{
51  this->init(NULL);
52  this->loadParams(root);
53
54  if (this->parent == NULL)
55    NullParent::getInstance()->addChild(this);
56}
57
58/**
59 *  constructor with coodinates
60 * @param absCoordinate the Absolute coordinate of the Object
61 * @param parent The parent-node of this node.
62 */
63PNode::PNode (const Vector& absCoor, PNode* parent )
64{
65  this->init(parent);
66
67  if (likely(parent != NULL))
68    parent->addChild (this);
69
70  this->setAbsCoor(absCoor);
71}
72
73/**
74 * standard deconstructor
75 *
76 * There are two general ways to delete a PNode
77 * 1. delete instance;
78 *   -> result
79 *    delete this Node and all its children and children's children...
80 *    (danger if you still need the children's instance somewhere else!!)
81 *
82 * 2. instance->remove2D(); delete instance;
83 *   -> result:
84 *    moves its children to the NullParent
85 *    then deletes the Element.
86 */
87
88#include "class_list.h"
89PNode::~PNode ()
90{
91  // remove the Node, delete it's children.
92  PNode* tmp;
93  while (this->children.size() > 0)
94  {
95    tmp = this->children.front();
96    this->children.pop_front();
97      delete tmp;
98  }
99  if (this->parent != NULL)
100   {
101     this->parent->children.remove(this);
102     this->parent = NULL;
103   }
104
105  // remove all other allocated memory.
106  if (this->toCoordinate != NULL)
107    delete this->toCoordinate;
108  if (this->toDirection != NULL)
109    delete this->toDirection;
110}
111
112
113/**
114 *  initializes a PNode
115 * @param parent the parent for this PNode
116 */
117void PNode::init(PNode* parent)
118{
119  this->setClassID(CL_PARENT_NODE, "PNode");
120
121  this->bRelCoorChanged = true;
122  this->bRelDirChanged = true;
123  this->parent = parent;
124  this->parentMode = PNODE_PARENT_MODE_DEFAULT;
125
126  // iterators
127  this->toCoordinate = NULL;
128  this->toDirection = NULL;
129  this->bias = 1.0;
130}
131
132/**
133 *  loads parameters of the PNode
134 * @param root the XML-element to load the properties of
135 */
136void PNode::loadParams(const TiXmlElement* root)
137{
138  static_cast<BaseObject*>(this)->loadParams(root);
139
140  LoadParam(root, "rel-coor", this, PNode, setRelCoor)
141      .describe("Sets The relative position of the Node to its parent.");
142
143  LoadParam(root, "abs-coor", this, PNode, setAbsCoor)
144      .describe("Sets The absolute Position of the Node.");
145
146  LoadParam(root, "rel-dir", this, PNode, setRelDir)
147      .describe("Sets The relative rotation of the Node to its parent.");
148
149  LoadParam(root, "abs-dir", this, PNode, setAbsDir)
150      .describe("Sets The absolute rotation of the Node.");
151
152  LoadParam(root, "parent", this, PNode, setParent)
153      .describe("the Name of the Parent of this PNode");
154
155  LoadParam(root, "parent-mode", this, PNode, setParentMode)
156      .describe("the mode to connect this node to its parent ()");
157
158  // cycling properties
159  if (root != NULL)
160  {
161    LOAD_PARAM_START_CYCLE(root, element);
162    {
163      LoadParam_CYCLE(element, "parent", this, PNode, addChild)
164          .describe("adds a new Child to the current Node.");
165
166    }
167    LOAD_PARAM_END_CYCLE(element);
168  }
169}
170
171/**
172 *  set relative coordinates
173 * @param relCoord relative coordinates to its parent
174 *
175 *
176 * it is very importand, that you use this function, if you want to update the
177 * relCoordinates. If you don't use this, the PNode won't recognize, that something
178 * has changed and won't update the children Nodes.
179 */
180void PNode::setRelCoor (const Vector& relCoord)
181{
182  if (this->toCoordinate!= NULL)
183  {
184    delete this->toCoordinate;
185    this->toCoordinate = NULL;
186  }
187
188  this->relCoordinate = relCoord;
189  this->bRelCoorChanged = true;
190}
191
192/**
193 *  set relative coordinates
194 * @param x x-relative coordinates to its parent
195 * @param y y-relative coordinates to its parent
196 * @param z z-relative coordinates to its parent
197 * @see  void PNode::setRelCoor (const Vector& relCoord)
198 */
199void PNode::setRelCoor (float x, float y, float z)
200{
201  this->setRelCoor(Vector(x, y, z));
202}
203
204/**
205 * sets a new relative position smoothely
206 * @param relCoordSoft the new Position to iterate to
207 * @param bias how fast to iterate to this position
208 */
209void PNode::setRelCoorSoft(const Vector& relCoordSoft, float bias)
210{
211  if (likely(this->toCoordinate == NULL))
212    this->toCoordinate = new Vector();
213
214  *this->toCoordinate = relCoordSoft;
215  this->bias = bias;
216}
217
218
219/**
220 *  set relative coordinates smoothely
221 * @param x x-relative coordinates to its parent
222 * @param y y-relative coordinates to its parent
223 * @param z z-relative coordinates to its parent
224 * @see  void PNode::setRelCoorSoft (const Vector&, float)
225 */
226void PNode::setRelCoorSoft (float x, float y, float z, float bias)
227{
228  this->setRelCoorSoft(Vector(x, y, z), bias);
229}
230
231
232/**
233 * @param absCoord set absolute coordinate
234 */
235void PNode::setAbsCoor (const Vector& absCoord)
236{
237  if (this->toCoordinate!= NULL)
238  {
239    delete this->toCoordinate;
240    this->toCoordinate = NULL;
241  }
242
243  if( likely(this->parentMode & PNODE_MOVEMENT))
244  {
245      /* if you have set the absolute coordinates this overrides all other changes */
246    if (likely(this->parent != NULL))
247      this->relCoordinate = absCoord - parent->getAbsCoor ();
248    else
249      this->relCoordinate = absCoord;
250  }
251  if( this->parentMode & PNODE_ROTATE_MOVEMENT)
252  {
253    if (likely(this->parent != NULL))
254      this->relCoordinate = absCoord - parent->getAbsCoor ();
255    else
256      this->relCoordinate = absCoord;
257  }
258
259  this->bRelCoorChanged = true;
260//  this->absCoordinate = absCoord;
261}
262
263
264/**
265 * @param x x-coordinate.
266 * @param y y-coordinate.
267 * @param z z-coordinate.
268 * @see void PNode::setAbsCoor (const Vector& absCoord)
269 */
270void PNode::setAbsCoor(float x, float y, float z)
271{
272  this->setAbsCoor(Vector(x, y, z));
273}
274
275/**
276 * @param absCoord set absolute coordinate
277 * @todo check off
278 */
279void PNode::setAbsCoorSoft (const Vector& absCoordSoft, float bias)
280{
281  if (this->toCoordinate == NULL)
282    this->toCoordinate = new Vector;
283
284  if( likely(this->parentMode & PNODE_MOVEMENT))
285  {
286      /* if you have set the absolute coordinates this overrides all other changes */
287    if (likely(this->parent != NULL))
288      *this->toCoordinate = absCoordSoft - parent->getAbsCoor ();
289    else
290      *this->toCoordinate = absCoordSoft;
291  }
292  if( this->parentMode & PNODE_ROTATE_MOVEMENT)
293  {
294    if (likely(this->parent != NULL))
295      *this->toCoordinate = absCoordSoft - parent->getAbsCoor ();
296    else
297      *this->toCoordinate = absCoordSoft;
298  }
299}
300
301
302/**
303 *  shift coordinate relative
304 * @param shift shift vector
305 *
306 * this function shifts the current coordinates about the vector shift. this is
307 * usefull because from some place else you can:
308 * PNode* someNode = ...;
309 * Vector objectMovement = calculateShift();
310 * someNode->shiftCoor(objectMovement);
311 *
312 * this is the internal method of:
313 * PNode* someNode = ...;
314 * Vector objectMovement = calculateShift();
315 * Vector currentCoor = someNode->getRelCoor();
316 * Vector newCoor = currentCoor + objectMovement;
317 * someNode->setRelCoor(newCoor);
318 *
319 */
320void PNode::shiftCoor (const Vector& shift)
321{
322  this->relCoordinate += shift;
323  this->bRelCoorChanged = true;
324}
325
326/**
327 *  set relative direction
328 * @param relDir to its parent
329 */
330void PNode::setRelDir (const Quaternion& relDir)
331{
332  if (this->toDirection!= NULL)
333  {
334    delete this->toDirection;
335    this->toDirection = NULL;
336  }
337  this->relDirection = relDir;
338  this->bRelCoorChanged = true;
339}
340
341/**
342 * @see void PNode::setRelDir (const Quaternion& relDir)
343 * @param x the x direction
344 * @param y the y direction
345 * @param z the z direction
346 *
347 * main difference is, that here you give a directional vector, that will be translated into a Quaternion
348 */
349void PNode::setRelDir (float x, float y, float z)
350{
351  this->setRelDir(Quaternion(Vector(x,y,z), Vector(0,1,0)));
352}
353
354
355/**
356 * sets the Relative Direction of this node to its parent in a Smoothed way
357 * @param relDirSoft the direction to iterate to smoothely.
358 * @param bias how fast to iterate to the new Direction
359 */
360void PNode::setRelDirSoft(const Quaternion& relDirSoft, float bias)
361{
362  if (likely(this->toDirection == NULL))
363    this->toDirection = new Quaternion();
364
365  *this->toDirection = relDirSoft;
366  this->bias = bias;
367}
368
369/**
370 * @see void PNode::setRelDirSoft (const Quaternion& relDir)
371 * @param x the x direction
372 * @param y the y direction
373 * @param z the z direction
374 *
375 * main difference is, that here you give a directional vector, that will be translated into a Quaternion
376 */
377void PNode::setRelDirSoft(float x, float y, float z, float bias)
378{
379  this->setRelDirSoft(Quaternion(Vector(x,y,z), Vector(0,1,0)), bias);
380}
381
382/**
383 *  sets the absolute direction
384 * @param absDir absolute coordinates
385 */
386void PNode::setAbsDir (const Quaternion& absDir)
387{
388  if (this->toDirection!= NULL)
389  {
390    delete this->toDirection;
391    this->toDirection = NULL;
392  }
393
394  if (likely(this->parent != NULL))
395    this->relDirection = absDir / this->parent->getAbsDir();
396  else
397   this->relDirection = absDir;
398
399  this->bRelDirChanged = true;
400}
401
402/**
403 * @see void PNode::setAbsDir (const Quaternion& relDir)
404 * @param x the x direction
405 * @param y the y direction
406 * @param z the z direction
407 *
408 * main difference is, that here you give a directional vector, that will be translated into a Quaternion
409 */
410void PNode::setAbsDir (float x, float y, float z)
411{
412  this->setAbsDir(Quaternion(Vector(x,y,z), Vector(0,1,0)));
413}
414
415/**
416 * sets the absolute direction
417 * @param absDir absolute coordinates
418 */
419void PNode::setAbsDirSoft (const Quaternion& absDirSoft, float bias)
420{
421  if (this->toDirection == NULL)
422    this->toDirection = new Quaternion();
423
424  if (likely(this->parent != NULL))
425    *this->toDirection = absDirSoft / this->parent->getAbsDir();
426  else
427   *this->toDirection = absDirSoft;
428
429  this->bias = bias;
430}
431
432/**
433 * @see void PNode::setAbsDir (const Quaternion& relDir)
434 * @param x the x direction
435 * @param y the y direction
436 * @param z the z direction
437 *
438 * main difference is, that here you give a directional vector, that will be translated into a Quaternion
439 */
440void PNode::setAbsDirSoft (float x, float y, float z, float bias)
441{
442  this->setAbsDirSoft(Quaternion(Vector(x,y,z), Vector(0,1,0)), bias);
443}
444
445
446/**
447 * shift Direction
448 * @param shift the direction around which to shift.
449 */
450void PNode::shiftDir (const Quaternion& shift)
451{
452  this->relDirection = this->relDirection * shift;
453  this->bRelDirChanged = true;
454}
455
456/**
457 *  adds a child and makes this node to a parent
458 * @param child child reference
459 * use this to add a child to this node.
460 */
461void PNode::addChild (PNode* child)
462{
463  if( likely(child->parent != NULL))
464    {
465      PRINTF(5)("PNode::addChild() - reparenting node: removing it and adding it again\n");
466      child->parent->children.remove(child);
467    }
468  child->parent = this;
469  if (unlikely(this != NULL))
470    this->children.push_back(child);
471  child->parentCoorChanged();
472}
473
474/**
475 * @see PNode::addChild(PNode* child);
476 * @param childName the name of the child to add to this PNode
477 */
478void PNode::addChild (const char* childName)
479{
480  PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE));
481  if (childNode != NULL)
482    this->addChild(childNode);
483}
484
485/**
486 *  removes a child from the node
487 * @param child the child to remove from this pNode.
488 *
489 * Children from pNode will not be lost, they are referenced to NullPointer
490 */
491void PNode::removeChild (PNode* child)
492{
493  if (child != NULL)
494  {
495   child->removeNode();
496//   this->children->remove(child);
497//   child->parent = NULL;
498  }
499}
500
501/**
502 *  remove this pnode from the tree and adds all following to NullParent
503 *
504 * this can be the case, if an entity in the world is being destroyed.
505 */
506void PNode::removeNode()
507{
508  list<PNode*>::iterator child;
509  for (child = this->children.begin(); child != this->children.end(); child ++)
510    NullParent::getInstance()->addChild(*child);
511
512  if (this->parent != NULL)
513    this->parent->children.remove(this);
514}
515
516/**
517 * sets the parent of this PNode
518 * @param parent the Parent to set
519 */
520void PNode::setParent (PNode* parent)
521{
522  parent->addChild(this);
523}
524
525/**
526 * @see PNode::setParent(PNode* parent);
527 * @param parentName the name of the Parent to set to this PNode
528 */
529void PNode::setParent (const char* parentName)
530{
531  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
532  if (parentNode != NULL)
533    parentNode->addChild(this);
534}
535
536/**
537 * does the reparenting in a very smooth way
538 * @param parentNode the new Node to connect this node to.
539 * @param bias the speed to iterate to this new Positions
540 */
541void PNode::setParentSoft(PNode* parentNode, float bias)
542{
543  // return if the new parent and the old one match
544  if (this->parent == parentNode)
545    return;
546
547  // store the Valures to iterate to.
548  if (likely(this->toCoordinate == NULL))
549  {
550    this->toCoordinate = new Vector();
551    *this->toCoordinate = this->getRelCoor();
552  }
553  if (likely(this->toDirection == NULL))
554  {
555    this->toDirection = new Quaternion();
556    *this->toDirection = this->getRelDir();
557  }
558  this->bias = bias;
559
560
561  Vector tmpV = this->getAbsCoor();
562  Quaternion tmpQ = this->getAbsDir();
563
564  parentNode->addChild(this);
565
566 if (this->parentMode & PNODE_ROTATE_MOVEMENT && this->parent != NULL)
567   this->relCoordinate = this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor());
568 else
569   this->relCoordinate = tmpV - parentNode->getAbsCoor();
570
571 this->relDirection = tmpQ / parentNode->getAbsDir();
572}
573
574/**
575 * does the reparenting in a very smooth way
576 * @param parentName the name of the Parent to reconnect to
577 * @param bias the speed to iterate to this new Positions
578 */
579void PNode::setParentSoft(const char* parentName, float bias)
580{
581  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
582  if (parentNode != NULL)
583    this->setParentSoft(parentNode, bias);
584}
585
586/**
587 *  sets the mode of this parent manually
588 * @param parentMode a String representing this parentingMode
589 */
590void PNode::setParentMode (const char* parentingMode)
591{
592  this->setParentMode(PNode::charToParentingMode(parentingMode));
593}
594
595/**
596 *  updates the absCoordinate/absDirection
597 * @param dt The time passed since the last update
598 *
599 * this is used to go through the parent-tree to update all the absolute coordinates
600 * and directions. this update should be done by the engine, so you don't have to
601 * worry, normaly...
602 */
603void PNode::updateNode (float dt)
604{
605  if( likely(this->parent != NULL))
606    {
607      // movement for nodes with smoothMove enabled
608      if (unlikely(this->toCoordinate != NULL))
609      {
610        Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias;
611        if (likely(moveVect.len() >= PNODE_ITERATION_DELTA))
612        {
613          this->shiftCoor(moveVect);
614        }
615        else
616        {
617          delete this->toCoordinate;
618          this->toCoordinate = NULL;
619          PRINTF(5)("SmoothMove of %s finished\n", this->getName());
620        }
621      }
622      if (unlikely(this->toDirection != NULL))
623      {
624        Quaternion rotQuat = Quaternion::quatSlerp(this->relDirection,*this->toDirection, fabsf(dt)*this->bias);
625        if (this->relDirection.distance(rotQuat) >PNODE_ITERATION_DELTA)
626        {
627          this->relDirection = rotQuat;
628          this->bRelDirChanged;
629        }
630        else
631        {
632          delete this->toDirection;
633          this->toDirection = NULL;
634          PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
635        }
636      }
637
638      // MAIN UPDATE /////////////////////////////////////
639      this->lastAbsCoordinate = this->absCoordinate;
640
641      PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
642
643
644      if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)
645      {
646        /* update the current absDirection - remember * means rotation around sth.*/
647        this->prevRelCoordinate = this->relCoordinate;
648        this->absDirection = this->relDirection * parent->getAbsDir();;
649      }
650
651      if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
652      {
653        /* update the current absCoordinate */
654        this->prevRelCoordinate = this->relCoordinate;
655        this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
656      }
657      else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
658      {
659        /* update the current absCoordinate */
660        this->prevRelCoordinate = this->relCoordinate;
661        this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
662      }
663      /////////////////////////////////////////////////
664   }
665  else
666    {
667      PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
668      if (this->bRelCoorChanged)
669      {
670        this->prevRelCoordinate = this->relCoordinate;
671        this->absCoordinate = this->relCoordinate;
672      }
673      if (this->bRelDirChanged)
674      {
675        this->prevRelDirection = this->relDirection;
676        this->absDirection = this->getAbsDir () * this->relDirection;
677      }
678    }
679
680    if(this->children.size() > 0)
681    {
682      list<PNode*>::iterator child;
683      for (child = this->children.begin(); child != this->children.end(); child ++)
684      {
685        /* if this node has changed, make sure, that all children are updated also */
686        if( likely(this->bRelCoorChanged))
687          (*child)->parentCoorChanged ();
688        if( likely(this->bRelDirChanged))
689          (*child)->parentDirChanged ();
690
691        (*child)->updateNode(dt);
692      }
693    }
694    this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
695    this->bRelCoorChanged = false;
696    this->bRelDirChanged = false;
697}
698
699
700void PNode::countChildNodes(int& nodes) const
701{
702  nodes++;
703  list<PNode*>::const_iterator child;
704  for (child = this->children.begin(); child != this->children.end(); child ++)
705    (*child)->countChildNodes(nodes);
706}
707
708
709/**
710 *  displays some information about this pNode
711 * @param depth The deph into which to debug the children of this PNode to.
712 * (0: all children will be debugged, 1: only this PNode, 2: this and direct children, ...)
713 * @param level !! INTERNAL !! The n-th level of the Node we draw (this is internal and only for nice output).
714 */
715void PNode::debugNode(unsigned int depth, unsigned int level) const
716{
717  for (unsigned int i = 0; i < level; i++)
718    PRINT(0)(" |");
719  if (this->children.size() > 0)
720    PRINT(0)(" +");
721  else
722    PRINT(0)(" -");
723
724  int childNodeCount = 0;
725  this->countChildNodes(childNodeCount);
726
727  PRINT(0)("PNode(%s::%s) - absCoord: (%0.2f, %0.2f, %0.2f), relCoord(%0.2f, %0.2f, %0.2f), direction(%0.2f, %0.2f, %0.2f) - %s - %d childs\n",
728           this->getClassName(),
729           this->getName(),
730           this->absCoordinate.x,
731           this->absCoordinate.y,
732           this->absCoordinate.z,
733           this->relCoordinate.x,
734           this->relCoordinate.y,
735           this->relCoordinate.z,
736           this->getAbsDirV().x,
737           this->getAbsDirV().y,
738           this->getAbsDirV().z,
739           this->parentingModeToChar(parentMode),
740           childNodeCount);
741  if (depth >= 2 || depth == 0)
742  {
743    list<PNode*>::const_iterator child;
744    for (child = this->children.begin(); child != this->children.end(); child ++)
745    {
746      if (depth == 0)
747        (*child)->debugNode(0, level + 1);
748      else
749        (*child)->debugNode(depth - 1, level +1);
750    }
751  }
752}
753
754/**
755 * displays the PNode at its position with its rotation as a cube.
756 * @param  depth The deph into which to debug the children of this PNode to.
757 * (0: all children will be displayed, 1: only this PNode, 2: this and direct children, ...)
758 * @param size the Size of the Box to draw.
759 * @param color the color of the Box to display.
760 * @param level !! INTERNAL !! The n-th level of the Node we draw (this is internal and only for nice output).
761 */
762void PNode::debugDraw(unsigned int depth, float size, const Vector& color, unsigned int level) const
763{
764  // if this is the first Element we draw
765  if (level == 0)
766  {
767    glPushAttrib(GL_ENABLE_BIT); // save the Enable-attributes
768    glMatrixMode(GL_MODELVIEW);  // goto the ModelView Matrix
769
770    glDisable(GL_LIGHTING);      // disable lighting (we do not need them for just lighting)
771    glDisable(GL_BLEND);         // ''
772    glDisable(GL_TEXTURE_2D);    // ''
773    glDisable(GL_DEPTH_TEST);    // ''
774  }
775
776  glPushMatrix();                // repush the Matrix-stack
777  /* translate */
778  glTranslatef (this->getAbsCoor ().x,
779                this->getAbsCoor ().y,
780                this->getAbsCoor ().z);
781//  this->getAbsDir ().matrix (matrix);
782
783  /* rotate */
784  Vector tmpRot = this->getAbsDir().getSpacialAxis();
785  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
786  /* set the new Color */
787  glColor3f(color.x, color.y, color.z);
788  { /* draw a cube of size size */
789    glBegin(GL_LINE_STRIP);
790    glVertex3f(-.5*size, -.5*size,  -.5*size);
791    glVertex3f(+.5*size, -.5*size,  -.5*size);
792    glVertex3f(+.5*size, -.5*size,  +.5*size);
793    glVertex3f(-.5*size, -.5*size,  +.5*size);
794    glVertex3f(-.5*size, -.5*size,  -.5*size);
795    glEnd();
796    glBegin(GL_LINE_STRIP);
797    glVertex3f(-.5*size, +.5*size,  -.5*size);
798    glVertex3f(+.5*size, +.5*size,  -.5*size);
799    glVertex3f(+.5*size, +.5*size,  +.5*size);
800    glVertex3f(-.5*size, +.5*size,  +.5*size);
801    glVertex3f(-.5*size, +.5*size,  -.5*size);
802    glEnd();
803
804    glBegin(GL_LINES);
805    glVertex3f(-.5*size, -.5*size,  -.5*size);
806    glVertex3f(-.5*size, +.5*size,  -.5*size);
807    glVertex3f(+.5*size, -.5*size,  -.5*size);
808    glVertex3f(+.5*size, +.5*size,  -.5*size);
809    glVertex3f(+.5*size, -.5*size,  +.5*size);
810    glVertex3f(+.5*size, +.5*size,  +.5*size);
811    glVertex3f(-.5*size, -.5*size,  +.5*size);
812    glVertex3f(-.5*size, +.5*size,  +.5*size);
813    glEnd();
814  }
815
816  glPopMatrix();
817  if (depth >= 2 || depth == 0)
818  {
819    /* rotate the current color in HSV space around 20 degree */
820    Vector childColor =  Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(20,0,.0));
821    list<PNode*>::const_iterator child;
822    for (child = this->children.begin(); child != this->children.end(); child ++)
823    {
824      // drawing the Dependency graph
825     if (this != NullParent::getInstance())
826      {
827       glBegin(GL_LINES);
828       glColor3f(color.x, color.y, color.z);
829       glVertex3f(this->getAbsCoor ().x,
830                  this->getAbsCoor ().y,
831                  this->getAbsCoor ().z);
832        glColor3f(childColor.x, childColor.y, childColor.z);
833        glVertex3f((*child)->getAbsCoor ().x,
834                   (*child)->getAbsCoor ().y,
835                   (*child)->getAbsCoor ().z);
836        glEnd();
837      }
838      /* if we want to draw the children too */
839      if (depth == 0) /* -> all of them */
840        (*child)->debugDraw(0, size, childColor, level+1);
841      else            /* -> only the Next one */
842        (*child)->debugDraw(depth - 1, size, childColor, level +1);
843    }
844  }
845  if (level == 0)
846    glPopAttrib(); /* pop the saved attributes back out */
847}
848
849
850
851/////////////////////
852// HELPER_FUCTIONS //
853/////////////////////
854
855/**
856 * converts a parentingMode into a string that is the name of it
857 * @param parentingMode the ParentingMode to convert
858 * @return the converted string
859 */
860const char* PNode::parentingModeToChar(int parentingMode)
861{
862  if (parentingMode == PNODE_LOCAL_ROTATE)
863    return "local-rotate";
864  else if (parentingMode == PNODE_ROTATE_MOVEMENT)
865    return "rotate-movement";
866  else if (parentingMode == PNODE_MOVEMENT)
867    return "movement";
868  else if (parentingMode == PNODE_ALL)
869    return "all";
870  else if (parentingMode == PNODE_ROTATE_AND_MOVE)
871    return "rotate-and-move";
872}
873
874/**
875 * converts a parenting-mode-string into a int
876 * @param parentingMode the string naming the parentingMode
877 * @return the int corresponding to the named parentingMode
878 */
879PARENT_MODE PNode::charToParentingMode(const char* parentingMode)
880{
881  if (!strcmp(parentingMode, "local-rotate"))
882    return (PNODE_LOCAL_ROTATE);
883  else  if (!strcmp(parentingMode, "rotate-movement"))
884    return (PNODE_ROTATE_MOVEMENT);
885  else  if (!strcmp(parentingMode, "movement"))
886    return (PNODE_MOVEMENT);
887  else  if (!strcmp(parentingMode, "all"))
888    return (PNODE_ALL);
889  else  if (!strcmp(parentingMode, "rotate-and-move"))
890    return (PNODE_ROTATE_AND_MOVE);
891}
Note: See TracBrowser for help on using the repository browser.