Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9964 in orxonox.OLD for branches/playability/src


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

added dummy guiding/homing function for missile

Location:
branches/playability/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/playability/src/lib/coord/p_node.h

    r9869 r9964  
    9898  inline const Vector& getRelCoor () const { return this->prevRelCoordinate; };
    9999  /** @returns the Relative Coordinate Destination */
    100 inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)? *this->toCoordinate : this->relCoordinate; };
     100  inline const Vector& getRelCoorSoft2D() const { return (this->toCoordinate)? *this->toCoordinate : this->relCoordinate; };
    101101  void setAbsCoor (const Vector& absCoord);
    102102  void setAbsCoor (float x, float y, float z);
  • 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
  • branches/playability/src/world_entities/projectiles/projectile.h

    r9960 r9964  
    6464  protected:
    6565    // energy
    66     float                  energyMin;                 //!< The minimal Energy a Projectile needs to be emitted.
    67     bool                   bChargeable;               //!< if the Projectile is Charegeable
     66    float                   energyMin;                //!< The minimal Energy a Projectile needs to be emitted.
     67    bool                    bChargeable;              //!< if the Projectile is Charegeable
    6868
    69     float                  lifeCycle;                 //!< The percentage of the Lifetime done [0-1]
    70     float                  lifeSpan;                  //!< The entire lifespan of the Shoot. in seconds
     69    float                   lifeCycle;                //!< The percentage of the Lifetime done [0-1]
     70    float                   lifeSpan;                 //!< The entire lifespan of the Shoot. in seconds
    7171
    7272    float                   physDamage;               //!< damage to shield and armor
    7373    float                   elecDamage;               //!< damage to elctronic
     74    float                   turningSpeed;             //!< degrees per tick
    7475
    75     Vector                 flightDirection;           //!< DOF direction in which the shoot flighs
     76    Vector                  flightDirection;          //!< DOF direction in which the shoot flighs
    7677
    77     Vector                 velocity;                  //!< velocity of the projectile.
     78    Vector                  velocity;                 //!< velocity of the projectile.
    7879
    79     PNode*                 target;                    //!< A target for guided Weapons.
     80    PNode*                  target;                   //!< A target for guided Weapons.
     81    Vector                  targetPosition;           //!< current target position relative to projectile
     82    Vector                  targetVelocity;           //!< current target speed and direction
     83    float                   eta;                      //!< estimated time of arrival == time to kaboom!
    8084
    8185    OrxSound::SoundSource  soundSource;
     
    8387    OrxSound::SoundBuffer  explosionBuffer;
    8488    OrxSound::SoundBuffer  engineBuffer;
     89
     90    virtual Vector newDirection(Vector curDirection, Vector estTargetDir, float angle);
    8591};
    8692
Note: See TracChangeset for help on using the changeset viewer.