Changeset 4477 in orxonox.OLD for orxonox/trunk
- Timestamp:
- Jun 2, 2005, 4:35:22 AM (20 years ago)
- Location:
- orxonox/trunk/src/lib/math
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/math/vector.cc
r4476 r4477 24 24 using namespace std; 25 25 26 ///////////// 27 /* VECTORS */ 28 ///////////// 26 29 /** 27 30 \brief returns the this-vector normalized to length 1.0 … … 43 46 44 47 /** 48 \brief Vector is looking in the positive direction on all axes after this 49 */ 50 Vector Vector::abs() 51 { 52 Vector v(fabs(x), fabs(y), fabs(z)); 53 return v; 54 } 55 56 57 58 /** 45 59 \brief Outputs the values of the Vector 46 60 */ … … 53 67 } 54 68 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 ///////////////// 69 72 /** 70 73 \brief calculates a lookAt rotation … … 109 112 110 113 /** 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 118 118 */ 119 119 Quaternion::Quaternion (float roll, float pitch, float yaw) 120 120 { 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 } 140 141 /** 142 143 144 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)) 145 145 */ 146 146 Quaternion Quaternion::operator*(const Quaternion& q) const … … 165 165 return r; 166 166 } 167 168 /**169 \brief add two Quaternions170 \param q: another Quaternion171 \return the sum of both Quaternions172 */173 /*174 Quaternion Quaternion::operator+(const Quaternion& q) const175 {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 Quaternions185 \param q: another Quaternion186 \return the difference of both Quaternions187 */188 /*189 Quaternion Quaternion::operator- (const Quaternion& q) const190 {191 Quaternion r(*this);192 r.w = r.w - q.w;193 r.v = r.v - q.v;194 return r;195 }196 */197 167 198 168 /** -
orxonox/trunk/src/lib/math/vector.h
r4476 r4477 52 52 /** \param v: the corss-product partner \returns the cross-product between this and v (this (x) v) */ 53 53 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 */ 55 55 void scale(const Vector& v) { x *= v.x; y *= v.y; z *= v.z; }; 56 56 /** \returns the length of the vector */ … … 102 102 { 103 103 public: 104 Vector v; //!< Imaginary Vector 105 float w; //!< Real part of the number 106 104 /** \brief creates a Default quaternion (multiplicational identity Quaternion)*/ 107 105 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 */ 108 107 inline Quaternion (const Vector& v, float f) { this->w = f; this->v = v; } 109 108 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 */ 110 110 inline Quaternion (float angle, const Vector& axis) { w = cos(angle/2); v = axis * sin(angle/2); } 111 111 Quaternion (const Vector& dir, const Vector& up); 112 112 Quaternion (float roll, float pitch, float yaw); 113 113 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;} 115 116 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;} 117 119 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) */ 121 127 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) */ 123 131 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;} 127 134 Quaternion inverse () const; 128 135 Vector apply (const Vector& f) const; … … 131 138 132 139 void debug(); 140 141 public: 142 Vector v; //!< Imaginary Vector 143 float w; //!< Real part of the number 144 133 145 }; 134 146
Note: See TracChangeset
for help on using the changeset viewer.