Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5378 in orxonox.OLD for trunk/src/world_entities/weapons


Ignore:
Timestamp:
Oct 14, 2005, 6:54:55 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: crosshair now more compliant with Element2D
Element2D now also nows size

Location:
trunk/src/world_entities/weapons
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/weapons/crosshair.cc

    r5357 r5378  
    6464
    6565  this->setLayer(E2D_TOP);
    66   this->rotation = 0;
    6766  this->setRotationSpeed(5);
    6867  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
    6968
    70   this->position2D[0] = 0;
    71   this->position2D[1] = 0;
    72 
     69  this->setBindNode(this);
    7370  this->material = new Material;
    7471
     
    104101void Crosshair::setSize(float size)
    105102{
    106   this->size = size*.5;
    107 };
     103  this->setSize2D(size/2, size/2);
     104}
    108105
    109106/**
     
    124121  if  (event.type == EV_MOUSE_MOTION)
    125122  {
    126     this->position2D[0] = event.x;
    127     this->position2D[1] = event.y;
     123    this->setAbsCoor2D(event.x, event.y);
    128124  }
    129 
    130   /*
    131   GLdouble z;
    132   GLdouble objX, objY, objZ;
    133   glReadPixels (event.x, event.y, 1, 1, GL_DEPTH_COMPONENT, GL_DOUBLE, &z);
    134 
    135 
    136   if (gluUnProject(event.x,
    137       event.y,
    138       10,
    139       GraphicsEngine::modMat,
    140       GraphicsEngine::projMat,
    141       GraphicsEngine::viewPort,
    142       &objX,
    143       &objY,
    144       &objZ ))
    145     PRINT(0)("screen %d %d -> obj(%f/%f/%f)\n", event.x, event.y, objX, objY, objZ);
    146   else
    147     PRINT(0)("shit\n");
    148 */
    149125}
    150126
     
    156132{
    157133  // let the crosshair rotate
    158   this->rotation += dt * rotationSpeed;
     134  this->shiftDir2D(dt * rotationSpeed);
    159135
    160136
    161137  float z = 0.0f;
    162   glReadPixels ((int)position2D[0], GraphicsEngine::getInstance()->getResolutionY()-(int)position2D[1]-1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
    163   //cout << z << endl;
     138  glReadPixels ((int)this->getAbsCoor2D().x,
     139                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
     140                 1,
     141                 1,
     142                 GL_DEPTH_COMPONENT,
     143                 GL_FLOAT,
     144                 &z);
     145
    164146
    165147  GLdouble objX=.0, objY=.0, objZ=.0;
    166   gluUnProject(position2D[0],
    167                GraphicsEngine::getInstance()->getResolutionY()-position2D[1]-1,
     148  gluUnProject(this->getAbsCoor2D().x,
     149               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
    168150               .99,  // z
    169151               GraphicsEngine::modMat,
     
    175157
    176158  this->setAbsCoor(objX, objY, objZ);
    177 
    178   //this->positioning();
    179159}
    180160
     
    184164void Crosshair::draw() const
    185165{
    186 //   glBegin(GL_TRIANGLES);
    187 //   glColor3f(1,0,0);
    188 //   glVertex3f(objX, objY, objZ);
    189 //   glVertex3f(objX, objY+1, objZ);
    190 //   glVertex3f(objX, objY, objZ+1);
    191 //   glEnd();
    192166  glPushMatrix();
    193   GLdouble pos[3] = { 0.0, 0.0, 0.0};
    194   gluProject(this->getAbsCoor().x,
    195              this->getAbsCoor().y,
    196              this->getAbsCoor().z,
    197              GraphicsEngine::modMat,
    198              GraphicsEngine::projMat,
    199              GraphicsEngine::viewPort,
    200              pos, pos+1, pos+2 );
     167  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
    201168
    202 
    203   glTranslatef(position2D[0], position2D[1], 0);
    204   glRotatef(this->rotation, 0,0,1);
     169  glRotatef(this->getAbsDir2D(), 0,0,1);
    205170  this->material->select();
    206171  glBegin(GL_TRIANGLE_STRIP);
    207172  glTexCoord2f(0, 0);
    208   glVertex2f(-size, -size);
     173  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
    209174  glTexCoord2f(1, 0);
    210   glVertex2f(size, -size);
     175  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
    211176  glTexCoord2f(0, 1);
    212   glVertex2f(-size, size);
     177  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
    213178  glTexCoord2f(1, 1);
    214   glVertex2f(size, size);
     179  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
    215180  glEnd();
    216181  glPopMatrix();
  • trunk/src/world_entities/weapons/crosshair.h

    r5039 r5378  
    4040
    4141 private:
    42    float            position2D[2];        //!< The 2D-position on the screen
    43 
    4442   Material*        material;             //!< a material for the Aim.
    45    float            rotation;             //!< a rotation of the aim.
    4643   float            rotationSpeed;        //!< Speed of the Rotation.
    47    float            size;                 //!< The Size of the Crosshair (in % of screen resolution 1 is fullscreen)
    4844};
    4945
Note: See TracChangeset for help on using the changeset viewer.