Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5082 in orxonox.OLD for trunk/src/lib/graphics


Ignore:
Timestamp:
Aug 19, 2005, 1:29:18 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: implemented PNode-functionality in Element2D,
update and debugDraw still missing

Location:
trunk/src/lib/graphics/render2D
Files:
2 edited

Legend:

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

    r5081 r5082  
    2424#include "tinyxml.h"
    2525#include "class_list.h"
     26#include "list.h"
    2627
    2728using namespace std;
     
    5960  this->setAlignment(E2D_ALIGN_NONE);
    6061  this->layer = E2D_TOP;
     62  this->setParentMode2D(E2D_PARENT_ALL);
     63
     64  this->bRelCoorChanged = true;
     65  this->bRelDirChanged = true;
    6166
    6267  Render2D::getInstance()->registerElement2D(this);
     
    180185void Element2D::setRelCoor2D (const Vector& relCoord)
    181186{
     187  this->relCoordinate = relCoord;
     188  this->bRelCoorChanged = true;
    182189}
    183190
     
    185192void Element2D::setRelCoor2D (float x, float y, float z)
    186193{
     194  this->setAbsCoor2D(Vector(x,y,z));
    187195}
    188196
    189197void Element2D::setRelCoorSoft2D(const Vector& relCoordSoft, float bias)
    190198{
    191 }
    192 
    193 void Element2D::setRelCoorSoft2D(float x, float y, float dontCare, float bias)
    194 {
     199  if (likely(this->toCoordinate == NULL))
     200    this->toCoordinate = new Vector();
     201
     202  *this->toCoordinate = relCoordSoft;
     203  this->bias = bias;
     204}
     205
     206void Element2D::setRelCoorSoft2D(float x, float y, float depth, float bias)
     207{
     208  this->setRelCoorSoft2D(Vector(x, y, depth), bias);
    195209}
    196210
    197211void Element2D::setAbsCoor2D (const Vector& absCoord)
    198212{
     213  if( likely(this->parentMode & E2D_PARENT_MOVEMENT))
     214  {
     215    /* if you have set the absolute coordinates this overrides all other changes */
     216    if (likely(this->parent != NULL))
     217      this->relCoordinate = absCoord - parent->getAbsCoor2D ();
     218    else
     219      this->relCoordinate = absCoord;
     220  }
     221  if( this->parentMode & E2D_PARENT_ROTATE_MOVEMENT)
     222  {
     223    if (likely(this->parent != NULL))
     224      this->relCoordinate = absCoord - parent->getAbsCoor2D ();
     225    else
     226      this->relCoordinate = absCoord;
     227  }
     228
     229  this->bRelCoorChanged = true;
    199230}
    200231
    201232void Element2D::setAbsCoor2D (float x, float y, float depth)
    202233{
     234  this->setAbsCoor2D(Vector(x, y, depth));
    203235}
    204236
    205237void Element2D::shiftCoor (const Vector& shift)
    206238{
     239  this->relCoordinate += shift;
     240  this->bRelCoorChanged = true;
     241
    207242}
    208243
     
    210245void Element2D::setRelDir2D (float relDir)
    211246{
     247  this->relDirection = relDir;
     248  this->bRelDirChanged = true;
    212249}
    213250
    214251void Element2D::setRelDirSoft2D(float relDirSoft, float bias)
    215252{
     253  if (likely(this->toDirection == NULL))
     254    this->toDirection = new float;
     255
     256  *this->toDirection = relDirSoft;
     257  this->bias = bias;
    216258}
    217259
    218260void Element2D::setAbsDir2D (float absDir)
    219261{
     262  if (likely(this->parent != NULL))
     263    this->relDirection = absDir - this->parent->getAbsDir2D();
     264  else
     265    this->relDirection = absDir;
     266
     267  this->bRelDirChanged = true;
    220268}
    221269
    222270void Element2D::shiftDir (float shiftDir)
    223271{
     272  this->relDirection = this->relDirection + shiftDir;
     273  this->bRelDirChanged = true;
    224274}
    225275
     
    227277void Element2D::addChild2D (Element2D* child, int parentingMod)
    228278{
     279  if( likely(child->parent != NULL))
     280  {
     281    PRINTF(4)("PNode::addChild() - reparenting node: removing it and adding it again\n");
     282    child->parent->children->remove(child);
     283  }
     284  child->parentMode = parentMode;
     285  child->parent = this;
     286  this->children->add(child);
     287  child->parentCoorChanged();
    229288}
    230289
    231290void Element2D::addChild2D (const char* childName)
    232291{
     292  Element2D* childNode = dynamic_cast<Element2D*>(ClassList::getObject(childName, CL_ELEMENT_2D));
     293  if (childNode != NULL)
     294    this->addChild2D(childNode);
    233295}
    234296
    235297void Element2D::removeChild2D (Element2D* child)
    236298{
     299  child->remove2D();
     300  this->children->remove(child);
     301  child->parent = NULL;
    237302}
    238303
    239304void Element2D::remove2D()
    240305{
     306  tIterator<Element2D>* iterator = this->children->getIterator();
     307  Element2D* pn = iterator->nextElement();
     308
     309  while( pn != NULL)
     310  {
     311    NullElement2D::getInstance()->addChild2D(pn, pn->getParentMode2D());
     312    pn = iterator->nextElement();
     313  }
     314  delete iterator;
     315  this->parent->children->remove(this);
    241316}
    242317
     
    244319void Element2D::setParent2D (Element2D* parent)
    245320{
     321  parent->addChild2D(this);
    246322}
    247323
    248324void Element2D::setParent2D (const char* parentName)
    249325{
    250 }
    251 
    252 
    253 void Element2D::softReparent(PNode* parentNode, float bias)
    254 {
    255 }
    256 
    257 void Element2D::softReparent(const char* parentName, float bias)
    258 {
     326  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
     327  if (parentNode != NULL)
     328    parentNode->addChild2D(this);
     329
     330}
     331
     332
     333void Element2D::softReparent2D(Element2D* parentNode, float bias)
     334{
     335  if (this->parent == parentNode)
     336    return;
     337
     338  if (likely(this->toCoordinate == NULL))
     339  {
     340    this->toCoordinate = new Vector();
     341    *this->toCoordinate = this->getRelCoor2D();
     342  }
     343  if (likely(this->toDirection == NULL))
     344  {
     345    this->toDirection = new float;
     346    *this->toDirection = this->getRelDir2D();
     347  }
     348  this->bias = bias;
     349
     350
     351  Vector tmpV = this->getAbsCoor2D();
     352  float tmpQ = this->getAbsDir2D();
     353
     354  parentNode->addChild2D(this);
     355
     356  if (this->parentMode & PNODE_ROTATE_MOVEMENT)
     357    ;//this->setRelCoor(this->parent->getAbsDir().inverse().apply(tmpV - this->parent->getAbsCoor()));
     358  else
     359    this->setRelCoor2D(tmpV - parentNode->getAbsCoor2D());
     360
     361  this->setRelDir2D(tmpQ - parentNode->getAbsDir2D());
     362}
     363
     364void Element2D::softReparent2D(const char* parentName, float bias)
     365{
     366  Element2D* parentNode = dynamic_cast<Element2D*>(ClassList::getObject(parentName, CL_ELEMENT_2D));
     367  if (parentNode != NULL)
     368    this->softReparent2D(parentNode, bias);
    259369}
    260370
     
    262372void Element2D::setParentMode2D (const char* parentingMode)
    263373{
     374  this->setParentMode2D(Element2D::charToParentingMode2D(parentingMode));
    264375}
    265376
     
    267378void Element2D::update2D (float dt)
    268379{
     380
    269381}
    270382
     
    272384void Element2D::debug (unsigned int depth, unsigned int level) const
    273385{
    274 }
     386  for (unsigned int i = 0; i < level; i++)
     387    PRINT(0)(" |");
     388  if (this->children->getSize() > 0)
     389    PRINT(0)(" +");
     390  else
     391    PRINT(0)(" -");
     392  PRINT(0)("Element2D(%s::%s) - absCoord: (%0.2f, %0.2f), relCoord(%0.2f, %0.2f), direction(%0.2f) - %s\n",
     393  this->getClassName(),
     394  this->getName(),
     395  this->absCoordinate.x,
     396  this->absCoordinate.y,
     397  this->relCoordinate.x,
     398  this->relCoordinate.y,
     399  this->getAbsDir2D(),
     400  Element2D::parentingModeToChar2D(parentMode));
     401  if (depth >= 2 || depth == 0)
     402  {
     403    tIterator<Element2D>* iterator = this->children->getIterator();
     404      //PNode* pn = this->children->enumerate ();
     405    Element2D* pn = iterator->nextElement();
     406    while( pn != NULL)
     407    {
     408      if (depth == 0)
     409        pn->debug(0, level + 1);
     410      else
     411        pn->debug(depth - 1, level +1);
     412      pn = iterator->nextElement();
     413    }
     414    delete iterator;
     415  }
     416}
     417
     418#include "color.h"
    275419
    276420void Element2D::debugDraw2D(unsigned int depth, float size, Vector color) const
    277421{
     422
    278423}
    279424
    280425
    281426// helper functions //
    282 const char* Element2D::parentingModeToChar(int parentingMode)
    283 {
    284 }
    285 
    286 E2D_PARENT_MODE Element2D::charToParentingMode(const char* parentingMode)
    287 {
     427const char* Element2D::parentingModeToChar2D(int parentingMode)
     428{
     429  if (parentingMode == E2D_PARENT_LOCAL_ROTATE)
     430    return "local-rotate";
     431  else if (parentingMode == E2D_PARENT_ROTATE_MOVEMENT)
     432    return "rotate-movement";
     433  else if (parentingMode == E2D_PARENT_MOVEMENT)
     434    return "movement";
     435  else if (parentingMode == E2D_PARENT_ALL)
     436    return "all";
     437  else if (parentingMode == E2D_PARENT_ROTATE_AND_MOVE)
     438    return "rotate-and-move";
     439}
     440
     441E2D_PARENT_MODE Element2D::charToParentingMode2D(const char* parentingMode)
     442{
     443  if (!strcmp(parentingMode, "local-rotate"))
     444    return (E2D_PARENT_LOCAL_ROTATE);
     445  else  if (!strcmp(parentingMode, "rotate-movement"))
     446    return (E2D_PARENT_ROTATE_MOVEMENT);
     447  else  if (!strcmp(parentingMode, "movement"))
     448    return (E2D_PARENT_MOVEMENT);
     449  else  if (!strcmp(parentingMode, "all"))
     450    return (E2D_PARENT_ALL);
     451  else  if (!strcmp(parentingMode, "rotate-and-move"))
     452    return (E2D_PARENT_ROTATE_AND_MOVE);
    288453}
    289454
     
    301466  this->positioning();
    302467}
     468
     469
     470
     471
     472
     473
     474
     475NullElement2D* NullElement2D::singletonRef = 0;
     476
     477/**
     478 *  creates the one and only NullElement2D
     479 * @param absCoordinate the cordinate of the Parent (normally Vector(0,0,0))
     480 */
     481NullElement2D::NullElement2D ()
     482{
     483  this->setClassID(CL_NULL_PARENT, "NullElement2D");
     484  this->setName("NullElement2D");
     485
     486  this->setParentMode2D(E2D_PARENT_ALL);
     487  NullElement2D::singletonRef = this;
     488}
     489
     490
     491/**
     492 *  standard deconstructor
     493 */
     494NullElement2D::~NullElement2D ()
     495{
     496  //delete singletonRef;
     497  NullElement2D::singletonRef = NULL;
     498}
  • trunk/src/lib/graphics/render2D/element_2d.h

    r5081 r5082  
    4040typedef enum
    4141{
    42   E2D_LOCAL_ROTATE          =   1,    //!< Rotates all the children around their centers.
    43   E2D_ROTATE_MOVEMENT       =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
    44 
    45   E2D_MOVEMENT              =   4,    //!< Moves all children along with the parent.
     42  E2D_PARENT_LOCAL_ROTATE       =   1,    //!< Rotates all the children around their centers.
     43  E2D_PARENT_ROTATE_MOVEMENT    =   2,    //!< Moves all the children around the center of their parent, without the rotation around their own centers.
     44
     45  E2D_PARENT_MOVEMENT           =   4,    //!< Moves all children along with the parent.
    4646// special linkage modes
    47   E2D_ALL                   =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
    48   E2D_ROTATE_AND_MOVE       =   5     //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent.
     47  E2D_PARENT_ALL                =   3,    //!< Moves all children around the center of their parent, and also rotates their centers
     48  E2D_PARENT_ROTATE_AND_MOVE    =   5     //!< Rotates all children around their axis, and moves them as the Parent Moves, but does not rotate around the center of their parent.
    4949} E2D_PARENT_MODE;
    50 #define     E2D_DEFAULT_PARENTING_MODE  E2D_ALL
     50#define     E2D_DEFAULT_PARENTING_MODE  E2D_PARENT_ALL
    5151
    5252//! A Struct defining the Position of an Element in 2D-space
     
    137137    Element2D* getParent () const { return this->parent; };
    138138
    139     void softReparent(PNode* parentNode, float bias = 1.0);
    140     void softReparent(const char* parentName, float bias = 1.0);
     139    void softReparent2D(Element2D* parentNode, float bias = 1.0);
     140    void softReparent2D(const char* parentName, float bias = 1.0);
    141141
    142142    /** @param parentMode sets the parentingMode of this Node */
     
    152152
    153153    // helper functions //
    154     static const char* parentingModeToChar(int parentingMode);
    155     static E2D_PARENT_MODE charToParentingMode(const char* parentingMode);
     154    static const char* parentingModeToChar2D(int parentingMode);
     155    static E2D_PARENT_MODE charToParentingMode2D(const char* parentingMode);
    156156
    157157  private:
     
    213213};
    214214
     215//! The top joint of all Element2D's every Element2D is somehow connected to this one.
     216class NullElement2D : public Element2D {
     217
     218  public:
     219    /** @returns a Pointer to the only object of this Class */
     220    inline static NullElement2D* getInstance() { if (!singletonRef) singletonRef = new NullElement2D();  return singletonRef; };
     221    virtual ~NullElement2D ();
     222
     223  private:
     224    NullElement2D ();
     225    virtual void draw() const {};
     226
     227  private:
     228    static NullElement2D* singletonRef;        //!< A reference to the NullElement2D
     229
     230};
    215231
    216232#endif /* _ELEMENT_2D_H */
Note: See TracChangeset for help on using the changeset viewer.