d3dx8: Implement D3DXQuaternionInverse.

This commit is contained in:
David Adam 2007-11-19 16:18:09 +01:00 committed by Alexandre Julliard
parent 45b13a6cab
commit 54e8d08e45
4 changed files with 37 additions and 3 deletions

View File

@ -55,7 +55,7 @@
@ stub D3DXQuaternionRotationYawPitchRoll @ stub D3DXQuaternionRotationYawPitchRoll
@ stdcall D3DXQuaternionMultiply(ptr ptr ptr) @ stdcall D3DXQuaternionMultiply(ptr ptr ptr)
@ stdcall D3DXQuaternionNormalize(ptr ptr) @ stdcall D3DXQuaternionNormalize(ptr ptr)
@ stub D3DXQuaternionInverse @ stdcall D3DXQuaternionInverse(ptr ptr)
@ stub D3DXQuaternionLn @ stub D3DXQuaternionLn
@ stub D3DXQuaternionExp @ stub D3DXQuaternionExp
@ stub D3DXQuaternionSlerp @ stub D3DXQuaternionSlerp

View File

@ -581,7 +581,31 @@ D3DXPLANE* WINAPI D3DXPlaneTransform(D3DXPLANE *pout, CONST D3DXPLANE *pplane, C
/*_________________D3DXQUATERNION________________*/ /*_________________D3DXQUATERNION________________*/
D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION * pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION * pq2) D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq)
{
D3DXQUATERNION temp;
FLOAT norm;
norm = D3DXQuaternionLengthSq(pq);
if ( !norm )
{
pout->x = 0.0f;
pout->y = 0.0f;
pout->z = 0.0f;
pout->w = 0.0f;
}
else
{
D3DXQuaternionConjugate(&temp, pq);
pout->x = temp.x / norm;
pout->y = temp.y / norm;
pout->z = temp.z / norm;
pout->w = temp.w / norm;
}
return pout;
}
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;
pout->y = pq2->w * pq1->y - pq2->x * pq1->z + pq2->y * pq1->w + pq2->z * pq1->x; pout->y = pq2->w * pq1->y - pq2->x * pq1->z + pq2->y * pq1->w + pq2->z * pq1->x;

View File

@ -591,6 +591,15 @@ static void D3X8QuaternionTest(void)
funcpointer = D3DXQuaternionIdentity(NULL); funcpointer = D3DXQuaternionIdentity(NULL);
ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer); ok(funcpointer == NULL, "Expected: %p, Got: %p\n", NULL, funcpointer);
/*_______________D3DXQuaternionInverse________________________*/
expectedquat.x = -1.0f/121.0f; expectedquat.y = -2.0f/121.0f; expectedquat.z = -4.0f/121.0f; expectedquat.w = 10.0f/121.0f;
D3DXQuaternionInverse(&gotquat,&q);
expect_vec4(expectedquat,gotquat);
/* test the null quaternion */
expectedquat.x = 0.0f; expectedquat.y = 0.0f; expectedquat.z = 0.0f; expectedquat.w = 0.0f;
D3DXQuaternionInverse(&gotquat,&nul);
expect_vec4(expectedquat,gotquat);
/*_______________D3DXQuaternionIsIdentity________________*/ /*_______________D3DXQuaternionIsIdentity________________*/
s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f; s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
expectedbool = TRUE; expectedbool = TRUE;

View File

@ -302,7 +302,8 @@ D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine(D3DXVECTOR3 *pout, CONST D3DXPLANE *p
D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp); D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp);
D3DXPLANE* WINAPI D3DXPlaneTransform(D3DXPLANE *pout, CONST D3DXPLANE *pplane, CONST D3DXMATRIX *pm); D3DXPLANE* WINAPI D3DXPlaneTransform(D3DXPLANE *pout, CONST D3DXPLANE *pplane, CONST D3DXMATRIX *pm);
D3DXQUATERNION* WINAPI D3DXQuaternionMultiply(D3DXQUATERNION * pout, CONST D3DXQUATERNION *pq1, CONST D3DXQUATERNION * pq2); D3DXQUATERNION* WINAPI D3DXQuaternionInverse(D3DXQUATERNION *pout, CONST D3DXQUATERNION *pq);
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);
D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2, CONST D3DXVECTOR2 *pv3, FLOAT f, FLOAT g); D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2, CONST D3DXVECTOR2 *pv3, FLOAT f, FLOAT g);