Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4997 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Aug 13, 2005, 3:10:52 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: optimized vector class

Location:
orxonox/trunk/src
Files:
5 edited

Legend:

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

    r4996 r4997  
    339339{
    340340  if (this->parent)
    341     this->relDirection = absDir * parent->getAbsDir().inverse();
     341    this->relDirection = absDir / parent->getAbsDir();
    342342  else
    343343    this->relDirection = absDir;
     
    489489  this->setRelCoor(tmpV - parentNode->getAbsCoor());
    490490
    491   this->setRelDir(tmpQ * parentNode->getAbsDir().inverse());
     491  this->setRelDir(tmpQ / parentNode->getAbsDir());
    492492}
    493493
     
    543543      if (unlikely(this->toDirection != NULL))
    544544      {
    545         Quaternion rotQuat = (*this->toDirection * this->getRelDir().inverse()) *dt*bias;
     545        Quaternion rotQuat = (*this->toDirection / this->getRelDir()) *dt*bias;
     546        rotQuat.debug();
    546547//        if (likely(rotQuat.len() >= .001))
    547548        {
  • orxonox/trunk/src/lib/math/vector.cc

    r4987 r4997  
    158158
    159159  return r;
    160 }
    161 
    162 /**
    163  *  rotate a Vector by a Quaternion
    164  * @param v: the Vector
    165  * @return a new Vector representing v rotated by the Quaternion
    166 */
    167 
    168 Vector Quaternion::apply (const Vector& v) const
    169 {
    170   Quaternion q;
    171   q.v = v;
    172   q.w = 0;
    173   q = *this * q * conjugate();
    174   return q.v;
    175 }
    176 
    177 
    178 /**
    179  *  multiply a Quaternion with a real value
    180  * @param f: a real value
    181  * @return a new Quaternion containing the product
    182 */
    183 Quaternion Quaternion::operator*(const float& f) const
    184 {
    185   Quaternion r(*this);
    186   r.w = r.w*f;
    187   r.v = r.v*f;
    188   return r;
    189 }
    190 
    191 /**
    192  *  divide a Quaternion by a real value
    193  * @param f: a real value
    194  * @return a new Quaternion containing the quotient
    195 */
    196 Quaternion Quaternion::operator/(const float& f) const
    197 {
    198   if( f == 0) return Quaternion();
    199   Quaternion r(*this);
    200   r.w = r.w/f;
    201   r.v = r.v/f;
    202   return r;
    203 }
    204 
    205 /**
    206  *  calculate the conjugate value of the Quaternion
    207  * @return the conjugate Quaternion
    208 */
    209 /*
    210 Quaternion Quaternion::conjugate() const
    211 {
    212   Quaternion r(*this);
    213   r.v = Vector() - r.v;
    214   return r;
    215 }
    216 */
    217 
    218 /**
    219  *  calculate the norm of the Quaternion
    220  * @return the norm of The Quaternion
    221 */
    222 float Quaternion::norm() const
    223 {
    224   return w*w + v.x*v.x + v.y*v.y + v.z*v.z;
    225 }
    226 
    227 /**
    228  *  calculate the inverse value of the Quaternion
    229  * @return the inverse Quaternion
    230 
    231         Note that this is equal to conjugate() if the Quaternion's norm is 1
    232 */
    233 Quaternion Quaternion::inverse() const
    234 {
    235   float n = norm();
    236   if (n != 0)
    237     {
    238       return conjugate() / norm();
    239     }
    240   else return Quaternion();
    241160}
    242161
  • orxonox/trunk/src/lib/math/vector.h

    r4994 r4997  
    5454  inline const Vector& operator*= (float f) { this->x *= f; this->y *= f; this->z *= f; return *this; };
    5555  /** @param f a factor to divide the vector with @returns the vector divided by f (this / f) */
    56   inline Vector operator/ (float f) const {return (unlikely(f == 0.0))?Vector(0,0,0):Vector(this->x / f, this->y / f, this->z / f); };
     56  inline Vector operator/ (float f) const { return (unlikely(f == 0.0))?Vector(0,0,0):Vector(this->x / f, this->y / f, this->z / f); };
    5757  /** @param f a factor to divide the vector with @returns the vector divided by f (this /= f) */
    5858  inline const Vector& operator/= (float f) {if (unlikely(f == 0.0)) {this->x=0;this->y=0;this->z=0;} else {this->x /= f; this->y /= f; this->z /= f;} return *this; };
     
    124124  Quaternion (const Vector& dir, const Vector& up);
    125125  Quaternion (float roll, float pitch, float yaw);
    126   Quaternion operator/ (const float& f) const;
     126  /** @param f: a real value @return a Quaternion containing the quotient */
     127  inline Quaternion operator/ (const float& f) const { return (unlikely(f==0.0)) ? Quaternion() : Quaternion(this->v/f, this->w/f); };
    127128  /** @param f: the value to divide by @returns the quaternion devided by f (this /= f) */
    128129  inline const Quaternion& operator/= (const float& f) {*this = *this / f; return *this;}
    129   Quaternion operator* (const float& f) const;
     130  /** @param f: a real value @return a Quaternion containing the product */
     131  inline Quaternion operator* (const float& f) const { return Quaternion(this->v*f, this->w*f); };
    130132  /** @param f: the value to multiply by @returns the quaternion multiplied by f (this *= f) */
    131133  inline const Quaternion& operator*= (const float& f) {*this = *this * f; return *this;}
    132134  Quaternion operator* (const Quaternion& q) const;
    133135  /** @param q: the Quaternion to multiply by @returns the quaternion multiplied by q (this *= q) */
    134   inline const Quaternion operator*= (const Quaternion& q) {*this = *this * q; return *this; };
     136  inline const Quaternion& operator*= (const Quaternion& q) {*this = *this * q; return *this; };
     137  /** @param q the Quaternion by which to devide @returns the division from this by q (this / q) */
     138  inline Quaternion operator/ (const Quaternion& q) const { return *this * q.inverse(); };
     139  /** @param q the Quaternion by which to devide @returns the division from this by q (this /= q) */
     140  inline const Quaternion& operator/= (const Quaternion& q) { *this = *this * q.inverse(); return *this; };
    135141  /** @param q the Quaternion to add to this @returns the quaternion added with q (this + q) */
    136142  inline Quaternion operator+ (const Quaternion& q) const { return Quaternion(q.v + v, q.w + w); };
     
    144150  inline Quaternion operator= (const Quaternion& q) {this->v = q.v; this->w = q.w; return *this;}
    145151  /** conjugates this Quaternion @returns the conjugate */
    146   inline Quaternion conjugate () const {  Quaternion r(*this);  r.v = Vector() - r.v;  return r;}
    147   Quaternion inverse () const;
    148   Vector apply (const Vector& f) const;
    149   float norm () const;
     152  inline Quaternion conjugate () const { Quaternion r(*this); r.v = Vector() - r.v; return r; };
     153  /** @returns the norm of The Quaternion */
     154  inline float norm () const { return w*w + v.x*v.x + v.y*v.y + v.z*v.z; };
     155  /** @returns the inverted Quaterntion of this */
     156  inline Quaternion inverse () const { return conjugate() / norm(); };
     157  /** @param v: the Vector  @return a new Vector representing v rotated by the Quaternion */
     158  inline Vector apply (const Vector& v) const { return (*this * Quaternion(v, 0) * conjugate()).v; };
    150159  void matrix (float m[4][4]) const;
    151160
     
    270279
    271280#endif /* _VECTOR_H */
     281
  • orxonox/trunk/src/world_entities/camera.cc

    r4996 r4997  
    5252  this->setViewMode(VIEW_NORMAL);
    5353
    54   this->setParentMode(PNODE_MOVEMENT);
     54  //this->setParentMode(PNODE_MOVEMENT);
    5555}
    5656
     
    257257{
    258258  this->setClassID(CL_CAMERA_TARGET, "CameraTarget");
    259   this->setParentMode(PNODE_MOVEMENT);
     259//  this->setParentMode(PNODE_MOVEMENT);
    260260}
    261261
  • orxonox/trunk/src/world_entities/player.cc

    r4994 r4997  
    121121void Player::init()
    122122{
     123  this->setAbsDir(0,1,0);
     124
    123125  this->setClassID(CL_PLAYER, "Player");
    124126
Note: See TracChangeset for help on using the changeset viewer.