Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4477 in orxonox.OLD


Ignore:
Timestamp:
Jun 2, 2005, 4:35:22 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: vector is completely documented again :)

Location:
orxonox/trunk/src/lib/math
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/math/vector.cc

    r4476 r4477  
    2424using namespace std;
    2525
     26/////////////
     27/* VECTORS */
     28/////////////
    2629/**
    2730   \brief returns the this-vector normalized to length 1.0
     
    4346
    4447/**
     48   \brief Vector is looking in the positive direction on all axes after this
     49*/
     50Vector Vector::abs()
     51{
     52  Vector v(fabs(x), fabs(y), fabs(z));
     53  return v;
     54}
     55
     56
     57
     58/**
    4559   \brief Outputs the values of the Vector
    4660*/
     
    5367}
    5468
    55 /**
    56         \brief creates a multiplicational identity Quaternion
    57 */
    58 //Quaternion::Quaternion ()
    59 
    60 
    61 /**
    62         \brief turns a rotation along an axis into a Quaternion
    63         \param angle: the amount of radians to rotate
    64         \param axis: the axis to rotate around
    65 */
    66 //Quaternion::Quaternion (float angle, const Vector& axis)
    67 
    68 
     69/////////////////
     70/* QUATERNIONS */
     71/////////////////
    6972/**
    7073   \brief calculates a lookAt rotation
     
    109112
    110113/**
    111         \brief calculates a rotation from euler angles
    112         \param roll: the roll in radians
    113         \param pitch: the pitch in radians
    114         \param yaw: the yaw in radians
    115        
    116         I DO HONESTLY NOT EXACTLY KNOW WHICH ANGLE REPRESENTS WHICH ROTATION. And I do not know
    117         in what order they are applied, I just copy-pasted the code.
     114   \brief calculates a rotation from euler angles
     115   \param roll: the roll in radians
     116   \param pitch: the pitch in radians
     117   \param yaw: the yaw in radians
    118118*/
    119119Quaternion::Quaternion (float roll, float pitch, float yaw)
    120120{
    121         float cr, cp, cy, sr, sp, sy, cpcy, spsy;
    122        
    123         // calculate trig identities
    124         cr = cos(roll/2);
    125         cp = cos(pitch/2);
    126         cy = cos(yaw/2);
    127        
    128         sr = sin(roll/2);
    129         sp = sin(pitch/2);
    130         sy = sin(yaw/2);
    131        
    132         cpcy = cp * cy;
    133         spsy = sp * sy;
    134        
    135         w = cr * cpcy + sr * spsy;
    136         v.x = sr * cpcy - cr * spsy;
    137         v.y = cr * sp * cy + sr * cp * sy;
    138         v.z = cr * cp * sy - sr * sp * cy;
    139 }
    140 
    141 /**
    142         \brief rotates one Quaternion by another
    143         \param q: another Quaternion to rotate this by
    144         \return a quaternion that represents the first one rotated by the second one (WARUNING: this operation is not commutative! e.g. (A*B) != (B*A))
     121  float cr, cp, cy, sr, sp, sy, cpcy, spsy;
     122 
     123  // calculate trig identities
     124  cr = cos(roll/2);
     125  cp = cos(pitch/2);
     126  cy = cos(yaw/2);
     127 
     128  sr = sin(roll/2);
     129  sp = sin(pitch/2);
     130  sy = sin(yaw/2);
     131 
     132  cpcy = cp * cy;
     133  spsy = sp * sy;
     134 
     135  w = cr * cpcy + sr * spsy;
     136  v.x = sr * cpcy - cr * spsy;
     137  v.y = cr * sp * cy + sr * cp * sy;
     138  v.z = cr * cp * sy - sr * sp * cy;
     139}
     140
     141/**
     142   \brief rotates one Quaternion by another
     143   \param q: another Quaternion to rotate this by
     144   \return a quaternion that represents the first one rotated by the second one (WARUNING: this operation is not commutative! e.g. (A*B) != (B*A))
    145145*/
    146146Quaternion Quaternion::operator*(const Quaternion& q) const
     
    165165  return r;
    166166}
    167 
    168 /**
    169    \brief add two Quaternions
    170    \param q: another Quaternion
    171    \return the sum of both Quaternions
    172 */
    173 /*
    174 Quaternion Quaternion::operator+(const Quaternion& q) const
    175 {
    176   Quaternion r(*this);
    177   r.w = r.w + q.w;
    178   r.v = r.v + q.v;
    179   return r;
    180 }
    181 */
    182 
    183 /**
    184    \brief subtract two Quaternions
    185    \param q: another Quaternion
    186    \return the difference of both Quaternions
    187 */
    188 /*
    189 Quaternion Quaternion::operator- (const Quaternion& q) const
    190 {
    191   Quaternion r(*this);
    192   r.w = r.w - q.w;
    193   r.v = r.v - q.v;
    194   return r;
    195 }
    196 */
    197167
    198168/**
  • orxonox/trunk/src/lib/math/vector.h

    r4476 r4477  
    5252  /** \param v: the corss-product partner \returns the cross-product between this and v (this (x) v) */
    5353  inline Vector cross (const Vector& v) const { return Vector(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x ); }
    54   /** \param scales the this vector with v */
     54  /** \brief scales the this vector with v  \param v the vector to scale this with */
    5555  void scale(const Vector& v) {   x *= v.x;  y *= v.y; z *= v.z; };
    5656  /** \returns the length of the vector */
     
    102102{
    103103 public:
    104   Vector    v;        //!< Imaginary Vector
    105   float     w;        //!< Real part of the number
    106  
     104  /** \brief creates a Default quaternion (multiplicational identity Quaternion)*/
    107105  inline Quaternion () { w = 1; v = Vector(0,0,0); }
     106  /** \brief creates a Quaternion looking into the direction v \param v: the direction \param f: the value */
    108107  inline Quaternion (const Vector& v, float f) { this->w = f; this->v = v; }
    109108  Quaternion (float m[4][4]);
     109  /** \brief turns a rotation along an axis into a Quaternion \param angle: the amount of radians to rotate \param axis: the axis to rotate around */
    110110  inline Quaternion (float angle, const Vector& axis) { w = cos(angle/2); v = axis * sin(angle/2); }
    111111  Quaternion (const Vector& dir, const Vector& up);
    112112  Quaternion (float roll, float pitch, float yaw);
    113113  Quaternion operator/ (const float& f) const;
    114   inline const Quaternion operator/= (const float& f) {*this = *this / f; return *this;}
     114  /** \param f: the value to divide by \returns the quaternion devided by f (this /= f) */
     115  inline const Quaternion& operator/= (const float& f) {*this = *this / f; return *this;}
    115116  Quaternion operator* (const float& f) const;
    116   inline const Quaternion operator*= (const float& f) {*this = *this * f; return *this;}
     117  /** \param f: the value to multiply by \returns the quaternion multiplied by f (this *= f) */
     118  inline const Quaternion& operator*= (const float& f) {*this = *this * f; return *this;}
    117119  Quaternion operator* (const Quaternion& q) const;
    118   inline const Quaternion operator*= (const Quaternion& q) {*this = *this * q; return *this;}
    119   inline Quaternion operator+ (const Quaternion& q) const { return Quaternion(q.v + v, q.w + w); }
    120   inline const Quaternion& operator+= (const Quaternion& q) {this->v += q.v; this->w += q.w; return *this;}
     120  /** \param q: the Quaternion to multiply by \returns the quaternion multiplied by q (this *= q) */ 
     121  inline const Quaternion operator*= (const Quaternion& q) {*this = *this * q; return *this; };
     122  /** \param q the Quaternion to add to this \returns the quaternion added with q (this + q) */
     123  inline Quaternion operator+ (const Quaternion& q) const { return Quaternion(q.v + v, q.w + w); };
     124  /** \param q the Quaternion to add to this \returns the quaternion added with q (this += q) */
     125  inline const Quaternion& operator+= (const Quaternion& q) { this->v += q.v; this->w += q.w; return *this; };
     126  /** \param q the Quaternion to substrace from this \returns the quaternion substracted by q (this - q) */
    121127  inline Quaternion operator- (const Quaternion& q) const { return Quaternion(q.v - v, q.w - w); }
    122   inline const Quaternion& operator-= (const Quaternion& q) {this->v -= q.v; this->w -= q.w; return *this;}
     128  /** \param q the Quaternion to substrace from this \returns the quaternion substracted by q (this -= q) */
     129  inline const Quaternion& operator-= (const Quaternion& q) { this->v -= q.v; this->w -= q.w; return *this; };
     130  /** \brief copy constructor \param q: the Quaternion to set this to. \returns the Quaternion q (or this) */
    123131  inline Quaternion operator= (const Quaternion& q) {this->v = q.v; this->w = q.w; return *this;}
    124   Quaternion conjugate () const {  Quaternion r(*this);
    125   r.v = Vector() - r.v;
    126   return r;}
     132  /** \brief conjugates this Quaternion \returns the conjugate */
     133  inline Quaternion conjugate () const {  Quaternion r(*this);  r.v = Vector() - r.v;  return r;}
    127134  Quaternion inverse () const;
    128135  Vector apply (const Vector& f) const;
     
    131138 
    132139  void debug();
     140
     141 public:
     142  Vector    v;        //!< Imaginary Vector
     143  float     w;        //!< Real part of the number
     144
    133145};
    134146
Note: See TracChangeset for help on using the changeset viewer.