Changeset 5089 in orxonox.OLD for trunk/src/lib/graphics/render2D
- Timestamp:
- Aug 21, 2005, 8:17:31 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/render2D
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/render2D/element_2d.cc
r5088 r5089 28 28 using namespace std; 29 29 30 Element2D::Element2D() 31 { 32 this->init(); 33 this->setParent2D(NullElement2D::getInstance()); 34 } 30 35 31 36 /** … … 35 40 Element2D::Element2D (Element2D* parent) 36 41 { 37 this->init(parent); 42 this->init(); 43 44 if (this->parent != NULL) 45 this->setParent2D(parent); 38 46 } 39 47 … … 45 53 // delete what has to be deleted here 46 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); 47 68 48 69 if (this->toCoordinate != NULL) … … 56 77 * initializes a Element2D 57 78 */ 58 void Element2D::init( Element2D* parent)79 void Element2D::init() 59 80 { 60 81 this->setClassID(CL_ELEMENT_2D, "Element2D"); … … 62 83 this->setVisibility(true); 63 84 this->setActiveness(true); 64 this->setPosition2D(0,0);65 85 this->setAlignment(E2D_ALIGN_NONE); 66 86 this->layer = E2D_TOP; 87 this->bindNode = NULL; 67 88 68 89 this->setParentMode2D(E2D_PARENT_ALL); 90 this->parent = NULL; 69 91 this->children = new tList<Element2D>; 92 this->relDirection = 0.0; 70 93 this->bRelCoorChanged = true; 71 94 this->bRelDirChanged = true; 72 95 this->toCoordinate = NULL; 73 96 this->toDirection = NULL; 74 if (parent == NULL)75 this->parent = NULL;76 97 // else 77 98 // this->setParent2D(parent); … … 95 116 .describe("sets a node, this 2D-Element should be shown upon (name of the node)"); 96 117 97 LoadParam<Element2D>(root, "2d-position", this, &Element2D::setPosition2D)98 .describe("the _relative_ position (away from alignment) this 2d-element shows");99 100 118 LoadParam<Element2D>(root, "visibility", this, &Element2D::setVisibility) 101 119 .describe("if the Element is visible or not"); 120 121 // LoadParam<Element2D>(root, "2d-position", this, &Element2D::setPosition2D) 122 // .describe("the _relative_ position (away from alignment) this 2d-element shows"); 123 102 124 } 103 125 … … 157 179 } 158 180 159 /**160 * this sets the position of the Element on the screen.161 * Use this in the your tick function, if you want the element to be automatically positioned.162 *163 * @todo must be in update164 */165 void Element2D::positioning()166 {167 // setting the Position of this 2D-Element.168 if (this->alignment == E2D_ALIGN_SCREEN_CENTER)169 {170 absPos2D.x = GraphicsEngine::getInstance()->getResolutionX()/2 + this->relPos2D[0];171 absPos2D.y = GraphicsEngine::getInstance()->getResolutionY()/2 + this->relPos2D[1];172 absPos2D.depth = 0;173 }174 else if (this->bindNode)175 {176 GLdouble projectPos[3];177 gluProject(this->bindNode->getAbsCoor().x,178 this->bindNode->getAbsCoor().y,179 this->bindNode->getAbsCoor().z,180 GraphicsEngine::modMat,181 GraphicsEngine::projMat,182 GraphicsEngine::viewPort,183 projectPos,184 projectPos+1,185 projectPos+2);186 absPos2D.x = projectPos[0] + this->relPos2D[0];187 absPos2D.y = GraphicsEngine::getInstance()->getResolutionY() - projectPos[1] + this->relPos2D[1];188 absPos2D.depth = projectPos[2];189 }190 else191 {192 absPos2D.x = this->relPos2D[0];193 absPos2D.y = this->relPos2D[1];194 absPos2D.depth = 0;195 }196 }197 198 181 199 182 void Element2D::setRelCoor2D (const Vector& relCoord) … … 209 192 } 210 193 194 void Element2D::setRelCoor2Dpx (int x, int y) 195 { 196 this->setRelCoor2D(Vector((float)GraphicsEngine::getInstance()->getResolutionX()/(float)x, 197 (float)GraphicsEngine::getInstance()->getResolutionY()/(float)y, 198 0 199 )); 200 } 201 202 211 203 void Element2D::setRelCoorSoft2D(const Vector& relCoordSoft, float bias) 212 204 { … … 217 209 this->bias = bias; 218 210 } 211 212 void Element2D::setRelCoorSoft2Dpx (int x, int y, float bias) 213 { 214 this->setRelCoorSoft2D(Vector((float)GraphicsEngine::getInstance()->getResolutionX()/(float)x, 215 (float)GraphicsEngine::getInstance()->getResolutionY()/(float)y, 216 0), 217 bias); 218 } 219 219 220 220 221 void Element2D::setRelCoorSoft2D(float x, float y, float depth, float bias) … … 249 250 } 250 251 252 253 void Element2D::setAbsCoor2Dpx (int x, int y) 254 { 255 this->setAbsCoor2D(Vector((float)GraphicsEngine::getInstance()->getResolutionX()/(float)x, 256 (float)GraphicsEngine::getInstance()->getResolutionY()/(float)y, 257 0 258 )); 259 } 260 251 261 void Element2D::shiftCoor2D (const Vector& shift) 252 262 { … … 254 264 this->bRelCoorChanged = true; 255 265 266 } 267 268 269 void Element2D::shiftCoor2Dpx (int x, int y) 270 { 271 this->shiftCoor2D(Vector((float)GraphicsEngine::getInstance()->getResolutionX()/(float)x, 272 (float)GraphicsEngine::getInstance()->getResolutionY()/(float)y, 273 0)); 256 274 } 257 275 … … 392 410 void Element2D::update2D (float dt) 393 411 { 412 // setting the Position of this 2D-Element. 394 413 if( likely(this->parent != NULL)) 395 414 { … … 438 457 } 439 458 440 if(likely(this->parentMode & PNODE_MOVEMENT)) 441 {442 /* update the current absCoordinate */459 460 if (this->alignment == E2D_ALIGN_SCREEN_CENTER && this->bRelCoorChanged) 461 { 443 462 this->prevRelCoordinate = this->relCoordinate; 444 this->absCoordinate = this->parent->getAbsCoor2D() + this->relCoordinate; 445 } 446 else if( this->parentMode & PNODE_ROTATE_MOVEMENT) 447 { 448 /* update the current absCoordinate */ 449 this->prevRelCoordinate = this->relCoordinate; 450 this->absCoordinate.x = this->parent->getAbsCoor2D().x + (this->relCoordinate.x*cos(this->parent->getAbsDir2D()) - this->relCoordinate.y * sin(this->parent->getAbsDir2D())); 451 this->absCoordinate.y = this->parent->getAbsCoor2D().y + (this->relCoordinate.x*sin(this->parent->getAbsDir2D()) + this->relCoordinate.y * cos(this->parent->getAbsDir2D())); 452 463 this->absCoordinate.x = .5 + this->relCoordinate.x; 464 this->absCoordinate.y = .5 + this->relCoordinate.y; 465 this->absCoordinate.z = 0.0; 466 } 467 else if (this->bindNode) 468 { 469 GLdouble projectPos[3]; 470 gluProject(this->bindNode->getAbsCoor().x, 471 this->bindNode->getAbsCoor().y, 472 this->bindNode->getAbsCoor().z, 473 GraphicsEngine::modMat, 474 GraphicsEngine::projMat, 475 GraphicsEngine::viewPort, 476 projectPos, 477 projectPos+1, 478 projectPos+2); 479 this->absCoordinate.x = projectPos[0]/(float)GraphicsEngine::getInstance()->getResolutionX() + this->relCoordinate.x; 480 this->absCoordinate.y = projectPos[1]/(float)GraphicsEngine::getInstance()->getResolutionY() + this->relCoordinate.y; 481 this->absCoordinate.z = projectPos[2] + this->relCoordinate.z; 482 } 483 else 484 { 485 if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged)) 486 { 487 /* update the current absCoordinate */ 488 this->prevRelCoordinate = this->relCoordinate; 489 this->absCoordinate = this->parent->getAbsCoor2D() + this->relCoordinate; 490 } 491 else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged) 492 { 493 /* update the current absCoordinate */ 494 this->prevRelCoordinate = this->relCoordinate; 495 this->absCoordinate.x = this->parent->getAbsCoor2D().x + (this->relCoordinate.x*cos(this->parent->getAbsDir2D()) - this->relCoordinate.y * sin(this->parent->getAbsDir2D())); 496 this->absCoordinate.y = this->parent->getAbsCoor2D().y + (this->relCoordinate.x*sin(this->parent->getAbsDir2D()) + this->relCoordinate.y * cos(this->parent->getAbsDir2D())); 497 498 } 453 499 } 454 500 ///////////////////////////////////////////////// … … 463 509 } 464 510 511 512 // UPDATE CHILDREN 465 513 if(this->children->getSize() > 0) 466 514 { … … 481 529 delete iterator; 482 530 } 531 532 // FINISHING PROCESS 483 533 this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt; 484 534 this->bRelCoorChanged = false; … … 569 619 void Element2D::tick(float dt) 570 620 { 571 this->positioning(); 621 572 622 } 573 623 … … 584 634 * @param absCoordinate the cordinate of the Parent (normally Vector(0,0,0)) 585 635 */ 586 NullElement2D::NullElement2D () 636 NullElement2D::NullElement2D () : Element2D(NULL) 587 637 { 588 638 this->setClassID(CL_NULL_PARENT, "NullElement2D"); -
trunk/src/lib/graphics/render2D/element_2d.h
r5084 r5089 10 10 11 11 #include "base_object.h" 12 12 13 #include "vector.h" 13 14 … … 63 64 64 65 public: 65 Element2D(Element2D* parent = NULL); 66 Element2D(); 67 Element2D(Element2D* parent); 66 68 virtual ~Element2D(); 67 69 68 void init( Element2D* parent = NULL);70 void init(); 69 71 void loadParams(const TiXmlElement* root); 70 71 /** @param xCoord the xCoordinate @param yCoord the y-Coordinate. These coordinates are Relative */72 inline void setPosition2D(int xCoord, int yCoord) { this->relPos2D[0] = xCoord; this->relPos2D[1] = yCoord; };73 /** this returns the Absolute Position on the screen set by positioning in the tick-phase */74 inline const Position2D& getPosition2D() { return this->absPos2D; };75 72 76 73 /** @param alignment the new Alignment of the 2D-Element */ 77 74 inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; }; 78 75 void setAlignment(const char* alignment); 76 inline E2D_ALIGNMENT getAlignment() const { return this->alignment; }; 79 77 80 78 void setLayer(E2D_LAYER layer); … … 92 90 inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; }; 93 91 void setBindNode(const char* bindNode); 92 inline const PNode* getBindNode() const { return this->bindNode; }; 94 93 95 94 /** @returns the visibility state */ … … 102 101 public: 103 102 void setRelCoor2D (const Vector& relCoord); 104 void setRelCoor2D (float x, float y, float dontCare); 105 void setRelCoorSoft2D(const Vector& relCoordSoft, float bias = 1.0); 106 void setRelCoorSoft2D(float x, float y, float dontCare, float bias = 1.0); 103 void setRelCoor2D (float x, float y, float dontCare = 1.0); 104 void setRelCoor2Dpx (int x, int y); 105 void setRelCoorSoft2D (const Vector& relCoordSoft, float bias = 1.0); 106 void setRelCoorSoft2D (float x, float y, float dontCare = 1.0, float bias = 1.0); 107 void setRelCoorSoft2Dpx (int x, int y, float bias = 1.0); 107 108 /** @returns the relative position */ 108 109 inline const Vector& getRelCoor2D () const { return this->prevRelCoordinate; }; 110 const Vector& getRelCoor2Dpx() const; 109 111 void setAbsCoor2D (const Vector& absCoord); 110 void setAbsCoor2D (float x, float y, float depth); 112 void setAbsCoor2D (float x, float y, float depth = 1.0); 113 void setAbsCoor2Dpx (int x, int y); 111 114 /** @returns the absolute position */ 112 115 inline const Vector& getAbsCoor2D () const { return this->absCoordinate; }; 116 const Vector& getAbsCoor2Dpx () const; 117 113 118 void shiftCoor2D (const Vector& shift); 119 void shiftCoor2Dpx (int x, int y); 114 120 115 121 void setRelDir2D (float relDir); … … 168 174 virtual void draw() const = NULL; 169 175 170 protected: 171 void positioning(); 172 //void Element2D(NullElement2D* nullElem); 173 174 protected: 175 const PNode* bindNode; //!< a node over which to display this 2D-element 176 int relPos2D[2]; //!< X-coord, Y-Coord (relative to the Coordinates of the alignment if given.) 177 Position2D absPos2D; //!< The absolute position of the 2D-Element. 178 179 E2D_ALIGNMENT alignment; //!< How the Element is aligned around its Position 180 181 private: 182 bool visible; //!< If the given Element2D is visible. 183 bool active; //!< If the given Element2D is active. 184 E2D_LAYER layer; //!< What layer this Element2D is on. 185 186 187 private: 188 bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked 189 bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked 190 191 Vector relCoordinate; //!< coordinates relative to the parent 192 Vector absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) ) 193 float relDirection; //!< direction relative to the parent 194 float absDirection; //!< absolute direvtion in the world ( from (0,0,1) ) 195 196 Vector prevRelCoordinate; //!< The last Relative Coordinate from the last update-Cycle. 197 Vector lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate 198 float prevRelDirection; //!< The last Relative Direciton from the last update-Cycle. 199 // Quaternion lastAbsDirection; 200 201 Vector velocity; //!< Saves the velocity. 202 203 Vector* toCoordinate; //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft) 204 float* toDirection; //!< a direction to which to iterate. (This is used in conjunction with softReparent and set*DirSoft) 205 float bias; //!< how fast to iterate to the given position (default is 1) 206 207 Element2D* parent; //!< a pointer to the parent node 208 tList<Element2D>* children; //!< list of the children of this Element2D 209 210 unsigned int parentMode; //!< the mode of the binding 176 private: 177 const PNode* bindNode; //!< a node over which to display this 2D-element 178 179 E2D_ALIGNMENT alignment; //!< How the Element is aligned around its Position 180 181 bool visible; //!< If the given Element2D is visible. 182 bool active; //!< If the given Element2D is active. 183 E2D_LAYER layer; //!< What layer this Element2D is on. 184 185 bool bRelCoorChanged; //!< If Relative Coordinate has changed since last time we checked 186 bool bRelDirChanged; //!< If Relative Direction has changed since last time we checked 187 188 Vector relCoordinate; //!< coordinates relative to the parent 189 Vector absCoordinate; //!< absolute coordinates in the world ( from (0,0,0) ) 190 float relDirection; //!< direction relative to the parent 191 float absDirection; //!< absolute direvtion in the world ( from (0,0,1) ) 192 193 Vector prevRelCoordinate; //!< The last Relative Coordinate from the last update-Cycle. 194 Vector lastAbsCoordinate; //!< this is used for speedcalculation, it stores the last coordinate 195 float prevRelDirection; //!< The last Relative Direciton from the last update-Cycle. 196 // float lastAbsDirection; 197 198 Vector velocity; //!< Saves the velocity. 199 200 Vector* toCoordinate; //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft) 201 float* toDirection; //!< a direction to which to iterate. (This is used in conjunction with softReparent and set*DirSoft) 202 float bias; //!< how fast to iterate to the given position (default is 1) 203 204 Element2D* parent; //!< a pointer to the parent node 205 tList<Element2D>* children; //!< list of the children of this Element2D 206 207 unsigned int parentMode; //!< the mode of the binding 211 208 }; 212 209
Note: See TracChangeset
for help on using the changeset viewer.