d3drm: Implement D3DRMQuaternionFromRotation.

This commit is contained in:
David Adam 2007-04-19 21:13:51 +02:00 committed by Alexandre Julliard
parent f13c45f4dc
commit 909b502360
3 changed files with 33 additions and 1 deletions

View File

@ -5,7 +5,7 @@
@ stub D3DRMCreateColorRGB @ stub D3DRMCreateColorRGB
@ stub D3DRMCreateColorRGBA @ stub D3DRMCreateColorRGBA
@ stdcall D3DRMMatrixFromQuaternion(ptr ptr) @ stdcall D3DRMMatrixFromQuaternion(ptr ptr)
@ stub D3DRMQuaternionFromRotation @ stdcall D3DRMQuaternionFromRotation(ptr ptr long)
@ stdcall D3DRMQuaternionMultiply(ptr ptr ptr) @ stdcall D3DRMQuaternionMultiply(ptr ptr ptr)
@ stub D3DRMQuaternionSlerp @ stub D3DRMQuaternionSlerp
@ stdcall D3DRMVectorAdd(ptr ptr ptr) @ stdcall D3DRMVectorAdd(ptr ptr ptr)

View File

@ -70,6 +70,14 @@ void WINAPI D3DRMMatrixFromQuaternion(D3DRMMATRIX4D m, LPD3DRMQUATERNION q)
m[3][3] = 1.0; 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 */ /* Add Two Vectors */
LPD3DVECTOR WINAPI D3DRMVectorAdd(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DVECTOR s2) LPD3DVECTOR WINAPI D3DRMVectorAdd(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DVECTOR s2)
{ {

View File

@ -50,6 +50,15 @@
gotmat[3][0],gotmat[3][1],gotmat[3][2],gotmat[3][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) \ #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)), \ 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", \ "Expected Vector= (%f, %f, %f)\n , Got Vector= (%f, %f, %f)\n", \
@ -141,8 +150,23 @@ static void MatrixTest(void)
expect_mat(exp,mat); 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) START_TEST(vector)
{ {
VectorTest(); VectorTest();
MatrixTest(); MatrixTest();
QuaternionTest();
} }