patch [13/15]: Implements D3DRMQuaternionFromRotation [try2]

David.Adam at math.cnrs.fr David.Adam at math.cnrs.fr
Thu Apr 19 14:13:51 CDT 2007


-------------- next part --------------
>From 90a9e43a8614e1ae99d7dd71b3c0d29d39b52f42 Mon Sep 17 00:00:00 2001
From: Adam <David.Adam at math.cnrs.fr>
Date: Fri, 20 Apr 2007 03:29:09 +0200
Subject: [PATCH] Implements D3DRMQuaternionFromRotation with test.

---
 dlls/d3drm/d3drm.spec     |    2 +-
 dlls/d3drm/math.c         |    8 ++++++++
 dlls/d3drm/tests/vector.c |   21 +++++++++++++++++++++
 3 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/dlls/d3drm/d3drm.spec b/dlls/d3drm/d3drm.spec
index 7a9d8e5..8ae3687 100644
--- a/dlls/d3drm/d3drm.spec
+++ b/dlls/d3drm/d3drm.spec
@@ -5,7 +5,7 @@
 @ stub D3DRMCreateColorRGB
 @ stub D3DRMCreateColorRGBA
 @ stdcall D3DRMMatrixFromQuaternion(ptr ptr)
-@ stub D3DRMQuaternionFromRotation
+@ stdcall D3DRMQuaternionFromRotation(ptr ptr long)
 @ stub D3DRMQuaternionMultiply
 @ stub D3DRMQuaternionSlerp
 @ stdcall D3DRMVectorAdd(ptr ptr ptr)
diff --git a/dlls/d3drm/math.c b/dlls/d3drm/math.c
index ab93757..73d4e26 100644
--- a/dlls/d3drm/math.c
+++ b/dlls/d3drm/math.c
@@ -43,6 +43,14 @@ void WINAPI D3DRMMatrixFromQuaternion(D3
     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;
 }
 
+/* Returns a unit quaternion that represents a rotation of an angle around an axis */
+LPD3DRMQUATERNION WINAPI D3DRMQuaternionFromRotation(LPD3DRMQUATERNION q, LPD3DVECTOR v, D3DVALUE theta)
+{
+    q->s=cos(theta/2.0);
+    D3DRMVectorScale(&(q->v),D3DRMVectorNormalize(v),sin(theta/2.0));
+    return q;
+}
+
 /* 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 63074df..7b5f4ec 100644
--- a/dlls/d3drm/tests/vector.c
+++ b/dlls/d3drm/tests/vector.c
@@ -41,6 +41,12 @@ #define expect_mat( expectedmat, gotmat)
     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_quat(expectedquat,gotquat) \
+  ok( (fabs(expectedquat.v.x-gotquat.v.x)<admit_error)&&(fabs(expectedquat.v.y-gotquat.v.y)<admit_error)&&(fabs(expectedquat.v.z-gotquat.v.z)<admit_error)&&(fabs(expectedquat.s-gotquat.s)<admit_error), \
+  "Expected Quaternion %f %f %f %f , Got Quaternion %f %f %f %f\n", \
+  expectedquat.s,expectedquat.v.x,expectedquat.v.y,expectedquat.v.z, \
+  gotquat.s,gotquat.v.x,gotquat.v.y,gotquat.v.z);
+
 #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", \
@@ -132,8 +138,23 @@ void MatrixTest(void)
    expect_mat(exp,mat);
 }
 
+void QuaternionTest(void)
+{
+    D3DVECTOR axis;
+    D3DVALUE theta;
+    D3DRMQUATERNION q,r;
+
+/*_________________QuaternionFromRotation___________________*/
+    axis.x=1.0;axis.y=1.0;axis.z=1.0;
+    theta=2.0*PI/3.0;
+    D3DRMQuaternionFromRotation(&r,&axis,theta);
+    q.s=0.5;q.v.x=0.5;q.v.y=0.5;q.v.z=0.5;
+    expect_quat(q,r);
+}
+
 START_TEST(vector)
 {
     VectorTest();
     MatrixTest();
+    QuaternionTest();
 }
-- 
1.4.2



More information about the wine-patches mailing list