Changeset 4862 in orxonox.OLD for orxonox/trunk/src/lib
- Timestamp:
- Jul 14, 2005, 2:49:33 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/graphics
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/graphics/graphics_engine.cc
r4856 r4862 432 432 void GraphicsEngine::draw() const 433 433 { 434 Render2D::getInstance()->draw( );434 Render2D::getInstance()->draw(E2D_ALL_LAYERS); 435 435 LightManager::getInstance()->draw(); 436 436 } -
orxonox/trunk/src/lib/graphics/render2D/element_2d.cc
r4861 r4862 57 57 this->setPosition2D(0,0); 58 58 this->setAlignment(E2D_ALIGN_NONE); 59 this-> setLayer(E2D_TOP);59 this->layer = E2D_TOP; 60 60 61 61 Render2D::getInstance()->registerElement2D(this); … … 98 98 else if (!strcmp(alignment, "screen-center")) 99 99 this->setAlignment(E2D_ALIGN_SCREEN_CENTER); 100 } 101 102 103 /** 104 * moves a Element to another layer 105 * @param layer the Layer this is drawn on 106 */ 107 void Element2D::setLayer(E2D_LAYER layer) 108 { 109 Render2D::getInstance()->moveToLayer(this, layer); 110 this->layer = layer; 100 111 } 101 112 -
orxonox/trunk/src/lib/graphics/render2D/element_2d.h
r4861 r4862 16 16 typedef enum 17 17 { 18 E2D_ TOP, //!< Will be rendered on top of everything else19 E2D_ MEDIUM, //!< Will be rendered on the medium Layer.20 E2D_ BOTTOM, //!< Will be rendered on the bottom Layer21 E2D_ BELOW_ALL, //!< Will be rendered below the 3D-scene. @todo make this work.18 E2D_BELOW_ALL = 1, //!< Will be rendered below the 3D-scene. @todo make this work. 19 E2D_BOTTOM = 2, //!< Will be rendered on the bottom Layer 20 E2D_MEDIUM = 4, //!< Will be rendered on the medium Layer. 21 E2D_TOP = 8, //!< Will be rendered on top of everything else 22 22 23 E2D_LAYER_COUNT //!< The count of Layers. 24 } E2DLayer; 25 23 E2D_LAYER_COUNT = 4 //!< The count of Layers. 24 } E2D_LAYER; 25 #define E2D_DEFAULT_LAYER E2D_TOP 26 #define E2D_ALL_LAYERS E2D_TOP | E2D_MEDIUM | E2D_BOTTOM | E2D_BELOW_ALL 26 27 27 28 typedef enum … … 56 57 /** this returns the Absolute Position on the screen set by positioning in the tick-phase */ 57 58 inline const Position2D& getPosition2D() { return this->absPos2D; }; 59 58 60 /** @param alignment the new Alignment of the 2D-Element */ 59 61 inline void setAlignment(E2D_ALIGNMENT alignment) { this->alignment = alignment; }; 60 62 void setAlignment(const char* alignment); 61 /** @param layer the Layer this is drawn on */ 62 inline void setLayer(E2DLayer layer) { this->layer = layer; };63 64 void setLayer(E2D_LAYER layer); 63 65 void setLayer(const char* layer); 66 /** @returns the Layer this Element is drawn to */ 67 inline E2D_LAYER getLayer() { return this->layer; }; 68 64 69 /** @param visible true if the Element should be visible false otherwise (will not be rendered) */ 65 70 inline void setVisibility(bool visible) { this->visible = visible; }; 71 66 72 /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */ 67 73 inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; }; … … 86 92 private: 87 93 bool visible; 88 E2D Layerlayer;94 E2D_LAYER layer; 89 95 }; 90 96 -
orxonox/trunk/src/lib/graphics/render2D/render_2d.cc
r4849 r4862 23 23 #include "element_2d.h" 24 24 25 #include <math.h> 26 25 27 using namespace std; 26 28 … … 35 37 this->setName("Render2D"); 36 38 37 this->element2DList = new tList<Element2D>; 39 for (int i = 0; i < E2D_LAYER_COUNT; i++) 40 this->element2DList[i] = new tList<Element2D>; 38 41 } 39 42 … … 48 51 Render2D::~Render2D () 49 52 { 50 delete this->element2DList; 53 for (int i = 0; i < E2D_LAYER_COUNT; i++) 54 delete this->element2DList[i]; 51 55 52 56 Render2D::singletonRef = NULL; … … 62 66 void Render2D::registerElement2D(Element2D* element2D) 63 67 { 64 this->element2DList ->add(element2D);68 this->element2DList[(int)log2(E2D_DEFAULT_LAYER)]->add(element2D); 65 69 } 66 70 … … 73 77 void Render2D::unregisterElement2D(Element2D* element2D) 74 78 { 75 this->element2DList ->remove(element2D);79 this->element2DList[(int)log2(element2D->getLayer())]->remove(element2D); 76 80 } 77 81 78 82 83 /** 84 * moves an 2D-Element to another Layer 85 * @param element2D the Element to move 86 * @param to which layer to move it to. 87 */ 88 void Render2D::moveToLayer(Element2D* element2D, E2D_LAYER to) 89 { 90 this->element2DList[(int)log2(element2D->getLayer())]->remove(element2D); 91 this->element2DList[(int)log2(to)]->add(element2D); 92 } 93 94 95 /** 96 * ticks all the 2d-elements 97 * @param dt the timestep since last dt 98 */ 79 99 void Render2D::tick(float dt) 80 100 { 81 tIterator<Element2D>* iterator = this->element2DList->getIterator(); 82 Element2D* elem = iterator->nextElement(); 83 while (elem != NULL) 101 for (int i = 0; i < E2D_LAYER_COUNT; i++) 84 102 { 85 elem->tick(dt); 86 elem = iterator->nextElement(); 103 tIterator<Element2D>* iterator = this->element2DList[i]->getIterator(); 104 Element2D* elem = iterator->nextElement(); 105 while (elem != NULL) 106 { 107 elem->tick(dt); 108 elem = iterator->nextElement(); 109 } 110 delete iterator; 87 111 } 88 delete iterator;89 90 112 } 91 113 … … 93 115 * renders all the Elements of the Render2D-engine 94 116 */ 95 void Render2D::draw( ) const117 void Render2D::draw(unsigned int layer) const 96 118 { 97 119 GraphicsEngine::enter2DMode(); 98 120 99 tIterator<Element2D>* iterator = this->element2DList->getIterator();100 Element2D* elem = iterator->nextElement(); 101 while (elem != NULL)121 int drawLayer = 1; 122 123 for (int i = 0; i < E2D_LAYER_COUNT; i++) 102 124 { 103 if (elem->isVisible()) 104 elem->draw(); 105 elem = iterator->nextElement(); 125 if (layer & drawLayer && this->element2DList[i]->getSize() > 0) 126 { 127 tIterator<Element2D>* iterator = this->element2DList[i]->getIterator(); 128 Element2D* elem = iterator->nextElement(); 129 while (elem != NULL) 130 { 131 if (elem->isVisible()) 132 elem->draw(); 133 elem = iterator->nextElement(); 134 } 135 delete iterator; 136 } 137 drawLayer << 1; 106 138 } 107 delete iterator;108 139 109 140 GraphicsEngine::leave2DMode(); 141 110 142 } -
orxonox/trunk/src/lib/graphics/render2D/render_2d.h
r4849 r4862 22 22 23 23 void tick(float dt); 24 void draw( ) const;24 void draw(unsigned int layer) const; 25 25 26 26 void registerElement2D(Element2D* element2D); 27 27 void unregisterElement2D(Element2D* element2D); 28 void moveToLayer(Element2D* element2D, E2D_LAYER to); 28 29 29 30 private: 30 31 Render2D(); 31 static Render2D* singletonRef; //!< Reference to this class.32 static Render2D* singletonRef; //!< Reference to this class. 32 33 33 tList<Element2D>* element2DList; //!< List of all valid 2D-elements. 34 // tList<Element2D>* element2DList; //!< List of all valid 2D-elements. 35 tList<Element2D>* element2DList[E2D_LAYER_COUNT]; //!< List of all valid 2D-elements in the different Layers. 34 36 }; 35 37
Note: See TracChangeset
for help on using the changeset viewer.