Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10655 in orxonox.OLD


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

ActionboxEnemy looks at Player :D

Location:
branches/vs-enhencements/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/vs-enhencements/src/ai/swarm_gorel.cc

    r10618 r10655  
    2323
    2424        //calculate  movement parameters..
    25         float averageRadius;
     25        float averageRadius = 0;
    2626        for (it=members.begin(); it!= members.end(); it++ ){
    2727                averageRadius+=it->second->getNPCRadius();
  • branches/vs-enhencements/src/lib/math/quaternion.h

    r10640 r10655  
    115115
    116116
    117     inline void slerpTo(const Quaternion& toQuat, float t);
     117    void slerpTo(const Quaternion& toQuat, float t);
    118118    static Quaternion quatSlerp(const Quaternion& from, const Quaternion& to, float t);
    119119
  • branches/vs-enhencements/src/lib/math/vector.h

    r10376 r10655  
    6464  /** @param v The vector to substract  @returns the substraction between two vectors (this - v) */
    6565  inline Vector operator- (const sVec3D& v) const { return Vector(x - v[0], y - v[1], z - v[2]); }
     66  /** @returns the substraction between (0, 0, 0) and this (null-this) */
     67  inline Vector operator- () const { return Vector(-x, -y, -z); }
    6668  /** @param v The vector to substract  @returns the substraction between two vectors (this -= v) */
    6769  inline const Vector& operator-= (const Vector& v) { this->x -= v.x; this->y -= v.y; this->z -= v.z; return *this; };
  • 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.