Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 13, 2007, 1:27:37 PM (18 years ago)
Author:
rennerc
Message:

ActionboxEnemy looks at Player :D

File:
1 edited

Legend:

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

    r10651 r10655  
    8383{
    8484  Vector targetPos = State::getPlayer()->getPlayable()->getAbsCoor();
     85  Vector targetDir = targetPos - this->getAbsCoor();
    8586 
    86   Vector fw = this->getAbsDir().apply( Vector( 0, 0, -1 ) );
    87   fw.normalize();
    8887 
    89   Vector dv = targetPos - this->getAbsCoor();
    90   dv.normalize();
     88  Quaternion cur = this->getAbsDir();
     89  Quaternion rx( 5*dt, Vector( 0, 0, 1 ) );
    9190 
    92   Vector up = fw.cross( dv )*-1;
     91  Quaternion tmp1 = cur * rx;
     92  Quaternion tmp2 = cur * rx.inverse();
    9393 
    94   Quaternion rot(up, 10.0*dt);
    95   rot.normalize();
    96   Quaternion cur = this->getAbsDir();
    97   Quaternion ne = rot * cur;
    98   this->setAbsDir( ne );
     94  if ( tmp1.apply( Vector(1, 0, 0) ).dot(targetDir) > tmp2.apply( Vector(1, 0, 0)).dot(targetDir) )
     95    cur = tmp1;
     96  else
     97    cur = tmp2;
    9998 
    100   // 1, 0, 0
    101   // 0, 1, 0
    102   return;
    103   Vector k = ne.apply( Vector( 1, 0, 0 ) );
    104   k.normalize();
     99  Quaternion ry( 5*dt, cur.inverse().apply( Vector( 0, 1, 0 ) ) );
    105100 
    106   Vector vr = k.cross( Vector( 0, 1, 0) );
     101  tmp1 = cur * ry;
     102  tmp2 = cur * ry.inverse();
    107103 
    108   rot = Quaternion(vr, 10.0*dt);
    109   rot.normalize();
    110   cur = ne;
    111   ne = rot * cur;
    112   ne.normalize();
    113  
    114   this->setAbsDir( ne );
     104  if ( tmp1.apply( Vector(1, 0, 0) ).dot(targetDir) > tmp2.apply( Vector(1, 0, 0)).dot(targetDir) )
     105    cur = tmp1;
     106  else
     107    cur = tmp2;
     108 
     109  this->setAbsDir( cur );
    115110}
    116111
     
    130125  dv += mp;
    131126 
    132   Vector up = fw.cross( dv )*-1;
     127  Vector spUp = this->getAbsDir().inverse().apply( this->getAbsDir().apply( Vector( 0, 1, 0 ) ) );
     128  spUp.normalize();
     129  spUp *= 100;
     130  spUp += mp;
     131 
     132  Vector up = fw.cross( dv );
    133133  up += mp;
    134134 
     
    154154  glEnd();
    155155 
     156  glColor3f(0.0, 1.0, 0.0 );
    156157  glBegin(GL_LINE_STRIP);
    157158    glVertex3f(mp.x, mp.y, mp.z);
     
    159160  glEnd();
    160161 
     162  glColor3f(0.0, 0.0, 1.0 );
    161163  glBegin(GL_LINE_STRIP);
    162164    glVertex3f(mp.x, mp.y, mp.z);
    163165    glVertex3f(up.x, up.y, up.z);
     166  glEnd();
     167 
     168  glColor3f(1.0, 1.0, 1.0 );
     169  glBegin(GL_LINE_STRIP);
     170    glVertex3f(mp.x, mp.y, mp.z);
     171    glVertex3f(spUp.x, spUp.y, spUp.z);
    164172  glEnd();
    165173
Note: See TracChangeset for help on using the changeset viewer.