Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: removed unused Text

File size: 4.9 KB
Line 
1/*
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.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "aim.h"
19
20#include "load_param.h"
21#include "graphics_engine.h"
22#include "state.h"
23#include "material.h"
24#include "t_animation.h"
25#include "text.h"
26
27#include "world_entity.h"
28
29using namespace std;
30
31
32/**
33 * standart constructor
34 */
35Aim::Aim (PNode* source, const TiXmlElement* root)
36{
37  this->init();
38
39  this->source = source;
40
41  if (root)
42    this->loadParams(root);
43  else
44    this->setTexture("maps/aim.png");
45}
46
47/**
48 * destroys a Aim
49*/
50Aim::~Aim ()
51{
52  if (this->material)
53    delete this->material;
54
55/*  if (this->text != NULL)
56    delete this->text;*/
57}
58
59/**
60 * initializes the Aim
61 */
62void Aim::init()
63{
64  this->setClassID(CL_CROSSHAIR, "Aim");
65  this->setName("Aim");
66
67  this->setLayer(E2D_LAYER_TOP);
68  this->setRotationSpeed(30.0* (float)rand()/RAND_MAX + 10.0);
69  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
70
71  this->setBindNode(this);
72  this->material = new Material;
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
81/*  this->text = new Text();
82  this->text->setLayer(this->getLayer());
83  this->text->setParent2D(this);
84  this->text->setRelCoor2D(10, -50);
85  this->text->setParentMode2D(E2D_PARENT_MOVEMENT);
86  this->text->setText("Testing");*/
87}
88
89void Aim::loadParams(const TiXmlElement* root)
90{
91  static_cast<PNode*>(this)->loadParams(root);
92
93  LoadParam(root, "texture", this, Aim, setTexture)
94      .describe("the texture-file to load onto the Aim");
95
96  LoadParam(root, "size", this, Aim, setSize)
97      .describe("the size of the Aim in Pixels");
98
99  LoadParam(root, "rotation-speed", this, Aim, setRotationSpeed)
100      .describe("the Speed with which the Aim should rotate");
101}
102
103void Aim::searchTarget(float range)
104{
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 ++)
110  {
111    if (this->source->getAbsCoor().x < (*entity)->getAbsCoor().x && (this->source->getAbsCoor() - (*entity)->getAbsCoor()).len() < range)
112    {
113      if (this->getParent() != (*entity))
114      {
115        this->anim->replay();
116        this->setParentSoft(*entity, 5);
117        return;
118      }
119    }
120  }
121}
122
123
124
125/**
126 * @brief sets the size of the Aim.
127 * @param size the size in pixels
128 */
129void Aim::setSize(float size)
130{
131  this->setSize2D(size/2, size/2);
132}
133
134/**
135 * sets the material to load
136 * @param textureFile The texture-file to load onto the crosshair
137 */
138void Aim::setTexture(const char* textureFile)
139{
140  this->material->setDiffuseMap(textureFile);
141}
142
143/**
144 * ticks the Aim
145 * @param dt the time to ticks
146 */
147void Aim::tick(float dt)
148{
149  // let the crosshair rotate
150  this->shiftDir2D(dt * rotationSpeed);
151
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);
155
156
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);
181}
182
183/**
184 * draws the crosshair
185 */
186void Aim::draw() const
187{
188
189  glPushMatrix();
190  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
191
192  glRotatef(this->getAbsDir2D(), 0,0,1);
193  this->material->select();
194  glBegin(GL_TRIANGLE_STRIP);
195  glTexCoord2f(0, 0);
196  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
197  glTexCoord2f(1, 0);
198  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
199  glTexCoord2f(0, 1);
200  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
201  glTexCoord2f(1, 1);
202  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
203  glEnd();
204  glPopMatrix();
205
206}
Note: See TracBrowser for help on using the repository browser.