Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4847 in orxonox.OLD for orxonox/trunk/src/lib


Ignore:
Timestamp:
Jul 13, 2005, 6:25:44 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: more functions to the elem-2d-renderer

Location:
orxonox/trunk/src/lib/graphics/render2D
Files:
3 edited

Legend:

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

    r4843 r4847  
    3131Element2D::Element2D ()
    3232{
    33    this->setClassID(CL_ELEMENT_2D, "Element2D");
    34 
    35    Render2D::getInstance()->registerElement2D(this);
     33  this->init();
    3634}
    3735
     
    4644
    4745
     46void Element2D::init()
     47{
     48  this->setClassID(CL_ELEMENT_2D, "Element2D");
     49
     50  Render2D::getInstance()->registerElement2D(this);
     51
     52}
     53
    4854/**
    4955 * this sets the position of the Element on the screen.
     56 * Use this in the your tick function, if you want the element to be automatically positioned.
    5057 */
    5158void Element2D::positioning()
    5259{
    5360  // setting the Position of this ELEM2D.
    54   Vector pos;
    5561  if (this->bindNode)
    5662  {
    57     GLdouble x = this->bindNode->getAbsCoor().x;
    58     GLdouble y = this->bindNode->getAbsCoor().y;
    59     GLdouble z = this->bindNode->getAbsCoor().z;
    6063    GLdouble projectPos[3];
    61     gluProject(x, y, z, GraphicsEngine::modMat, GraphicsEngine::projMat, GraphicsEngine::viewPort, projectPos, projectPos+1, projectPos+2);
    62     pos.x = projectPos[0] + this->position2D[0];
    63     pos.y = GraphicsEngine::getInstance()->getResolutionY() - projectPos[1] + this->position2D[1];
    64     pos.z = projectPos[2];
     64    gluProject(this->bindNode->getAbsCoor().x,
     65               this->bindNode->getAbsCoor().y,
     66               this->bindNode->getAbsCoor().z,
     67               GraphicsEngine::modMat,
     68               GraphicsEngine::projMat,
     69               GraphicsEngine::viewPort,
     70               projectPos,
     71               projectPos+1,
     72               projectPos+2);
     73    absPos2D.x = projectPos[0] + this->relPos2D[0];
     74    absPos2D.y = GraphicsEngine::getInstance()->getResolutionY() - projectPos[1] + this->relPos2D[1];
     75    absPos2D.depth = projectPos[2];
    6576  }
    6677  else
    6778  {
    68     pos.x = this->position2D[0];
    69     pos.y = this->position2D[1];
    70     pos.z = 0;
     79    absPos2D.x = this->relPos2D[0];
     80    absPos2D.y = this->relPos2D[1];
     81    absPos2D.depth = 0;
    7182  }
    72 
    73   glPushMatrix();
    7483}
    7584
     85/**
     86 * ticks the 2d-Element
     87 * @param dt the time elapsed since the last tick
     88 */
     89void Element2D::tick(float dt)
     90{
     91  this->positioning();
     92}
  • orxonox/trunk/src/lib/graphics/render2D/element_2d.h

    r4843 r4847  
    2424typedef enum
    2525{
     26  ELEM2D_ALIGN_NONE,
    2627  ELEM2D_ALIGN_LEFT,
    2728  ELEM2D_ALIGN_RIGHT,
     
    3031} ELEM2D_ALIGNMENT;
    3132
     33//! A Struct defining the Position of an Element in 2D-space
     34struct Position2D
     35{
     36  float       x;                 //!< The x-coordinate.
     37  float       y;                 //!< The y-coordinate.
     38  float       depth;             //!< The distance from the viewing plane.
     39
     40};
    3241
    3342//! A class for ...
     
    3847  virtual ~Element2D();
    3948
    40 
    4149  void setPosition(int xCoord, int yCoord);
    4250  void setLayer(E2DLayer layer);
     51  /** @param visible true if the Element should be visible false otherwise (will not be rendered) */
     52  inline void setVisibility(bool visible) { this->visible = visible; };
     53  /** @param bindNode the Node this 2D-element should follow. if NULL the Element will not follow anything */
     54  inline void setBindNode(const PNode* bindNode) { this->bindNode = bindNode; };
    4355
     56  /** @returns the visibility state */
     57  inline bool isVisible() { return this->visible; };
    4458
    4559  void positioning();
     60  virtual void tick(float dt);
    4661  virtual void draw() const = NULL;
    4762
     63  private:
     64    void init();
     65
    4866 private:
    49    bool               visible;
    50    int                position2D[2];    //!< X-coord, Y-Coord
    51    E2DLayer           layer;
     67   bool                    visible;
     68   int                     relPos2D[2];      //!< X-coord, Y-Coord (relative to the Coordinates of the alignment if given.)
     69   Position2D              absPos2D;         //!< The absolute position of the 2D-Element.
     70   E2DLayer                layer;
    5271
    53    ELEM2D_ALIGNMENT   alignment;
    54    PNode*             bindNode;         //!< a node over which to display this 2D-element
     72   ELEM2D_ALIGNMENT        alignment;        //!< How the Element is aligned around its Position
     73   const PNode*            bindNode;         //!< a node over which to display this 2D-element
    5574};
    5675
  • orxonox/trunk/src/lib/graphics/render2D/render_2d.cc

    r4840 r4847  
    7171  this->element2DList->remove(element2D);
    7272}
     73
     74
     75void Render2D::draw() const
     76{
     77  tIterator<Element2D>* iterator = this->element2DList->getIterator();
     78  Element2D* elem = iterator->nextElement();
     79  while (elem != NULL)
     80  {
     81    if (elem->isVisible())
     82      elem->draw();
     83    elem = iterator->nextElement();
     84  }
     85  delete iterator;
     86}
Note: See TracChangeset for help on using the changeset viewer.