Revision 2b07acc9
utility/quaternion.h | ||
---|---|---|
79 | 79 |
|
80 | 80 |
double magnitude() const |
81 | 81 |
{ |
82 |
double res = (_w*_w) + (_x*_x) + (_y*_y) + (_z*_z); |
|
83 |
return sqrt(res); |
|
82 |
return sqrt(_w*_w + _x*_x + _y*_y + _z*_z); |
|
84 | 83 |
} |
85 | 84 |
|
86 | 85 |
void normalize() |
... | ... | |
89 | 88 |
*this = this->scale(1/mag); |
90 | 89 |
} |
91 | 90 |
|
92 |
const Quaternion conjugate() const
|
|
91 |
Quaternion conjugate() const |
|
93 | 92 |
{ |
94 | 93 |
return Quaternion(_w, -_x, -_y, -_z); |
95 | 94 |
} |
96 | 95 |
|
97 |
void fromAxisAngle(Vector<3> axis, double theta)
|
|
96 |
void fromAxisAngle(const Vector<3>& axis, double theta)
|
|
98 | 97 |
{ |
99 | 98 |
_w = cos(theta/2); |
100 | 99 |
//only need to calculate sine of half theta once |
... | ... | |
214 | 213 |
return ret; |
215 | 214 |
} |
216 | 215 |
|
217 |
Vector<3> rotateVector(Vector<2> v) const
|
|
216 |
Vector<3> rotateVector(const Vector<2>& v) const
|
|
218 | 217 |
{ |
219 |
Vector<3> ret(v.x(), v.y(), 0.0); |
|
220 |
return rotateVector(ret); |
|
218 |
return rotateVector(Vector<3>(v.x(), v.y())); |
|
221 | 219 |
} |
222 | 220 |
|
223 |
Vector<3> rotateVector(Vector<3> v) const
|
|
221 |
Vector<3> rotateVector(const Vector<3>& v) const
|
|
224 | 222 |
{ |
225 |
Vector<3> qv(this->x(), this->y(), this->z()); |
|
226 |
Vector<3> t; |
|
227 |
t = qv.cross(v) * 2.0; |
|
228 |
return v + (t * _w) + qv.cross(t); |
|
223 |
Vector<3> qv(_x, _y, _z); |
|
224 |
Vector<3> t = qv.cross(v) * 2.0; |
|
225 |
return v + t*_w + qv.cross(t); |
|
229 | 226 |
} |
230 | 227 |
|
231 | 228 |
|
Also available in: Unified diff