Commit 23478625 authored by David Adam's avatar David Adam Committed by Alexandre Julliard

d3dx8: Implement the spherical interpolation part for D3DXQuaternionSlerp.

parent 687ce938
...@@ -1173,15 +1173,27 @@ D3DXQUATERNION* WINAPI D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION *pout, ...@@ -1173,15 +1173,27 @@ D3DXQUATERNION* WINAPI D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION *pout,
D3DXQUATERNION* WINAPI D3DXQuaternionSlerp(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2, FLOAT t) D3DXQUATERNION* WINAPI D3DXQuaternionSlerp(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2, FLOAT t)
{ {
FLOAT dot, epsilon; FLOAT dot, epsilon, temp, theta, u;
epsilon = 1.0f; epsilon = 1.0f;
temp = 1.0f - t;
u = t;
dot = D3DXQuaternionDot(pq1, pq2); dot = D3DXQuaternionDot(pq1, pq2);
if ( dot < 0.0f) epsilon = -1.0f; if ( dot < 0.0f )
pout->x = (1.0f - t) * pq1->x + epsilon * t * pq2->x; {
pout->y = (1.0f - t) * pq1->y + epsilon * t * pq2->y; epsilon = -1.0f;
pout->z = (1.0f - t) * pq1->z + epsilon * t * pq2->z; dot = -dot;
pout->w = (1.0f - t) * pq1->w + epsilon * t * pq2->w; }
if( 1.0f - dot > 0.001f )
{
theta = acos(dot);
temp = sin(theta * temp) / sin(theta);
u = sin(theta * u) / sin(theta);
}
pout->x = temp * pq1->x + epsilon * u * pq2->x;
pout->y = temp * pq1->y + epsilon * u * pq2->y;
pout->z = temp * pq1->z + epsilon * u * pq2->z;
pout->w = temp * pq1->w + epsilon * u * pq2->w;
return pout; return pout;
} }
......
...@@ -582,7 +582,7 @@ static void D3DXPlaneTest(void) ...@@ -582,7 +582,7 @@ static void D3DXPlaneTest(void)
static void D3X8QuaternionTest(void) static void D3X8QuaternionTest(void)
{ {
D3DXMATRIX mat; D3DXMATRIX mat;
D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, q, r, s, t, u; D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, smallq, smallr, q, r, s, t, u;
LPD3DXQUATERNION funcpointer; LPD3DXQUATERNION funcpointer;
D3DXVECTOR3 axis, expectedvec; D3DXVECTOR3 axis, expectedvec;
FLOAT angle, expected, got, scale, scale2; FLOAT angle, expected, got, scale, scale2;
...@@ -591,8 +591,10 @@ static void D3X8QuaternionTest(void) ...@@ -591,8 +591,10 @@ static void D3X8QuaternionTest(void)
nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f; nul.x = 0.0f; nul.y = 0.0f; nul.z = 0.0f; nul.w = 0.0f;
q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f; q.x = 1.0f, q.y = 2.0f; q.z = 4.0f; q.w = 10.0f;
r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0; r.x = -3.0f; r.y = 4.0f; r.z = -5.0f; r.w = 7.0;
t.x = -1111.0f, t.y= 111.0f; t.z = -11.0f; t.w = 1.0f; t.x = -1111.0f, t.y = 111.0f; t.z = -11.0f; t.w = 1.0f;
u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f; u.x = 91.0f; u.y = - 82.0f; u.z = 7.3f; u.w = -6.4f;
smallq.x = 0.1f; smallq.y = 0.2f; smallq.z= 0.3f; smallq.w = 0.4f;
smallr.x = 0.5f; smallr.y = 0.6f; smallr.z= 0.7f; smallq.w = 0.8f;
scale = 0.3f; scale = 0.3f;
scale2 = 0.78f; scale2 = 0.78f;
...@@ -873,6 +875,9 @@ static void D3X8QuaternionTest(void) ...@@ -873,6 +875,9 @@ static void D3X8QuaternionTest(void)
expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f; expectedquat.x = 334.0f; expectedquat.y = -31.9f; expectedquat.z = 6.1f; expectedquat.w = 6.7f;
D3DXQuaternionSlerp(&gotquat,&q,&t,scale); D3DXQuaternionSlerp(&gotquat,&q,&t,scale);
expect_vec4(expectedquat,gotquat); expect_vec4(expectedquat,gotquat);
expectedquat.x = 0.267071f; expectedquat.y = 0.384114f; expectedquat.z = 0.501157f; expectedquat.w = 0.636291f;
D3DXQuaternionSlerp(&gotquat,&smallq,&smallr,scale);
expect_vec4(expectedquat,gotquat);
/*_______________D3DXQuaternionSquad________________________*/ /*_______________D3DXQuaternionSquad________________________*/
expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f; expectedquat.x = -156.296f; expectedquat.y = 30.242f; expectedquat.z = -2.5022f; expectedquat.w = 7.3576f;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment