Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 15, 2006, 11:48:40 PM (18 years ago)
Author:
nicolasc
Message:

Working SwarmMissile guidance system
CD/CR needs update

Location:
branches/playability/src/world_entities/projectiles
Files:
2 edited

Legend:

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

    r10079 r10080  
    4949  this->lifeSpan = 4.0;
    5050  this->agility = 3.5;
    51   this->maxVelocity = 100;
    5251
    5352  this->emitter = new DotEmitter(100, 5, M_2_PI);
     
    5554  this->emitter->setSpread(M_PI, M_PI);
    5655
    57   this->target = NULL;
     56  this->turningSpeed = 30;
     57
     58  this->physDamage = 200;
    5859}
    5960
     
    151152    this->destroy( entity );
    152153  this->hitEntity = entity;
    153   dynamic_cast<SpaceShip*>(entity)->damage(this->getDamage(),0);
     154  dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),0);
     155}
     156
     157
     158void SwarmProjectile::setTarget(PNode* target)
     159{
     160    this->target = target;
    154161}
    155162
     
    167174  if (unlikely(curDirection.len() == 0))
    168175    return curDirection;
    169   printf("recalculating direction\n");
    170   float tmp = angleDeg ( curDirection, estTargetDir);
     176  //printf("recalculating direction\n");
     177  float tmp = angleRad ( curDirection, estTargetDir);
    171178  if ( unlikely(tmp == 0) ) { return curDirection * maxVelocity / curDirection.len(); }
     179//   printf("turning angle: %f\ntemp: %f\n", angle, tmp);
    172180
    173181  if( fabsf(angle) >  fabsf(tmp) ) { angle = tmp; }
     
    220228  this->shiftCoor(v);*/
    221229
    222 //   float projectileVelocity = this->getVelocity().len();
     230  float projectileVelocity = this->getVelocity().len();
    223231//   if (target != NULL){
    224 //     float tti;  //Time To Impact
    225 // //     float targetVelocity = this->target->getVelocity().len();
    226 // // /*    if (unlikely(projectileVelocity == 0 && targetVelocity == 0)) // TODO calculate this reasonably*/
    227 //       tti = 1; // we do have a problem....
    228 // // //     else
    229 // // //       tti = (this->getAbsCoor() - this->target->getAbsCoor()).len() / sqrt ( projectileVelocity * projectileVelocity + targetVelocity * targetVelocity);
    230 //     Vector estTargetDir =  this->getAbsCoor() - this->target->getAbsCoor() + this->target->getVelocity() * (0.5);
    231 // //     this->setVelocity((this->getAbsCoor() - this->target->getAbsCoor()).getNormalized() * this->velocity.len());
    232 //     this->velocity = this->newDirection(this->velocity, estTargetDir, this->turningSpeed * time ) * this->maxVelocity;
     232    float tti;  //Time To Impact
     233    float targetVelocity = this->target->getVelocity().len();
     234    if (unlikely(projectileVelocity == 0 && targetVelocity == 0)) // TODO calculate this reasonably
     235      tti = 1; // we do have a problem....
     236    else
     237      tti = (this->getAbsCoor() - this->target->getAbsCoor()).len() / sqrt ( projectileVelocity * projectileVelocity + targetVelocity * targetVelocity);
     238    Vector estTargetDir = (this->target->getAbsCoor() - this->getAbsCoor()).getNormalized() * maxVelocity;
     239//     Vector estTargetDir = (this->target->getAbsCoor() - (Vector(2000, 30, 300) + VECTOR_RAND(20))).getNormalized() * projectileVelocity;
     240    this->velocity = this->newDirection(this->velocity, estTargetDir, this->turningSpeed * time );
    233241//   }
    234242//   else
    235243//     if (likely(projectileVelocity != 0))
    236244//       this->velocity *= (this->maxVelocity / projectileVelocity); // set speed to max
    237 /*
    238   Vector v = this->velocity + this->target->getAbsCoor() - this->getAbsCoor();
    239   v.normalize();
    240   v *= projectileVelocity;*/
    241   this->shiftCoor(velocity * (time));
     245
     246//   printf("position: %f, %f, %f\n", this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
     247//   printf("target position: %f, %f, %f\n", this->target->getAbsCoor().x, this->target->getAbsCoor().y, this->target->getAbsCoor().z);
     248
     249  this->shiftCoor(this->velocity * (time));
    242250
    243251  if(this->tickLifeCycle(time))
     
    287295
    288296}
    289 
  • branches/playability/src/world_entities/projectiles/swarm_projectile.h

    r10079 r10080  
    3232    virtual void draw () const;
    3333
     34    void setTarget(PNode* target);
    3435
    3536  private:
     
    4546    Vector                            correctionVector;
    4647
    47     WorldEntity*                      target;
    48 
    4948    WorldEntity* hitEntity; // FIXME TEMPORARY
    5049
Note: See TracChangeset for help on using the changeset viewer.