d3dx8: Implement D3DXQuaternionLn.

This commit is contained in:
David Adam 2007-11-21 14:34:32 +01:00 committed by Alexandre Julliard
parent 16a8efa410
commit 41029cc88c
4 changed files with 48 additions and 3 deletions

View File

@ -56,7 +56,7 @@
@ stdcall D3DXQuaternionMultiply(ptr ptr ptr) @ stdcall D3DXQuaternionMultiply(ptr ptr ptr)
@ stdcall D3DXQuaternionNormalize(ptr ptr) @ stdcall D3DXQuaternionNormalize(ptr ptr)
@ stdcall D3DXQuaternionInverse(ptr ptr) @ stdcall D3DXQuaternionInverse(ptr ptr)
@ stub D3DXQuaternionLn @ stdcall D3DXQuaternionLn(ptr ptr)
@ stub D3DXQuaternionExp @ stub D3DXQuaternionExp
@ stdcall D3DXQuaternionSlerp(ptr ptr ptr long) @ stdcall D3DXQuaternionSlerp(ptr ptr ptr long)
@ stdcall D3DXQuaternionSquad(ptr ptr ptr ptr ptr long) @ stdcall D3DXQuaternionSquad(ptr ptr ptr ptr ptr long)

View File

@ -612,6 +612,34 @@ D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3DXQUA
return pout; return pout;
} }
D3DXQUATERNION* WINAPI D3DXQuaternionLn(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq)
{
FLOAT norm, normvec, theta;
norm = D3DXQuaternionLengthSq(pq);
if ( norm > 1.0001f )
{
pout->x = pq->x;
pout->y = pq->y;
pout->z = pq->z;
pout->w = 0.0f;
}
else if( norm > 0.99999f)
{
normvec = sqrt( pq->x * pq->x + pq->y * pq->y + pq->z * pq->z );
theta = atan2(normvec, pq->w) / normvec;
pout->x = theta * pq->x;
pout->y = theta * pq->y;
pout->z = theta * pq->z;
pout->w = 0.0f;
}
else
{
FIXME("The quaternion (%f, %f, %f, %f) has a norm <1. This should not happen. Windows returns a result anyway. This case is not implemented yet.\n", pq->x, pq->y, pq->z, pq->w);
}
return pout;
}
D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2) D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2)
{ {
pout->x = pq2->w * pq1->x + pq2->x * pq1->w + pq2->y * pq1->z - pq2->z * pq1->y; pout->x = pq2->w * pq1->x + pq2->x * pq1->w + pq2->y * pq1->z - pq2->z * pq1->y;

View File

@ -553,7 +553,7 @@ static void D3DXPlaneTest(void)
static void D3X8QuaternionTest(void) static void D3X8QuaternionTest(void)
{ {
D3DXMATRIX mat; D3DXMATRIX mat;
D3DXQUATERNION expectedquat, gotquat, Nq, nul, q, r, s, t, u; D3DXQUATERNION expectedquat, gotquat, Nq, Nq1, nul, 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;
@ -643,6 +643,23 @@ static void D3X8QuaternionTest(void)
got = D3DXQuaternionLengthSq(NULL); got = D3DXQuaternionLengthSq(NULL);
ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got); ok(fabs( got - expected ) < admitted_error, "Expected: %f, Got: %f\n", expected, got);
/*_______________D3DXQuaternionLn______________________________*/
expectedquat.x = 1.0f; expectedquat.y = 2.0f; expectedquat.z = 4.0f; expectedquat.w = 0.0f;
D3DXQuaternionLn(&gotquat,&q);
expect_vec4(expectedquat,gotquat);
expectedquat.x = -3.0f; expectedquat.y = 4.0f; expectedquat.z = -5.0f; expectedquat.w = 0.0f;
D3DXQuaternionLn(&gotquat,&r);
expect_vec4(expectedquat,gotquat);
Nq.x = 1.0f/11.0f; Nq.y = 2.0f/11.0f; Nq.z = 4.0f/11.0f; Nq.w=10.0f/11.0f;
expectedquat.x = 0.093768f; expectedquat.y = 0.187536f; expectedquat.z = 0.375073f; expectedquat.w = 0.0f;
D3DXQuaternionLn(&gotquat,&Nq);
expect_vec4(expectedquat,gotquat);
/* Test the cas where the norm of the quaternion is <1 */
Nq1.x = 0.2f; Nq1.y = 0.1f; Nq1.z = 0.3; Nq1.w= 0.9f;
expectedquat.x = 0.206945f; expectedquat.y = 0.103473f; expectedquat.z = 0.310418f; expectedquat.w = 0.0f;
D3DXQuaternionLn(&gotquat,&Nq1);
todo_wine{ expect_vec4(expectedquat,gotquat) };
/*_______________D3DXQuaternionMultiply________________________*/ /*_______________D3DXQuaternionMultiply________________________*/
expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f; expectedquat.x = 3.0f; expectedquat.y = 61.0f; expectedquat.z = -32.0f; expectedquat.w = 85.0f;
D3DXQuaternionMultiply(&gotquat,&q,&r); D3DXQuaternionMultiply(&gotquat,&q,&r);
@ -706,7 +723,6 @@ static void D3X8QuaternionTest(void)
D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,D3DX_PI/3.0f); D3DXQuaternionRotationYawPitchRoll(&gotquat,D3DX_PI/4.0f,D3DX_PI/11.0f,D3DX_PI/3.0f);
expect_vec4(expectedquat,gotquat); expect_vec4(expectedquat,gotquat);
/*_______________D3DXQuaternionSlerp________________________*/ /*_______________D3DXQuaternionSlerp________________________*/
expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f; expectedquat.x = -0.2f; expectedquat.y = 2.6f; expectedquat.z = 1.3f; expectedquat.w = 9.1f;
D3DXQuaternionSlerp(&gotquat,&q,&r,scale); D3DXQuaternionSlerp(&gotquat,&q,&r,scale);

View File

@ -304,6 +304,7 @@ D3DXPLANE* WINAPI D3DXPlaneTransform(D3DXPLANE *pout, CONST D3DXPLANE *pplane, C
D3DXQUATERNION* WINAPI D3DXQuaternionBaryCentric(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2, CONST D3DXQUATERNION *pq3, FLOAT f, FLOAT g); D3DXQUATERNION* WINAPI D3DXQuaternionBaryCentric(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2, CONST D3DXQUATERNION *pq3, FLOAT f, FLOAT g);
D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq); D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq);
D3DXQUATERNION* WINAPI D3DXQuaternionLn(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq);
D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2); D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION *pq2);
D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq); D3DXQUATERNION* WINAPI D3DXQuaternionNormalize(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq);
D3DXQUATERNION* WINAPI D3DXQuaternionRotationAxis(D3DXQUATERNION *pout, CONST D3DXVECTOR3 *pv, FLOAT angle); D3DXQUATERNION* WINAPI D3DXQuaternionRotationAxis(D3DXQUATERNION *pout, CONST D3DXVECTOR3 *pv, FLOAT angle);