11 #ifndef CAL_QUATERNION_H 12 #define CAL_QUATERNION_H 18 #include "cal3d/global.h" 19 #include "cal3d/vector.h" 46 inline CalQuaternion() : x(0.0f), y(0.0f), z(0.0f), w(1.0f){};
48 inline CalQuaternion(
float qx,
float qy,
float qz,
float qw): x(qx), y(qy), z(qz), w(qw) {};
53 inline float& operator[](
unsigned int index)
58 inline const float& operator[](
unsigned int index)
const 73 float mx( x ), my( y ), mz( z ), mw( w );
74 float qx(q.x), qy(q.y), qz(q.z), qw(q.w);
76 x = mw * qx + mx * qw + my * qz - mz * qy;
77 y = mw * qy - mx * qz + my * qw + mz * qx;
78 z = mw * qz + mx * qy - my * qx + mz * qw;
79 w = mw * qw - mx * qx - my * qy - mz * qz;
90 inline void operator*=(
const CalVector& v)
98 x = qw * v.x + qy * v.z - qz * v.y;
99 y = qw * v.y - qx * v.z + qz * v.x;
100 z = qw * v.z + qx * v.y - qy * v.x;
101 w = - qx * v.x - qy * v.y - qz * v.z;
104 inline void operator*=(
float s )
122 return !operator==(rhs);
138 norm = x * q.x + y * q.y + z * q.z + w * q.w;
150 if(1.0f - norm < 0.000001f)
157 theta = (float) acos(norm);
160 s = (float) (1.0f / sin(theta));
162 inv_d = (float) sin((1.0f - d) * theta) * s;
163 d = (float) sin(d * theta) * s;
171 x = inv_d * x + d * q.x;
172 y = inv_d * y + d * q.y;
173 z = inv_d * z + d * q.z;
174 w = inv_d * w + d * q.w;
184 inline void conjugate()
194 const float norm = (x*x) + (y*y) + (z*z) + (w*w);
196 if (norm == 0.0f)
return;
198 const float inv_norm = 1 / norm;
202 inline void set(
float qx,
float qy,
float qz,
float qw)
210 void compress(
short &s0,
short &s1,
short &s2);
211 void decompress(
short &s0,
short &s1,
short &s2);
236 r.w * q.x + r.x * q.w + r.y * q.z - r.z * q.y,
237 r.w * q.y - r.x * q.z + r.y * q.w + r.z * q.x,
238 r.w * q.z + r.x * q.y - r.y * q.x + r.z * q.w,
239 r.w * q.w - r.x * q.x - r.y * q.y - r.z * q.z
255 float dot = from * to ;
257 dot = (float) sqrt( 2*(dot+1) ) ;
263 return CalQuaternion( cross[0], cross[1], cross[2], -dot/2 ) ;
The vector class.
Definition: vector.h:36
The quaternion class.
Definition: quaternion.h:35