Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: saver change between fonts in Shell

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