Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10656 in orxonox.OLD for branches/vs-enhencements/src


Ignore:
Timestamp:
May 14, 2007, 11:27:18 AM (18 years ago)
Author:
rennerc
Message:

ActionboxEnemy does not rotate around its z-axix more than ±pi/2-epsilon

Location:
branches/vs-enhencements/src/world_entities/npcs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.cc

    r10655 r10656  
    3838  this->isActive = true;
    3939 
    40   //TODO init to zero for non-debug
    4140  this->pitch = 0.0f;
    42   this->dPitch = PI;
     41  this->dPitch = 0.0;
    4342 
    4443  if ( root )
     
    5756void ActionboxEnemy::tick( float dt )
    5857{
     58  myDir = this->getAbsDir();
     59  myCoor = this->getAbsCoor();
     60 
    5961  this->pitch += this->dPitch*dt;
     62  while ( pitch > 2*PI )
     63    pitch -= 2*PI;
     64  while ( pitch < 0 )
     65    pitch += 2*PI;
     66 
     67  myDir *= qPitch.inverse();
     68 
     69  qPitch = Quaternion( pitch, Vector( 1, 0, 0 ) );
    6070 
    6171  moveTowardsBox( NULL, dt );
    62   return;
    63  
     72   
    6473  if ( isActive && State::getActionBox() )
    6574  {
     
    7483    }
    7584  }
     85 
     86  myDir *= qPitch;
     87 
     88  this->setAbsDir( myDir );
     89  this->setAbsCoor( myCoor );
    7690}
    7791
     
    8397{
    8498  Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor();
    85   Vector targetDir = targetPos - this->getAbsCoor();
     99  Vector targetDir = targetPos - myCoor;
    86100 
    87  
    88   Quaternion cur = this->getAbsDir();
     101  Quaternion cur = myDir;
    89102  Quaternion rx( 5*dt, Vector( 0, 0, 1 ) );
    90103 
     
    92105  Quaternion tmp2 = cur * rx.inverse();
    93106 
     107  Quaternion dec;
    94108  if ( tmp1.apply( Vector(1, 0, 0) ).dot(targetDir) > tmp2.apply( Vector(1, 0, 0)).dot(targetDir) )
    95     cur = tmp1;
     109    dec = tmp1;
    96110  else
    97     cur = tmp2;
     111    dec = tmp2;
     112 
     113  float dp = dec.apply( Vector(1, 0, 0) ).dot(Vector(0, 1, 0));
     114  if ( dp > -0.9 && dp < 0.9 )
     115  {
     116    cur = dec;
     117  }
    98118 
    99119  Quaternion ry( 5*dt, cur.inverse().apply( Vector( 0, 1, 0 ) ) );
     
    107127    cur = tmp2;
    108128 
    109   this->setAbsDir( cur );
     129  myDir = cur;
    110130}
    111131
    112132void ActionboxEnemy::draw( ) const
    113133{
     134#if 0
    114135  Vector fw = this->getAbsDir().apply( Vector( 1, 0, 0 ) );
    115136  fw.normalize();
     
    173194
    174195  glPopMatrix();
    175  
     196#enif
    176197  WorldEntity::draw();
    177198}
  • branches/vs-enhencements/src/world_entities/npcs/actionbox_enemy.h

    r10651 r10656  
    2424    float pitch;      // rotate angle around x-axix
    2525    float dPitch;     // change pitch += dPitch*dt
     26    Quaternion qPitch;
     27   
     28    Quaternion myDir;
     29    Vector     myCoor;
    2630   
    2731    void attackPlayer( ActionBox* box, float dt );
Note: See TracChangeset for help on using the changeset viewer.