Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10672 was 10317, checked in by patrick, 18 years ago

merged branche data-fix back to trunk. this breaks compatibility with the old data/trunk data repository! be sure to update your data trunk

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