Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/aim.cc @ 6508

Last change on this file since 6508 was 6305, checked in by bensch, 19 years ago

trunk: removed unused Text

File size: 4.9 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
[5556]18#include "aim.h"
[4781]19
[4832]20#include "load_param.h"
[4781]21#include "graphics_engine.h"
22#include "state.h"
[4832]23#include "material.h"
[5750]24#include "t_animation.h"
25#include "text.h"
[4781]26
[5750]27#include "world_entity.h"
28
[1856]29using namespace std;
[1853]30
[1856]31
[3245]32/**
[4832]33 * standart constructor
34 */
[5750]35Aim::Aim (PNode* source, const TiXmlElement* root)
[4832]36{
37  this->init();
38
[5750]39  this->source = source;
40
[4832]41  if (root)
42    this->loadParams(root);
43  else
44    this->setTexture("maps/aim.png");
45}
46
47/**
[5556]48 * destroys a Aim
[3245]49*/
[5556]50Aim::~Aim ()
[3365]51{
[4832]52  if (this->material)
[5557]53    delete this->material;
[5750]54
[6305]55/*  if (this->text != NULL)
56    delete this->text;*/
[4832]57}
58
59/**
[5556]60 * initializes the Aim
[4832]61 */
[5556]62void Aim::init()
[4832]63{
[5556]64  this->setClassID(CL_CROSSHAIR, "Aim");
65  this->setName("Aim");
[4320]66
[5398]67  this->setLayer(E2D_LAYER_TOP);
[5750]68  this->setRotationSpeed(30.0* (float)rand()/RAND_MAX + 10.0);
[4832]69  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
[4830]70
[5750]71  this->setBindNode(this);
[4832]72  this->material = new Material;
[5750]73  this->source = NULL;
74
75  this->anim = new tAnimation<Aim>(this, &Aim::setSize);
76  this->anim->setInfinity(ANIM_INF_CONSTANT);
77  this->anim->addKeyFrame(500, .3, ANIM_LINEAR);
78  this->anim->addKeyFrame(100, .2, ANIM_LINEAR);
79  this->anim->addKeyFrame(50, .01, ANIM_LINEAR);
80
[6305]81/*  this->text = new Text();
[5779]82  this->text->setLayer(this->getLayer());
[5750]83  this->text->setParent2D(this);
84  this->text->setRelCoor2D(10, -50);
85  this->text->setParentMode2D(E2D_PARENT_MOVEMENT);
[6305]86  this->text->setText("Testing");*/
[3365]87}
[1853]88
[5556]89void Aim::loadParams(const TiXmlElement* root)
[3543]90{
[4832]91  static_cast<PNode*>(this)->loadParams(root);
[4830]92
[5671]93  LoadParam(root, "texture", this, Aim, setTexture)
[5556]94      .describe("the texture-file to load onto the Aim");
[4831]95
[5671]96  LoadParam(root, "size", this, Aim, setSize)
[5556]97      .describe("the size of the Aim in Pixels");
[4832]98
[5671]99  LoadParam(root, "rotation-speed", this, Aim, setRotationSpeed)
[5556]100      .describe("the Speed with which the Aim should rotate");
[3543]101}
[4779]102
[5750]103void Aim::searchTarget(float range)
104{
[6222]105  std::list<WorldEntity*>::iterator entity;
106
107  for (entity = State::getObjectManager()->getObjectList(OM_GROUP_00).begin();
108       entity != State::getObjectManager()->getObjectList(OM_GROUP_00).end();
109       entity ++)
[5750]110  {
[6222]111    if (this->source->getAbsCoor().x < (*entity)->getAbsCoor().x && (this->source->getAbsCoor() - (*entity)->getAbsCoor()).len() < range)
[5750]112    {
[6222]113      if (this->getParent() != (*entity))
[5750]114      {
115        this->anim->replay();
[6222]116        this->setParentSoft(*entity, 5);
117        return;
[5750]118      }
119    }
120  }
121}
122
123
124
[4832]125/**
[6305]126 * @brief sets the size of the Aim.
[4832]127 * @param size the size in pixels
128 */
[5556]129void Aim::setSize(float size)
[4832]130{
[5378]131  this->setSize2D(size/2, size/2);
132}
[4832]133
134/**
135 * sets the material to load
136 * @param textureFile The texture-file to load onto the crosshair
137 */
[5556]138void Aim::setTexture(const char* textureFile)
[4832]139{
140  this->material->setDiffuseMap(textureFile);
141}
142
143/**
[5556]144 * ticks the Aim
[4832]145 * @param dt the time to ticks
146 */
[5556]147void Aim::tick(float dt)
[4832]148{
[4834]149  // let the crosshair rotate
[5378]150  this->shiftDir2D(dt * rotationSpeed);
[4781]151
[6305]152//   char outputText[100];
153//   sprintf(outputText, "%s - distance: %f\n", this->getParent()->getName(), (this->source->getAbsCoor() - this->getAbsCoor()).len());
154//   this->text->setText(outputText);
[4832]155
156
[5750]157  if (this->source->getAbsCoor().x > this->getAbsCoor().x )
158    this->searchTarget(1000);
159//   float z = 0.0f;
160//   glReadPixels ((int)this->getAbsCoor2D().x,
161//                  GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
162//                  1,
163//                  1,
164//                  GL_DEPTH_COMPONENT,
165//                  GL_FLOAT,
166//                  &z);
167//
168//
169//   GLdouble objX=.0, objY=.0, objZ=.0;
170//   gluUnProject(this->getAbsCoor2D().x,
171//                GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
172//                .99,  // z
173//                GraphicsEngine::modMat,
174//                GraphicsEngine::projMat,
175//                GraphicsEngine::viewPort,
176//                &objX,
177//                &objY,
178//                &objZ );
179//
180//   this->setAbsCoor(objX, objY, objZ);
[4834]181}
182
183/**
184 * draws the crosshair
185 */
[5556]186void Aim::draw() const
[4834]187{
[5750]188
[4955]189  glPushMatrix();
[5378]190  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
[4830]191
[5378]192  glRotatef(this->getAbsDir2D(), 0,0,1);
[4832]193  this->material->select();
194  glBegin(GL_TRIANGLE_STRIP);
195  glTexCoord2f(0, 0);
[5378]196  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
[4832]197  glTexCoord2f(1, 0);
[5378]198  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
[4832]199  glTexCoord2f(0, 1);
[5378]200  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
[4832]201  glTexCoord2f(1, 1);
[5378]202  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
[4832]203  glEnd();
[4955]204  glPopMatrix();
[4830]205
[4781]206}
Note: See TracBrowser for help on using the repository browser.