patch [12/15]: Implements D3DRMMatrixFromQuaternion [resend try 2]

David.Adam at math.cnrs.fr David.Adam at math.cnrs.fr
Thu Apr 19 14:12:40 CDT 2007


-------------- next part --------------
>From 4b19cf7acfaec11163ed0daab2f893cb25c2fecc Mon Sep 17 00:00:00 2001
From: Adam <David.Adam at math.cnrs.fr>
Date: Fri, 20 Apr 2007 03:23:50 +0200
Subject: [PATCH] Implements D3DRMMAtrixFromQuaternion with test.

---
 dlls/d3drm/d3drm.spec     |    2 +-
 dlls/d3drm/math.c         |   12 ++++++++++++
 dlls/d3drm/tests/vector.c |   32 ++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletions(-)

diff --git a/dlls/d3drm/d3drm.spec b/dlls/d3drm/d3drm.spec
index 0010468..7a9d8e5 100644
--- a/dlls/d3drm/d3drm.spec
+++ b/dlls/d3drm/d3drm.spec
@@ -4,7 +4,7 @@
 @ stub D3DRMColorGetRed
 @ stub D3DRMCreateColorRGB
 @ stub D3DRMCreateColorRGBA
-@ stub D3DRMMatrixFromQuaternion
+@ stdcall D3DRMMatrixFromQuaternion(ptr ptr)
 @ stub D3DRMQuaternionFromRotation
 @ stub D3DRMQuaternionMultiply
 @ stub D3DRMQuaternionSlerp
diff --git a/dlls/d3drm/math.c b/dlls/d3drm/math.c
index fd2df81..ab93757 100644
--- a/dlls/d3drm/math.c
+++ b/dlls/d3drm/math.c
@@ -31,6 +31,18 @@ #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
 
+/* Matrix for the Rotation that a unit quaternion represents */
+void WINAPI D3DRMMatrixFromQuaternion(D3DRMMATRIX4D m, LPD3DRMQUATERNION q)
+{
+    D3DVALUE w,x,y,z;
+    w=q->s; x=(q->v).x; y=(q->v).y; z=(q->v).z;
+    m[0][0]=1.0-2.0*(y*y+z*z); m[1][1]=1.0-2.0*(x*x+z*z); m[2][2]=1.0-2.0*(x*x+y*y);
+    m[1][0]=2.0*(x*y+z*w); m[0][1]=2.0*(x*y-z*w);
+    m[2][0]=2.0*(x*z-y*w); m[0][2]=2.0*(x*z+y*w);
+    m[2][1]=2.0*(y*z+x*w); m[1][2]=2.0*(y*z-x*w);
+    m[3][0]=0.0; m[3][1]=0.0; m[3][2]=0.0; m[0][3]=0.0; m[1][3]=0.0; m[2][3]=0.0; m[3][3]=1.0;
+}
+
 /* Add Two Vectors */
 LPD3DVECTOR WINAPI D3DRMVectorAdd(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DVECTOR s2)
 {
diff --git a/dlls/d3drm/tests/vector.c b/dlls/d3drm/tests/vector.c
index c7419fe..63074df 100644
--- a/dlls/d3drm/tests/vector.c
+++ b/dlls/d3drm/tests/vector.c
@@ -25,6 +25,22 @@ #include <math.h>
 #define PI 4*atan(1.0)
 #define admit_error 0.000001
 
+#define expect_mat( expectedmat, gotmat)\
+{ \
+   int i,j,equal=1; \
+    for (i=0; i<4; i++)\
+        {\
+         for (j=0; j<4; j++)\
+             {\
+              if (fabs(expectedmat[i][j]-gotmat[i][j])>admit_error)\
+                 {\
+                  equal=0;\
+                 }\
+             }\
+        }\
+    ok(equal, "Expected matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n)\n\n Got matrix=\n(%f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f\n %f,%f,%f,%f)\n",expectedmat[0][0],expectedmat[0][1],expectedmat[0][2],expectedmat[0][3],expectedmat[1][0],expectedmat[1][1],expectedmat[1][2],expectedmat[1][3],expectedmat[2][0],expectedmat[2][1],expectedmat[2][2],expectedmat[2][3],expectedmat[3][0],expectedmat[3][1],expectedmat[3][2],expectedmat[3][3],gotmat[0][0],gotmat[0][1],gotmat[0][2],gotmat[0][3],gotmat[1][0],gotmat[1][1],gotmat[1][2],gotmat[1][3],gotmat[2][0],gotmat[2][1],gotmat[2][2],gotmat[2][3],gotmat[3][0],gotmat[3][1],gotmat[3][2],gotmat[3][3]);\
+}\
+
 #define expect_vec(expectedvec,gotvec) \
   ok( ((fabs(expectedvec.x-gotvec.x)<admit_error)&&(fabs(expectedvec.y-gotvec.y)<admit_error)&&(fabs(expectedvec.z-gotvec.z)<admit_error)), \
   "Expected Vector= (%f, %f, %f)\n , Got Vector= (%f, %f, %f)\n", \
@@ -101,7 +117,23 @@ void VectorTest(void)
     expect_vec(e,r);
 }
 
+void MatrixTest(void)
+{
+    D3DRMQUATERNION q;
+    D3DRMMATRIX4D exp,mat;
+
+    exp[0][0]=-49.0; exp[0][1]=4.0;   exp[0][2]=22.0;  exp[0][3]=0.0;
+    exp[1][0]=20.0;  exp[1][1]=-39.0; exp[1][2]=20.0;  exp[1][3]=0.0;
+    exp[2][0]=10.0;  exp[2][1]=28.0;  exp[2][2]=-25.0; exp[2][3]=0.0;
+    exp[3][0]=0.0;   exp[3][1]=0.0;   exp[3][2]=0.0;   exp[3][3]=1.0;
+    q.s=1.0; q.v.x=2.0; q.v.y=3.0; q.v.z=4.0;
+
+   D3DRMMatrixFromQuaternion(mat,&q);
+   expect_mat(exp,mat);
+}
+
 START_TEST(vector)
 {
     VectorTest();
+    MatrixTest();
 }
-- 
1.4.2



More information about the wine-patches mailing list