Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10679 in orxonox.OLD


Ignore:
Timestamp:
Jun 8, 2007, 4:21:36 PM (17 years ago)
Author:
rennerc
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/adm/src/world_entities/npcs/adm_turret.cc

    r10677 r10679  
    7474
    7575        }
     76       
     77        //HACK this is really ugly because if you move the AdmTurret its cannons wont follow
     78        if ( this->cannons )
     79          this->cannons->setParent( NullParent::getNullParent() );
    7680}
    7781
     
    9599{
    96100        this->registerObject(this, AdmTurret::_objectList);
    97 
    98        
    99         // this-> loadModel ("models/guns/turret1.obj", ,1 )
    100        
    101 
    102         //Cannon Node: 2 Cannons fixed left and right of the main turret
    103        
    104         // this->sensor.setRelCoor( , , )
    105 
    106         // initialise Weapons here
     101       
     102        //this->removeNodeFlags( 7 );
    107103}
    108104
     
    201197        this->cannons->loadParams( root );
    202198
    203         this->cannons->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
    204         this->cannons->addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
     199        //this->cannons->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     200        //this->cannons->addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
    205201       
    206202        this->cannons->toList( getOMListNumber() );
     
    213209        this->sensor->loadParams( root );
    214210
    215         this->sensor->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
    216         this->sensor->addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
     211        //this->sensor->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
     212        //this->sensor->addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE);
    217213        this->sensor->toList( getOMListNumber() );
    218214}
     
    220216void AdmTurret::moveTowards( Vector targetDir, float dt )
    221217{
    222 
    223 if(false){
     218#if 0
     219  static Quaternion mrot = this->getAbsDir();
     220  Quaternion ry( dt, Vector(0, 1, 0) );
     221  mrot *= ry;
     222  this->setAbsDir(mrot);
     223
     224  static Quaternion rot = this->cannons->getAbsDir();
     225  Quaternion rx( dt, Vector( 0, 0, 1 ) );
     226  rot *= rx;
     227  this->cannons->setAbsDir(rot*mrot);
     228  return;
     229#endif
     230
     231
    224232
    225233
    226234  Quaternion cur = this->getAbsDir();
    227235 
    228   Quaternion ry( dt, cur.apply( Vector( 0, 1, 0 ) ) );
     236  Quaternion ry( dt, cur.inverse().apply( Vector( 0, 1, 0 ) ) );
    229237 
    230238  Quaternion tmp1 = cur * ry;
    231239  Quaternion tmp2 = cur * ry.inverse();
    232240 
     241  bool usetmp1 = false;
     242  Quaternion r1;
    233243  if ( tmp1.apply( Vector(1, 0, 0) ).dot(targetDir) < tmp2.apply( Vector(1, 0, 0)).dot(targetDir) )
     244  {
     245    usetmp1 = true;
    234246    cur = tmp1;
     247    r1 = ry;
     248  }
    235249  else
     250  {
    236251    cur = tmp2;
     252    r1 = ry.inverse();
     253  }
    237254 
    238255  this->setAbsDir( cur );
    239 }
    240 
    241 {
    242   //targetDir = this->getAbsDir().apply( targetDir );
    243   Quaternion cur = this->cannons->getAbsDir();
    244   //Quaternion rx( dt, Vector( 0, 0, 1 ) );
    245   Quaternion rx( dt, Vector( 0, 0, 1 ) );
    246  
    247   Quaternion tmp1 = cur * rx;
    248   Quaternion tmp2 = cur * rx.inverse();
     256
     257 
     258  Quaternion cur2 = this->cannons->getAbsDir();
     259  Quaternion rx( dt, cur.inverse().apply( Vector( 0, 0, 1 ) ) );
     260  Quaternion rr( dt, cur2.inverse().apply( Vector( 0, 1, 0 ) ) );
     261  if ( !usetmp1 )
     262    rr = rr.inverse();
     263 
     264 
     265  tmp1 = cur2 * rx;
     266  tmp2 = cur2 * rx.inverse();
    249267
    250268  Quaternion dec;
    251   if ( tmp1.apply(  Vector(-1, 0, 0) ).dot(targetDir) < tmp2.apply( Vector(-1, 0, 0) ).dot(targetDir) )
     269  Quaternion r2;
     270  if ( tmp1.apply(  Vector(-1, 0, 0) ).dot(targetDir) > tmp2.apply( Vector(-1, 0, 0) ).dot(targetDir) )
     271  {
     272    r2 = rx;
    252273    dec = tmp1;
     274  }
    253275  else
     276  {
     277    r2 = rx.inverse();
    254278    dec = tmp2;
     279  }
    255280 
    256281  float dp = dec.apply( Vector(-1, 0, 0) ).dot(Vector(0, 1, 0));
    257   if ( true /*dp > -0.9 && dp < 0.9*/ )
    258   {
    259     cur = dec;
    260   }
    261 
    262   this->cannons->setAbsDir( cur );
    263 }
    264 
    265 
    266 }
     282  if ( dp > -0.9 && dp < 0.9 )
     283  {
     284    cur2 = dec;
     285  }
     286
     287  this->cannons->setAbsDir( cur2 );
     288
     289
     290
     291}
Note: See TracChangeset for help on using the changeset viewer.