62#define SLERP_EPSILON 0.001
64static int _nxt[3] = { 1 , 2 , 0 };
70static float project_to_sphere(
float,
float,
float);
114 float len2=
X *
X +
Y *
Y +
Z *
Z +
W *
W;
141 float cos_t = qto.
X *
X + qto.
Y *
Y + qto.
Z *
Z + qto.
W *
W;
178 if ((x0 == x1) && (y0 == y1)) {
187 p1[2] = project_to_sphere(sphsize, x0, y0);
191 p2[2] = project_to_sphere(sphsize, x1, y1);
199 t = d.
Length() / (2.0f * sphsize);
202 if (t > 1.0f) t = 1.0f;
203 if (t < -1.0f) t = -1.0f;
255#pragma warning (disable : 4725)
257#define ARC_TABLE_SIZE_MASK 1023
258#define SIN_TABLE_SIZE_MASK 1023
290 fld dword ptr [esi+08h]
291 fmul dword ptr [edi+08h]
292 fld dword ptr [esi+04h]
293 fmul dword ptr [edi+04h]
294 fld dword ptr [edi+0ch]
295 fmul dword ptr [esi+0ch]
339 fld HalfOfSinTableSize
340 fld HalfOfArcTableSize
344 add eax,ARC_TABLE_SIZE_PER_2
351 mov eax,ARC_TABLE_SIZE_MASK
359 mov ecx,SIN_TABLE_SIZE_MASK
409 fld dword ptr [edi+4]
411 fld dword ptr [edi+8]
413 fld dword ptr [edi+12]
419 fld dword ptr [esi+4]
421 fld dword ptr [esi+8]
426 fmul dword ptr [esi+12]
450 cos_t = p.
X *
q.X + p.
Y *
q.Y + p.
Z *
q.Z + p.
W *
q.W;
470 oo_sin_t = 1.0f / sin_t;
479 res.
X = beta*p.
X + alpha*
q.X;
480 res.
Y = beta*p.
Y + alpha*
q.Y;
481 res.
Z = beta*p.
Z + alpha*
q.Z;
482 res.
W = beta*p.
W + alpha*
q.W;
497 cos_t = p.
X *
q.X + p.
Y *
q.Y + p.
Z *
q.Z + p.
W *
q.W;
518 oo_sin_t = 1.0f / sin_t;
519 beta =
WWMath::Sin(theta - alpha*theta) * oo_sin_t;
527 res.
X = beta*p.
X + alpha*
q.X;
528 res.
Y = beta*p.
Y + alpha*
q.Y;
529 res.
Z = beta*p.
Z + alpha*
q.Z;
530 res.
W = beta*p.
W + alpha*
q.W;
549 assert(slerpinfo !=
NULL);
552 cos_t = p.
X *
q.X + p.
Y *
q.Y + p.
Z *
q.Z + p.
W *
q.W;
557 slerpinfo->
Flip =
true;
559 slerpinfo->
Flip =
false;
565 slerpinfo->
Theta = 0.0f;
566 slerpinfo->
SinT = 0.0f;
570 slerpinfo->
Linear =
false;
603 oo_sin_t = 1.0f / slerpinfo->
Theta;
608 if (slerpinfo->
Flip) {
613 res.
X = beta*p.
X + alpha*
q.X;
614 res.
Y = beta*p.
Y + alpha*
q.Y;
615 res.
Z = beta*p.
Z + alpha*
q.Z;
616 res.
W = beta*p.
W + alpha*
q.W;
635 oo_sin_t = 1.0f / slerpinfo->
Theta;
640 if (slerpinfo->
Flip) {
644 set_q->
X = beta*p.
X + alpha*
q.X;
645 set_q->
Y = beta*p.
Y + alpha*
q.Y;
646 set_q->
Z = beta*p.
Z + alpha*
q.Z;
647 set_q->
W = beta*p.
W + alpha*
q.W;
670 tr = mat[0][0] + mat[1][1] + mat[2][2];
678 q[0] = (mat[2][1] - mat[1][2]) * s;
679 q[1] = (mat[0][2] - mat[2][0]) * s;
680 q[2] = (mat[1][0] - mat[0][1]) * s;
685 if (mat[1][1] > mat[0][0]) i = 1;
686 if (mat[2][2] > mat[i][i]) i = 2;
690 s = sqrt((mat[i][i] - (mat[j][j] + mat[k][k])) + 1.0);
697 q[3] = ( mat[k][j] - mat[j][k] ) * s;
698 q[j] = ( mat[j][i] + mat[i][j] ) * s;
699 q[k] = ( mat[k][i] + mat[i][k] ) * s;
713 tr = mat[0][0] + mat[1][1] + mat[2][2];
721 q[0] = (mat[2][1] - mat[1][2]) * s;
722 q[1] = (mat[0][2] - mat[2][0]) * s;
723 q[2] = (mat[1][0] - mat[0][1]) * s;
728 if (mat[1][1] > mat[0][0]) i = 1;
729 if (mat[2][2] > mat[i][i]) i = 2;
734 s = sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0);
742 q[3] = ( mat[k][j] - mat[j][k] ) * s;
743 q[j] = ( mat[j][i] + mat[i][j] ) * s;
744 q[k] = ( mat[k][i] + mat[i][k] ) * s;
757 tr = mat[0][0] + mat[1][1] + mat[2][2];
765 q[0] = (mat[2][1] - mat[1][2]) * s;
766 q[1] = (mat[0][2] - mat[2][0]) * s;
767 q[2] = (mat[1][0] - mat[0][1]) * s;
772 if (mat[1][1] > mat[0][0]) i = 1;
773 if (mat[2][2] > mat[i][i]) i = 2;
778 s = sqrt( (mat[i][i] - (mat[j][j]+mat[k][k])) + 1.0);
784 q[3] = ( mat[k][j] - mat[j][k] ) * s;
785 q[j] = ( mat[j][i] + mat[i][j] ) * s;
786 q[k] = ( mat[k][i] + mat[i][k] ) * s;
809 m[0][0] = (float)(1.0 - 2.0 * (
q[1] *
q[1] +
q[2] *
q[2]));
810 m[0][1] = (float)(2.0 * (
q[0] *
q[1] -
q[2] *
q[3]));
811 m[0][2] = (float)(2.0 * (
q[2] *
q[0] +
q[1] *
q[3]));
813 m[1][0] = (float)(2.0 * (
q[0] *
q[1] +
q[2] *
q[3]));
814 m[1][1] = (float)(1.0 - 2.0f * (
q[2] *
q[2] +
q[0] *
q[0]));
815 m[1][2] = (float)(2.0 * (
q[1] *
q[2] -
q[0] *
q[3]));
817 m[2][0] = (float)(2.0 * (
q[2] *
q[0] -
q[1] *
q[3]));
818 m[2][1] = (float)(2.0 * (
q[1] *
q[2] +
q[0] *
q[3]));
819 m[2][2] =(float)(1.0 - 2.0 * (
q[1] *
q[1] +
q[0] *
q[0]));
829 m[0][0] = (float)(1.0 - 2.0 * (
q[1] *
q[1] +
q[2] *
q[2]));
830 m[0][1] = (float)(2.0 * (
q[0] *
q[1] -
q[2] *
q[3]));
831 m[0][2] = (float)(2.0 * (
q[2] *
q[0] +
q[1] *
q[3]));
833 m[1][0] = (float)(2.0 * (
q[0] *
q[1] +
q[2] *
q[3]));
834 m[1][1] = (float)(1.0 - 2.0f * (
q[2] *
q[2] +
q[0] *
q[0]));
835 m[1][2] = (float)(2.0 * (
q[1] *
q[2] -
q[0] *
q[3]));
837 m[2][0] = (float)(2.0 * (
q[2] *
q[0] -
q[1] *
q[3]));
838 m[2][1] = (float)(2.0 * (
q[1] *
q[2] +
q[0] *
q[3]));
839 m[2][2] = (float)(1.0 - 2.0 * (
q[1] *
q[1] +
q[0] *
q[0]));
842 m[0][3] = m[1][3] = m[2][3] = 0.0f;
845 m[3][0] = m[3][1] = m[3][2] = 0.0f;
868float project_to_sphere(
float r,
float x,
float y)
870 const float SQRT2 = 1.41421356f;
874 if (d < r * (SQRT2/(2.0f)))
887 X = ((float) (rand() & 0xFFFF)) / 65536.0f;
888 Y = ((float) (rand() & 0xFFFF)) / 65536.0f;
889 Z = ((float) (rand() & 0xFFFF)) / 65536.0f;
890 W = ((float) (rand() & 0xFFFF)) / 65536.0f;
float _FastInvSinTable[SIN_TABLE_SIZE]
float _FastAcosTable[ARC_TABLE_SIZE]
float _FastSinTable[SIN_TABLE_SIZE]
void add(float *sum, float *addend)
WWINLINE Quaternion(void)
void Rotate_Y(float theta)
Quaternion & Make_Closest(const Quaternion &qto)
void Rotate_X(float theta)
void Rotate_Z(float theta)
WWINLINE float Length(void) const
static WWINLINE void Cross_Product(const Vector3 &a, const Vector3 &b, Vector3 *result)
static WWINLINE float Asin(float val)
static float Sqrt(float val)
static WWINLINE float Fast_Sin(float val)
static float Inv_Sqrt(float a)
static WWINLINE float Acos(float val)
static float Sin(float val)
static WWINLINE float Fast_Acos(float val)
static float Cos(float val)
Quaternion Cached_Slerp(const Quaternion &p, const Quaternion &q, float alpha, SlerpInfoStruct *slerpinfo)
void Slerp(Quaternion &res, const Quaternion &p, const Quaternion &q, float alpha)
void Slerp_Setup(const Quaternion &p, const Quaternion &q, SlerpInfoStruct *slerpinfo)
Quaternion Build_Quaternion(const Matrix3D &mat)
Matrix4x4 Build_Matrix4(const Quaternion &q)
Quaternion Trackball(float x0, float y0, float x1, float y1, float sphsize)
Quaternion Axis_To_Quat(const Vector3 &a, float phi)
Matrix3x3 Build_Matrix3(const Quaternion &q)
void __cdecl Fast_Slerp(Quaternion &res, const Quaternion &p, const Quaternion &q, float alpha)