Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 18, 2006, 5:35:11 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: Layer Sorting works as expected

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/render2D/element_2d.cc

    r7330 r7332  
    2929#include "color.h"
    3030
    31 //#include "shell_command.h"
    32 //SHELL_COMMAND(debug, Element2D, debug2D);
     31#include "shell_command.h"
     32SHELL_COMMAND(debug, Element2D, debug2DSC);
    3333
    3434using namespace std;
     
    9999      deleteNode = tmp;
    100100      tmp++;
    101 //      printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());
     101      //      printf("TEST::%s(%s) %s\n", (*deleteNode)->getName(), (*deleteNode)->getClassName(), this->getName());
    102102      if ((this->parentMode & E2D_PROHIBIT_CHILD_DELETE) ||
    103103          ((*deleteNode)->parentMode & E2D_PROHIBIT_DELETE_WITH_PARENT))
     
    139139  // ELEMENT2D-native settings.
    140140  LoadParam(root, "alignment", this, Element2D, setAlignment)
    141       .describe("loads the alignment: (either: center, left, right or screen-center)");
     141  .describe("loads the alignment: (either: center, left, right or screen-center)");
    142142
    143143  LoadParam(root, "layer", this, Element2D, setLayer)
    144       .describe("loads the layer onto which to project: (either: top, medium, bottom, below-all)");
     144  .describe("loads the layer onto which to project: (either: top, medium, bottom, below-all)");
    145145
    146146  LoadParam(root, "bind-node", this, Element2D, setBindNode)
    147       .describe("sets a node, this 2D-Element should be shown upon (name of the node)");
     147  .describe("sets a node, this 2D-Element should be shown upon (name of the node)");
    148148
    149149  LoadParam(root, "visibility", this, Element2D, setVisibility)
    150       .describe("if the Element is visible or not");
    151 
    152 
    153 // PNode-style:
     150  .describe("if the Element is visible or not");
     151
     152
     153  // PNode-style:
    154154  LoadParam(root, "rel-coor-2d", this, Element2D, setRelCoor2D)
    155       .describe("Sets The relative position of the Node to its parent.");
     155  .describe("Sets The relative position of the Node to its parent.");
    156156
    157157  LoadParam(root, "abs-coor-2d", this, Element2D, setAbsCoor2D)
    158       .describe("Sets The absolute Position of the Node.");
     158  .describe("Sets The absolute Position of the Node.");
    159159
    160160  LoadParam(root, "rel-dir-2d", this, Element2D, setRelDir2D)
    161       .describe("Sets The relative rotation of the Node to its parent.");
     161  .describe("Sets The relative rotation of the Node to its parent.");
    162162
    163163  LoadParam(root, "abs-dir-2d", this, Element2D, setAbsDir2D)
    164       .describe("Sets The absolute rotation of the Node.");
     164  .describe("Sets The absolute rotation of the Node.");
    165165
    166166  LoadParam(root, "parent", this, Element2D, setParent2D)
    167       .describe("the Name of the Parent of this Element2D");
     167  .describe("the Name of the Parent of this Element2D");
    168168
    169169  LoadParam(root, "parent-mode", this, Element2D, setParentMode2D)
    170       .describe("the mode to connect this node to its parent ()");
     170  .describe("the mode to connect this node to its parent ()");
    171171
    172172  // cycling properties
     
    174174  {
    175175    LoadParam_CYCLE(element, "child", this, Element2D, addChild2D)
    176         .describe("adds a new Child to the current Node.");
     176    .describe("adds a new Child to the current Node.");
    177177  }
    178178  LOAD_PARAM_END_CYCLE(element);
     
    282282{
    283283  this->setRelCoor2D(Vector2D((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
    284                      (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
     284                              (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
    285285}
    286286
     
    308308{
    309309  this->setRelCoorSoft2D(Vector2D((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
    310                          (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()),
     310                                  (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()),
    311311                         bias);
    312312}
     
    373373{
    374374  this->setAbsCoor2D(Vector2D((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
    375                      (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
     375                              (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
    376376}
    377377
     
    436436{
    437437  this->shiftCoor2D(Vector2D((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
    438                     (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
     438                             (float)y/(float)GraphicsEngine::getInstance()->getResolutionY()));
    439439}
    440440
     
    533533  if (this->checkIntegrity(child))
    534534  {
     535    // Setting the New Parent.
    535536    child->parent = this;
    536537    if (likely(this != NULL))
    537538    {
    538      // ELEMENT SORTING TO LAYERS  //
    539      unsigned int childCount = this->children.size();
    540 
    541      list<Element2D*>::iterator elem;
    542      for (elem = this->children.begin(); elem != this->children.end(); elem++)
    543      {
    544        if ((*elem)->layer < child->layer)
    545        {
    546          this->children.insert(elem, child);
    547          break;
    548        }
    549      }
    550      if (childCount == this->children.size())
    551        this->children.push_back(child);
    552      ////////////////////////////////
    553      if (unlikely(this->layer > child->getLayer()))
    554      {
    555        PRINTF(2)("Layer '%s' of Child(%s) lower than parents(%s) layer '%s'. updating...\n",
    556        Element2D::layer2DToChar(child->getLayer()),child->getName(), this->getName(), Element2D::layer2DToChar(this->layer));
    557        child->setLayer(this->layer);
    558      }
    559    }
    560    else
    561    {
    562      PRINTF(1)("Tried to reparent2D to own child '%s::%s' to '%s::%s'.\n",
    563               this->getClassName(), this->getName(), child->getClassName(), child->getName());
    564      child->parent = NULL;
    565    }
     539      // Layers of Children that are smaller than this(parents) Layer will be updated, and pushed to the front.
     540      if (unlikely(this->layer > child->getLayer()))
     541      {
     542        PRINTF(2)("Layer '%s' of Child(%s::%s) lower than parents(%s::%s) layer '%s'. updating...\n",
     543                  Element2D::layer2DToChar(child->getLayer()),child->getClassName(), child->getName(),
     544                  this->getClassName(), this->getName(), Element2D::layer2DToChar(this->layer));
     545        child->layer = this->layer;
     546        this->children.push_front(child);
     547      }
     548      else
     549      {
     550        // Inserting the Element at the right Layer depth.
     551        list<Element2D*>::iterator elem;
     552        for (elem = this->children.begin(); elem != this->children.end(); elem++)
     553        {
     554          if ((*elem)->layer <= child->layer)
     555          {
     556            this->children.insert(elem, child);
     557            break;
     558          }
     559        }
     560        // if we are at the Last child push it back.
     561        if (elem == this->children.end())
     562          this->children.push_back(child);
     563      }
     564    }
     565    else
     566    {
     567      PRINTF(1)("Tried to reparent2D to own child '%s::%s' to '%s::%s'.\n",
     568                this->getClassName(), this->getName(), child->getClassName(), child->getName());
     569      child->parent = NULL;
     570    }
    566571  }
    567572  child->parentCoorChanged2D();
     
    658663  else
    659664    PRINTF(2)("Not Found Element2D's (%s::%s) new Parent by Name: %s\n",
    660                 this->getClassName(), this->getName(), parentName.c_str());
     665              this->getClassName(), this->getName(), parentName.c_str());
    661666}
    662667
     
    787792  if( likely(this->parent != NULL))
    788793  {
    789       // movement for nodes with smoothMove enabled
     794    // movement for nodes with smoothMove enabled
    790795    if (unlikely(this->toCoordinate != NULL))
    791796    {
     
    865870                 projectPos+1,
    866871                 projectPos+2);
    867 //       printf("%s::%s  == %f %f %f :: %f %f\n", this->getClassName(), this->getName(),
    868 //              this->bindNode->getAbsCoor().x,
    869 //              this->bindNode->getAbsCoor().y,
    870 //              this->bindNode->getAbsCoor().z,
    871 //              projectPos[0],
    872 //              projectPos[1]);
     872      //       printf("%s::%s  == %f %f %f :: %f %f\n", this->getClassName(), this->getName(),
     873      //              this->bindNode->getAbsCoor().x,
     874      //              this->bindNode->getAbsCoor().y,
     875      //              this->bindNode->getAbsCoor().z,
     876      //              projectPos[0],
     877      //              projectPos[1]);
    873878
    874879      this->prevRelCoordinate.x = this->absCoordinate.x = projectPos[0] /* /(float)GraphicsEngine::getInstance()->getResolutionX() */ + this->relCoordinate.x;
     
    890895        float sine = sin(this->parent->getAbsDir2D());
    891896        float cose = cos(this->parent->getAbsDir2D());
    892 //        this->absCoordinate.x = this->relCoordinate.x*cose - this->relCoordinate.y*sine + this->parent->getRelCoor2D().x*(1-cose) +this->parent->getRelCoor2D().y*sine;
    893 //        this->absCoordinate.y = this->relCoordinate.x*sine + this->relCoordinate.y*cose + this->parent->getRelCoor2D().y*(1-cose) +this->parent->getRelCoor2D().x*sine;
     897        //        this->absCoordinate.x = this->relCoordinate.x*cose - this->relCoordinate.y*sine + this->parent->getRelCoor2D().x*(1-cose) +this->parent->getRelCoor2D().y*sine;
     898        //        this->absCoordinate.y = this->relCoordinate.x*sine + this->relCoordinate.y*cose + this->parent->getRelCoor2D().y*(1-cose) +this->parent->getRelCoor2D().x*sine;
    894899
    895900        this->absCoordinate.x = this->parent->getAbsCoor2D().x + (this->relCoordinate.x*cos(this->parent->getAbsDir2D()) - this->relCoordinate.y * sin(this->parent->getAbsDir2D()));
     
    953958  else
    954959    PRINT(0)(" -");
    955   PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s, layer:%s\n",
    956             this->getClassName(),
    957             this->getName(),
    958             this->absCoordinate.x,
    959             this->absCoordinate.y,
    960             this->relCoordinate.x,
    961             this->relCoordinate.y,
    962             this->getAbsDir2D(),
    963             Element2D::parentingModeToString2D(parentMode),
    964             Element2D::layer2DToChar(this->layer));
     960  PRINT(0)("E2D(%s::%s);AC:(%0.2f, %0.2f);RC:(%0.2f, %0.2f);AD(%0.2f)->%s;Layer:(%s)\n",
     961           this->getClassName(),
     962           this->getName(),
     963           this->absCoordinate.x,
     964           this->absCoordinate.y,
     965           this->relCoordinate.x,
     966           this->relCoordinate.y,
     967           this->getAbsDir2D(),
     968           Element2D::parentingModeToString2D(parentMode),
     969           Element2D::layer2DToChar(this->layer));
    965970
    966971  if (depth >= 2 || depth == 0)
Note: See TracChangeset for help on using the changeset viewer.