From f13c45f4dc71a4faa59707012a79ab0270d33537 Mon Sep 17 00:00:00 2001 From: David Adam Date: Thu, 19 Apr 2007 21:12:40 +0200 Subject: [PATCH] d3drm: Implement D3DRMMatrixFromQuaternion. --- dlls/d3drm/d3drm.spec | 2 +- dlls/d3drm/math.c | 26 +++++++++++++++++++++++ dlls/d3drm/tests/vector.c | 43 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/dlls/d3drm/d3drm.spec b/dlls/d3drm/d3drm.spec index c907bab354b..a8133ab7ea1 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 @ stdcall D3DRMQuaternionMultiply(ptr ptr ptr) @ stub D3DRMQuaternionSlerp diff --git a/dlls/d3drm/math.c b/dlls/d3drm/math.c index 02dd965d060..714f35f6e43 100644 --- a/dlls/d3drm/math.c +++ b/dlls/d3drm/math.c @@ -44,6 +44,32 @@ LPD3DRMQUATERNION WINAPI D3DRMQuaternionMultiply(LPD3DRMQUATERNION q, LPD3DRMQUA return q; } +/* 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 9f89893a00e..b71805b3b84 100644 --- a/dlls/d3drm/tests/vector.c +++ b/dlls/d3drm/tests/vector.c @@ -25,12 +25,37 @@ #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)