Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5559 in orxonox.OLD


Ignore:
Timestamp:
Nov 13, 2005, 4:30:07 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: simple-aiming function, with visible targetting-system

Location:
branches/world_entities/src/world_entities
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/world_entities/src/world_entities/player.cc

    r5558 r5559  
    341341void Player::ADDWEAPON()
    342342{
    343   Weapon* turret1;
    344   if ((float)rand()/RAND_MAX < .7)
    345     turret1 = new Turret(this->weaponMan);
     343  Weapon* turret;
     344  if ((float)rand()/RAND_MAX < .1)
     345  {
     346    turret = new Turret(this->weaponMan);
     347    this->weaponMan->addWeapon(turret, 2);
     348    this->weaponMan->changeWeaponConfig(2);
     349  }
    346350  else
    347     turret1 = new AimingTurret(this->weaponMan);
    348 
    349   turret1->setName("Turret");
    350   turret1->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1);
    351 
    352   this->weaponMan->addWeapon(turret1, 2);
    353 
    354   this->weaponMan->changeWeaponConfig(2);
    355 }
     351  {
     352    turret = new AimingTurret(this->weaponMan);
     353    this->weaponMan->addWeapon(turret, 3);
     354
     355    this->weaponMan->changeWeaponConfig(3);
     356  }
     357
     358  turret->setName("Turret");
     359  turret->setStateDuration(WS_SHOOTING, (float)rand()/RAND_MAX*.5+.1);
     360}
  • branches/world_entities/src/world_entities/weapons/aim.cc

    r5558 r5559  
    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
     26#include "world_entity.h"
    2527
    2628using namespace std;
     
    5860
    5961  this->setLayer(E2D_LAYER_TOP);
    60   this->setRotationSpeed(5);
     62  this->setRotationSpeed(30.0* (float)rand()/RAND_MAX + 10.0);
    6163  this->setSize(GraphicsEngine::getInstance()->getResolutionX()/10.0);
    6264
    63 //  this->setBindNode(this);
     65  this->setBindNode(this);
    6466  this->material = new Material;
    6567}
     
    7981      .describe("the Speed with which the Aim should rotate");
    8082}
     83
     84void Aim::searchTarget(PNode* source)
     85{
     86  tIterator<WorldEntity>* iterator = State::getWorldEntityList()->getIterator();
     87  WorldEntity* entity = iterator->firstElement();
     88  while (likely(entity != NULL))
     89  {
     90    if (entity->isA(CL_NPC) && (source->getAbsCoor() - entity->getAbsCoor()).len() < 100)
     91    {
     92      this->setParent(entity);
     93      delete iterator;
     94      return;
     95    }
     96    entity = iterator->nextElement();
     97  }
     98
     99  delete iterator;
     100}
     101
    81102
    82103
     
    109130
    110131
    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);
     132//   float z = 0.0f;
     133//   glReadPixels ((int)this->getAbsCoor2D().x,
     134//                  GraphicsEngine::getInstance()->getResolutionY()-(int)this->getAbsCoor2D().y-1,
     135//                  1,
     136//                  1,
     137//                  GL_DEPTH_COMPONENT,
     138//                  GL_FLOAT,
     139//                  &z);
     140//
     141//
     142//   GLdouble objX=.0, objY=.0, objZ=.0;
     143//   gluUnProject(this->getAbsCoor2D().x,
     144//                GraphicsEngine::getInstance()->getResolutionY()-this->getAbsCoor2D().y-1,
     145//                .99,  // z
     146//                GraphicsEngine::modMat,
     147//                GraphicsEngine::projMat,
     148//                GraphicsEngine::viewPort,
     149//                &objX,
     150//                &objY,
     151//                &objZ );
     152//
     153//   this->setAbsCoor(objX, objY, objZ);
    133154}
    134155
  • branches/world_entities/src/world_entities/weapons/aim.h

    r5558 r5559  
    2828  inline PNode* getTarget(PNode* target) { return this->getParent(); };
    2929
     30  void searchTarget(PNode* source);
    3031
    3132  void setSize(float size);
  • branches/world_entities/src/world_entities/weapons/aiming_turret.cc

    r5527 r5559  
    1818
    1919#include "weapon_manager.h"
     20#include "aim.h"
    2021#include "projectile.h"
    2122
     
    4546  this->init();
    4647
    47   this->loadModel("models/guns/turret1.obj");
     48  this->loadModel("models/guns/turret2.obj");
    4849
    4950
     
    6667{
    6768  // model will be deleted from WorldEntity-destructor
     69  delete this->target;
    6870}
    6971
     
    99101  //this->getProjectileFactory()->prepare(100);
    100102
    101   this->target = NULL;
     103  this->target = new Aim();
    102104}
    103105
     
    119121{
    120122  Quaternion quat;
    121   if (this->target == NULL)
    122     this->target = this->getWeaponManager()->getDistanceTarget(this, 50);
    123123  Vector direction = this->target->getAbsCoor() - this->getAbsCoor();
    124124
     
    130130    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
    131131
    132   this->setAbsDirSoft(quat, 20);
     132  this->setAbsDirSoft(quat, 5);
     133
     134  this->target->tick(dt);
    133135}
    134136
     
    143145  if (target != NULL)
    144146  {
    145     pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*100.0 + VECTOR_RAND(13)
     147    pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
    146148            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
    147149  }
     
    153155  pj->setAbsDir(this->getAbsDir());
    154156  pj->activate();
    155   this->target = this->getWeaponManager()->getDistanceTarget(this, 50);
     157  this->target->searchTarget(this);
    156158}
    157159
  • branches/world_entities/src/world_entities/weapons/aiming_turret.h

    r5527 r5559  
    88
    99#include "weapon.h"
     10
     11/* FORWARD DECLARATION */
     12class Aim;
    1013
    1114class AimingTurret : public Weapon
     
    2932
    3033  private:
    31     PNode*          target;
     34    Aim*          target;
    3235  };
    3336
Note: See TracChangeset for help on using the changeset viewer.