Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/crosshair.cc @ 10760

Last change on this file since 10760 was 10759, checked in by bknecht, 18 years ago

hud updated

File size: 4.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "crosshair.h"
19
20#include "util/loading/load_param.h"
21#include "graphics_engine.h"
22#include "glincl.h"
23#include "state.h"
24#include "material.h"
25
26#include "tools/camera.h"
27
28
29
30ObjectListDefinition(Crosshair);
31/**
32 * standart constructor
33 */
34Crosshair::Crosshair (const TiXmlElement* root)
35{
36
37  this->init();
38
39  if (root)
40    this->loadParams(root);
41  else
42    this->setTexture("textures/aim.png");
43}
44
45/**
46 * destroys a Crosshair
47*/
48Crosshair::~Crosshair ()
49{
50  if (this->material)
51  delete this->material;
52}
53
54/**
55 * initializes the Crosshair
56 */
57void Crosshair::init()
58{
59  this->registerObject(this, Crosshair::_objectList);
60  this->setName("Crosshair");
61
62  this->setLayer(E2D_LAYER_TOP);
63  this->setRotationSpeed(5);
64  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
65
66  this->setBindNode(this);
67  this->material = new Material;
68
69//   this->subscribeEvent(ES_GAME, EV_MOUSE_MOTION);
70
71  // center the mouse on the screen, and also hide the cursors
72/*  SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);*/
73//   GraphicsEngine::showMouse(false);
74//   SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
75}
76
77
78void Crosshair::loadParams(const TiXmlElement* root)
79{
80  PNode::loadParams(root);
81  EventListener::loadParams(root);
82
83  LoadParam(root, "texture", this->material, Material, setDiffuseMap)
84      .describe("the texture-file to load onto the Crosshair");
85
86  LoadParam(root, "size", this, Crosshair, setSize)
87      .describe("the size of the Crosshair in Pixels");
88
89  LoadParam(root, "rotation-speed", this, Crosshair, setRotationSpeed)
90      .describe("the Speed with which the Crosshair should rotate");
91}
92
93
94/**
95 * sets the size of the Crosshair.
96 * @param size the size in pixels
97 */
98void Crosshair::setSize(float size)
99{
100  this->setSize2D(size/2, size/2);
101}
102
103/**
104 * sets the material to load
105 * @param textureFile The texture-file to load onto the crosshair
106 */
107void Crosshair::setTexture(const std::string& textureFile)
108{
109  this->material->setDiffuseMap(textureFile);
110}
111
112/**
113 * processes the input
114 * @param event the Event coming as input
115 */
116void Crosshair::process(const Event &event)
117{
118  if  (event.type == EV_MOUSE_MOTION)
119  {
120    printf("Processing Crosshair Mouse Event\n");
121    this->setAbsCoor2D(event.x, event.y);
122  }
123}
124
125/**
126 * ticks the Crosshair
127 * @param dt the time to ticks
128 */
129void Crosshair::tick(float dt)
130{
131  // let the crosshair rotate
132  this->shiftDir2D(dt * rotationSpeed);
133
134/*
135  float z = 0.0f;
136  glReadPixels ((int)this->getAbsCoor2D().x,
137                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
138                 1,
139                 1,
140                 GL_DEPTH_COMPONENT,
141                 GL_FLOAT,
142                 &z);
143
144
145  GLdouble objX=.0, objY=.0, objZ=.0;
146  gluUnProject(this->getAbsCoor2D().x,
147               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
148               .99,  // z
149               GraphicsEngine::modMat,
150               GraphicsEngine::projMat,
151               GraphicsEngine::viewPort,
152               &objX,
153               &objY,
154               &objZ );*/
155
156  //this->setAbsCoor(objX, objY, objZ);
157}
158
159/**
160 * draws the crosshair
161 */
162void Crosshair::draw() const
163{
164  glPushMatrix();
165  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
166
167  glRotatef(this->getAbsDir2D(), 0,0,1);
168  this->material->select();
169  glBegin(GL_TRIANGLE_STRIP);
170  glTexCoord2f(0, 0);
171  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
172  glTexCoord2f(1, 0);
173  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
174  glTexCoord2f(0, 1);
175  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
176  glTexCoord2f(1, 1);
177  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
178  glEnd();
179  glPopMatrix();
180}
Note: See TracBrowser for help on using the repository browser.