Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9607 was 9406, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 5.6 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
[7193]20#include "util/loading/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
[1853]29
[1856]30
[9406]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
[6724]75  this->range = 10000;
76  this->angle = M_PI_4;
77  this->group = OM_GROUP_01;
[5750]78  this->anim = new tAnimation<Aim>(this, &Aim::setSize);
79  this->anim->setInfinity(ANIM_INF_CONSTANT);
80  this->anim->addKeyFrame(500, .3, ANIM_LINEAR);
81  this->anim->addKeyFrame(100, .2, ANIM_LINEAR);
82  this->anim->addKeyFrame(50, .01, ANIM_LINEAR);
83
[6760]84
[6305]85/*  this->text = new Text();
[5779]86  this->text->setLayer(this->getLayer());
[5750]87  this->text->setParent2D(this);
88  this->text->setRelCoor2D(10, -50);
89  this->text->setParentMode2D(E2D_PARENT_MOVEMENT);
[6305]90  this->text->setText("Testing");*/
[3365]91}
[1853]92
[5556]93void Aim::loadParams(const TiXmlElement* root)
[3543]94{
[6512]95  PNode::loadParams(root);
[4830]96
[5671]97  LoadParam(root, "texture", this, Aim, setTexture)
[5556]98      .describe("the texture-file to load onto the Aim");
[4831]99
[5671]100  LoadParam(root, "size", this, Aim, setSize)
[5556]101      .describe("the size of the Aim in Pixels");
[4832]102
[5671]103  LoadParam(root, "rotation-speed", this, Aim, setRotationSpeed)
[5556]104      .describe("the Speed with which the Aim should rotate");
[3543]105}
[4779]106
[6637]107void Aim::searchTarget()
[5750]108{
[7370]109  ObjectManager::EntityList::iterator entity;
[6222]110
[6724]111  for (entity = State::getObjectManager()->getObjectList(group).begin();
112       entity != State::getObjectManager()->getObjectList(group).end();
[6222]113       entity ++)
[5750]114  {
[6637]115    diffVec = ( (*entity)->getAbsCoor() - this->source->getAbsCoor() );
116
[6760]117    if ( diffVec.len() < range &&  acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) )  < angle)
[5750]118    {
[6724]119      //if (this->getParent() != (*entity))
[5750]120      {
121        this->anim->replay();
[6222]122        this->setParentSoft(*entity, 5);
123        return;
[5750]124      }
125    }
126  }
[6724]127
128   //if no target found:
129   this->setParent(PNode::getNullParent());
130
131
132
[5750]133}
134
135
[4832]136/**
[6305]137 * @brief sets the size of the Aim.
[4832]138 * @param size the size in pixels
139 */
[5556]140void Aim::setSize(float size)
[4832]141{
[5378]142  this->setSize2D(size/2, size/2);
143}
[4832]144
145/**
146 * sets the material to load
147 * @param textureFile The texture-file to load onto the crosshair
148 */
[7221]149void Aim::setTexture(const std::string& textureFile)
[4832]150{
151  this->material->setDiffuseMap(textureFile);
152}
153
154/**
[5556]155 * ticks the Aim
[4832]156 * @param dt the time to ticks
157 */
[5556]158void Aim::tick(float dt)
[4832]159{
[4834]160  // let the crosshair rotate
[5378]161  this->shiftDir2D(dt * rotationSpeed);
[4781]162
[6305]163//   char outputText[100];
164//   sprintf(outputText, "%s - distance: %f\n", this->getParent()->getName(), (this->source->getAbsCoor() - this->getAbsCoor()).len());
165//   this->text->setText(outputText);
[4832]166
167
[6637]168//  if (this->source->getAbsCoor().x > this->getAbsCoor().x )
[6724]169  diffVec = ( this->getAbsCoor() - this->source->getAbsCoor() );
170//only look for target if the aim hasn`t locked a target yet or if the actual target is out of range
[6760]171   if(this->getParent() == PNode::getNullParent() ||
172      diffVec.len() > range  ||
173     ( acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) > angle))
[6724]174    {
[6760]175     this->setParentSoft(PNode::getNullParent(),5);
[6637]176     this->searchTarget();
[6724]177    }
178
[5750]179//   float z = 0.0f;
180//   glReadPixels ((int)this->getAbsCoor2D().x,
181//                  GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
182//                  1,
183//                  1,
184//                  GL_DEPTH_COMPONENT,
185//                  GL_FLOAT,
186//                  &z);
187//
188//
189//   GLdouble objX=.0, objY=.0, objZ=.0;
190//   gluUnProject(this->getAbsCoor2D().x,
191//                GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
192//                .99,  // z
193//                GraphicsEngine::modMat,
194//                GraphicsEngine::projMat,
195//                GraphicsEngine::viewPort,
196//                &objX,
197//                &objY,
198//                &objZ );
[6760]199//aa
[5750]200//   this->setAbsCoor(objX, objY, objZ);
[4834]201}
202
203/**
204 * draws the crosshair
205 */
[5556]206void Aim::draw() const
[4834]207{
[5750]208
[6724]209 if( this->getParent() != PNode::getNullParent() )
210  {
[4955]211  glPushMatrix();
[5378]212  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
[4830]213
[5378]214  glRotatef(this->getAbsDir2D(), 0,0,1);
[4832]215  this->material->select();
216  glBegin(GL_TRIANGLE_STRIP);
217  glTexCoord2f(0, 0);
[5378]218  glVertex2f(-this->getSizeX2D(), -this->getSizeY2D());
[4832]219  glTexCoord2f(1, 0);
[5378]220  glVertex2f(this->getSizeX2D(), -this->getSizeY2D());
[4832]221  glTexCoord2f(0, 1);
[5378]222  glVertex2f(-this->getSizeX2D(), this->getSizeY2D());
[4832]223  glTexCoord2f(1, 1);
[5378]224  glVertex2f(this->getSizeX2D(), this->getSizeY2D());
[4832]225  glEnd();
[4955]226  glPopMatrix();
[6724]227  }
[4830]228
[4781]229}
Note: See TracBrowser for help on using the repository browser.