David Adam : d3dx8: Implement D3DXQuaternionInverse.
Alexandre Julliard
julliard at winehq.org
Tue Nov 20 10:55:00 CST 2007
Module: wine
Branch: master
Commit: 54e8d08e45ea69653cbca8735d9435606d4207ee
URL: http://source.winehq.org/git/wine.git/?a=commit;h=54e8d08e45ea69653cbca8735d9435606d4207ee
Author: David Adam <David.Adam at math.cnrs.fr>
Date: Mon Nov 19 16:18:09 2007 +0100
d3dx8: Implement D3DXQuaternionInverse.
---
dlls/d3dx8/d3dx8.spec | 2 +-
dlls/d3dx8/math.c | 26 +++++++++++++++++++++++++-
dlls/d3dx8/tests/math.c | 9 +++++++++
include/d3dx8math.h | 3 ++-
4 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index ea9d87f..ffa82a8 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -55,7 +55,7 @@
@ stub D3DXQuaternionRotationYawPitchRoll
@ stdcall D3DXQuaternionMultiply(ptr ptr ptr)
@ stdcall D3DXQuaternionNormalize(ptr ptr)
-@ stub D3DXQuaternionInverse
+@ stdcall D3DXQuaternionInverse(ptr ptr)
@ stub D3DXQuaternionLn
@ stub D3DXQuaternionExp
@ stub D3DXQuaternionSlerp
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 242c2b1..99c4a42 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -581,7 +581,31 @@ D3DXPLANE* WINAPI D3DXPlaneTransform(D3DXPLANE *pout, CONST D3DXPLANE *pplane, C
/*_________________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->y = pq2->w * pq1->y - pq2->x * pq1->z + pq2->y * pq1->w + pq2->z * pq1->x;
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index fe9893b..399bf46 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -591,6 +591,15 @@ static void D3X8QuaternionTest(void)
funcpointer = D3DXQuaternionIdentity(NULL);
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________________*/
s.x = 0.0f; s.y = 0.0f; s.z = 0.0f; s.w = 1.0f;
expectedbool = TRUE;
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index 08c7c63..37641ed 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -302,7 +302,8 @@ D3DXVECTOR3* WINAPI D3DXPlaneIntersectLine(D3DXVECTOR3 *pout, CONST D3DXPLANE *p
D3DXPLANE* WINAPI D3DXPlaneNormalize(D3DXPLANE *pout, CONST D3DXPLANE *pp);
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);
D3DXVECTOR2* WINAPI D3DXVec2BaryCentric(D3DXVECTOR2 *pout, CONST D3DXVECTOR2 *pv1, CONST D3DXVECTOR2 *pv2, CONST D3DXVECTOR2 *pv3, FLOAT f, FLOAT g);
More information about the wine-cvs
mailing list