Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5394 was 5394, checked in by bensch, 19 years ago

orxonox/trunk: drawing dependency-graph of PNode

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