Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/render2D/element_2d.cc @ 5107

Last change on this file since 5107 was 5107, checked in by bensch, 20 years ago

orxonox/trunk: shell is now properly moving through the bufferlines

File size: 22.9 KB
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[4838]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[4839]18#include "element_2d.h"
[4840]19#include "render_2d.h"
[1853]20
[4843]21#include "graphics_engine.h"
22#include "p_node.h"
[4858]23#include "load_param.h"
24#include "tinyxml.h"
25#include "class_list.h"
[5082]26#include "list.h"
[4843]27
[1856]28using namespace std;
[1853]29
[5089]30Element2D::Element2D()
31{
32  this->init();
33  this->setParent2D(NullElement2D::getInstance());
34}
[1856]35
[3245]36/**
[4838]37 * standard constructor
38 * @todo this constructor is not jet implemented - do it
[3245]39*/
[5084]40Element2D::Element2D (Element2D* parent)
[3365]41{
[5089]42  this->init();
43
44  if (this->parent != NULL)
45    this->setParent2D(parent);
[3365]46}
[1853]47
[3245]48/**
[4838]49 * standard deconstructor
[3245]50*/
[4838]51Element2D::~Element2D ()
[3543]52{
53  // delete what has to be deleted here
[4840]54  Render2D::getInstance()->unregisterElement2D(this);
[5088]55
[5089]56  tIterator<Element2D>* iterator = this->children->getIterator();
57  Element2D* pn = iterator->nextElement();
58  while( pn != NULL)
59  {
60    delete pn;
61    pn = iterator->nextElement();
62  }
63  delete iterator;
64  /* this deletes all children in the list */
65  delete this->children;
66  if (this->parent)
67    this->parent->removeChild2D(this);
68
[5088]69  if (this->toCoordinate != NULL)
70    delete this->toCoordinate;
71  if (this->toDirection != NULL)
72    delete this->toDirection;
[3543]73}
[4843]74
75
[4858]76/**
77 * initializes a Element2D
78 */
[5089]79void Element2D::init()
[4847]80{
81  this->setClassID(CL_ELEMENT_2D, "Element2D");
82
[4861]83  this->setVisibility(true);
[5068]84  this->setActiveness(true);
[4861]85  this->setAlignment(E2D_ALIGN_NONE);
[4862]86  this->layer = E2D_TOP;
[5089]87  this->bindNode = NULL;
[5084]88
[5082]89  this->setParentMode2D(E2D_PARENT_ALL);
[5089]90  this->parent = NULL;
[5084]91  this->children = new tList<Element2D>;
[5089]92  this->relDirection = 0.0;
[5082]93  this->bRelCoorChanged = true;
94  this->bRelDirChanged = true;
[5088]95  this->toCoordinate = NULL;
96  this->toDirection = NULL;
[5084]97//  else
98  //  this->setParent2D(parent);
[5082]99
[4847]100  Render2D::getInstance()->registerElement2D(this);
101}
102
[4843]103/**
[4858]104 * Loads the Parameters of an Element2D from...
105 * @param root The XML-element to load from
106 */
107void Element2D::loadParams(const TiXmlElement* root)
108{
109  LoadParam<Element2D>(root, "alignment", this, &Element2D::setAlignment)
110      .describe("loads the alignment: (either: center, left, right or screen-center)");
111
112  LoadParam<Element2D>(root, "layer", this, &Element2D::setLayer)
113      .describe("loads the layer onto which to project: (either: top, medium, bottom, below-all)");
114
115  LoadParam<Element2D>(root, "bind-node", this, &Element2D::setBindNode)
116      .describe("sets a node, this 2D-Element should be shown upon (name of the node)");
117
[4860]118  LoadParam<Element2D>(root, "visibility", this, &Element2D::setVisibility)
119      .describe("if the Element is visible or not");
[5089]120
121
[5091]122  // PNode-style:
123  LoadParam<Element2D>(root, "rel-coor", this, &Element2D::setRelCoor2D)
124      .describe("Sets The relative position of the Node to its parent.");
125
126  LoadParam<Element2D>(root, "abs-coor", this, &Element2D::setAbsCoor2D)
127      .describe("Sets The absolute Position of the Node.");
128
129  LoadParam<Element2D>(root, "rel-dir", this, &Element2D::setRelDir2D)
130      .describe("Sets The relative rotation of the Node to its parent.");
131
132  LoadParam<Element2D>(root, "abs-dir", this, &Element2D::setAbsDir2D)
133      .describe("Sets The absolute rotation of the Node.");
134
135  LoadParam<Element2D>(root, "parent", this, &Element2D::setParent2D)
136      .describe("the Name of the Parent of this Element2D");
137
138  LoadParam<Element2D>(root, "parent-mode", this, &Element2D::setParentMode2D)
139      .describe("the mode to connect this node to its parent ()");
140
141  // cycling properties
142  if (root != NULL)
143  {
144    const TiXmlElement* element = root->FirstChildElement();
145    while (element != NULL)
146    {
147      LoadParam<Element2D>(root, "parent", this, &Element2D::addChild2D, true)
148          .describe("adds a new Child to the current Node.");
149
150      element = element->NextSiblingElement();
151    }
152  }
[4858]153}
154
155/**
156 * sets the alignment of the 2D-element in form of a String
157 * @param alignment the alignment @see loadParams
158*/
159void Element2D::setAlignment(const char* alignment)
160{
161  if (!strcmp(alignment, "center"))
162    this->setAlignment(E2D_ALIGN_CENTER);
163  else if (!strcmp(alignment, "left"))
164    this->setAlignment(E2D_ALIGN_LEFT);
165  else if (!strcmp(alignment, "right"))
166    this->setAlignment(E2D_ALIGN_RIGHT);
167  else if (!strcmp(alignment, "screen-center"))
168    this->setAlignment(E2D_ALIGN_SCREEN_CENTER);
169}
170
[4862]171
[4858]172/**
[4862]173 * moves a Element to another layer
174 * @param layer the Layer this is drawn on
175 */
176void Element2D::setLayer(E2D_LAYER layer)
177{
178  Render2D::getInstance()->moveToLayer(this, layer);
179  this->layer = layer;
180}
181
182/**
[4858]183 * sets the layer onto which this 2D-element is projected to.
184 * @param layer the layer @see loadParams
185 */
186void Element2D::setLayer(const char* layer)
187{
188  if (!strcmp(layer, "top"))
189    this->setLayer(E2D_TOP);
190  else if (!strcmp(layer, "medium"))
191    this->setLayer(E2D_MEDIUM);
192  else if (!strcmp(layer, "bottom"))
193    this->setLayer(E2D_BOTTOM);
194  else if (!strcmp(layer, "below-all"))
195    this->setLayer(E2D_BELOW_ALL);
196}
197
198
199/**
200 * sets a node, this 2D-Element should be shown upon
201 * @param bindNode the name of the Node (should be existing)
202 */
203void Element2D::setBindNode(const char* bindNode)
204{
205  const PNode* tmpBindNode = dynamic_cast<const PNode*>(ClassList::getObject(bindNode, CL_PARENT_NODE));
206  if (tmpBindNode != NULL)
207    this->bindNode = tmpBindNode;
208}
209
[5091]210/**
211 * sets the relative coordinate of the Element2D to its parent
212 * @param relCoord the relative coordinate to the parent
213 */
[5081]214void Element2D::setRelCoor2D (const Vector& relCoord)
215{
[5082]216  this->relCoordinate = relCoord;
217  this->bRelCoorChanged = true;
[5081]218}
219
220
[5091]221/**
222 * sets the relative coordinate of the Element2D to its Parent
223 * @param x the x coordinate
224 * @param y the y coordinate
225 * @param z the z coordinate
226 */
[5081]227void Element2D::setRelCoor2D (float x, float y, float z)
228{
[5082]229  this->setAbsCoor2D(Vector(x,y,z));
[5081]230}
231
[5091]232/**
233 * sets the Relative coordinate to the parent in Pixels
234 * @param x the relCoord X
235 * @param y the relCoord Y
236 */
[5089]237void Element2D::setRelCoor2Dpx (int x, int y)
238{
[5090]239  this->setRelCoor2D(Vector((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
240                     (float)y/(float)GraphicsEngine::getInstance()->getResolutionY(),
[5089]241                     0
242                           ));
243}
244
[5091]245/**
246 * sets a new relative position smoothely
247 * @param relCoordSoft the new Position to iterate to
248 * @param bias how fast to iterate to this position
249 */
[5081]250void Element2D::setRelCoorSoft2D(const Vector& relCoordSoft, float bias)
251{
[5082]252  if (likely(this->toCoordinate == NULL))
253    this->toCoordinate = new Vector();
254
255  *this->toCoordinate = relCoordSoft;
256  this->bias = bias;
[5081]257}
258
[5091]259/**
260 * sets a new relative position smoothely
261 * @param x the new x-coordinate in Pixels of the Position to iterate to
262 * @param y the new y-coordinate in Pixels of the Position to iterate to
263 * @param bias how fast to iterate to this position
264 */
[5089]265void Element2D::setRelCoorSoft2Dpx (int x, int y, float bias)
266{
[5090]267  this->setRelCoorSoft2D(Vector((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
268                         (float)y/(float)GraphicsEngine::getInstance()->getResolutionY(),
[5089]269                         0),
270                         bias);
271}
272
[5091]273/**
274 * set relative coordinates smoothely
275 * @param x x-relative coordinates to its parent
276 * @param y y-relative coordinates to its parent
277 * @param z z-relative coordinates to its parent
278 * @see  void PNode::setRelCoorSoft (const Vector&, float)
279 */
[5082]280void Element2D::setRelCoorSoft2D(float x, float y, float depth, float bias)
[5081]281{
[5082]282  this->setRelCoorSoft2D(Vector(x, y, depth), bias);
[5081]283}
284
[5091]285/**
286 * @param absCoord set absolute coordinate
287 */
[5081]288void Element2D::setAbsCoor2D (const Vector& absCoord)
289{
[5082]290  if( likely(this->parentMode & E2D_PARENT_MOVEMENT))
291  {
292    /* if you have set the absolute coordinates this overrides all other changes */
293    if (likely(this->parent != NULL))
294      this->relCoordinate = absCoord - parent->getAbsCoor2D ();
295    else
296      this->relCoordinate = absCoord;
297  }
298  if( this->parentMode & E2D_PARENT_ROTATE_MOVEMENT)
299  {
300    if (likely(this->parent != NULL))
301      this->relCoordinate = absCoord - parent->getAbsCoor2D ();
302    else
303      this->relCoordinate = absCoord;
304  }
305
306  this->bRelCoorChanged = true;
[5081]307}
308
[5091]309/**
310 * @param x x-coordinate.
311 * @param y y-coordinate.
312 * @param z z-coordinate.
313 * @see void PNode::setAbsCoor (const Vector& absCoord)
314 */
[5081]315void Element2D::setAbsCoor2D (float x, float y, float depth)
316{
[5082]317  this->setAbsCoor2D(Vector(x, y, depth));
[5081]318}
319
[5091]320/**
321 * @param x x-coordinate in Pixels
322 * @param y y-coordinate in Pixels
323 * @see void PNode::setAbsCoor (const Vector& absCoord)
324 */
[5089]325void Element2D::setAbsCoor2Dpx (int x, int y)
326{
[5090]327  this->setAbsCoor2D(Vector((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
328                     (float)y/(float)GraphicsEngine::getInstance()->getResolutionY(),
[5089]329                     0
330                           ));
331}
332
[5091]333/**
334 *  shift coordinate ralative
335 * @param shift shift vector
336 *
337 * This simply adds the shift-Vector to the relative Coordinate
338 */
[5083]339void Element2D::shiftCoor2D (const Vector& shift)
[5081]340{
[5082]341  this->relCoordinate += shift;
342  this->bRelCoorChanged = true;
343
[5081]344}
345
[5091]346/**
347 * shifts in PixelSpace
348 * @param x the pixels to shift in X
349 * @param y the pixels to shift in Y
350 */
[5089]351void Element2D::shiftCoor2Dpx (int x, int y)
352{
[5090]353  this->shiftCoor2D(Vector((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
354                    (float)y/(float)GraphicsEngine::getInstance()->getResolutionY(),
[5089]355                     0));
356}
357
[5091]358/**
359 *  set relative direction
360 * @param relDir to its parent
361 */
[5081]362void Element2D::setRelDir2D (float relDir)
363{
[5082]364  this->relDirection = relDir;
365  this->bRelDirChanged = true;
[5081]366}
367
[5091]368/**
369 * sets the Relative Direction of this node to its parent in a Smoothed way
370 * @param relDirSoft the direction to iterate to smoothely.
371 * @param bias how fast to iterate to the new Direction
372 */
[5081]373void Element2D::setRelDirSoft2D(float relDirSoft, float bias)
374{
[5082]375  if (likely(this->toDirection == NULL))
376    this->toDirection = new float;
377
378  *this->toDirection = relDirSoft;
379  this->bias = bias;
[5081]380}
381
[5091]382/**
383 *  sets the absolute direction
384 * @param absDir absolute coordinates
385 */
[5081]386void Element2D::setAbsDir2D (float absDir)
387{
[5082]388  if (likely(this->parent != NULL))
389    this->relDirection = absDir - this->parent->getAbsDir2D();
390  else
391    this->relDirection = absDir;
392
393  this->bRelDirChanged = true;
[5081]394}
395
[5091]396/**
397 * shift Direction
398 * @param shift the direction around which to shift.
399 */
[5083]400void Element2D::shiftDir2D (float shiftDir)
[5081]401{
[5082]402  this->relDirection = this->relDirection + shiftDir;
403  this->bRelDirChanged = true;
[5081]404}
405
[5091]406/**
407 *  adds a child and makes this node to a parent
408 * @param child child reference
409 * @param parentMode on which changes the child should also change ist state
410 *
411 * use this to add a child to this node.
412 */
[5081]413void Element2D::addChild2D (Element2D* child, int parentingMod)
414{
[5082]415  if( likely(child->parent != NULL))
416  {
[5084]417    PRINTF(4)("Element2D::addChild() - reparenting node: removing it and adding it again\n");
[5082]418    child->parent->children->remove(child);
419  }
420  child->parentMode = parentMode;
421  child->parent = this;
422  this->children->add(child);
423  child->parentCoorChanged();
[5081]424}
425
[5091]426/**
427 * @see Element2D::addChild(Element2D* child);
428 * @param childName the name of the child to add to this PNode
429 */
[5081]430void Element2D::addChild2D (const char* childName)
431{
[5082]432  Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D));
433  if (childNode != NULL)
434    this->addChild2D(childNode);
[5081]435}
436
[5091]437/**
438 * removes a child from the node
439 * @param child the child to remove from this Node..
440 *
441 * Children from nodes will not be lost, they are referenced to NullPointer
442 */
[5081]443void Element2D::removeChild2D (Element2D* child)
444{
[5082]445  child->remove2D();
446  this->children->remove(child);
447  child->parent = NULL;
[5081]448}
449
[5091]450/**
451 * remove this pnode from the tree and adds all following to NullParent
452 *
453 * this can be the case, if an entity in the world is being destroyed.
454 */
[5081]455void Element2D::remove2D()
456{
[5082]457  tIterator<Element2D>* iterator = this->children->getIterator();
458  Element2D* pn = iterator->nextElement();
459
460  while( pn != NULL)
461  {
462    NullElement2D::getInstance()->addChild2D(pn, pn->getParentMode2D());
463    pn = iterator->nextElement();
464  }
465  delete iterator;
466  this->parent->children->remove(this);
[5081]467}
468
[5091]469/**
470 * sets the parent of this Element2D
471 * @param parent the Parent to set
472 */
[5081]473void Element2D::setParent2D (Element2D* parent)
474{
[5082]475  parent->addChild2D(this);
[5081]476}
477
[5091]478/**
479 * @see Element2D::setParent(Element2D* parent);
480 * @param parentName the name of the Parent to set to this Element2D
481 */
[5081]482void Element2D::setParent2D (const char* parentName)
483{
[5082]484  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
485  if (parentNode != NULL)
486    parentNode->addChild2D(this);
487
[5081]488}
489
[5091]490/**
491 * does the reparenting in a very smooth way
492 * @param parentNode the new Node to connect this node to.
493 * @param bias the speed to iterate to this new Positions
494 */
[5082]495void Element2D::softReparent2D(Element2D* parentNode, float bias)
[5081]496{
[5082]497  if (this->parent == parentNode)
498    return;
499
500  if (likely(this->toCoordinate == NULL))
501  {
502    this->toCoordinate = new Vector();
503    *this->toCoordinate = this->getRelCoor2D();
504  }
505  if (likely(this->toDirection == NULL))
506  {
507    this->toDirection = new float;
508    *this->toDirection = this->getRelDir2D();
509  }
510  this->bias = bias;
511
512
513  Vector tmpV = this->getAbsCoor2D();
514  float tmpQ = this->getAbsDir2D();
515
516  parentNode->addChild2D(this);
517
518  if (this->parentMode & PNODE_ROTATE_MOVEMENT)
519    ;//this->setRelCoor(this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()));
520  else
521    this->setRelCoor2D(tmpV - parentNode->getAbsCoor2D());
522
523  this->setRelDir2D(tmpQ - parentNode->getAbsDir2D());
[5081]524}
525
[5091]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 */
[5082]531void Element2D::softReparent2D(const char* parentName, float bias)
[5081]532{
[5082]533  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
534  if (parentNode != NULL)
535    this->softReparent2D(parentNode, bias);
[5081]536}
537
[5091]538/**
539 *  sets the mode of this parent manually
540 * @param parentMode a String representing this parentingMode
541 */
[5081]542void Element2D::setParentMode2D (const char* parentingMode)
543{
[5082]544  this->setParentMode2D(Element2D::charToParentingMode2D(parentingMode));
[5081]545}
546
[5091]547/**
548 *  updates the absCoordinate/absDirection
549 * @param dt The time passed since the last update
[5081]550
[5091]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 */
[5081]555void Element2D::update2D (float dt)
556{
[5089]557  // setting the Position of this 2D-Element.
[5083]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->getRelCoor2D()) *dt*bias;
[5082]564
[5083]565      if (likely(moveVect.len() >= .001))//PNODE_ITERATION_DELTA))
566      {
567        this->shiftCoor2D(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      float rotFlot = (*this->toDirection - this->getRelDir2D()) *dt*bias;
579      if (likely(rotFlot >= .001))//PNODE_ITERATION_DELTA))
580      {
581        this->shiftDir2D(rotFlot);
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
[5084]594    PRINTF(5)("Element2D::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
[5083]595
596
597    if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)
598    {
599      /* update the current absDirection - remember * means rotation around sth.*/
[5090]600      this->prevRelDirection = this->relDirection;
[5083]601      this->absDirection = this->relDirection + parent->getAbsDir2D();;
602    }
603
[5089]604
605    if (this->alignment == E2D_ALIGN_SCREEN_CENTER && this->bRelCoorChanged)
[5083]606    {
607      this->prevRelCoordinate = this->relCoordinate;
[5089]608      this->absCoordinate.x = .5 + this->relCoordinate.x;
609      this->absCoordinate.y = .5 + this->relCoordinate.y;
610      this->absCoordinate.z = 0.0;
[5083]611    }
[5089]612    else if (this->bindNode)
[5083]613    {
[5089]614      GLdouble projectPos[3];
615      gluProject(this->bindNode->getAbsCoor().x,
616                 this->bindNode->getAbsCoor().y,
617                 this->bindNode->getAbsCoor().z,
618                 GraphicsEngine::modMat,
619                 GraphicsEngine::projMat,
620                 GraphicsEngine::viewPort,
621                 projectPos,
622                 projectPos+1,
623                 projectPos+2);
624      this->absCoordinate.x = projectPos[0]/(float)GraphicsEngine::getInstance()->getResolutionX() + this->relCoordinate.x;
625      this->absCoordinate.y = projectPos[1]/(float)GraphicsEngine::getInstance()->getResolutionY() + this->relCoordinate.y;
626      this->absCoordinate.z = projectPos[2] + this->relCoordinate.z;
627    }
628    else
629    {
630      if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
631      {
632        /* update the current absCoordinate */
633        this->prevRelCoordinate = this->relCoordinate;
634        this->absCoordinate = this->parent->getAbsCoor2D() + this->relCoordinate;
635      }
636      else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
637      {
638        /* update the current absCoordinate */
639        this->prevRelCoordinate = this->relCoordinate;
[5090]640        float sine = sin(this->parent->getAbsDir2D());
641        float cose = cos(this->parent->getAbsDir2D());
642//        this->absCoordinate.x = this->relCoordinate.x*cose - this->relCoordinate.y*sine + this->parent->getRelCoor2D().x*(1-cose) +this->parent->getRelCoor2D().y*sine;
643//        this->absCoordinate.y = this->relCoordinate.x*sine + this->relCoordinate.y*cose + this->parent->getRelCoor2D().y*(1-cose) +this->parent->getRelCoor2D().x*sine;
644
[5089]645        this->absCoordinate.x = this->parent->getAbsCoor2D().x + (this->relCoordinate.x*cos(this->parent->getAbsDir2D()) - this->relCoordinate.y * sin(this->parent->getAbsDir2D()));
646        this->absCoordinate.y = this->parent->getAbsCoor2D().y + (this->relCoordinate.x*sin(this->parent->getAbsDir2D()) + this->relCoordinate.y * cos(this->parent->getAbsDir2D()));
[5083]647
[5089]648      }
[5083]649    }
650    /////////////////////////////////////////////////
651  }
652  else
653  {
[5084]654    PRINTF(5)("Element2D::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
[5083]655    if (this->bRelCoorChanged)
656      this->absCoordinate = this->relCoordinate;
657    if (this->bRelDirChanged)
658      this->absDirection = this->getAbsDir2D() * this->relDirection;
659  }
660
[5089]661
662  // UPDATE CHILDREN
[5083]663  if(this->children->getSize() > 0)
664  {
665    tIterator<Element2D>* iterator = this->children->getIterator();
666    Element2D* pn = iterator->nextElement();
667    while( pn != NULL)
668    {
669      /* if this node has changed, make sure, that all children are updated also */
670      if( likely(this->bRelCoorChanged))
671        pn->parentCoorChanged ();
672      if( likely(this->bRelDirChanged))
673        pn->parentDirChanged ();
674
675      pn->update2D(dt);
676          //pn = this->children->nextElement();
677      pn = iterator->nextElement();
678    }
679    delete iterator;
680  }
[5089]681
682  // FINISHING PROCESS
[5083]683  this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
684  this->bRelCoorChanged = false;
685  this->bRelDirChanged = false;
[5081]686}
687
[5091]688/**
689 *  displays some information about this pNode
690 * @param depth The deph into which to debug the children of this Element2D to.
691 * (0: all children will be debugged, 1: only this Element2D, 2: this and direct children...)
692 * @param level The n-th level of the Node we draw (this is internal and only for nice output)
693 */
[5081]694void Element2D::debug (unsigned int depth, unsigned int level) const
695{
[5082]696  for (unsigned int i = 0; i < level; i++)
697    PRINT(0)(" |");
698  if (this->children->getSize() > 0)
699    PRINT(0)(" +");
700  else
701    PRINT(0)(" -");
702  PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s\n",
703  this->getClassName(),
704  this->getName(),
705  this->absCoordinate.x,
706  this->absCoordinate.y,
707  this->relCoordinate.x,
708  this->relCoordinate.y,
709  this->getAbsDir2D(),
710  Element2D::parentingModeToChar2D(parentMode));
711  if (depth >= 2 || depth == 0)
712  {
713    tIterator<Element2D>* iterator = this->children->getIterator();
714    Element2D* pn = iterator->nextElement();
715    while( pn != NULL)
716    {
717      if (depth == 0)
718        pn->debug(0, level + 1);
719      else
720        pn->debug(depth - 1, level +1);
721      pn = iterator->nextElement();
722    }
723    delete iterator;
724  }
[5081]725}
726
[5082]727#include "color.h"
728
[5091]729/**
730 * displays the Element2D at its position with its rotation as a Plane.
731 */
[5081]732void Element2D::debugDraw2D(unsigned int depth, float size, Vector color) const
733{
[5082]734
[5081]735}
736
737
738// helper functions //
[5091]739/**
740 * converts a parentingMode into a string that is the name of it
741 * @param parentingMode the ParentingMode to convert
742 * @return the converted string
743 */
[5082]744const char* Element2D::parentingModeToChar2D(int parentingMode)
[5081]745{
[5082]746  if (parentingMode == E2D_PARENT_LOCAL_ROTATE)
747    return "local-rotate";
748  else if (parentingMode == E2D_PARENT_ROTATE_MOVEMENT)
749    return "rotate-movement";
750  else if (parentingMode == E2D_PARENT_MOVEMENT)
751    return "movement";
752  else if (parentingMode == E2D_PARENT_ALL)
753    return "all";
754  else if (parentingMode == E2D_PARENT_ROTATE_AND_MOVE)
755    return "rotate-and-move";
[5081]756}
757
[5091]758/**
759 * converts a parenting-mode-string into a int
760 * @param parentingMode the string naming the parentingMode
761 * @return the int corresponding to the named parentingMode
762 */
[5082]763E2D_PARENT_MODE Element2D::charToParentingMode2D(const char* parentingMode)
[5081]764{
[5082]765  if (!strcmp(parentingMode, "local-rotate"))
766    return (E2D_PARENT_LOCAL_ROTATE);
767  else  if (!strcmp(parentingMode, "rotate-movement"))
768    return (E2D_PARENT_ROTATE_MOVEMENT);
769  else  if (!strcmp(parentingMode, "movement"))
770    return (E2D_PARENT_MOVEMENT);
771  else  if (!strcmp(parentingMode, "all"))
772    return (E2D_PARENT_ALL);
773  else  if (!strcmp(parentingMode, "rotate-and-move"))
774    return (E2D_PARENT_ROTATE_AND_MOVE);
[5081]775}
776
777
778
779
780
781
[4847]782/**
783 * ticks the 2d-Element
784 * @param dt the time elapsed since the last tick
785 */
786void Element2D::tick(float dt)
787{
[5089]788
[4843]789}
[5082]790
791
792
793
794
795
796
797NullElement2D* NullElement2D::singletonRef = 0;
798
799/**
800 *  creates the one and only NullElement2D
801 * @param absCoordinate the cordinate of the Parent (normally Vector(0,0,0))
802 */
[5089]803NullElement2D::NullElement2D () : Element2D(NULL)
[5082]804{
805  this->setClassID(CL_NULL_PARENT, "NullElement2D");
806  this->setName("NullElement2D");
807
808  this->setParentMode2D(E2D_PARENT_ALL);
809  NullElement2D::singletonRef = this;
810}
811
812
813/**
814 *  standard deconstructor
815 */
816NullElement2D::~NullElement2D ()
817{
818  //delete singletonRef;
819  NullElement2D::singletonRef = NULL;
820}
Note: See TracBrowser for help on using the repository browser.