/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Benjamin Grauer co-programmer: ... */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON #include "aim.h" #include "load_param.h" #include "graphics_engine.h" #include "glincl.h" #include "state.h" #include "material.h" using namespace std; /** * standart constructor */ Aim::Aim (const TiXmlElement* root) { this->init(); if (root) this->loadParams(root); else this->setTexture("maps/aim.png"); } /** * destroys a Aim */ Aim::~Aim () { if (this->material) delete this->material; } /** * initializes the Aim */ void Aim::init() { this->setClassID(CL_CROSSHAIR, "Aim"); this->setName("Aim"); this->setLayer(E2D_LAYER_TOP); this->setRotationSpeed(5); this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0); // this->setBindNode(this); this->material = new Material; } void Aim::loadParams(const TiXmlElement* root) { static_cast(this)->loadParams(root); LoadParamNEW(root, "texture", this, Aim, setTexture) .describe("the texture-file to load onto the Aim"); LoadParamNEW(root, "size", this, Aim, setSize) .describe("the size of the Aim in Pixels"); LoadParamNEW(root, "rotation-speed", this, Aim, setRotationSpeed) .describe("the Speed with which the Aim should rotate"); } /** * sets the size of the Aim. * @param size the size in pixels */ void Aim::setSize(float size) { this->setSize2D(size/2, size/2); } /** * sets the material to load * @param textureFile The texture-file to load onto the crosshair */ void Aim::setTexture(const char* textureFile) { this->material->setDiffuseMap(textureFile); } /** * ticks the Aim * @param dt the time to ticks */ void Aim::tick(float dt) { // let the crosshair rotate this->shiftDir2D(dt * rotationSpeed); float z = 0.0f; glReadPixels ((int)this->getAbsCoor2D().x, GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z); GLdouble objX=.0, objY=.0, objZ=.0; gluUnProject(this->getAbsCoor2D().x, GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1, .99, // z GraphicsEngine::modMat, GraphicsEngine::projMat, GraphicsEngine::viewPort, &objX, &objY, &objZ ); this->setAbsCoor(objX, objY, objZ); } /** * draws the crosshair */ void Aim::draw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); glRotatef(this->getAbsDir2D(), 0,0,1); this->material->select(); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0, 0); glVertex2f(-this->getSizeX2D(), -this->getSizeY2D()); glTexCoord2f(1, 0); glVertex2f(this->getSizeX2D(), -this->getSizeY2D()); glTexCoord2f(0, 1); glVertex2f(-this->getSizeX2D(), this->getSizeY2D()); glTexCoord2f(1, 1); glVertex2f(this->getSizeX2D(), this->getSizeY2D()); glEnd(); glPopMatrix(); }