Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: update the Element2D-tree in the right order

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