Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/2d-recalc/src/lib/coord/p_node.cc @ 5648

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

orxonox/trunk: nicer rendering of the Shell

File size: 21.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 * @param absCoord set absolute coordinate
239 */
240void PNode::setAbsCoor (const Vector& absCoord)
241{
242  if (this->toCoordinate!= NULL)
243  {
244    delete this->toCoordinate;
245    this->toCoordinate = NULL;
246  }
247
248  if( likely(this->parentMode & PNODE_MOVEMENT))
249  {
250      /* if you have set the absolute coordinates this overrides all other changes */
251    if (likely(this->parent != NULL))
252      this->relCoordinate = absCoord - parent->getAbsCoor ();
253    else
254      this->relCoordinate = absCoord;
255  }
256  if( this->parentMode & PNODE_ROTATE_MOVEMENT)
257  {
258    if (likely(this->parent != NULL))
259      this->relCoordinate = absCoord - parent->getAbsCoor ();
260    else
261      this->relCoordinate = absCoord;
262  }
263
264  this->bRelCoorChanged = true;
265//  this->absCoordinate = absCoord;
266}
267
268/**
269 * @param x x-coordinate.
270 * @param y y-coordinate.
271 * @param z z-coordinate.
272 * @see void PNode::setAbsCoor (const Vector& absCoord)
273 */
274void PNode::setAbsCoor(float x, float y, float z)
275{
276  this->setAbsCoor(Vector(x, y, z));
277}
278
279/**
280 *  shift coordinate relative
281 * @param shift shift vector
282
283   this function shifts the current coordinates about the vector shift. this is
284   usefull because from some place else you can:
285   PNode* someNode = ...;
286   Vector objectMovement = calculateShift();
287   someNode->shiftCoor(objectMovement);
288
289   elsewhere you would have to:
290   PNode* someNode = ...;
291   Vector objectMovement = calculateShift();
292   Vector currentCoor = someNode->getRelCoor();
293   Vector newCoor = currentCoor + objectMovement;
294   someNode->setRelCoor(newCoor);
295
296   yea right... shorter...
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 * @param parentMode on which changes the child should also change ist state
408 *
409 * use this to add a child to this node.
410*/
411void PNode::addChild (PNode* child, int parentMode)
412{
413  if( likely(child->parent != NULL))
414    {
415      PRINTF(5)("PNode::addChild() - reparenting node: removing it and adding it again\n");
416      child->parent->children->remove(child);
417    }
418  child->parentMode = parentMode;
419  child->parent = this;
420  this->children->add(child);
421  child->parentCoorChanged();
422}
423
424/**
425 * @see PNode::addChild(PNode* child);
426 * @param childName the name of the child to add to this PNode
427 */
428void PNode::addChild (const char* childName)
429{
430  PNode* childNode = dynamic_cast<PNode*>(ClassList::getObject(childName, CL_PARENT_NODE));
431  if (childNode != NULL)
432    this->addChild(childNode);
433}
434
435/**
436 *  removes a child from the node
437 * @param child the child to remove from this pNode.
438 *
439 * Children from pNode will not be lost, they are referenced to NullPointer
440*/
441void PNode::removeChild (PNode* child)
442{
443  if (child != NULL)
444  {
445   child->remove();
446//   this->children->remove(child);
447//   child->parent = NULL;
448  }
449}
450
451/**
452 *  remove this pnode from the tree and adds all following to NullParent
453
454   this can be the case, if an entity in the world is being destroyed.
455*/
456void PNode::remove()
457{
458  tIterator<PNode>* iterator = this->children->getIterator();
459  PNode* pn = iterator->firstElement();
460
461  while( pn != NULL)
462    {
463      NullParent::getInstance()->addChild(pn, pn->getParentMode());
464      pn = iterator->nextElement();
465    }
466  delete iterator;
467  if (this->parent != NULL)
468    this->parent->children->remove(this);
469}
470
471/**
472 * sets the parent of this PNode
473 * @param parent the Parent to set
474*/
475void PNode::setParent (PNode* parent)
476{
477  parent->addChild(this);
478}
479
480/**
481 * @see PNode::setParent(PNode* parent);
482 * @param parentName the name of the Parent to set to this PNode
483 */
484void PNode::setParent (const char* parentName)
485{
486  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
487  if (parentNode != NULL)
488    parentNode->addChild(this);
489}
490
491/**
492 * does the reparenting in a very smooth way
493 * @param parentNode the new Node to connect this node to.
494 * @param bias the speed to iterate to this new Positions
495 */
496void PNode::softReparent(PNode* parentNode, float bias)
497{
498  if (this->parent == parentNode)
499    return;
500
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)
520   this->setRelCoor(this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()));
521 else
522   this->setRelCoor(tmpV - parentNode->getAbsCoor());
523
524  this->setRelDir(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::softReparent(const char* parentName, float bias)
533{
534  PNode* parentNode = dynamic_cast<PNode*>(ClassList::getObject(parentName, CL_PARENT_NODE));
535  if (parentNode != NULL)
536    this->softReparent(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->getRelCoor()) *fabsf(dt)*bias;
564
565        if (likely(moveVect.len() >= PNODE_ITERATION_DELTA))
566        {
567          this->shiftCoor(moveVect);
568        }
569        else
570        {
571          delete this->toCoordinate;
572          this->toCoordinate = NULL;
573          PRINTF(5)("SmoothMove of %s finished\n", this->getName());
574        }
575      }
576      if (unlikely(this->toDirection != NULL))
577      {
578        Quaternion rotQuat = Quaternion::quatSlerp(Quaternion(), (*this->toDirection / this->relDirection), fabsf(dt)*this->bias);
579        if (likely(rotQuat.getSpacialAxisAngle() > PNODE_ITERATION_DELTA))
580        {
581          this->shiftDir(rotQuat);
582        }
583        else
584        {
585          delete this->toDirection;
586          this->toDirection = NULL;
587          PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
588        }
589      }
590
591      // MAIN UPDATE /////////////////////////////////////
592      this->lastAbsCoordinate = this->absCoordinate;
593
594      PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
595
596
597      if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)
598      {
599        /* update the current absDirection - remember * means rotation around sth.*/
600        this->prevRelCoordinate = this->relCoordinate;
601        this->absDirection = this->relDirection * parent->getAbsDir();;
602      }
603
604      if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
605      {
606        /* update the current absCoordinate */
607        this->prevRelCoordinate = this->relCoordinate;
608        this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
609      }
610      else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
611      {
612        /* update the current absCoordinate */
613        this->prevRelCoordinate = this->relCoordinate;
614        this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
615      }
616      /////////////////////////////////////////////////
617   }
618  else
619    {
620      PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
621      if (this->bRelCoorChanged)
622      {
623        this->prevRelCoordinate = this->relCoordinate;
624        this->absCoordinate = this->relCoordinate;
625      }
626      if (this->bRelDirChanged)
627      {
628        this->prevRelDirection = this->relDirection;
629        this->absDirection = this->getAbsDir () * this->relDirection;
630      }
631    }
632
633    if(this->children->getSize() > 0)
634    {
635      tIterator<PNode>* iterator = this->children->getIterator();
636      PNode* pn = iterator->firstElement();
637      while( pn != NULL)
638      {
639        /* if this node has changed, make sure, that all children are updated also */
640        if( likely(this->bRelCoorChanged))
641          pn->parentCoorChanged ();
642        if( likely(this->bRelDirChanged))
643          pn->parentDirChanged ();
644
645        pn->update(dt);
646        pn = iterator->nextElement();
647      }
648      delete iterator;
649    }
650    this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
651    this->bRelCoorChanged = false;
652    this->bRelDirChanged = false;
653}
654
655/**
656 *  displays some information about this pNode
657 * @param depth The deph into which to debug the children of this PNode to.
658 * (0: all children will be debugged, 1: only this PNode, 2: this and direct children...)
659 * @param level The n-th level of the Node we draw (this is internal and only for nice output)
660*/
661void PNode::debug(unsigned int depth, unsigned int level) const
662{
663  for (unsigned int i = 0; i < level; i++)
664    PRINT(0)(" |");
665  if (this->children->getSize() > 0)
666    PRINT(0)(" +");
667  else
668    PRINT(0)(" -");
669  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",
670           this->getClassName(),
671           this->getName(),
672           this->absCoordinate.x,
673           this->absCoordinate.y,
674           this->absCoordinate.z,
675           this->relCoordinate.x,
676           this->relCoordinate.y,
677           this->relCoordinate.z,
678           this->getAbsDirV().x,
679           this->getAbsDirV().y,
680           this->getAbsDirV().z,
681           this->parentingModeToChar(parentMode));
682  if (depth >= 2 || depth == 0)
683  {
684    tIterator<PNode>* iterator = this->children->getIterator();
685      //PNode* pn = this->children->enumerate ();
686    PNode* pn = iterator->firstElement();
687    while( pn != NULL)
688    {
689      if (depth == 0)
690        pn->debug(0, level + 1);
691      else
692        pn->debug(depth - 1, level +1);
693      pn = iterator->nextElement();
694    }
695    delete iterator;
696  }
697}
698#include "color.h"
699
700/**
701   displays the PNode at its position with its rotation as a cube.
702*/
703void PNode::debugDraw(unsigned int depth, float size, Vector color) const
704{
705  glMatrixMode(GL_MODELVIEW);
706  glPushMatrix();
707  glDisable(GL_LIGHTING);
708
709  /* translate */
710  glTranslatef (this->getAbsCoor ().x,
711                this->getAbsCoor ().y,
712                this->getAbsCoor ().z);
713  /* rotate */
714//  this->getAbsDir ().matrix (matrix);
715//  glMultMatrixf((float*)matrix);
716
717  Vector tmpRot = this->getAbsDir().getSpacialAxis();
718  glColor3f(color.x, color.y, color.z);
719  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
720  {
721    glBegin(GL_LINE_STRIP);
722    glVertex3f(-.5*size, -.5*size,  -.5*size);
723    glVertex3f(+.5*size, -.5*size,  -.5*size);
724    glVertex3f(+.5*size, -.5*size,  +.5*size);
725    glVertex3f(-.5*size, -.5*size,  +.5*size);
726    glVertex3f(-.5*size, -.5*size,  -.5*size);
727    glEnd();
728    glBegin(GL_LINE_STRIP);
729    glVertex3f(-.5*size, +.5*size,  -.5*size);
730    glVertex3f(+.5*size, +.5*size,  -.5*size);
731    glVertex3f(+.5*size, +.5*size,  +.5*size);
732    glVertex3f(-.5*size, +.5*size,  +.5*size);
733    glVertex3f(-.5*size, +.5*size,  -.5*size);
734    glEnd();
735
736    glBegin(GL_LINES);
737    glVertex3f(-.5*size, -.5*size,  -.5*size);
738    glVertex3f(-.5*size, +.5*size,  -.5*size);
739    glVertex3f(+.5*size, -.5*size,  -.5*size);
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
748  glPopMatrix();
749  glEnable(GL_LIGHTING);
750  if (depth >= 2 || depth == 0)
751  {
752    Vector childColor =  Color::HSVtoRGB(Color::RGBtoHSV(color)+Vector(20,0,.0));
753
754    tIterator<PNode>* iterator = this->children->getIterator();
755    PNode* pn = iterator->firstElement();
756    while( pn != NULL)
757    {
758      if (depth == 0)
759        pn->debugDraw(0, size, childColor);
760      else
761        pn->debugDraw(depth - 1, size, childColor);
762      pn = iterator->nextElement();
763    }
764    delete iterator;
765  }
766}
767
768
769
770/////////////////////
771// HELPER_FUCTIONS //
772/////////////////////
773
774/**
775 * converts a parentingMode into a string that is the name of it
776 * @param parentingMode the ParentingMode to convert
777 * @return the converted string
778 */
779const char* PNode::parentingModeToChar(int parentingMode)
780{
781  if (parentingMode == PNODE_LOCAL_ROTATE)
782    return "local-rotate";
783  else if (parentingMode == PNODE_ROTATE_MOVEMENT)
784    return "rotate-movement";
785  else if (parentingMode == PNODE_MOVEMENT)
786    return "movement";
787  else if (parentingMode == PNODE_ALL)
788    return "all";
789  else if (parentingMode == PNODE_ROTATE_AND_MOVE)
790    return "rotate-and-move";
791}
792
793/**
794 * converts a parenting-mode-string into a int
795 * @param parentingMode the string naming the parentingMode
796 * @return the int corresponding to the named parentingMode
797 */
798PARENT_MODE PNode::charToParentingMode(const char* parentingMode)
799{
800  if (!strcmp(parentingMode, "local-rotate"))
801    return (PNODE_LOCAL_ROTATE);
802  else  if (!strcmp(parentingMode, "rotate-movement"))
803    return (PNODE_ROTATE_MOVEMENT);
804  else  if (!strcmp(parentingMode, "movement"))
805    return (PNODE_MOVEMENT);
806  else  if (!strcmp(parentingMode, "all"))
807    return (PNODE_ALL);
808  else  if (!strcmp(parentingMode, "rotate-and-move"))
809    return (PNODE_ROTATE_AND_MOVE);
810}
Note: See TracBrowser for help on using the repository browser.