| 1 |
5 |
guilt |
#ifndef __XGL_QUAT_H__ |
| 2 |
|
|
#define __XGL_QUAT_H__ |
| 3 |
|
|
|
| 4 |
|
|
#include <allegro.h> |
| 5 |
|
|
#include <alleggl.h> |
| 6 |
|
|
#include <math.h> |
| 7 |
|
|
|
| 8 |
|
|
class Quaternion |
| 9 |
|
|
{ |
| 10 |
|
|
public: |
| 11 |
|
|
double x, y, z, w; |
| 12 |
|
|
|
| 13 |
|
|
Quaternion() : x(0), y(0), z(0), w(0) { } |
| 14 |
|
|
Quaternion (float _c) : x(_c), y(_c), z(_c), w(_c) { } |
| 15 |
|
|
Quaternion(float _x, float _y, float _z, float _w) : x(_x), y(_y), z(_z), w(_w) { } |
| 16 |
|
|
Quaternion(const QUAT &q) { |
| 17 |
|
|
x = q.x; |
| 18 |
|
|
y = q.y; |
| 19 |
|
|
z = q.z; |
| 20 |
|
|
w = q.w; |
| 21 |
|
|
} |
| 22 |
|
|
Quaternion(const Quaternion &q) { |
| 23 |
|
|
x = q.x; |
| 24 |
|
|
y = q.y; |
| 25 |
|
|
z = q.z; |
| 26 |
|
|
w = q.w; |
| 27 |
|
|
} |
| 28 |
|
|
|
| 29 |
|
|
QUAT toQUAT(){ |
| 30 |
|
|
QUAT q; |
| 31 |
|
|
q.x=x; q.y=y; q.z=z; q.w=w; |
| 32 |
|
|
return q; |
| 33 |
|
|
} |
| 34 |
|
|
|
| 35 |
|
|
// Operators |
| 36 |
|
|
inline Quaternion operator = (QUAT Q){ |
| 37 |
|
|
return Quaternion(Q); |
| 38 |
|
|
} |
| 39 |
|
|
|
| 40 |
|
|
inline Vector operator + (Vector v) |
| 41 |
|
|
{ |
| 42 |
|
|
QUAT q=toQUAT(); |
| 43 |
|
|
float x, y, z; |
| 44 |
|
|
|
| 45 |
|
|
apply_quat(&q, v.x, v.y, v.z, &x, &y, &z); |
| 46 |
|
|
|
| 47 |
|
|
return Vector(x,y,z); |
| 48 |
|
|
} |
| 49 |
|
|
|
| 50 |
|
|
inline Quaternion operator * (Quaternion q) |
| 51 |
|
|
{ |
| 52 |
|
|
QUAT q1,q2,q3; |
| 53 |
|
|
|
| 54 |
|
|
q1=toQUAT(); |
| 55 |
|
|
q2=q.toQUAT(); |
| 56 |
|
|
|
| 57 |
|
|
quat_mul(&q3, &q1, &q2); |
| 58 |
|
|
|
| 59 |
|
|
return Quaternion(q3); |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
|
|
inline Quaternion operator *= (Quaternion q) |
| 63 |
|
|
{ |
| 64 |
|
|
QUAT q1,q2; |
| 65 |
|
|
|
| 66 |
|
|
q1=q.toQUAT(); |
| 67 |
|
|
q2=toQUAT(); |
| 68 |
|
|
|
| 69 |
|
|
quat_mul(&q2, &q1, &q2); |
| 70 |
|
|
|
| 71 |
|
|
x=q2.x; |
| 72 |
|
|
y=q2.y; |
| 73 |
|
|
z=q2.z; |
| 74 |
|
|
w=q2.w; |
| 75 |
|
|
|
| 76 |
|
|
return *this; |
| 77 |
|
|
} |
| 78 |
|
|
|
| 79 |
|
|
inline Quaternion operator * (QUAT q) { |
| 80 |
|
|
QUAT q1,q2; |
| 81 |
|
|
|
| 82 |
|
|
q1=toQUAT(); |
| 83 |
|
|
|
| 84 |
|
|
quat_mul(&q2, &q1, &q); |
| 85 |
|
|
|
| 86 |
|
|
return Quaternion(q2); |
| 87 |
|
|
} |
| 88 |
|
|
|
| 89 |
|
|
}; |
| 90 |
|
|
|
| 91 |
|
|
#endif /* __XGL_QUAT_H__ */ |