Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10753 was 10753, checked in by bknecht, 17 years ago

few changes

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
27
28ObjectListDefinition(Crosshair);
29/**
30 * standart constructor
31 */
32Crosshair::Crosshair (const TiXmlElement* root)
33{
34
35  this->init();
36
37  if (root)
38    this->loadParams(root);
39  else
40    this->setTexture("textures/aim.png");
41}
42
43/**
44 * destroys a Crosshair
45*/
46Crosshair::~Crosshair ()
47{
48  if (this->material)
49  delete this->material;
50}
51
52/**
53 * initializes the Crosshair
54 */
55void Crosshair::init()
56{
57  this->registerObject(this, Crosshair::_objectList);
58  this->setName("Crosshair");
59
60  this->setLayer(E2D_LAYER_TOP);
61  this->setRotationSpeed(5);
62  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
63
64  this->setBindNode(this);
65  this->material = new Material;
66
67//   this->subscribeEvent(ES_GAME, EV_MOUSE_MOTION);
68
69  // center the mouse on the screen, and also hide the cursors
70/*  SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);*/
71//   GraphicsEngine::showMouse(false);
72//   SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
73}
74
75
76void Crosshair::loadParams(const TiXmlElement* root)
77{
78  PNode::loadParams(root);
79  EventListener::loadParams(root);
80
81  LoadParam(root, "texture", this->material, Material, setDiffuseMap)
82      .describe("the texture-file to load onto the Crosshair");
83
84  LoadParam(root, "size", this, Crosshair, setSize)
85      .describe("the size of the Crosshair in Pixels");
86
87  LoadParam(root, "rotation-speed", this, Crosshair, setRotationSpeed)
88      .describe("the Speed with which the Crosshair should rotate");
89}
90
91
92/**
93 * sets the size of the Crosshair.
94 * @param size the size in pixels
95 */
96void Crosshair::setSize(float size)
97{
98  this->setSize2D(size/2, size/2);
99}
100
101/**
102 * sets the material to load
103 * @param textureFile The texture-file to load onto the crosshair
104 */
105void Crosshair::setTexture(const std::string& textureFile)
106{
107  this->material->setDiffuseMap(textureFile);
108}
109
110/**
111 * processes the input
112 * @param event the Event coming as input
113 */
114void Crosshair::process(const Event &event)
115{
116  if  (event.type == EV_MOUSE_MOTION)
117  {
118    printf("Processing Crosshair Mouse Event\n");
119    this->setAbsCoor2D(event.x, event.y);
120  }
121}
122
123/**
124 * ticks the Crosshair
125 * @param dt the time to ticks
126 */
127void Crosshair::tick(float dt)
128{
129  // let the crosshair rotate
130  this->shiftDir2D(dt * rotationSpeed);
131
132/*
133  float z = 0.0f;
134  glReadPixels ((int)this->getAbsCoor2D().x,
135                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
136                 1,
137                 1,
138                 GL_DEPTH_COMPONENT,
139                 GL_FLOAT,
140                 &z);
141
142
143  GLdouble objX=.0, objY=.0, objZ=.0;
144  gluUnProject(this->getAbsCoor2D().x,
145               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
146               .99,  // z
147               GraphicsEngine::modMat,
148               GraphicsEngine::projMat,
149               GraphicsEngine::viewPort,
150               &objX,
151               &objY,
152               &objZ );*/
153
154  //this->setAbsCoor(objX, objY, objZ);
155}
156
157/**
158 * draws the crosshair
159 */
160void Crosshair::draw() const
161{
162  glPushMatrix();
163  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
164
165  glRotatef(this->getAbsDir2D(), 0,0,1);
166  this->material->select();
167  glBegin(GL_TRIANGLE_STRIP);
168  glTexCoord2f(0, 0);
169  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
170  glTexCoord2f(1, 0);
171  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
172  glTexCoord2f(0, 1);
173  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
174  glTexCoord2f(1, 1);
175  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
176  glEnd();
177  glPopMatrix();
178}
Note: See TracBrowser for help on using the repository browser.