Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5750 in orxonox.OLD for trunk/src/world_entities/weapons/aim.cc


Ignore:
Timestamp:
Nov 24, 2005, 12:13:22 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the WorldEntities into the Trunk.
Merged with command:
svn merge branches/world_entities/ trunk/ -r5516:HEAD

conflics from world_entities changed in favor of branches/world_entity
all other conflict in favor of the trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/world_entities/weapons/aim.cc

    r5671 r5750  
    2020#include "load_param.h"
    2121#include "graphics_engine.h"
    22 #include "glincl.h"
    2322#include "state.h"
     23#include "list.h"
    2424#include "material.h"
     25#include "t_animation.h"
     26#include "text.h"
     27
     28#include "world_entity.h"
    2529
    2630using namespace std;
     
    3034 * standart constructor
    3135 */
    32 Aim::Aim (const TiXmlElement* root)
     36Aim::Aim (PNode* source, const TiXmlElement* root)
    3337{
    3438  this->init();
     39
     40  this->source = source;
    3541
    3642  if (root)
     
    4753  if (this->material)
    4854    delete this->material;
     55
     56  if (this->text != NULL)
     57    delete this->text;
    4958}
    5059
     
    5867
    5968  this->setLayer(E2D_LAYER_TOP);
    60   this->setRotationSpeed(5);
     69  this->setRotationSpeed(30.0* (float)rand()/RAND_MAX + 10.0);
    6170  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
    6271
    63 //  this->setBindNode(this);
     72  this->setBindNode(this);
    6473  this->material = new Material;
    65 }
    66 
     74  this->source = NULL;
     75
     76  this->anim = new tAnimation<Aim>(this, &Aim::setSize);
     77  this->anim->setInfinity(ANIM_INF_CONSTANT);
     78  this->anim->addKeyFrame(500, .3, ANIM_LINEAR);
     79  this->anim->addKeyFrame(100, .2, ANIM_LINEAR);
     80  this->anim->addKeyFrame(50, .01, ANIM_LINEAR);
     81
     82  this->text = new Text();
     83  this->text->setParent2D(this);
     84  this->text->setRelCoor2D(10, -50);
     85  this->text->setParentMode2D(E2D_PARENT_MOVEMENT);
     86  this->text->setText("Testing");
     87}
    6788
    6889void Aim::loadParams(const TiXmlElement* root)
     
    80101}
    81102
     103void Aim::searchTarget(float range)
     104{
     105  tIterator<WorldEntity>* iterator = State::getWorldEntityList()->getIterator();
     106  WorldEntity* entity = iterator->firstElement();
     107  while (likely(entity != NULL))
     108  {
     109    if (entity->isA(CL_NPC) && this->source->getAbsCoor().x < entity->getAbsCoor().x && (this->source->getAbsCoor() - entity->getAbsCoor()).len() < range)
     110    {
     111      if (this->getParent() != entity)
     112      {
     113        this->anim->replay();
     114        this->setParentSoft(entity, 5);
     115      }
     116      delete iterator;
     117      return;
     118    }
     119    entity = iterator->nextElement();
     120  }
     121
     122  delete iterator;
     123}
     124
     125
    82126
    83127/**
     
    108152  this->shiftDir2D(dt * rotationSpeed);
    109153
    110 
    111   float z = 0.0f;
    112   glReadPixels ((int)this->getAbsCoor2D().x,
    113                  GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
    114                  1,
    115                  1,
    116                  GL_DEPTH_COMPONENT,
    117                  GL_FLOAT,
    118                  &z);
    119 
    120 
    121   GLdouble objX=.0, objY=.0, objZ=.0;
    122   gluUnProject(this->getAbsCoor2D().x,
    123                GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
    124                .99,  // z
    125                GraphicsEngine::modMat,
    126                GraphicsEngine::projMat,
    127                GraphicsEngine::viewPort,
    128                &objX,
    129                &objY,
    130                &objZ );
    131 
    132   this->setAbsCoor(objX, objY, objZ);
     154  char outputText[100];
     155  sprintf(outputText, "%s - distance: %f\n", this->getParent()->getName(), (this->source->getAbsCoor() - this->getAbsCoor()).len());
     156  this->text->setText(outputText);
     157
     158
     159  if (this->source->getAbsCoor().x > this->getAbsCoor().x )
     160    this->searchTarget(1000);
     161//   float z = 0.0f;
     162//   glReadPixels ((int)this->getAbsCoor2D().x,
     163//                  GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
     164//                  1,
     165//                  1,
     166//                  GL_DEPTH_COMPONENT,
     167//                  GL_FLOAT,
     168//                  &z);
     169//
     170//
     171//   GLdouble objX=.0, objY=.0, objZ=.0;
     172//   gluUnProject(this->getAbsCoor2D().x,
     173//                GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
     174//                .99,  // z
     175//                GraphicsEngine::modMat,
     176//                GraphicsEngine::projMat,
     177//                GraphicsEngine::viewPort,
     178//                &objX,
     179//                &objY,
     180//                &objZ );
     181//
     182//   this->setAbsCoor(objX, objY, objZ);
    133183}
    134184
     
    138188void Aim::draw() const
    139189{
     190
    140191  glPushMatrix();
    141192  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
Note: See TracChangeset for help on using the changeset viewer.