Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 11, 2005, 5:45:27 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: loadParams and timing

File:
1 edited

Legend:

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

    r4831 r4832  
    1919#include "event_handler.h"
    2020
     21#include "load_param.h"
    2122#include "graphics_engine.h"
    2223#include "glincl.h"
    23 #include "p_node.h"
    2424#include "state.h"
    25 #include "model.h"
     25#include "material.h"
    2626
    2727#include <iostream>
     
    3131
    3232/**
    33    \brief standard constructor
     33 * standart constructor
     34 */
     35Crosshair::Crosshair (const TiXmlElement* root)
     36{
     37  this->init();
     38
     39  if (root)
     40    this->loadParams(root);
     41  else
     42    this->setTexture("maps/aim.png");
     43}
     44
     45
     46/**
     47 * destroys a Crosshair
    3448*/
    35 Crosshair::Crosshair ()
     49Crosshair::~Crosshair ()
     50{
     51  if (this->material)
     52  delete this->material;
     53
     54  // delete what has to be deleted here
     55  EventHandler::getInstance()->unsubscribe(this);
     56
     57  GraphicsEngine::showMouse(true);
     58  GraphicsEngine::stealWMEvents(false);
     59}
     60
     61/**
     62 * initializes the Crosshair
     63 */
     64void Crosshair::init()
    3665{
    3766  this->setClassID(CL_CROSSHAIR, "Crosshair");
    3867  this->setName("Crosshair");
    3968
    40   this->material = NULL;
    41   this->model = NULL;
    4269  this->rotation = 0;
    43 
    44   this->material = new Material("Crosshair Material");
    45   this->material->setDiffuseMap("maps/aim.png");
    46 
    47   float size = 50;
    48   this->model = new Model();
    49   this->model->addVertex (-0.5*size, -0.5*size, 0);
    50   this->model->addVertex (0.5*size, -0.5*size, 0);
    51   this->model->addVertex (0.5*size, 0.5*size, 0);
    52   this->model->addVertex (-0.5*size, 0.5*size, 0);
    53 
    54   this->model->addVertexTexture(0,0);
    55   this->model->addVertexTexture(1,0);
    56   this->model->addVertexTexture(1,1);
    57   this->model->addVertexTexture(0,1);
    58 
    59   this->model->setMaterial(this->material);
    60   this->model->addFace(4, VERTEX_TEXCOORD, 0,0, 1,1 ,2,2, 3,3);
    61   this->model->finalize();
     70  this->rotationSpeed = 5;
     71  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
     72
     73  this->material = new Material;
    6274
    6375  EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION);
     
    7082
    7183
    72 /**
    73    \brief standard deconstructor
    74 */
    75 Crosshair::~Crosshair ()
    76 {
    77  // delete this->model;
    78 
    79   // delete what has to be deleted here
    80   EventHandler::getInstance()->unsubscribe(this);
    81 
    82   GraphicsEngine::showMouse(true);
    83   GraphicsEngine::stealWMEvents(false);
    84 }
    85 
     84void Crosshair::loadParams(const TiXmlElement* root)
     85{
     86  static_cast<PNode*>(this)->loadParams(root);
     87  static_cast<EventListener*>(this)->loadParams(root);
     88
     89  LoadParam<Crosshair>(root, "texture", this, &Crosshair::setTexture)
     90      .describe("the texture-file to load onto the Crosshair");
     91
     92  LoadParam<Crosshair>(root, "size", this, &Crosshair::setSize)
     93      .describe("the size of the Crosshair in Pixels");
     94
     95  LoadParam<Crosshair>(root, "rotation-speed", this, &Crosshair::setRotationSpeed)
     96      .describe("the Speed with which the Crosshair should rotate");
     97}
     98
     99
     100/**
     101 * sets the size of the Crosshair.
     102 * @param size the size in pixels
     103 */
     104void Crosshair::setSize(float size)
     105{
     106  this->size = size*.5;
     107};
     108
     109/**
     110 * sets the material to load
     111 * @param textureFile The texture-file to load onto the crosshair
     112 */
     113void Crosshair::setTexture(const char* textureFile)
     114{
     115  this->material->setDiffuseMap(textureFile);
     116}
     117
     118/**
     119 * processes the input
     120 * @param event the Event coming as input
     121 */
    86122void Crosshair::process(const Event &event)
    87123{
     
    113149}
    114150
    115 
     151/**
     152 * ticks the Crosshair
     153 * @param dt the time to ticks
     154 */
     155void Crosshair::tick(float dt)
     156{
     157  this->rotation += dt * rotationSpeed;
     158
     159
     160
     161}
     162
     163/**
     164 * draws the crosshair
     165 */
    116166void Crosshair::draw()
    117167{
     
    189239             pos, pos+1, pos+2 );
    190240
    191   this->rotation += 1;
    192241
    193242  glTranslatef(position2D[0], position2D[1], 0);
    194243  glRotatef(this->rotation, 0,0,1);
    195   this->model->draw();
     244  this->material->select();
     245  glBegin(GL_TRIANGLE_STRIP);
     246  glTexCoord2f(0, 0);
     247  glVertex2f(-size, -size);
     248  glTexCoord2f(1, 0);
     249  glVertex2f(size, -size);
     250  glTexCoord2f(0, 1);
     251  glVertex2f(-size, size);
     252  glTexCoord2f(1, 1);
     253  glVertex2f(size, size);
     254  glEnd();
    196255  /*
    197256  glBegin(GL_QUADS);
Note: See TracChangeset for help on using the changeset viewer.