Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6606 in orxonox.OLD for branches/spaceshipcontrol/src


Ignore:
Timestamp:
Jan 18, 2006, 7:32:59 PM (19 years ago)
Author:
snellen
Message:

aim.cc, targeting_turret.cc and aiming turret.cc updated

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

Legend:

Unmodified
Added
Removed
  • branches/spaceshipcontrol/src/world_entities/weapons/aim.cc

    r6305 r6606  
    101101}
    102102
    103 void Aim::searchTarget(float range)
     103void Aim::searchTarget(float range, float angle)
    104104{
    105105  std::list<WorldEntity*>::iterator entity;
    106 
     106  Vector diffVec(0.0, 0.0, 0.0);
     107  diffVec = ( this->getAbsCoor() - this->source->getAbsCoor() );
     108
     109//only look for target if the aim hasn`t locked a target yet or if the actual target is out of range
     110  if( this == PNode::getNullParent() || diffVec.len() > range  || ( acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) > angle && (this->source->getAbsDirX()).dot(diffVec) > 0))
    107111  for (entity = State::getObjectManager()->getObjectList(OM_GROUP_00).begin();
    108112       entity != State::getObjectManager()->getObjectList(OM_GROUP_00).end();
    109113       entity ++)
    110114  {
    111     if (this->source->getAbsCoor().x < (*entity)->getAbsCoor().x && (this->source->getAbsCoor() - (*entity)->getAbsCoor()).len() < range)
     115    diffVec = ( (*entity)->getAbsCoor() - this->source->getAbsCoor() );
     116
     117    if ( diffVec.len() < range  &&  acos( (this->source->getAbsDirX()).dot(diffVec)/(diffVec.len() * (this->source->getAbsDirX()).len() ) ) < angle && (this->source->getAbsDirX()).dot(diffVec) > 0)
    112118    {
    113119      if (this->getParent() != (*entity))
     
    119125    }
    120126  }
     127//if no target found:
     128  this->setParent(PNode::getNullParent());
    121129}
    122130
     
    155163
    156164
    157   if (this->source->getAbsCoor().x > this->getAbsCoor().x )
    158     this->searchTarget(1000);
     165//  if (this->source->getAbsCoor().x > this->getAbsCoor().x )
     166//    this->searchTarget(1000,M_PI_2);
    159167//   float z = 0.0f;
    160168//   glReadPixels ((int)this->getAbsCoor2D().x,
  • branches/spaceshipcontrol/src/world_entities/weapons/aim.h

    r5750 r6606  
    3838  inline PNode* getTarget(PNode* target) { return this->getParent(); };
    3939
    40   void searchTarget(float range);
     40  void searchTarget(float range, float angle);
    4141
    4242  void setSize(float size);
  • branches/spaceshipcontrol/src/world_entities/weapons/aiming_turret.cc

    r6439 r6606  
    130130  this->setAbsDirSoft(quat, 5);
    131131
    132   this->target->tick(dt);
     132  this->target->searchTarget(100,M_PI_2);
    133133}
    134134
     
    146146  pj->setAbsDir(this->getAbsDir());
    147147  pj->activate();
    148   this->target->searchTarget(100);
     148  this->target->searchTarget(100,M_PI_2);
    149149}
    150150
  • branches/spaceshipcontrol/src/world_entities/weapons/targeting_turret.cc

    r6439 r6606  
    9292  this->target = new Aim(this);
    9393  this->target->setVisibility(false);
    94 
     94  this->lockedTime = 0;
     95  this->neededLockTime = 2;
     96  this->lockedTarget->setParent(PNode::getNullParent());
    9597  this->loadModel("models/guns/turret2.obj");
    9698
     
    119121void TargetingTurret::tick(float dt)
    120122{
     123  if( lockedTime >= neededLockTime )
     124   {
     125    lockedTarget = this->target->getParent();
     126    lockedTime = 0;
     127   }
    121128
    122129  this->target->tick(dt);
     130
     131  if(this->target->getParent() == PNode::getNullParent())
     132   lockedTime = 0;
     133  else
     134   lockedTime += dt;
     135
    123136}
    124137
     
    137150  pj->setAbsDir(this->getAbsDir());
    138151  pj->activate();
    139   this->target->searchTarget(100);
     152  this->target->searchTarget(100,M_PI_2);
    140153}
    141154
  • branches/spaceshipcontrol/src/world_entities/weapons/targeting_turret.h

    r6426 r6606  
    3232
    3333  private:
    34     Aim*          target;
    35   };
     34    Aim*           target;
     35    PNode*         lockedTarget;
     36    float          lockedTime;
     37    float          neededLockTime;
     38  };
    3639
    3740#endif /* _TARGETING_TURRET_H */
Note: See TracChangeset for help on using the changeset viewer.