Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 28, 2006, 11:43:26 PM (19 years ago)
Author:
nicolasc
Message:

added dummy guiding/homing function for missile

File:
1 edited

Legend:

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

    r9960 r9964  
    2323#include "model.h"
    2424#include "sound/resource_sound_buffer.h"
     25
     26#include <cmath>
    2527
    2628#include "debug.h"
     
    157159}
    158160
     161
     162/**
     163 *  this function gets called by tick to calculate the new flight direction
     164 *  @param curDirection direction vector
     165 *  @param estTargetDir target vector, pointing to where the target will be on hit
     166 *  @param angle = tick * turningSpeed
     167 *  @return normalized (new) direction vector
     168*/
     169Vector Projectile::newDirection(Vector curDirection, Vector estTargetDir, float angle)
     170{
     171  float tmp = angleDeg ( curDirection, estTargetDir);
     172  if (tmp == 0) { return curDirection; }
     173
     174  if( angle >  tmp ) { angle = tmp; }
     175
     176  //Vector n = curDirection.cross(estTargetDir);
     177  //Vector d = n.cross(curDirection);
     178  Vector d = curDirection.cross(estTargetDir).cross(curDirection);
     179  d.normalize();
     180  if( angle == 90) { return d; }
     181
     182  Vector newDir = curDirection + d *  curDirection.len() * tan (angle);
     183  newDir.normalize();
     184  return newDir;
     185}
     186
     187
    159188/**
    160189 * signal tick, time dependent things will be handled here
     
    163192void Projectile::tick (float dt)
    164193{
     194  Vector estTargetDir = this->targetPosition + this->targetVelocity * this->eta;
     195  //Vector estTargetDir = (this->target.getRelCoor() + this->target.getVelocity()) / this->velocity.len() ;
     196  this->velocity = this->newDirection(this->velocity, estTargetDir, this->turningSpeed * dt ) * this->velocity.len();
    165197  Vector v = this->velocity * (dt);
    166198  this->shiftCoor(v);
     
    179211    this->soundSource.play(this->explosionBuffer);
    180212}
     213
Note: See TracChangeset for help on using the changeset viewer.