Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: softDir/softCoor is now overwritten(deleted) if one sets the relCoor/relDir/absDir/absCoor
shell is also in smooth-mode now :)

File size: 23.3 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->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
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->relDirection = 0.0;
93  this->bRelCoorChanged = true;
94  this->bRelDirChanged = true;
95  this->toCoordinate = NULL;
96  this->toDirection = NULL;
97//  else
98  //  this->setParent2D(parent);
99
100  Render2D::getInstance()->registerElement2D(this);
101}
102
103/**
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
118  LoadParam<Element2D>(root, "visibility", this, &Element2D::setVisibility)
119      .describe("if the Element is visible or not");
120
121
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  }
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
171
172/**
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/**
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
210/**
211 * sets the relative coordinate of the Element2D to its parent
212 * @param relCoord the relative coordinate to the parent
213 */
214void Element2D::setRelCoor2D (const Vector& relCoord)
215{
216  if (this->toCoordinate!= NULL)
217  {
218    delete this->toCoordinate;
219    this->toCoordinate = NULL;
220  }
221  this->relCoordinate = relCoord;
222  this->bRelCoorChanged = true;
223}
224
225
226/**
227 * sets the relative coordinate of the Element2D to its Parent
228 * @param x the x coordinate
229 * @param y the y coordinate
230 * @param z the z coordinate
231 */
232void Element2D::setRelCoor2D (float x, float y, float z)
233{
234  this->setRelCoor2D(Vector(x,y,z));
235}
236
237/**
238 * sets the Relative coordinate to the parent in Pixels
239 * @param x the relCoord X
240 * @param y the relCoord Y
241 */
242void Element2D::setRelCoor2Dpx (int x, int y)
243{
244  this->setRelCoor2D(Vector((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
245                     (float)y/(float)GraphicsEngine::getInstance()->getResolutionY(),
246                     0
247                           ));
248}
249
250/**
251 * sets a new relative position smoothely
252 * @param relCoordSoft the new Position to iterate to
253 * @param bias how fast to iterate to this position
254 */
255void Element2D::setRelCoorSoft2D(const Vector& relCoordSoft, float bias)
256{
257  if (likely(this->toCoordinate == NULL))
258    this->toCoordinate = new Vector();
259
260  *this->toCoordinate = relCoordSoft;
261  this->bias = bias;
262}
263
264/**
265 * sets a new relative position smoothely
266 * @param x the new x-coordinate in Pixels of the Position to iterate to
267 * @param y the new y-coordinate in Pixels of the Position to iterate to
268 * @param bias how fast to iterate to this position
269 */
270void Element2D::setRelCoorSoft2Dpx (int x, int y, float bias)
271{
272  this->setRelCoorSoft2D(Vector((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
273                         (float)y/(float)GraphicsEngine::getInstance()->getResolutionY(),
274                         0),
275                         bias);
276}
277
278/**
279 * set relative coordinates smoothely
280 * @param x x-relative coordinates to its parent
281 * @param y y-relative coordinates to its parent
282 * @param z z-relative coordinates to its parent
283 * @see  void PNode::setRelCoorSoft (const Vector&, float)
284 */
285void Element2D::setRelCoorSoft2D(float x, float y, float depth, float bias)
286{
287  this->setRelCoorSoft2D(Vector(x, y, depth), bias);
288}
289
290/**
291 * @param absCoord set absolute coordinate
292 */
293void Element2D::setAbsCoor2D (const Vector& absCoord)
294{
295  if (this->toCoordinate!= NULL)
296  {
297    delete this->toCoordinate;
298    this->toCoordinate = NULL;
299  }
300
301  if( likely(this->parentMode & E2D_PARENT_MOVEMENT))
302  {
303    /* if you have set the absolute coordinates this overrides all other changes */
304    if (likely(this->parent != NULL))
305      this->relCoordinate = absCoord - parent->getAbsCoor2D ();
306    else
307      this->relCoordinate = absCoord;
308  }
309  if( this->parentMode & E2D_PARENT_ROTATE_MOVEMENT)
310  {
311    if (likely(this->parent != NULL))
312      this->relCoordinate = absCoord - parent->getAbsCoor2D ();
313    else
314      this->relCoordinate = absCoord;
315  }
316
317  this->bRelCoorChanged = true;
318}
319
320/**
321 * @param x x-coordinate.
322 * @param y y-coordinate.
323 * @param z z-coordinate.
324 * @see void PNode::setAbsCoor (const Vector& absCoord)
325 */
326void Element2D::setAbsCoor2D (float x, float y, float depth)
327{
328  this->setAbsCoor2D(Vector(x, y, depth));
329}
330
331/**
332 * @param x x-coordinate in Pixels
333 * @param y y-coordinate in Pixels
334 * @see void PNode::setAbsCoor (const Vector& absCoord)
335 */
336void Element2D::setAbsCoor2Dpx (int x, int y)
337{
338  this->setAbsCoor2D(Vector((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
339                     (float)y/(float)GraphicsEngine::getInstance()->getResolutionY(),
340                     0
341                           ));
342}
343
344/**
345 *  shift coordinate ralative
346 * @param shift shift vector
347 *
348 * This simply adds the shift-Vector to the relative Coordinate
349 */
350void Element2D::shiftCoor2D (const Vector& shift)
351{
352  this->relCoordinate += shift;
353  this->bRelCoorChanged = true;
354
355}
356
357/**
358 * shifts in PixelSpace
359 * @param x the pixels to shift in X
360 * @param y the pixels to shift in Y
361 */
362void Element2D::shiftCoor2Dpx (int x, int y)
363{
364  this->shiftCoor2D(Vector((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
365                    (float)y/(float)GraphicsEngine::getInstance()->getResolutionY(),
366                     0));
367}
368
369/**
370 *  set relative direction
371 * @param relDir to its parent
372 */
373void Element2D::setRelDir2D (float relDir)
374{
375  if (this->toDirection!= NULL)
376  {
377    delete this->toDirection;
378    this->toDirection = NULL;
379  }
380
381  this->relDirection = relDir;
382  this->bRelDirChanged = true;
383}
384
385/**
386 * sets the Relative Direction of this node to its parent in a Smoothed way
387 * @param relDirSoft the direction to iterate to smoothely.
388 * @param bias how fast to iterate to the new Direction
389 */
390void Element2D::setRelDirSoft2D(float relDirSoft, float bias)
391{
392  if (likely(this->toDirection == NULL))
393    this->toDirection = new float;
394
395  *this->toDirection = relDirSoft;
396  this->bias = bias;
397}
398
399/**
400 *  sets the absolute direction
401 * @param absDir absolute coordinates
402 */
403void Element2D::setAbsDir2D (float absDir)
404{
405  if (this->toDirection!= NULL)
406  {
407    delete this->toDirection;
408    this->toDirection = NULL;
409  }
410
411  if (likely(this->parent != NULL))
412    this->relDirection = absDir - this->parent->getAbsDir2D();
413  else
414    this->relDirection = absDir;
415
416  this->bRelDirChanged = true;
417}
418
419/**
420 * shift Direction
421 * @param shift the direction around which to shift.
422 */
423void Element2D::shiftDir2D (float shiftDir)
424{
425  this->relDirection = this->relDirection + shiftDir;
426  this->bRelDirChanged = true;
427}
428
429/**
430 *  adds a child and makes this node to a parent
431 * @param child child reference
432 * @param parentMode on which changes the child should also change ist state
433 *
434 * use this to add a child to this node.
435 */
436void Element2D::addChild2D (Element2D* child, int parentingMod)
437{
438  if( likely(child->parent != NULL))
439  {
440    PRINTF(4)("Element2D::addChild() - reparenting node: removing it and adding it again\n");
441    child->parent->children->remove(child);
442  }
443  child->parentMode = parentMode;
444  child->parent = this;
445  this->children->add(child);
446  child->parentCoorChanged();
447}
448
449/**
450 * @see Element2D::addChild(Element2D* child);
451 * @param childName the name of the child to add to this PNode
452 */
453void Element2D::addChild2D (const char* childName)
454{
455  Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D));
456  if (childNode != NULL)
457    this->addChild2D(childNode);
458}
459
460/**
461 * removes a child from the node
462 * @param child the child to remove from this Node..
463 *
464 * Children from nodes will not be lost, they are referenced to NullPointer
465 */
466void Element2D::removeChild2D (Element2D* child)
467{
468  child->remove2D();
469  this->children->remove(child);
470  child->parent = NULL;
471}
472
473/**
474 * remove this pnode from the tree and adds all following to NullParent
475 *
476 * this can be the case, if an entity in the world is being destroyed.
477 */
478void Element2D::remove2D()
479{
480  tIterator<Element2D>* iterator = this->children->getIterator();
481  Element2D* pn = iterator->nextElement();
482
483  while( pn != NULL)
484  {
485    NullElement2D::getInstance()->addChild2D(pn, pn->getParentMode2D());
486    pn = iterator->nextElement();
487  }
488  delete iterator;
489  this->parent->children->remove(this);
490}
491
492/**
493 * sets the parent of this Element2D
494 * @param parent the Parent to set
495 */
496void Element2D::setParent2D (Element2D* parent)
497{
498  parent->addChild2D(this);
499}
500
501/**
502 * @see Element2D::setParent(Element2D* parent);
503 * @param parentName the name of the Parent to set to this Element2D
504 */
505void Element2D::setParent2D (const char* parentName)
506{
507  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
508  if (parentNode != NULL)
509    parentNode->addChild2D(this);
510
511}
512
513/**
514 * does the reparenting in a very smooth way
515 * @param parentNode the new Node to connect this node to.
516 * @param bias the speed to iterate to this new Positions
517 */
518void Element2D::softReparent2D(Element2D* parentNode, float bias)
519{
520  if (this->parent == parentNode)
521    return;
522
523  if (likely(this->toCoordinate == NULL))
524  {
525    this->toCoordinate = new Vector();
526    *this->toCoordinate = this->getRelCoor2D();
527  }
528  if (likely(this->toDirection == NULL))
529  {
530    this->toDirection = new float;
531    *this->toDirection = this->getRelDir2D();
532  }
533  this->bias = bias;
534
535
536  Vector tmpV = this->getAbsCoor2D();
537  float tmpQ = this->getAbsDir2D();
538
539  parentNode->addChild2D(this);
540
541  if (this->parentMode & PNODE_ROTATE_MOVEMENT)
542    ;//this->setRelCoor(this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()));
543  else
544    this->setRelCoor2D(tmpV - parentNode->getAbsCoor2D());
545
546  this->setRelDir2D(tmpQ - parentNode->getAbsDir2D());
547}
548
549/**
550 * does the reparenting in a very smooth way
551 * @param parentName the name of the Parent to reconnect to
552 * @param bias the speed to iterate to this new Positions
553 */
554void Element2D::softReparent2D(const char* parentName, float bias)
555{
556  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
557  if (parentNode != NULL)
558    this->softReparent2D(parentNode, bias);
559}
560
561/**
562 *  sets the mode of this parent manually
563 * @param parentMode a String representing this parentingMode
564 */
565void Element2D::setParentMode2D (const char* parentingMode)
566{
567  this->setParentMode2D(Element2D::charToParentingMode2D(parentingMode));
568}
569
570/**
571 *  updates the absCoordinate/absDirection
572 * @param dt The time passed since the last update
573
574   this is used to go through the parent-tree to update all the absolute coordinates
575   and directions. this update should be done by the engine, so you don't have to
576   worry, normaly...
577 */
578void Element2D::update2D (float dt)
579{
580  // setting the Position of this 2D-Element.
581  if( likely(this->parent != NULL))
582  {
583      // movement for nodes with smoothMove enabled
584    if (unlikely(this->toCoordinate != NULL))
585    {
586      Vector moveVect = (*this->toCoordinate - this->getRelCoor2D()) *dt*bias;
587
588      if (likely(moveVect.len() >= .001))//PNODE_ITERATION_DELTA))
589      {
590        this->shiftCoor2D(moveVect);
591      }
592      else
593      {
594        delete this->toCoordinate;
595        this->toCoordinate = NULL;
596        PRINTF(5)("SmoothMove of %s finished\n", this->getName());
597      }
598    }
599    if (unlikely(this->toDirection != NULL))
600    {
601      float rotFlot = (*this->toDirection - this->getRelDir2D()) *dt*bias;
602      if (likely(rotFlot >= .001))//PNODE_ITERATION_DELTA))
603      {
604        this->shiftDir2D(rotFlot);
605      }
606      else
607      {
608        delete this->toDirection;
609        this->toDirection = NULL;
610        PRINTF(5)("SmoothRotate of %s finished\n", this->getName());
611      }
612    }
613
614    // MAIN UPDATE /////////////////////////////////////
615    this->lastAbsCoordinate = this->absCoordinate;
616
617    PRINTF(5)("Element2D::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
618
619
620    if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)
621    {
622      /* update the current absDirection - remember * means rotation around sth.*/
623      this->prevRelDirection = this->relDirection;
624      this->absDirection = this->relDirection + parent->getAbsDir2D();;
625    }
626
627
628    if (this->alignment == E2D_ALIGN_SCREEN_CENTER && this->bRelCoorChanged)
629    {
630      this->prevRelCoordinate = this->relCoordinate;
631      this->absCoordinate.x = .5 + this->relCoordinate.x;
632      this->absCoordinate.y = .5 + this->relCoordinate.y;
633      this->absCoordinate.z = 0.0;
634    }
635    else if (this->bindNode)
636    {
637      GLdouble projectPos[3];
638      gluProject(this->bindNode->getAbsCoor().x,
639                 this->bindNode->getAbsCoor().y,
640                 this->bindNode->getAbsCoor().z,
641                 GraphicsEngine::modMat,
642                 GraphicsEngine::projMat,
643                 GraphicsEngine::viewPort,
644                 projectPos,
645                 projectPos+1,
646                 projectPos+2);
647      this->absCoordinate.x = projectPos[0]/(float)GraphicsEngine::getInstance()->getResolutionX() + this->relCoordinate.x;
648      this->absCoordinate.y = projectPos[1]/(float)GraphicsEngine::getInstance()->getResolutionY() + this->relCoordinate.y;
649      this->absCoordinate.z = projectPos[2] + this->relCoordinate.z;
650    }
651    else
652    {
653      if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged))
654      {
655        /* update the current absCoordinate */
656        this->prevRelCoordinate = this->relCoordinate;
657        this->absCoordinate = this->parent->getAbsCoor2D() + this->relCoordinate;
658      }
659      else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged)
660      {
661        /* update the current absCoordinate */
662        this->prevRelCoordinate = this->relCoordinate;
663        float sine = sin(this->parent->getAbsDir2D());
664        float cose = cos(this->parent->getAbsDir2D());
665//        this->absCoordinate.x = this->relCoordinate.x*cose - this->relCoordinate.y*sine + this->parent->getRelCoor2D().x*(1-cose) +this->parent->getRelCoor2D().y*sine;
666//        this->absCoordinate.y = this->relCoordinate.x*sine + this->relCoordinate.y*cose + this->parent->getRelCoor2D().y*(1-cose) +this->parent->getRelCoor2D().x*sine;
667
668        this->absCoordinate.x = this->parent->getAbsCoor2D().x + (this->relCoordinate.x*cos(this->parent->getAbsDir2D()) - this->relCoordinate.y * sin(this->parent->getAbsDir2D()));
669        this->absCoordinate.y = this->parent->getAbsCoor2D().y + (this->relCoordinate.x*sin(this->parent->getAbsDir2D()) + this->relCoordinate.y * cos(this->parent->getAbsDir2D()));
670
671      }
672    }
673    /////////////////////////////////////////////////
674  }
675  else
676  {
677    PRINTF(5)("Element2D::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
678    if (this->bRelCoorChanged)
679      this->absCoordinate = this->relCoordinate;
680    if (this->bRelDirChanged)
681      this->absDirection = this->getAbsDir2D() * this->relDirection;
682  }
683
684
685  // UPDATE CHILDREN
686  if(this->children->getSize() > 0)
687  {
688    tIterator<Element2D>* iterator = this->children->getIterator();
689    Element2D* pn = iterator->nextElement();
690    while( pn != NULL)
691    {
692      /* if this node has changed, make sure, that all children are updated also */
693      if( likely(this->bRelCoorChanged))
694        pn->parentCoorChanged ();
695      if( likely(this->bRelDirChanged))
696        pn->parentDirChanged ();
697
698      pn->update2D(dt);
699          //pn = this->children->nextElement();
700      pn = iterator->nextElement();
701    }
702    delete iterator;
703  }
704
705  // FINISHING PROCESS
706  this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
707  this->bRelCoorChanged = false;
708  this->bRelDirChanged = false;
709}
710
711/**
712 *  displays some information about this pNode
713 * @param depth The deph into which to debug the children of this Element2D to.
714 * (0: all children will be debugged, 1: only this Element2D, 2: this and direct children...)
715 * @param level The n-th level of the Node we draw (this is internal and only for nice output)
716 */
717void Element2D::debug (unsigned int depth, unsigned int level) const
718{
719  for (unsigned int i = 0; i < level; i++)
720    PRINT(0)(" |");
721  if (this->children->getSize() > 0)
722    PRINT(0)(" +");
723  else
724    PRINT(0)(" -");
725  PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s\n",
726  this->getClassName(),
727  this->getName(),
728  this->absCoordinate.x,
729  this->absCoordinate.y,
730  this->relCoordinate.x,
731  this->relCoordinate.y,
732  this->getAbsDir2D(),
733  Element2D::parentingModeToChar2D(parentMode));
734  if (depth >= 2 || depth == 0)
735  {
736    tIterator<Element2D>* iterator = this->children->getIterator();
737    Element2D* pn = iterator->nextElement();
738    while( pn != NULL)
739    {
740      if (depth == 0)
741        pn->debug(0, level + 1);
742      else
743        pn->debug(depth - 1, level +1);
744      pn = iterator->nextElement();
745    }
746    delete iterator;
747  }
748}
749
750#include "color.h"
751
752/**
753 * displays the Element2D at its position with its rotation as a Plane.
754 */
755void Element2D::debugDraw2D(unsigned int depth, float size, Vector color) const
756{
757
758}
759
760
761// helper functions //
762/**
763 * converts a parentingMode into a string that is the name of it
764 * @param parentingMode the ParentingMode to convert
765 * @return the converted string
766 */
767const char* Element2D::parentingModeToChar2D(int parentingMode)
768{
769  if (parentingMode == E2D_PARENT_LOCAL_ROTATE)
770    return "local-rotate";
771  else if (parentingMode == E2D_PARENT_ROTATE_MOVEMENT)
772    return "rotate-movement";
773  else if (parentingMode == E2D_PARENT_MOVEMENT)
774    return "movement";
775  else if (parentingMode == E2D_PARENT_ALL)
776    return "all";
777  else if (parentingMode == E2D_PARENT_ROTATE_AND_MOVE)
778    return "rotate-and-move";
779}
780
781/**
782 * converts a parenting-mode-string into a int
783 * @param parentingMode the string naming the parentingMode
784 * @return the int corresponding to the named parentingMode
785 */
786E2D_PARENT_MODE Element2D::charToParentingMode2D(const char* parentingMode)
787{
788  if (!strcmp(parentingMode, "local-rotate"))
789    return (E2D_PARENT_LOCAL_ROTATE);
790  else  if (!strcmp(parentingMode, "rotate-movement"))
791    return (E2D_PARENT_ROTATE_MOVEMENT);
792  else  if (!strcmp(parentingMode, "movement"))
793    return (E2D_PARENT_MOVEMENT);
794  else  if (!strcmp(parentingMode, "all"))
795    return (E2D_PARENT_ALL);
796  else  if (!strcmp(parentingMode, "rotate-and-move"))
797    return (E2D_PARENT_ROTATE_AND_MOVE);
798}
799
800
801
802
803
804
805/**
806 * ticks the 2d-Element
807 * @param dt the time elapsed since the last tick
808 */
809void Element2D::tick(float dt)
810{
811
812}
813
814
815
816
817
818
819
820NullElement2D* NullElement2D::singletonRef = 0;
821
822/**
823 *  creates the one and only NullElement2D
824 * @param absCoordinate the cordinate of the Parent (normally Vector(0,0,0))
825 */
826NullElement2D::NullElement2D () : Element2D(NULL)
827{
828  this->setClassID(CL_NULL_PARENT, "NullElement2D");
829  this->setName("NullElement2D");
830
831  this->setParentMode2D(E2D_PARENT_ALL);
832  NullElement2D::singletonRef = this;
833}
834
835
836/**
837 *  standard deconstructor
838 */
839NullElement2D::~NullElement2D ()
840{
841  //delete singletonRef;
842  NullElement2D::singletonRef = NULL;
843}
Note: See TracBrowser for help on using the repository browser.