Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7207 was 7193, checked in by bensch, 19 years ago

orxonox/trunk: new style for resources (prework/movement)

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