Commit 9fa78fd4 authored by David Adam's avatar David Adam Committed by Alexandre Julliard

d3drm: Implement D3DRMVectorRotate.

parent f289cf31
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
@ stdcall D3DRMVectorNormalize(ptr) @ stdcall D3DRMVectorNormalize(ptr)
@ stdcall D3DRMVectorRandom(ptr) @ stdcall D3DRMVectorRandom(ptr)
@ stdcall D3DRMVectorReflect(ptr ptr ptr) @ stdcall D3DRMVectorReflect(ptr ptr ptr)
@ stub D3DRMVectorRotate @ stdcall D3DRMVectorRotate(ptr ptr ptr long)
@ stdcall D3DRMVectorScale(ptr ptr long) @ stdcall D3DRMVectorScale(ptr ptr long)
@ stdcall D3DRMVectorSubtract(ptr ptr ptr) @ stdcall D3DRMVectorSubtract(ptr ptr ptr)
@ stub Direct3DRMCreate @ stub Direct3DRMCreate
......
...@@ -122,6 +122,25 @@ LPD3DVECTOR WINAPI D3DRMVectorReflect(LPD3DVECTOR r, LPD3DVECTOR ray, LPD3DVECTO ...@@ -122,6 +122,25 @@ LPD3DVECTOR WINAPI D3DRMVectorReflect(LPD3DVECTOR r, LPD3DVECTOR ray, LPD3DVECTO
return r; return r;
} }
/* Rotation of a vector */
LPD3DVECTOR WINAPI D3DRMVectorRotate(LPD3DVECTOR r, LPD3DVECTOR v, LPD3DVECTOR axis, D3DVALUE theta)
{
D3DRMQUATERNION quaternion,quaternion1, quaternion2, quaternion3, resultq;
D3DVECTOR NORM;
quaternion1.s = cos(theta*.5);
quaternion2.s = cos(theta*.5);
NORM = *D3DRMVectorNormalize(axis);
D3DRMVectorScale(&quaternion1.v, &NORM, sin(theta * .5));
D3DRMVectorScale(&quaternion2.v, &NORM, -sin(theta * .5));
quaternion3.s = 0.0;
quaternion3.v = *v;
D3DRMQuaternionMultiply(&quaternion, &quaternion1, &quaternion3);
D3DRMQuaternionMultiply(&resultq, &quaternion, &quaternion2);
*r = *D3DRMVectorNormalize(&resultq.v);
return r;
}
/* Scale a vector */ /* Scale a vector */
LPD3DVECTOR WINAPI D3DRMVectorScale(LPD3DVECTOR d, LPD3DVECTOR s, D3DVALUE factor) LPD3DVECTOR WINAPI D3DRMVectorScale(LPD3DVECTOR d, LPD3DVECTOR s, D3DVALUE factor)
{ {
......
...@@ -32,8 +32,8 @@ ...@@ -32,8 +32,8 @@
void VectorTest(void) void VectorTest(void)
{ {
D3DVALUE mod,par; D3DVALUE mod,par,theta;
D3DVECTOR e,r,u,v,casnul,norm,ray; D3DVECTOR e,r,u,v,w,axis,casnul,norm,ray;
u.x=2.0;u.y=2.0;u.z=1.0; u.x=2.0;u.y=2.0;u.z=1.0;
v.x=4.0;v.y=4.0;v.z=0.0; v.x=4.0;v.y=4.0;v.z=0.0;
...@@ -80,6 +80,20 @@ void VectorTest(void) ...@@ -80,6 +80,20 @@ void VectorTest(void)
D3DRMVectorReflect(&r,&ray,&norm); D3DRMVectorReflect(&r,&ray,&norm);
expect_vec(e,r); expect_vec(e,r);
/*_______________________VectorRotate_______________________________*/
w.x=3.0;w.y=4.0;w.z=0.0;
axis.x=0.0;axis.y=0.0;axis.z=1.0;
theta=2.0*PI/3.0;
D3DRMVectorRotate(&r,&w,&axis,theta);
e.x=-0.3-0.4*sqrt(3.0); e.y=0.3*sqrt(3.0)-0.4; e.z=0.0;
expect_vec(e,r);
/* The same formula gives D3DRMVectorRotate, for theta in [-PI/2;+PI/2] or not. The following test proves this fact.*/
theta=-PI/4.0;
D3DRMVectorRotate(&r,&w,&axis,-PI/4);
e.x=1.4/sqrt(2.0); e.y=0.2/sqrt(2.0); e.z=0.0;
expect_vec(e,r);
/*_______________________VectorScale__________________________*/ /*_______________________VectorScale__________________________*/
par=2.5; par=2.5;
D3DRMVectorScale(&r,&v,par); D3DRMVectorScale(&r,&v,par);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment