Changeset 4832 in orxonox.OLD for orxonox/trunk/src/world_entities/weapons/crosshair.cc
- Timestamp:
- Jul 11, 2005, 5:45:27 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/world_entities/weapons/crosshair.cc
r4831 r4832 19 19 #include "event_handler.h" 20 20 21 #include "load_param.h" 21 22 #include "graphics_engine.h" 22 23 #include "glincl.h" 23 #include "p_node.h"24 24 #include "state.h" 25 #include "m odel.h"25 #include "material.h" 26 26 27 27 #include <iostream> … … 31 31 32 32 /** 33 \brief standard constructor 33 * standart constructor 34 */ 35 Crosshair::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 34 48 */ 35 Crosshair::Crosshair () 49 Crosshair::~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 */ 64 void Crosshair::init() 36 65 { 37 66 this->setClassID(CL_CROSSHAIR, "Crosshair"); 38 67 this->setName("Crosshair"); 39 68 40 this->material = NULL;41 this->model = NULL;42 69 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; 62 74 63 75 EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION); … … 70 82 71 83 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 84 void 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 */ 104 void 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 */ 113 void 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 */ 86 122 void Crosshair::process(const Event &event) 87 123 { … … 113 149 } 114 150 115 151 /** 152 * ticks the Crosshair 153 * @param dt the time to ticks 154 */ 155 void Crosshair::tick(float dt) 156 { 157 this->rotation += dt * rotationSpeed; 158 159 160 161 } 162 163 /** 164 * draws the crosshair 165 */ 116 166 void Crosshair::draw() 117 167 { … … 189 239 pos, pos+1, pos+2 ); 190 240 191 this->rotation += 1;192 241 193 242 glTranslatef(position2D[0], position2D[1], 0); 194 243 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(); 196 255 /* 197 256 glBegin(GL_QUADS);
Note: See TracChangeset
for help on using the changeset viewer.