- Timestamp:
- Aug 13, 2005, 7:35:16 PM (19 years ago)
- Location:
- orxonox/trunk/src/lib/math
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/math/vector.cc
r4998 r4999 131 131 v.y = cr * sp * cy + sr * cp * sy; 132 132 v.z = cr * cp * sy - sr * sp * cy; 133 }134 135 /**136 * rotates one Quaternion by another137 * @param q: another Quaternion to rotate this by138 * @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))139 */140 Quaternion Quaternion::operator*(const Quaternion& q) const141 {142 float A, B, C, D, E, F, G, H;143 144 A = (w + v.x)*(q.w + q.v.x);145 B = (v.z - v.y)*(q.v.y - q.v.z);146 C = (w - v.x)*(q.v.y + q.v.z);147 D = (v.y + v.z)*(q.w - q.v.x);148 E = (v.x + v.z)*(q.v.x + q.v.y);149 F = (v.x - v.z)*(q.v.x - q.v.y);150 G = (w + v.y)*(q.w - q.v.z);151 H = (w - v.y)*(q.w + q.v.z);152 153 Quaternion r;154 r.v.x = A - (E + F + G + H)/2;155 r.v.y = C + (E - F + G - H)/2;156 r.v.z = D + (E - F - G + H)/2;157 r.w = B + (-E - F + G + H)/2;158 159 return r;160 133 } 161 134 -
orxonox/trunk/src/lib/math/vector.h
r4998 r4999 132 132 /** @param f: the value to multiply by @returns the quaternion multiplied by f (this *= f) */ 133 133 inline const Quaternion& operator*= (const float& f) {*this = *this * f; return *this;} 134 Quaternion operator* (const Quaternion& q) const; 134 /** @param q: another Quaternion to rotate this by @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)) */ 135 Quaternion operator* (const Quaternion& q) const { return Quaternion(Vector(this->w*q.v.x + this->v.x*q.w + this->v.y*q.v.z - this->v.z*q.v.y, 136 this->w*q.v.y + this->v.y*q.w + this->v.z*q.v.x - this->v.x*q.v.z, 137 this->w*q.v.z + this->v.z*q.w + this->v.x*q.v.y - this->v.y*q.v.x), 138 this->w*q.w - this->v.x*q.v.x - this->v.y*q.v.y - this->v.z*q.v.z); 139 }; 135 140 /** @param q: the Quaternion to multiply by @returns the quaternion multiplied by q (this *= q) */ 136 141 inline const Quaternion& operator*= (const Quaternion& q) {*this = *this * q; return *this; };
Note: See TracChangeset
for help on using the changeset viewer.