Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Elemet2D-drawing better
prevent segfault in setParent with NULL as new Parent in Element2D and PNode

File size: 22.8 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  if (unlikely(this != NULL))
418    this->children->add(child);
419  child->parentCoorChanged();
420}
421
422/**
423 * @see PNode::addChild(PNode* child);
424 * @param childName the name of the child to add to this PNode
425 */
426void PNode::addChild (const char* childName)
427{
428  PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE));
429  if (childNode != NULL)
430    this->addChild(childNode);
431}
432
433/**
434 *  removes a child from the node
435 * @param child the child to remove from this pNode.
436 *
437 * Children from pNode will not be lost, they are referenced to NullPointer
438*/
439void PNode::removeChild (PNode* child)
440{
441  if (child != NULL)
442  {
443   child->remove();
444//   this->children->remove(child);
445//   child->parent = NULL;
446  }
447}
448
449/**
450 *  remove this pnode from the tree and adds all following to NullParent
451
452   this can be the case, if an entity in the world is being destroyed.
453*/
454void PNode::remove()
455{
456  tIterator<PNode>* iterator = this->children->getIterator();
457  PNode* pn = iterator->firstElement();
458
459  while( pn != NULL)
460    {
461      NullParent::getInstance()->addChild(pn);
462      pn = iterator->nextElement();
463    }
464  delete iterator;
465  if (this->parent != NULL)
466    this->parent->children->remove(this);
467}
468
469/**
470 * sets the parent of this PNode
471 * @param parent the Parent to set
472*/
473void PNode::setParent (PNode* parent)
474{
475  parent->addChild(this);
476}
477
478/**
479 * @see PNode::setParent(PNode* parent);
480 * @param parentName the name of the Parent to set to this PNode
481 */
482void PNode::setParent (const char* parentName)
483{
484  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
485  if (parentNode != NULL)
486    parentNode->addChild(this);
487}
488
489/**
490 * does the reparenting in a very smooth way
491 * @param parentNode the new Node to connect this node to.
492 * @param bias the speed to iterate to this new Positions
493 */
494void PNode::setParentSoft(PNode* parentNode, float bias)
495{
496  // return if the new parent and the old one match
497  if (this->parent == parentNode)
498    return;
499
500  // store the Valures to iterate to.
501  if (likely(this->toCoordinate == NULL))
502  {
503    this->toCoordinate = new Vector();
504    *this->toCoordinate = this->getRelCoor();
505  }
506  if (likely(this->toDirection == NULL))
507  {
508    this->toDirection = new Quaternion();
509    *this->toDirection = this->getRelDir();
510  }
511  this->bias = bias;
512
513
514  Vector tmpV = this->getAbsCoor();
515  Quaternion tmpQ = this->getAbsDir();
516
517  parentNode->addChild(this);
518
519 if (this->parentMode & PNODE_ROTATE_MOVEMENT && this->parent != NULL)
520   this->relCoordinate = this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor());
521 else
522   this->relCoordinate = tmpV - parentNode->getAbsCoor();
523
524 this->relDirection = tmpQ / parentNode->getAbsDir();
525}
526
527/**
528 * does the reparenting in a very smooth way
529 * @param parentName the name of the Parent to reconnect to
530 * @param bias the speed to iterate to this new Positions
531 */
532void PNode::setParentSoft(const char* parentName, float bias)
533{
534  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
535  if (parentNode != NULL)
536    this->setParentSoft(parentNode, bias);
537}
538
539/**
540 *  sets the mode of this parent manually
541 * @param parentMode a String representing this parentingMode
542 */
543void PNode::setParentMode (const char* parentingMode)
544{
545  this->setParentMode(PNode::charToParentingMode(parentingMode));
546}
547
548/**
549 *  updates the absCoordinate/absDirection
550 * @param dt The time passed since the last update
551
552   this is used to go through the parent-tree to update all the absolute coordinates
553   and directions. this update should be done by the engine, so you don't have to
554   worry, normaly...
555*/
556void PNode::update (float dt)
557{
558  if( likely(this->parent != NULL))
559    {
560      // movement for nodes with smoothMove enabled
561      if (unlikely(this->toCoordinate != NULL))
562      {
563        Vector moveVect = (*this->toCoordinate - this->relCoordinate) *fabsf(dt)*bias;
564        if (likely(moveVect.len() >= PNODE_ITERATION_DELTA))
565        {
566          this->shiftCoor(moveVect);
567        }
568        else
569        {
570          delete this->toCoordinate;
571          this->toCoordinate = NULL;
572          PRINTF(5)("SmoothMove of %s finished\n", this->getName());
573        }
574      }
575      if (unlikely(this->toDirection != NULL))
576      {
577        Quaternion rotQuat = Quaternion::quatSlerp(Quaternion(), (*this->toDirection / this->relDirection), fabsf(dt)*this->bias);
578        if (likely(rotQuat.getSpacialAxisAngle() > PNODE_ITERATION_DELTA))
579        {
580          this->shiftDir(rotQuat);
581        }
582        else
583        {
584          delete this->toDirection;
585          this->toDirection = NULL;
586          PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
587        }
588      }
589
590      // MAIN UPDATE /////////////////////////////////////
591      this->lastAbsCoordinate = this->absCoordinate;
592
593      PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
594
595
596      if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)
597      {
598        /* update the current absDirection - remember * means rotation around sth.*/
599        this->prevRelCoordinate = this->relCoordinate;
600        this->absDirection = this->relDirection * parent->getAbsDir();;
601      }
602
603      if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
604      {
605        /* update the current absCoordinate */
606        this->prevRelCoordinate = this->relCoordinate;
607        this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
608      }
609      else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
610      {
611        /* update the current absCoordinate */
612        this->prevRelCoordinate = this->relCoordinate;
613        this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
614      }
615      /////////////////////////////////////////////////
616   }
617  else
618    {
619      PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
620      if (this->bRelCoorChanged)
621      {
622        this->prevRelCoordinate = this->relCoordinate;
623        this->absCoordinate = this->relCoordinate;
624      }
625      if (this->bRelDirChanged)
626      {
627        this->prevRelDirection = this->relDirection;
628        this->absDirection = this->getAbsDir () * this->relDirection;
629      }
630    }
631
632    if(this->children->getSize() > 0)
633    {
634      tIterator<PNode>* iterator = this->children->getIterator();
635      PNode* pn = iterator->firstElement();
636      while( pn != NULL)
637      {
638        /* if this node has changed, make sure, that all children are updated also */
639        if( likely(this->bRelCoorChanged))
640          pn->parentCoorChanged ();
641        if( likely(this->bRelDirChanged))
642          pn->parentDirChanged ();
643
644        pn->update(dt);
645        pn = iterator->nextElement();
646      }
647      delete iterator;
648    }
649    this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
650    this->bRelCoorChanged = false;
651    this->bRelDirChanged = false;
652}
653
654/**
655 *  displays some information about this pNode
656 * @param depth The deph into which to debug the children of this PNode to.
657 * (0: all children will be debugged, 1: only this PNode, 2: this and direct children, ...)
658 * @param level !! INTERNAL !! The n-th level of the Node we draw (this is internal and only for nice output).
659*/
660void PNode::debug(unsigned int depth, unsigned int level) const
661{
662  for (unsigned int i = 0; i < level; i++)
663    PRINT(0)(" |");
664  if (this->children->getSize() > 0)
665    PRINT(0)(" +");
666  else
667    PRINT(0)(" -");
668  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",
669           this->getClassName(),
670           this->getName(),
671           this->absCoordinate.x,
672           this->absCoordinate.y,
673           this->absCoordinate.z,
674           this->relCoordinate.x,
675           this->relCoordinate.y,
676           this->relCoordinate.z,
677           this->getAbsDirV().x,
678           this->getAbsDirV().y,
679           this->getAbsDirV().z,
680           this->parentingModeToChar(parentMode));
681  if (depth >= 2 || depth == 0)
682  {
683    tIterator<PNode>* iterator = this->children->getIterator();
684      //PNode* pn = this->children->enumerate ();
685    PNode* pn = iterator->firstElement();
686    while( pn != NULL)
687    {
688      if (depth == 0)
689        pn->debug(0, level + 1);
690      else
691        pn->debug(depth - 1, level +1);
692      pn = iterator->nextElement();
693    }
694    delete iterator;
695  }
696}
697#include "color.h"
698
699/**
700 * displays the PNode at its position with its rotation as a cube.
701 * @param  depth The deph into which to debug the children of this PNode to.
702 * (0: all children will be displayed, 1: only this PNode, 2: this and direct children, ...)
703 * @param size the Size of the Box to draw.
704 * @param color the color of the Box to display.
705 * @param level !! INTERNAL !! The n-th level of the Node we draw (this is internal and only for nice output).
706 */
707void PNode::debugDraw(unsigned int depth, float size, const Vector& color, unsigned int level) const
708{
709  if (level == 0)
710  {
711    glPushAttrib(GL_ENABLE_BIT);
712    glMatrixMode(GL_MODELVIEW);
713
714    glDisable(GL_LIGHTING);
715    glDisable(GL_BLEND);
716    glDisable(GL_TEXTURE_2D);
717  }
718
719  glPushMatrix();
720  /* translate */
721  glTranslatef (this->getAbsCoor ().x,
722                this->getAbsCoor ().y,
723                this->getAbsCoor ().z);
724  /* rotate */
725//  this->getAbsDir ().matrix (matrix);
726//  glMultMatrixf((float*)matrix);
727
728  Vector tmpRot = this->getAbsDir().getSpacialAxis();
729  glColor3f(color.x, color.y, color.z);
730
731  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
732  {
733    glBegin(GL_LINE_STRIP);
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    glVertex3f(-.5*size, -.5*size,  -.5*size);
739    glEnd();
740    glBegin(GL_LINE_STRIP);
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    glVertex3f(-.5*size, +.5*size,  -.5*size);
746    glEnd();
747
748    glBegin(GL_LINES);
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    glVertex3f(-.5*size, +.5*size,  +.5*size);
757    glEnd();
758  }
759
760  glPopMatrix();
761  if (depth >= 2 || depth == 0)
762  {
763    Vector childColor =  Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(20,0,.0));
764    tIterator<PNode>* iterator = this->children->getIterator();
765    PNode* pn = iterator->firstElement();
766    while( pn != NULL)
767    {
768      // drawing the Dependency graph
769      if (this != NullParent::getInstance())
770      {
771       glBegin(GL_LINES);
772       glColor3f(color.x, color.y, color.z);
773       glVertex3f(this->getAbsCoor ().x,
774                  this->getAbsCoor ().y,
775                  this->getAbsCoor ().z);
776        glColor3f(childColor.x, childColor.y, childColor.z);
777        glVertex3f(pn->getAbsCoor ().x,
778                   pn->getAbsCoor ().y,
779                   pn->getAbsCoor ().z);
780        glEnd();
781      }
782      if (depth == 0)
783        pn->debugDraw(0, size, childColor, level+1);
784      else
785        pn->debugDraw(depth - 1, size, childColor, level +1);
786      pn = iterator->nextElement();
787    }
788    delete iterator;
789  }
790  if (level == 0)
791    glPopAttrib();
792}
793
794
795
796/////////////////////
797// HELPER_FUCTIONS //
798/////////////////////
799
800/**
801 * converts a parentingMode into a string that is the name of it
802 * @param parentingMode the ParentingMode to convert
803 * @return the converted string
804 */
805const char* PNode::parentingModeToChar(int parentingMode)
806{
807  if (parentingMode == PNODE_LOCAL_ROTATE)
808    return "local-rotate";
809  else if (parentingMode == PNODE_ROTATE_MOVEMENT)
810    return "rotate-movement";
811  else if (parentingMode == PNODE_MOVEMENT)
812    return "movement";
813  else if (parentingMode == PNODE_ALL)
814    return "all";
815  else if (parentingMode == PNODE_ROTATE_AND_MOVE)
816    return "rotate-and-move";
817}
818
819/**
820 * converts a parenting-mode-string into a int
821 * @param parentingMode the string naming the parentingMode
822 * @return the int corresponding to the named parentingMode
823 */
824PARENT_MODE PNode::charToParentingMode(const char* parentingMode)
825{
826  if (!strcmp(parentingMode, "local-rotate"))
827    return (PNODE_LOCAL_ROTATE);
828  else  if (!strcmp(parentingMode, "rotate-movement"))
829    return (PNODE_ROTATE_MOVEMENT);
830  else  if (!strcmp(parentingMode, "movement"))
831    return (PNODE_MOVEMENT);
832  else  if (!strcmp(parentingMode, "all"))
833    return (PNODE_ALL);
834  else  if (!strcmp(parentingMode, "rotate-and-move"))
835    return (PNODE_ROTATE_AND_MOVE);
836}
Note: See TracBrowser for help on using the repository browser.