David Adam : d3drm: Implement D3DRMQuaternionFromRotation.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Apr 23 14:26:23 CDT 2007
Module: wine
Branch: master
Commit: 909b5023600bc7432c17cb57e28dce05cef66272
URL: http://source.winehq.org/git/wine.git/?a=commit;h=909b5023600bc7432c17cb57e28dce05cef66272
Author: David Adam <David.Adam at math.cnrs.fr>
Date: Thu Apr 19 21:13:51 2007 +0200
d3drm: Implement D3DRMQuaternionFromRotation.
---
dlls/d3drm/d3drm.spec | 2 +-
dlls/d3drm/math.c | 8 ++++++++
dlls/d3drm/tests/vector.c | 24 ++++++++++++++++++++++++
3 files changed, 33 insertions(+), 1 deletions(-)
diff --git a/dlls/d3drm/d3drm.spec b/dlls/d3drm/d3drm.spec
index a8133ab..8713d01 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)
@ stdcall D3DRMQuaternionMultiply(ptr ptr ptr)
@ stub D3DRMQuaternionSlerp
@ stdcall D3DRMVectorAdd(ptr ptr ptr)
diff --git a/dlls/d3drm/math.c b/dlls/d3drm/math.c
index 714f35f..21a4151 100644
--- a/dlls/d3drm/math.c
+++ b/dlls/d3drm/math.c
@@ -70,6 +70,14 @@ void WINAPI D3DRMMatrixFromQuaternion(D3DRMMATRIX4D m, LPD3DRMQUATERNION q)
m[3][3] = 1.0;
}
+/* Return 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 b71805b..744eb16 100644
--- a/dlls/d3drm/tests/vector.c
+++ b/dlls/d3drm/tests/vector.c
@@ -50,6 +50,15 @@
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", \
@@ -141,8 +150,23 @@ static void MatrixTest(void)
expect_mat(exp,mat);
}
+static 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();
}
More information about the wine-cvs
mailing list