Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4998 in orxonox.OLD for orxonox/trunk/src/lib


Ignore:
Timestamp:
Aug 13, 2005, 7:19:51 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: more optimizations of the Quaternion Class.
Now the 3D-rotation is much faster through this code:

Vector tmpRot = this→getAbsDir().getSpacialAxis();
glRotatef (this→getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );

instead of the old Matrix-approach. furthermore glRotate is optimized much better in openGL as is clearly stated in the red book

also implemented some other really useless functions for Quaternion

Location:
orxonox/trunk/src/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/coord/p_node.cc

    r4997 r4998  
    327327}
    328328
    329 
    330329/**
    331330 *  sets the absolute direction (0,0,1)
     
    543542      if (unlikely(this->toDirection != NULL))
    544543      {
    545         Quaternion rotQuat = (*this->toDirection / this->getRelDir()) *dt*bias;
    546         rotQuat.debug();
    547 //        if (likely(rotQuat.len() >= .001))
     544        Quaternion rotQuat = Quaternion(.1, Vector(0,1,0));// (*this->toDirection / this->relDirection);
     545//         printf("1: ");
     546//         this->relDirection.debug();
     547//         printf("2: ");
     548//         this->toDirection->debug();
     549//         printf("3: ");
     550//         rotQuat.debug();
     551
     552        if (true)//likely(rotQuat.len() >= .001))
    548553        {
    549554          this->shiftDir(rotQuat);
    550555        }
    551 /*        else
     556        else
    552557        {
    553558          delete this->toCoordinate;
    554559          this->toCoordinate = NULL;
    555560          PRINTF(5)("SmoothMove of %s finished\n", this->getName());
    556         }*/
     561        }
    557562      }
    558563
     
    664669  glMatrixMode(GL_MODELVIEW);
    665670  glPushMatrix();
    666   float matrix[4][4];
    667671
    668672  /* translate */
     
    671675                this->getAbsCoor ().z);
    672676  /* rotate */
    673   this->getAbsDir ().matrix (matrix);
    674   glMultMatrixf((float*)matrix);
     677//  this->getAbsDir ().matrix (matrix);
     678//  glMultMatrixf((float*)matrix);
     679
     680  Vector tmpRot = this->getAbsDir().getSpacialAxis();
     681  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
    675682  {
    676683    glBegin(GL_LINE_STRIP);
  • orxonox/trunk/src/lib/math/vector.cc

    r4997 r4998  
    197197 * @returns the Result of the smooth move
    198198*/
    199 Quaternion quatSlerp(const Quaternion& from, const Quaternion& to, float t)
     199Quaternion Quaternion::quatSlerp(const Quaternion& from, const Quaternion& to, float t)
    200200{
    201201  float tol[4];
     
    306306void Quaternion::debug()
    307307{
    308   PRINT(0)("Quaternion Debug Information\n");
    309308  PRINT(0)("real a=%f; imag: x=%f y=%f z=%f\n", w, v.x, v.y, v.z);
    310309}
  • orxonox/trunk/src/lib/math/vector.h

    r4997 r4998  
    150150  inline Quaternion operator= (const Quaternion& q) {this->v = q.v; this->w = q.w; return *this;}
    151151  /** conjugates this Quaternion @returns the conjugate */
    152   inline Quaternion conjugate () const { Quaternion r(*this); r.v = Vector() - r.v; return r; };
     152  inline Quaternion conjugate () const { return Quaternion(Vector(-v.x, -v.y, -v.z), this->w); };
    153153  /** @returns the norm of The Quaternion */
    154154  inline float norm () const { return w*w + v.x*v.x + v.y*v.y + v.z*v.z; };
     
    158158  inline Vector apply (const Vector& v) const { return (*this * Quaternion(v, 0) * conjugate()).v; };
    159159  void matrix (float m[4][4]) const;
     160  /** @returns the normalized Quaternion (|this|) */
     161  inline Quaternion getNormalized() const { float n = this->norm(); return Quaternion(this->v/n, this->w/n); };
     162  /** normalizes the current Quaternion */
     163  inline void normalize() { float n = this->norm(); this->v /= n; this->w/=n; };
     164
     165  /** @returns the rotational axis of this Quaternion */
     166  inline Vector getSpacialAxis() const { return this->v / sin(acos(w));/*sqrt(v.x*v.x + v.y*v.y + v.z+v.z);*/ };
     167  /** @returns the rotational angle of this Quaternion around getSpacialAxis()  !! IN DEGREE !! */
     168  inline float getSpacialAxisAngle() const { return 360 / M_PI * acos(this->w); };
     169
     170  static Quaternion quatSlerp(const Quaternion& from, const Quaternion& to, float t);
    160171
    161172  void debug();
     173
    162174
    163175 public:
     
    167179};
    168180
    169 Quaternion quatSlerp(const Quaternion& from, const Quaternion& to, float t);
    170181
    171182
Note: See TracChangeset for help on using the changeset viewer.