Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5381 in orxonox.OLD for branches/2d-recalc/src/lib/graphics


Ignore:
Timestamp:
Oct 15, 2005, 7:13:23 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/2d-recalc: some recalculations.. do not know it i will continue with this, as has certain disadvantages over the old approach… maybe later

Location:
branches/2d-recalc/src/lib/graphics
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2d-recalc/src/lib/graphics/graphics_engine.cc

    r5380 r5381  
    410410     depending on how you have your OpenGL state set up.
    411411  */
    412   glPushAttrib(GL_ENABLE_BIT);
     412  glPushAttrib(GL_ENABLE_BIT); // storte the state of all enable-bits.
    413413  glDisable(GL_DEPTH_TEST);
    414414  glDisable(GL_CULL_FACE);
    415   glDisable(GL_LIGHTING);  // will be set back when leaving 2D-mode
    416 
     415  glDisable(GL_LIGHTING);
    417416  glViewport(0, 0, screen->w, screen->h);
    418417
  • branches/2d-recalc/src/lib/graphics/render2D/element_2d.cc

    r5380 r5381  
    111111  this->setActiveness(true);
    112112  this->setAlignment(E2D_ALIGN_NONE);
    113   this->layer = E2D_TOP;
     113  this->layer = E2D_DEFAULT_LAYER;
    114114  this->bindNode = NULL;
    115115
     
    254254/**
    255255 * sets a node, this 2D-Element should be shown upon
    256  * @param bindNode the name of the Node (should be existing)
     256 * @param bindNode the name of the Node (should already be existing)
    257257 */
    258258void Element2D::setBindNode(const char* bindNode)
     
    280280
    281281/**
    282  * sets the relative coordinate of the Element2D to its Parent
    283  * @param x the x coordinate
    284  * @param y the y coordinate
    285  * @param z the z coordinate
    286  */
    287 void Element2D::setRelCoor2D (float x, float y, float z)
    288 {
    289   this->setRelCoor2D(Vector(x,y,z));
    290 }
    291 
    292 /**
    293282 * sets the Relative coordinate to the parent in Pixels
    294283 * @param x the relCoord X
     
    299288  this->setRelCoor2D(Vector((float)x/(float)GraphicsEngine::getInstance()->getResolutionX(),
    300289                     (float)y/(float)GraphicsEngine::getInstance()->getResolutionY(),
    301                      0
    302                            ));
     290                     0 ));
    303291}
    304292
     
    332320
    333321/**
    334  * set relative coordinates smoothely
    335  * @param x x-relative coordinates to its parent
    336  * @param y y-relative coordinates to its parent
    337  * @param z z-relative coordinates to its parent
    338  * @see  void PNode::setRelCoorSoft (const Vector&, float)
    339  */
    340 void Element2D::setRelCoorSoft2D(float x, float y, float depth, float bias)
    341 {
    342   this->setRelCoorSoft2D(Vector(x, y, depth), bias);
     322 * @returns the Relative coordinate of the Element2D in pixels (as float-Vector)
     323 */
     324Vector Element2D::getRelCoor2Dpx() const
     325{
     326  return Vector(this->prevRelCoordinate.x * (float)GraphicsEngine::getInstance()->getResolutionX(),
     327                this->prevRelCoordinate.y * (float)GraphicsEngine::getInstance()->getResolutionY(),
     328                0);
    343329}
    344330
     
    374360
    375361/**
    376  * @param x x-coordinate.
    377  * @param y y-coordinate.
    378  * @param z z-coordinate.
    379  * @see void PNode::setAbsCoor (const Vector& absCoord)
    380  */
    381 void Element2D::setAbsCoor2D (float x, float y, float depth)
    382 {
    383   this->setAbsCoor2D(Vector(x, y, depth));
    384 }
    385 
    386 /**
    387362 * @param x x-coordinate in Pixels
    388363 * @param y y-coordinate in Pixels
     
    398373
    399374/**
     375 * @returns the absolute coordinate of the Element2D in pixels (as float-Vector)
     376 */
     377Vector Element2D::getAbsCoor2Dpx() const
     378{
     379  return Vector(this->absCoordinate.x * (float)GraphicsEngine::getInstance()->getResolutionX(),
     380                this->absCoordinate.y * (float)GraphicsEngine::getInstance()->getResolutionY(),
     381                0);
     382}
     383
     384/**
    400385 *  shift coordinate ralative
    401386 * @param shift shift vector
     
    407392  this->relCoordinate += shift;
    408393  this->bRelCoorChanged = true;
    409 
    410394}
    411395
     
    684668    PRINTF(5)("Element2D::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    685669
    686 
     670    // update the direction
    687671    if( this->parentMode & E2D_PARENT_LOCAL_ROTATE && this->bRelDirChanged)
    688672    {
    689       /* update the current absDirection - remember * means rotation around sth.*/
    690673      this->prevRelDirection = this->relDirection;
    691674      this->absDirection = this->relDirection + parent->getAbsDir2D();;
    692675    }
    693 
    694676
    695677    if (this->alignment == E2D_ALIGN_SCREEN_CENTER && this->bRelCoorChanged)
     
    700682      this->absCoordinate.z = 0.0;
    701683    }
    702     else if (this->bindNode)
     684    // align at the bindNode.
     685    else if (unlikely(this->bindNode != NULL))
    703686    {
    704687      GLdouble projectPos[3];
     
    715698      this->absCoordinate.y = projectPos[1]/(float)GraphicsEngine::getInstance()->getResolutionY() + this->relCoordinate.y;
    716699      this->absCoordinate.z = projectPos[2] + this->relCoordinate.z;
     700      //! @todo check for corectness.
     701      //       printf("%f, %f, %f\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
    717702    }
    718703    else
  • branches/2d-recalc/src/lib/graphics/render2D/element_2d.h

    r5380 r5381  
    22 * @file element_2d.h
    33 * Definition of the 2D elements rendered on top through the GraphicsEngine
    4  *
    5  * @todo reimplement it, so it looks just like PNode.
    6 */
     4 */
    75
    86#ifndef _ELEMENT_2D_H
     
    3735  E2D_ALIGN_RIGHT               =     2,
    3836  E2D_ALIGN_CENTER              =     4,
    39   E2D_ALIGN_SCREEN_CENTER       =     8
     37  E2D_ALIGN_SCREEN_CENTER       =     8,
    4038} E2D_ALIGNMENT;
    4139
     
    9896    inline bool isActive() { return this->active; };
    9997
    100 
     98    /////////////
     99    // SCALING //
     100    /////////////
    101101    inline void setSize2D(float x, float y) { this->sizeX = x, this->sizeY = y; };
    102102    void setSize2Dpx(int x, int y);
     
    110110    int getSizeY2Dpx() const;
    111111
    112     // LIKE PNODE
    113   public:
     112    // PNODE-STYLE-behavioral
     113  public:
     114    /////////////////
     115    // COORDINATES //
     116    /////////////////
     117    // RELATIVE //
    114118    void setRelCoor2D (const Vector& relCoord);
    115     void setRelCoor2D (float x, float y, float dontCare = 1.0);
     119    /** @param x x-coordinate.  @param y y-coordinate. @param z z-coordinate. @see void PNode::setRelCoor2D (const Vector& absCoord) */
     120    void setRelCoor2D (float x, float y, float dontCare = 1.0) { this->setRelCoor2D(Vector(x, y, dontCare)); };
    116121    void setRelCoor2Dpx (int x, int y);
     122    inline void setRelCoor2Dpx (const Vector& relCoordpx) { this->setRelCoor2D(relCoordpx.x, relCoordpx.y); };
    117123    void setRelCoorSoft2D (const Vector& relCoordSoft, float bias = 1.0);
    118     void setRelCoorSoft2D (float x, float y, float dontCare = 1.0, float bias = 1.0);
     124    /** set relative coordinates smoothely @param x x-relative coordinates to its parent
     125     * @param y y-relative coordinates to its parent @param z z-relative coordinates to its parent
     126     * @see  void PNode::setRelCoorSoft (const Vector&, float) */
     127    void setRelCoorSoft2D (float x, float y, float dontCare = 1.0, float bias = 1.0) { this->setRelCoorSoft2D(Vector(x,y, dontCare), bias); };
    119128    void setRelCoorSoft2Dpx (int x, int y, float bias = 1.0);
    120129    /** @returns the relative position */
     
    122131    /** @returns the Relative Coordinate Destination */
    123132    inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)?*this->toCoordinate:this->relCoordinate; };
    124     const Vector& getRelCoor2Dpx() const;
     133    Vector getRelCoor2Dpx() const;
     134    // ABSOLUTE //
    125135    void setAbsCoor2D (const Vector& absCoord);
    126     void setAbsCoor2D (float x, float y, float depth = 1.0);
     136    /** @param x x-coordinate.  @param y y-coordinate. @param z z-coordinate. @see void PNode::setAbsCoor2D (const Vector& absCoord) */
     137    void setAbsCoor2D (float x, float y, float depth = 1.0) { this->setAbsCoor2D(Vector(x, y, depth)); };
    127138    void setAbsCoor2Dpx (int x, int y);
    128139    /** @returns the absolute position */
    129140    inline const Vector& getAbsCoor2D () const { return this->absCoordinate; };
    130     const Vector& getAbsCoor2Dpx () const;
     141    Vector getAbsCoor2Dpx () const;
    131142
    132143    void shiftCoor2D (const Vector& shift);
    133144    void shiftCoor2Dpx (int x, int y);
    134145
     146    /** @returns the Speed of the Node */
     147    inline float getSpeed() const { return 0; };
     148    /** @returns the Velocity of the Node */
     149    inline const Vector& getVelocity() const { return this->velocity; };
     150
     151    ////////////////
     152    // DIRECTIONS //
     153    ////////////////
     154    // RELATIVE //
    135155    void setRelDir2D (float relDir);
    136156    void setRelDirSoft2D(float relDirSoft, float bias = 1.0);
     
    139159    /** @returns the Relative Directional Destination */
    140160    inline float getRelDirSoft2D() const { return (this->toDirection)?*this->toDirection:this->relDirection; };
     161    // ABSOLUTE //
    141162    void setAbsDir2D (float absDir);
    142163    /** @returns the absolute Direction */
    143164    inline float getAbsDir2D () const { return this->absDirection; };
    144165    void shiftDir2D (float shiftDir);
    145 
    146     /** @returns the Speed of the Node */
    147     inline float getSpeed() const { return 0; };
    148     /** @returns the Velocity of the Node */
    149     inline const Vector& getVelocity() const { return this->velocity; };
    150 
    151 
     166    ///////////////
     167    // PARENTING //
     168    ///////////////
    152169    void addChild2D (Element2D* child, int parentingMode = E2D_PARENT_NONE);
    153170    void addChild2D (const char* childName);
     
    169186    int getParentMode2D() const { return this->parentMode; };
    170187
     188
     189    //////////////
     190    // HANDLING //
     191    //////////////
    171192    void update2D (float dt);
    172193
     
    192213  private:
    193214    const PNode*            bindNode;           //!< a node over which to display this 2D-element
     215    bool                    coordinateType;     //!< true if type is [0-1],[0-1]-style, false if type is [0-ResolutionX][0-ResolutionY]-style.
     216
    194217    float                   sizeX;              //!< The size of the rendered item in x-direction
    195218    float                   sizeY;              //!< The size of the rendered Item in y-direction
     
    212235    Vector                  lastAbsCoordinate;  //!< this is used for speedcalculation, it stores the last coordinate
    213236    float                   prevRelDirection;   //!< The last Relative Direciton from the last update-Cycle.
    214 //  float                   lastAbsDirection;
    215237
    216238    Vector                  velocity;           //!< Saves the velocity.
  • branches/2d-recalc/src/lib/graphics/render2D/render_2d.cc

    r5318 r5381  
    1414*/
    1515
    16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
     16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
    1717
    1818#include "render_2d.h"
     19#include "debug.h"
    1920
    2021#include "graphics_engine.h"
     
    8889void Render2D::moveToLayer(Element2D* element2D, E2D_LAYER to)
    8990{
     91  // prevent switching Layers if either Render2D is not Instanciated or element2D is NULL
     92  if (unlikely(element2D == NULL  || this == NULL))
     93    return;
     94  if(to > pow(2, E2D_LAYER_COUNT))
     95  {
     96    PRINTF(2)("trying to %s (%s) move to a to non-existing layer %d\n", element2D->getName(), element2D->getClassName() );
     97    to = E2D_DEFAULT_LAYER;
     98  }
    9099  if (element2D->getLayer() != to)
    91100  {
  • branches/2d-recalc/src/lib/graphics/render2D/render_2d.h

    r4862 r5381  
    33 * @brief Definition of the 2D-rendering engine singleton Class
    44 * @todo implement Layer-rendering
    5 */
     5 */
    66
    77#ifndef _RENDER_2D_H
Note: See TracChangeset for help on using the changeset viewer.