1 #include "..\include\raMain.h" 5 static float factorial(
float p)
7 if ( p == 0.0f || p == 1.0f )
return 1.0f;
8 else if ( p < 0.0f )
return 0.0f;
22 float cos_z_2 = cosf(0.5f*(
float)angles.
z);
23 float cos_y_2 = cosf(0.5f*(
float)angles.
y);
24 float cos_x_2 = cosf(0.5f*(
float)angles.
x);
26 float sin_z_2 = sinf(0.5f*(
float)angles.
z);
27 float sin_y_2 = sinf(0.5f*(
float)angles.
y);
28 float sin_x_2 = sinf(0.5f*(
float)angles.
x);
31 s = cos_z_2*cos_y_2*cos_x_2 + sin_z_2*sin_y_2*sin_x_2;
32 v.x = cos_z_2*cos_y_2*sin_x_2 - sin_z_2*sin_y_2*cos_x_2;
33 v.y = cos_z_2*sin_y_2*cos_x_2 + sin_z_2*cos_y_2*sin_x_2;
34 v.z = sin_z_2*cos_y_2*cos_x_2 - cos_z_2*sin_y_2*sin_x_2;
56 float tmp = fabs(mat(1,1) + mat(2,2) + mat(3,3) + 1);
61 v.x = (mat.
n[9]-mat.
n[6])/(4*s);
62 v.y = (mat.
n[2]-mat.
n[8])/(4*s);
63 v.z = (mat.
n[4]-mat.
n[1])/(4*s);
68 static int s_iNext[3] = { 2, 3, 1 };
70 if ( mat(2,2) > mat(1,1) )
72 if ( mat(3,3) > mat(2,2) )
77 float fRoot = sqrt(mat(i,i)-mat(j,j)-mat(k,k) + 1.0f);
79 float *tmp[3] = { (
float*)&v.x, (
float*)&v.y, (
float*)&v.z };
80 *tmp[i-1] = 0.5f*fRoot;
82 s = (mat(k,j)-mat(j,k))*fRoot;
83 *tmp[j-1] = (mat(j,i)+mat(i,j))*fRoot;
84 *tmp[k-1] = (mat(k,i)+mat(i,k))*fRoot;
100 s/=f; v.x/=f; v.y/=f; v.z/=f;
return *
this;
104 s*=f; v.x*=f; v.y*=f; v.z*=f;
return *
this;
108 float sinThetaOver2Sq = 1.0f - s*s;
110 if (sinThetaOver2Sq <= 0.0f)
117 float oneOverSinThetaOver2 = 1.0f / sqrt(sinThetaOver2Sq);
122 (
float)v.x * oneOverSinThetaOver2,
123 (
float)v.y * oneOverSinThetaOver2,
124 (
float)v.z * oneOverSinThetaOver2
129 float thetaOver2 = acos(s);
130 return thetaOver2 * 2.0f;
140 Mul = sin(Length)/Length;
144 temp.
s = cos(Length);
158 Length = atan(Length/temp.
s);
180 float recip = 1.0f/norme;
196 if (fabs(s) > FLT_EPSILON)
204 omega = -0.5f * Angle;
205 s = (float)sin(omega);
207 temp.
v =
raVector3(s*(
float)Axis.
x, s*(
float)Axis.
y, s*(
float)Axis.
z);
208 temp.
s = (float)cos(omega);
276 qtmp.
s = ((a.
s * b.
s) - (
float)(a.
v.
x * b.
v.
x) - (
float)(a.
v.
y * b.
v.
z) - (
float)(a.
v.
z * b.
v.
z));
277 qtmp.
v.
x = ((a.
s * (float)b.
v.
x) + ((float)a.
v.
x * b.
s) + ((float)a.
v.
y * (
float)b.
v.
y) - ((
float)a.
v.
z * (float)b.
v.
y));
278 qtmp.
v.
y = ((a.
s * (float)b.
v.
y) - ((float)a.
v.
x * (
float)b.
v.
z) + ((
float)a.
v.
y * b.
s) + ((
float)a.
v.
z * (float)b.
v.
x));
279 qtmp.
v.
z = ((a.
s * (float)b.
v.
z) + ((float)a.
v.
x * (
float)b.
v.
y) - ((
float)a.
v.
y * (float)b.
v.
x) + ((float)a.
v.
z * b.
s));
305 if (t <= 0.0f)
return q0;
306 if (t >= 1.0f)
return q1;
314 if (cosOmega < 0.0f) {
319 cosOmega = -cosOmega;
322 assert(cosOmega < 1.1f);
328 if (cosOmega > 0.9999f)
336 float sinOmega = sqrt(1.0f - cosOmega*cosOmega);
340 float omega = atan2(sinOmega, cosOmega);
345 float oneOverSinOmega = 1.0f / sinOmega;
349 k0 = sin((1.0f - t) * omega) * oneOverSinOmega;
350 k1 = sin(t * omega) * oneOverSinOmega;
356 result.
v.
x = k0*(float)q0.
v.
x + k1*q1x;
357 result.
v.
y = k0*(
float)q0.
v.
y + k1*q1y;
358 result.
v.
z = k0*(float)q0.
v.
z + k1*q1z;
359 result.
s = k0*q0.
s + k1*q1w;
367 if (fabs(v.
s) > .9999f)
373 float alpha = acos(v.
s);
376 float newAlpha = alpha * Exp;
380 result.
s = cos(newAlpha);
384 float mult = sin(newAlpha) / sin(alpha);
385 result.
v.
x = (float)v.
v.
x * mult;
386 result.
v.
y = (
float)v.
v.
y * mult;
387 result.
v.
z = (float)v.
v.
z * mult;
393 return a.
s*b.
s + (float)a.
v.
x*(
float)b.
v.
x + (float)a.
v.
y*(
float)b.
v.
y + (float)a.
v.
z*(
float)b.
v.
z;
409 if ( degree == 0 )
return raQuaternion(1.0f, 0.0f, 0.0f, 0.0f);
413 for (
float f = 1 ; f < abs(degree) ; f++ )
418 if ( degree < 0 )
return ( 1.0f / tmp_qu );
426 for(
float n = 0; n < 6.0f; n++ )
428 s += pow( -1.0f ,n ) * (
raQuaternionPower( q , 2.0f * n + 1.0f ) ) / ( factorial( 2.0f * n + 1.0f ) );
437 for(
float n = 1.0f; n <= 6.0f; n++ )
439 s += pow( -1.0f ,n ) *
raQuaternionPower( q , 2.0f * n ) / factorial( 2.0f * n ) ;
float raQuaternionLenght(const raQuaternion &v)
RAPI raQuaternion raQuaternionCos(const raQuaternion &q)
RAPI raQuaternion raQuaternionSlerp(const raQuaternion &q0, const raQuaternion &q1, float t)
raQuaternion & operator*=(const raQuaternion &q)
RAPI raQuaternion raQuaternionInvert(const raQuaternion &q)
raQuaternion & operator/=(const raQuaternion &q)
RAPI float raQuaternionDot(const raQuaternion &a, const raQuaternion &b)
RAPI raQuaternion operator+(const raQuaternion &a, const raQuaternion &b)
RAPI raMatrix raQuaternionToMatrix(const raQuaternion &v)
raVector3 GetRotationAxis() const
RAPI raQuaternion raQuaternionExp(const raQuaternion &v)
RAPI raQuaternion raQuaternionNormalize(const raQuaternion &v)
RAPI raQuaternion operator-(const raQuaternion &a, const raQuaternion &b)
RAPI raQuaternion raQuaternionPow(const raQuaternion &v, float Exp)
RAPI raQuaternion raQuaternionFromAxis(const float Angle, raVector3 Axis)
RAPI raQuaternion raQuaternionPower(const raQuaternion &qu, float degree)
RAPI raQuaternion raQuaternionLog(const raQuaternion &v)
raFloat raVector3Lenght(const raVector3 &v)
RAPI raQuaternion raQuaternionConjugate(const raQuaternion &v)
float GetRotationAngle() const
RAPI raQuaternion operator*(const raQuaternion &a, const float b)
RAPI raQuaternion operator/(const raQuaternion &a, const raQuaternion &b)
float raQuaternionLenghtSq(const raQuaternion &v)
RAPI raQuaternion raQuaternionCTan(const raQuaternion &q)
RAPI raQuaternion raQuaternionTan(const raQuaternion &q)
RAPI raQuaternion raQuaternionSin(const raQuaternion &q)