Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: valgrind mem-leak-recovered

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