Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 9, 2006, 7:00:44 PM (17 years ago)
Author:
nicolasc
Message:

updated swarm_projectile, model included in data
TE2 tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/playability/src/world_entities/projectiles/swarm_projectile.cc

    r10004 r10035  
    3737{
    3838
    39   this->loadModel("models/projectiles/orx-rocket.obj", 0.5);
     39/*  this->loadModel("models/projectiles/orx-rocket.obj", 0.5);*/
     40  this->loadModel("models/projectiles/swarm_projectile.obj");
    4041  this->loadExplosionSound("sound/explosions/explosion_4.wav");
    4142
     
    4546  this->lifeSpan = 2.0;
    4647  this->agility = 3.5;
    47   this->maxVelocity = 150;
     48  this->maxVelocity = 100;
    4849
    4950  this->emitter = new DotEmitter(100, 5, M_2_PI);
     
    141142}
    142143
     144
     145
     146/**
     147 *  this function gets called by tick to calculate the new flight direction
     148 *  @param curDirection direction vector
     149 *  @param estTargetDir target vector, pointing to where the target will be on hit
     150 *  @param angle = tick * turningSpeed
     151 *  @return (new) direction vector
     152*/
     153Vector SwarmProjectile::newDirection(Vector curDirection, Vector estTargetDir, float angle)
     154{
     155  printf("recalculating direction\n");
     156  float tmp = angleDeg ( curDirection, estTargetDir);
     157  if ( unlikely(tmp == 0) ) { return curDirection * maxVelocity / curDirection.len(); }
     158
     159  if( fabsf(angle) >  fabsf(tmp) ) { angle = tmp; }
     160
     161  Vector d = curDirection.cross(estTargetDir).cross(curDirection);
     162  d.normalize();
     163  if( unlikely( angle == 90)) { return d; } //avoid complication
     164
     165  Vector newDir = curDirection + d *  curDirection.len() * tan (angle);
     166  newDir.normalize();
     167  newDir *= curDirection.len();
     168  return newDir;
     169}
     170
     171
     172
     173
    143174/**
    144175 *  signal tick, time dependent things will be handled here
     
    147178void SwarmProjectile::tick (float time)
    148179{
    149 
     180/*
    150181  Vector targetFarFarAway = this->getAbsCoor() + Vector(100000, 0, 0);
    151182
     
    173204  velocity *= maxVelocity/velocity.len();
    174205  Vector v = this->velocity * (time);
    175   this->shiftCoor(v);
     206  this->shiftCoor(v);*/
     207
     208  if (target != NULL){
     209    float tti = this->target->getRelCoor().len() / this->getVelocity().len();
     210    Vector estTargetDir = (this->target->getRelCoor() + this->target->getVelocity()) * tti;
     211    this->velocity = this->newDirection(this->velocity, estTargetDir, this->turningSpeed * time );
     212  }
     213  else
     214    velocity *= maxVelocity / velocity.len(); // set speed to max
     215
     216  this->shiftCoor(velocity * time);
    176217
    177218  if(this->tickLifeCycle(time))
     
    208249  this->getAbsDir().matrix (matrix);
    209250  glMultMatrixf((float*)matrix);
    210   glScalef(2.0, 2.0, 2.0);
     251  //glScalef(2.0, 2.0, 2.0);
    211252  this->getModel()->draw();
    212253
Note: See TracChangeset for help on using the changeset viewer.