Changeset 5089 in orxonox.OLD for trunk/src/lib
- Timestamp:
- Aug 21, 2005, 8:17:31 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/coord/p_node.cc
r5088 r5089 95 95 if (this->toDirection != NULL) 96 96 delete this->toDirection; 97 98 97 } 99 98 … … 575 574 } 576 575 577 if(likely(this->parentMode & PNODE_MOVEMENT ))576 if(likely(this->parentMode & PNODE_MOVEMENT && this->bRelCoorChanged)) 578 577 { 579 578 /* update the current absCoordinate */ … … 581 580 this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate; 582 581 } 583 else if( this->parentMode & PNODE_ROTATE_MOVEMENT )582 else if( this->parentMode & PNODE_ROTATE_MOVEMENT && this->bRelCoorChanged) 584 583 { 585 584 /* update the current absCoordinate */ -
trunk/src/lib/graphics/graphics_engine.cc
r5084 r5089 410 410 void GraphicsEngine::update(float dt) 411 411 { 412 //NullElement2D::getInstance()->update2D(dt);412 NullElement2D::getInstance()->update2D(dt); 413 413 NullElement2D::getInstance()->debug(0); 414 414 … … 468 468 this->geTextCFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0); 469 469 this->geTextCFPS->setAlignment(TEXT_ALIGN_LEFT); 470 this->geTextCFPS->set Position2D(5, 5);470 this->geTextCFPS->setAbsCoor2D(5, 5); 471 471 } 472 472 if (this->geTextMaxFPS == NULL) … … 474 474 this->geTextMaxFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0); 475 475 this->geTextMaxFPS->setAlignment(TEXT_ALIGN_LEFT); 476 this->geTextMaxFPS->set Position2D(5, 35);476 this->geTextMaxFPS->setAbsCoor2D(5, 35); 477 477 } 478 478 if (this->geTextMinFPS == NULL) … … 480 480 this->geTextMinFPS = TextEngine::getInstance()->createText("fonts/arial_black.ttf", 15, TEXT_DYNAMIC, 0, 255, 0); 481 481 this->geTextMinFPS->setAlignment(TEXT_ALIGN_LEFT); 482 this->geTextMinFPS->set Position2D(5, 65);482 this->geTextMinFPS->setAbsCoor2D(5, 65); 483 483 } 484 484 #endif /* NO_TEXT */ -
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 -
trunk/src/lib/graphics/text_engine.cc
r5078 r5089 55 55 56 56 // initialize this Text 57 this->bindNode = NULL;58 57 this->font = font; 59 58 this->text = NULL; 60 this-> alignment = TEXT_DEFAULT_ALIGNMENT;59 this->setAlignment(TEXT_DEFAULT_ALIGNMENT); 61 60 this->texture = 0; 62 61 this->blending = 1.0f; … … 112 111 113 112 // setting up the Text-Width if DYNAMIC 114 if (this->type == TEXT_DYNAMIC && this-> alignment!= TEXT_ALIGN_LEFT)113 if (this->type == TEXT_DYNAMIC && this->getAlignment() != TEXT_ALIGN_LEFT) 115 114 { 116 115 Glyph** glyphArray = this->font->getGlyphArray(); … … 173 172 glPushMatrix(); 174 173 // transform for alignment. 175 if (this-> alignment== TEXT_ALIGN_RIGHT)174 if (this->getAlignment() == TEXT_ALIGN_RIGHT) 176 175 glTranslatef(-this->posSize.w, 0, 0); 177 else if (this-> alignment == TEXT_ALIGN_CENTER || this->alignment== TEXT_ALIGN_SCREEN_CENTER)176 else if (this->getAlignment() == TEXT_ALIGN_CENTER || this->getAlignment() == TEXT_ALIGN_SCREEN_CENTER) 178 177 glTranslatef(-this->posSize.w/2, 0, 0); 179 178 … … 191 190 192 191 glTexCoord2f(this->texCoord.minU, this->texCoord.minV); 193 glVertex2f(this-> absPos2D.x, this->absPos2D.y );192 glVertex2f(this->getAbsCoor2D().x, this->getAbsCoor2D().y ); 194 193 195 194 glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); 196 glVertex2f(this-> absPos2D.x + this->posSize.w, this->absPos2D.y );195 glVertex2f(this->getAbsCoor2D().x + this->posSize.w, this->getAbsCoor2D().y ); 197 196 198 197 glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); 199 glVertex2f(this-> absPos2D.x + this->posSize.w, absPos2D.y + this->posSize.h);198 glVertex2f(this->getAbsCoor2D().x + this->posSize.w, getAbsCoor2D().y + this->posSize.h); 200 199 201 200 glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); 202 glVertex2f( absPos2D.x, absPos2D.y + this->posSize.h);201 glVertex2f(getAbsCoor2D().x, getAbsCoor2D().y + this->posSize.h); 203 202 204 203 glEnd(); … … 209 208 glBindTexture(GL_TEXTURE_2D, this->font->getFastTextureID()); 210 209 // glEnable(GL_TEXTURE_2D); 211 glTranslatef( absPos2D.x, absPos2D.y, 0);210 glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0); 212 211 213 212 const char* tmpText = this->text; … … 231 230 { 232 231 PRINT(0)("=== TEXT: %s ===\n", this->text); 233 if (this-> bindNode)234 PRINT(0)("is bind to %s; ref=%p\n", this-> bindNode->getName(), this->bindNode);232 if (this->getBindNode()) 233 PRINT(0)("is bind to %s; ref=%p\n", this->getBindNode()->getName(), this->getBindNode()); 235 234 PRINT(0)("Relative Position: (%d::%d)\n", this->posSize.x, this->posSize.y); 236 235 PRINT(0)("Color: %d %d %d\n", this->color.r, this->color.g, this->color.b);
Note: See TracChangeset
for help on using the changeset viewer.