Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5381 in orxonox.OLD


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
Files:
8 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
  • branches/2d-recalc/src/lib/shell/shell.cc

    r5380 r5381  
    5757    ->defaultValues(1, SHELL_DEFAULT_FONT);
    5858
     59
    5960/**
    6061 * standard constructor
     
    8182  this->backgroundMaterial = new Material;
    8283  // Element2D and generals
    83   this->textSize = .001;
    84   this->lineSpacing = .001;
     84  this->textSize = 16;
     85  this->lineSpacing = 1;
    8586  this->bActive = false;
    8687  this->fontFile = new char[strlen(SHELL_DEFAULT_FONT)+1];
     
    9697  ShellBuffer::getInstance()->registerShell(this);
    9798}
     99
    98100
    99101/**
     
    115117}
    116118
     119
    117120/**
    118121 * activates the shell
     
    139142}
    140143
     144
    141145/**
    142146 * deactiveates the Shell.
     
    162166  this->bufferOffset = 0;
    163167}
     168
    164169
    165170/**
     
    183188  this->rebuildText();
    184189}
     190
    185191
    186192/**
     
    199205}
    200206
     207
    201208/**
    202209 * sets the color of the Font.
     
    229236  this->backgroundMaterial->setTransparency(a);
    230237}
     238
    231239
    232240/**
     
    271279}
    272280
     281
    273282/**
    274283 * rebuilds the Text's
     
    285294  this->setBufferDisplaySize(this->bufferDisplaySize);
    286295}
     296
    287297
    288298/**
     
    319329}
    320330
     331
    321332/**
    322333 * deletes all the Buffers
     
    334345    // BUFFER FLUSHING
    335346}
     347
    336348
    337349/**
     
    374386}
    375387
     388
    376389/**
    377390 * moves the Display buffer (up or down)
     
    424437}
    425438
     439
    426440/**
    427441 * clears the Shell (empties all buffers)
     
    432446  ShellBuffer::addBufferLineStatic("orxonox - shell\n ==================== \n", NULL);
    433447}
     448
    434449
    435450/**
     
    459474}
    460475
     476
    461477/**
    462478 * displays the Shell
     
    487503}
    488504
     505
    489506///////////////////////
    490507// HELPER FUNCTIONS  //
    491508///////////////////////
    492 
    493509/**
    494510 * calculates the position of a Buffer-Display Line
     
    500516  return Vector(5, (this->textSize + this->lineSpacing)*(this->bufferDisplaySize - lineNumber -1) + this->textSize, 0);
    501517}
    502 
    503518
    504519
  • branches/2d-recalc/src/world_entities/weapons/crosshair.cc

    r5378 r5381  
    6565  this->setLayer(E2D_TOP);
    6666  this->setRotationSpeed(5);
    67   this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
     67  this->setSize(0.1);
    6868
    69   this->setBindNode(this);
     69//  this->setBindNode(this);
    7070  this->material = new Material;
    7171
     
    7373
    7474  // center the mouse on the screen, and also hide the cursors
    75   SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
     75//  SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
    7676  GraphicsEngine::showMouse(false);
    7777  GraphicsEngine::stealWMEvents(true);
     
    121121  if  (event.type == EV_MOUSE_MOTION)
    122122  {
    123     this->setAbsCoor2D(event.x, event.y);
     123    this->setAbsCoor2Dpx(event.x, event.y);
    124124  }
    125125}
     
    134134  this->shiftDir2D(dt * rotationSpeed);
    135135
    136 
    137136  float z = 0.0f;
    138   glReadPixels ((int)this->getAbsCoor2D().x,
    139                  GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
     137  glReadPixels ((int)this->getAbsCoor2Dpx().x,
     138                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2Dpx().y-1,
    140139                 1,
    141140                 1,
     
    146145
    147146  GLdouble objX=.0, objY=.0, objZ=.0;
    148   gluUnProject(this->getAbsCoor2D().x,
    149                GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
     147  gluUnProject(this->getAbsCoor2Dpx().x,
     148               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2Dpx().y-1,
    150149               .99,  // z
    151150               GraphicsEngine::modMat,
     
    166165  glPushMatrix();
    167166  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
     167//  printf("%f, %f\n", this->getAbsCoor2D().x, this->getAbsCoor2D().y);
    168168
    169169  glRotatef(this->getAbsDir2D(), 0,0,1);
  • branches/2d-recalc/src/world_entities/weapons/weapon_manager.cc

    r5208 r5381  
    106106  this->crossHairSizeAnim = new tAnimation<Crosshair>(this->crosshair, &Crosshair::setSize);
    107107  this->crossHairSizeAnim->setInfinity(ANIM_INF_REWIND);
    108   this->crossHairSizeAnim->addKeyFrame(50, .1, ANIM_LINEAR);
    109   this->crossHairSizeAnim->addKeyFrame(100, .05, ANIM_LINEAR);
    110   this->crossHairSizeAnim->addKeyFrame(50, .01, ANIM_LINEAR);
     108  this->crossHairSizeAnim->addKeyFrame(.1, .1, ANIM_LINEAR);
     109  this->crossHairSizeAnim->addKeyFrame(.2, .05, ANIM_LINEAR);
     110  this->crossHairSizeAnim->addKeyFrame(.1, .01, ANIM_LINEAR);
    111111}
    112112
Note: See TracChangeset for help on using the changeset viewer.