Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/crosshair.cc @ 6220

Last change on this file since 6220 was 6162, checked in by bensch, 19 years ago

orxonox/trunk: merged the spaceshipcontroll branche into the trunk
merged with command
svn merge -r6036:HEAD spaceshipcontrol/ ../trunk/
no conflicts

File size: 4.3 KB
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[4779]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[5357]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[1853]17
[4779]18#include "crosshair.h"
[4780]19#include "event_handler.h"
[4781]20
[4832]21#include "load_param.h"
[4781]22#include "graphics_engine.h"
23#include "glincl.h"
24#include "state.h"
[4832]25#include "material.h"
[4781]26
[1856]27using namespace std;
[1853]28
[1856]29
[3245]30/**
[4832]31 * standart constructor
32 */
33Crosshair::Crosshair (const TiXmlElement* root)
34{
35  this->init();
36
37  if (root)
38    this->loadParams(root);
39  else
40    this->setTexture("maps/aim.png");
41}
42
43/**
44 * destroys a Crosshair
[3245]45*/
[4832]46Crosshair::~Crosshair ()
[3365]47{
[4832]48  if (this->material)
49  delete this->material;
50
51  // delete what has to be deleted here
52
53  GraphicsEngine::showMouse(true);
54  GraphicsEngine::stealWMEvents(false);
55}
56
57/**
58 * initializes the Crosshair
59 */
60void Crosshair::init()
61{
[4779]62  this->setClassID(CL_CROSSHAIR, "Crosshair");
63  this->setName("Crosshair");
[4320]64
[5398]65  this->setLayer(E2D_LAYER_TOP);
[4834]66  this->setRotationSpeed(5);
[4832]67  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
[4830]68
[6162]69  this->setBindNode(this);
[4832]70  this->material = new Material;
[4830]71
[5978]72  //EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION);
[4780]73
[4831]74  // center the mouse on the screen, and also hide the cursors
75  SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
76  GraphicsEngine::showMouse(false);
77  GraphicsEngine::stealWMEvents(true);
[5750]78  SDL_WarpMouse(GraphicsEngine::getInstance()->getResolutionX()/2, GraphicsEngine::getInstance()->getResolutionY()/2);
[3365]79}
[1853]80
81
[4832]82void Crosshair::loadParams(const TiXmlElement* root)
[3543]83{
[4832]84  static_cast<PNode*>(this)->loadParams(root);
85  static_cast<EventListener*>(this)->loadParams(root);
[4830]86
[5671]87  LoadParam(root, "texture", this, Crosshair, setTexture)
[4832]88      .describe("the texture-file to load onto the Crosshair");
[4831]89
[5671]90  LoadParam(root, "size", this, Crosshair, setSize)
[4832]91      .describe("the size of the Crosshair in Pixels");
92
[5671]93  LoadParam(root, "rotation-speed", this, Crosshair, setRotationSpeed)
[4832]94      .describe("the Speed with which the Crosshair should rotate");
[3543]95}
[4779]96
[4832]97
98/**
99 * sets the size of the Crosshair.
100 * @param size the size in pixels
101 */
102void Crosshair::setSize(float size)
103{
[5378]104  this->setSize2D(size/2, size/2);
105}
[4832]106
107/**
108 * sets the material to load
109 * @param textureFile The texture-file to load onto the crosshair
110 */
111void Crosshair::setTexture(const char* textureFile)
112{
113  this->material->setDiffuseMap(textureFile);
114}
115
116/**
117 * processes the input
118 * @param event the Event coming as input
119 */
[4779]120void Crosshair::process(const Event &event)
121{
[4781]122  if  (event.type == EV_MOUSE_MOTION)
123  {
[5978]124    //this->setAbsCoor2D(event.x, event.y);
[4781]125  }
[4779]126}
[4781]127
[4832]128/**
129 * ticks the Crosshair
130 * @param dt the time to ticks
131 */
132void Crosshair::tick(float dt)
133{
[4834]134  // let the crosshair rotate
[5378]135  this->shiftDir2D(dt * rotationSpeed);
[4781]136
[4832]137
[5219]138  float z = 0.0f;
[5378]139  glReadPixels ((int)this->getAbsCoor2D().x,
140                 GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
141                 1,
142                 1,
143                 GL_DEPTH_COMPONENT,
144                 GL_FLOAT,
145                 &z);
[4832]146
[5378]147
[5212]148  GLdouble objX=.0, objY=.0, objZ=.0;
[5378]149  gluUnProject(this->getAbsCoor2D().x,
150               GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
[4955]151               .99,  // z
[4826]152               GraphicsEngine::modMat,
153               GraphicsEngine::projMat,
154               GraphicsEngine::viewPort,
155               &objX,
156               &objY,
157               &objZ );
158
[5978]159  //this->setAbsCoor(objX, objY, objZ);
[4834]160}
161
162/**
163 * draws the crosshair
164 */
[4849]165void Crosshair::draw() const
[4834]166{
[4955]167  glPushMatrix();
[6162]168  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
[4830]169
[5378]170  glRotatef(this->getAbsDir2D(), 0,0,1);
[4832]171  this->material->select();
172  glBegin(GL_TRIANGLE_STRIP);
173  glTexCoord2f(0, 0);
[5378]174  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
[4832]175  glTexCoord2f(1, 0);
[5378]176  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
[4832]177  glTexCoord2f(0, 1);
[5378]178  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
[4832]179  glTexCoord2f(1, 1);
[5378]180  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
[4832]181  glEnd();
[4955]182  glPopMatrix();
[4830]183
[4781]184}
Note: See TracBrowser for help on using the repository browser.