Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: some little errors corrected via Valgrind

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  if (child != NULL)
470  {
471    child->remove2D();
472    this->children->remove(child);
473    child->parent = NULL;
474  }
475}
476
477/**
478 * remove this pnode from the tree and adds all following to NullParent
479 *
480 * this can be the case, if an entity in the world is being destroyed.
481 */
482void Element2D::remove2D()
483{
484  tIterator<Element2D>* iterator = this->children->getIterator();
485  Element2D* pn = iterator->firstElement();
486
487  while( pn != NULL)
488  {
489    NullElement2D::getInstance()->addChild2D(pn, pn->getParentMode2D());
490    pn = iterator->nextElement();
491  }
492  delete iterator;
493  this->parent->children->remove(this);
494}
495
496/**
497 * sets the parent of this Element2D
498 * @param parent the Parent to set
499 */
500void Element2D::setParent2D (Element2D* parent)
501{
502  parent->addChild2D(this);
503}
504
505/**
506 * @see Element2D::setParent(Element2D* parent);
507 * @param parentName the name of the Parent to set to this Element2D
508 */
509void Element2D::setParent2D (const char* parentName)
510{
511  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
512  if (parentNode != NULL)
513    parentNode->addChild2D(this);
514
515}
516
517/**
518 * does the reparenting in a very smooth way
519 * @param parentNode the new Node to connect this node to.
520 * @param bias the speed to iterate to this new Positions
521 */
522void Element2D::softReparent2D(Element2D* parentNode, float bias)
523{
524  if (this->parent == parentNode)
525    return;
526
527  if (likely(this->toCoordinate == NULL))
528  {
529    this->toCoordinate = new Vector();
530    *this->toCoordinate = this->getRelCoor2D();
531  }
532  if (likely(this->toDirection == NULL))
533  {
534    this->toDirection = new float;
535    *this->toDirection = this->getRelDir2D();
536  }
537  this->bias = bias;
538
539
540  Vector tmpV = this->getAbsCoor2D();
541  float tmpQ = this->getAbsDir2D();
542
543  parentNode->addChild2D(this);
544
545  if (this->parentMode & PNODE_ROTATE_MOVEMENT)
546    ;//this->setRelCoor(this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()));
547  else
548    this->setRelCoor2D(tmpV - parentNode->getAbsCoor2D());
549
550  this->setRelDir2D(tmpQ - parentNode->getAbsDir2D());
551}
552
553/**
554 * does the reparenting in a very smooth way
555 * @param parentName the name of the Parent to reconnect to
556 * @param bias the speed to iterate to this new Positions
557 */
558void Element2D::softReparent2D(const char* parentName, float bias)
559{
560  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
561  if (parentNode != NULL)
562    this->softReparent2D(parentNode, bias);
563}
564
565/**
566 *  sets the mode of this parent manually
567 * @param parentMode a String representing this parentingMode
568 */
569void Element2D::setParentMode2D (const char* parentingMode)
570{
571  this->setParentMode2D(Element2D::charToParentingMode2D(parentingMode));
572}
573
574/**
575 *  updates the absCoordinate/absDirection
576 * @param dt The time passed since the last update
577
578   this is used to go through the parent-tree to update all the absolute coordinates
579   and directions. this update should be done by the engine, so you don't have to
580   worry, normaly...
581 */
582void Element2D::update2D (float dt)
583{
584  // setting the Position of this 2D-Element.
585  if( likely(this->parent != NULL))
586  {
587      // movement for nodes with smoothMove enabled
588    if (unlikely(this->toCoordinate != NULL))
589    {
590      Vector moveVect = (*this->toCoordinate - this->getRelCoor2D()) *dt*bias;
591
592      if (likely(moveVect.len() >= .001))//PNODE_ITERATION_DELTA))
593      {
594        this->shiftCoor2D(moveVect);
595      }
596      else
597      {
598        delete this->toCoordinate;
599        this->toCoordinate = NULL;
600        PRINTF(5)("SmoothMove of %s finished\n", this->getName());
601      }
602    }
603    if (unlikely(this->toDirection != NULL))
604    {
605      float rotFlot = (*this->toDirection - this->getRelDir2D()) *dt*bias;
606      if (likely(rotFlot >= .001))//PNODE_ITERATION_DELTA))
607      {
608        this->shiftDir2D(rotFlot);
609      }
610      else
611      {
612        delete this->toDirection;
613        this->toDirection = NULL;
614        PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
615      }
616    }
617
618    // MAIN UPDATE /////////////////////////////////////
619    this->lastAbsCoordinate = this->absCoordinate;
620
621    PRINTF(5)("Element2D::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
622
623
624    if( this->parentMode & E2D_PARENT_LOCAL_ROTATE && this->bRelDirChanged)
625    {
626      /* update the current absDirection - remember * means rotation around sth.*/
627      this->prevRelDirection = this->relDirection;
628      this->absDirection = this->relDirection + parent->getAbsDir2D();;
629    }
630
631
632    if (this->alignment == E2D_ALIGN_SCREEN_CENTER && this->bRelCoorChanged)
633    {
634      this->prevRelCoordinate = this->relCoordinate;
635      this->absCoordinate.x = .5 + this->relCoordinate.x;
636      this->absCoordinate.y = .5 + this->relCoordinate.y;
637      this->absCoordinate.z = 0.0;
638    }
639    else if (this->bindNode)
640    {
641      GLdouble projectPos[3];
642      gluProject(this->bindNode->getAbsCoor().x,
643                 this->bindNode->getAbsCoor().y,
644                 this->bindNode->getAbsCoor().z,
645                 GraphicsEngine::modMat,
646                 GraphicsEngine::projMat,
647                 GraphicsEngine::viewPort,
648                 projectPos,
649                 projectPos+1,
650                 projectPos+2);
651      this->absCoordinate.x = projectPos[0]/(float)GraphicsEngine::getInstance()->getResolutionX() + this->relCoordinate.x;
652      this->absCoordinate.y = projectPos[1]/(float)GraphicsEngine::getInstance()->getResolutionY() + this->relCoordinate.y;
653      this->absCoordinate.z = projectPos[2] + this->relCoordinate.z;
654    }
655    else
656    {
657      if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
658      {
659        /* update the current absCoordinate */
660        this->prevRelCoordinate = this->relCoordinate;
661        this->absCoordinate = this->parent->getAbsCoor2D() + this->relCoordinate;
662      }
663      else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
664      {
665        /* update the current absCoordinate */
666        this->prevRelCoordinate = this->relCoordinate;
667        float sine = sin(this->parent->getAbsDir2D());
668        float cose = cos(this->parent->getAbsDir2D());
669//        this->absCoordinate.x = this->relCoordinate.x*cose - this->relCoordinate.y*sine + this->parent->getRelCoor2D().x*(1-cose) +this->parent->getRelCoor2D().y*sine;
670//        this->absCoordinate.y = this->relCoordinate.x*sine + this->relCoordinate.y*cose + this->parent->getRelCoor2D().y*(1-cose) +this->parent->getRelCoor2D().x*sine;
671
672        this->absCoordinate.x = this->parent->getAbsCoor2D().x + (this->relCoordinate.x*cos(this->parent->getAbsDir2D()) - this->relCoordinate.y * sin(this->parent->getAbsDir2D()));
673        this->absCoordinate.y = this->parent->getAbsCoor2D().y + (this->relCoordinate.x*sin(this->parent->getAbsDir2D()) + this->relCoordinate.y * cos(this->parent->getAbsDir2D()));
674
675      }
676    }
677    /////////////////////////////////////////////////
678  }
679  else
680  {
681    PRINTF(5)("Element2D::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
682    if (this->bRelCoorChanged)
683    {
684      this->prevRelCoordinate = this->relCoordinate;
685      this->absCoordinate = this->relCoordinate;
686    }
687    if (this->bRelDirChanged)
688    {
689      this->prevRelDirection = this->relDirection;
690      this->absDirection = this->getAbsDir2D() * this->relDirection;
691    }
692  }
693
694
695  // UPDATE CHILDREN
696  if(this->children->getSize() > 0)
697  {
698    tIterator<Element2D>* iterator = this->children->getIterator();
699    Element2D* pn = iterator->firstElement();
700    while( pn != NULL)
701    {
702      /* if this node has changed, make sure, that all children are updated also */
703      if( likely(this->bRelCoorChanged))
704        pn->parentCoorChanged ();
705      if( likely(this->bRelDirChanged))
706        pn->parentDirChanged ();
707
708      pn->update2D(dt);
709      pn = iterator->nextElement();
710    }
711    delete iterator;
712  }
713
714  // FINISHING PROCESS
715  this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
716  this->bRelCoorChanged = false;
717  this->bRelDirChanged = false;
718}
719
720/**
721 *  displays some information about this pNode
722 * @param depth The deph into which to debug the children of this Element2D to.
723 * (0: all children will be debugged, 1: only this Element2D, 2: this and direct children...)
724 * @param level The n-th level of the Node we draw (this is internal and only for nice output)
725 */
726void Element2D::debug (unsigned int depth, unsigned int level) const
727{
728  for (unsigned int i = 0; i < level; i++)
729    PRINT(0)(" |");
730  if (this->children->getSize() > 0)
731    PRINT(0)(" +");
732  else
733    PRINT(0)(" -");
734  PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s\n",
735  this->getClassName(),
736  this->getName(),
737  this->absCoordinate.x,
738  this->absCoordinate.y,
739  this->relCoordinate.x,
740  this->relCoordinate.y,
741  this->getAbsDir2D(),
742  Element2D::parentingModeToChar2D(parentMode));
743  if (depth >= 2 || depth == 0)
744  {
745    tIterator<Element2D>* iterator = this->children->getIterator();
746    Element2D* pn = iterator->firstElement();
747    while( pn != NULL)
748    {
749      if (depth == 0)
750        pn->debug(0, level + 1);
751      else
752        pn->debug(depth - 1, level +1);
753      pn = iterator->nextElement();
754    }
755    delete iterator;
756  }
757}
758
759#include "color.h"
760
761/**
762 * displays the Element2D at its position with its rotation as a Plane.
763 */
764void Element2D::debugDraw2D(unsigned int depth, float size, Vector color) const
765{
766
767}
768
769
770// helper functions //
771/**
772 * converts a parentingMode into a string that is the name of it
773 * @param parentingMode the ParentingMode to convert
774 * @return the converted string
775 */
776const char* Element2D::parentingModeToChar2D(int parentingMode)
777{
778  if (parentingMode == E2D_PARENT_LOCAL_ROTATE)
779    return "local-rotate";
780  else if (parentingMode == E2D_PARENT_ROTATE_MOVEMENT)
781    return "rotate-movement";
782  else if (parentingMode == E2D_PARENT_MOVEMENT)
783    return "movement";
784  else if (parentingMode == E2D_PARENT_ALL)
785    return "all";
786  else if (parentingMode == E2D_PARENT_ROTATE_AND_MOVE)
787    return "rotate-and-move";
788}
789
790/**
791 * converts a parenting-mode-string into a int
792 * @param parentingMode the string naming the parentingMode
793 * @return the int corresponding to the named parentingMode
794 */
795E2D_PARENT_MODE Element2D::charToParentingMode2D(const char* parentingMode)
796{
797  if (!strcmp(parentingMode, "local-rotate"))
798    return (E2D_PARENT_LOCAL_ROTATE);
799  else  if (!strcmp(parentingMode, "rotate-movement"))
800    return (E2D_PARENT_ROTATE_MOVEMENT);
801  else  if (!strcmp(parentingMode, "movement"))
802    return (E2D_PARENT_MOVEMENT);
803  else  if (!strcmp(parentingMode, "all"))
804    return (E2D_PARENT_ALL);
805  else  if (!strcmp(parentingMode, "rotate-and-move"))
806    return (E2D_PARENT_ROTATE_AND_MOVE);
807}
808
809
810
811
812
813
814/**
815 * ticks the 2d-Element
816 * @param dt the time elapsed since the last tick
817 */
818void Element2D::tick(float dt)
819{
820
821}
822
823
824
825
826
827
828
829NullElement2D* NullElement2D::singletonRef = 0;
830
831/**
832 *  creates the one and only NullElement2D
833 * @param absCoordinate the cordinate of the Parent (normally Vector(0,0,0))
834 */
835NullElement2D::NullElement2D () : Element2D(NULL)
836{
837  this->setClassID(CL_NULL_ELEMENT_2D, "NullElement2D");
838  this->setName("NullElement2D");
839
840  this->setParentMode2D(E2D_PARENT_ALL);
841  NullElement2D::singletonRef = this;
842}
843
844
845/**
846 *  standard deconstructor
847 */
848NullElement2D::~NullElement2D ()
849{
850  NullElement2D::singletonRef = NULL;
851}
Note: See TracBrowser for help on using the repository browser.