Revision 88b09bb5
utility/quaternion.h | ||
---|---|---|
35 | 35 |
class Quaternion |
36 | 36 |
{ |
37 | 37 |
public: |
38 |
Quaternion() |
|
39 |
{ |
|
40 |
_w = 1.0; |
|
41 |
_x = _y = _z = 0.0; |
|
42 |
} |
|
38 |
Quaternion(): _w(1.0), _x(0.0), _y(0.0), _z(0.0) {} |
|
43 | 39 |
|
44 |
Quaternion(double iw, double ix, double iy, double iz) |
|
45 |
{ |
|
46 |
_w = iw; |
|
47 |
_x = ix; |
|
48 |
_y = iy; |
|
49 |
_z = iz; |
|
50 |
} |
|
40 |
Quaternion(double w, double x, double y, double z): |
|
41 |
_w(w), _x(x), _y(y), _z(z) {} |
|
51 | 42 |
|
52 |
Quaternion(double w, Vector<3> vec) |
|
53 |
{ |
|
54 |
_w = w; |
|
55 |
_x = vec.x(); |
|
56 |
_y = vec.y(); |
|
57 |
_z = vec.z(); |
|
58 |
} |
|
43 |
Quaternion(double w, Vector<3> vec): |
|
44 |
_w(w), _x(vec.x()), _y(vec.y()), _z(vec.z()) {} |
|
59 | 45 |
|
60 | 46 |
double& w() |
61 | 47 |
{ |
... | ... | |
243 | 229 |
} |
244 | 230 |
|
245 | 231 |
|
246 |
const Quaternion operator*(const Quaternion& q) const
|
|
232 |
Quaternion operator*(const Quaternion& q) const |
|
247 | 233 |
{ |
248 | 234 |
return Quaternion( |
249 | 235 |
_w*q._w - _x*q._x - _y*q._y - _z*q._z, |
... | ... | |
253 | 239 |
); |
254 | 240 |
} |
255 | 241 |
|
256 |
const Quaternion operator+(const Quaternion& q) const
|
|
242 |
Quaternion operator+(const Quaternion& q) const |
|
257 | 243 |
{ |
258 | 244 |
return Quaternion(_w + q._w, _x + q._x, _y + q._y, _z + q._z); |
259 | 245 |
} |
260 | 246 |
|
261 |
const Quaternion operator-(const Quaternion& q) const
|
|
247 |
Quaternion operator-(const Quaternion& q) const |
|
262 | 248 |
{ |
263 | 249 |
return Quaternion(_w - q._w, _x - q._x, _y - q._y, _z - q._z); |
264 | 250 |
} |
265 | 251 |
|
266 |
const Quaternion operator/(double scalar) const
|
|
252 |
Quaternion operator/(double scalar) const |
|
267 | 253 |
{ |
268 | 254 |
return Quaternion(_w / scalar, _x / scalar, _y / scalar, _z / scalar); |
269 | 255 |
} |
270 | 256 |
|
271 |
const Quaternion operator*(double scalar) const
|
|
257 |
Quaternion operator*(double scalar) const |
|
272 | 258 |
{ |
273 | 259 |
return scale(scalar); |
274 | 260 |
} |
275 | 261 |
|
276 |
const Quaternion scale(double scalar) const
|
|
262 |
Quaternion scale(double scalar) const |
|
277 | 263 |
{ |
278 | 264 |
return Quaternion(_w * scalar, _x * scalar, _y * scalar, _z * scalar); |
279 | 265 |
} |
Also available in: Unified diff