d3drm: Allow output pointer to be equal to input pointer.

This commit is contained in:
David Adam 2009-02-14 14:35:42 +01:00 committed by Alexandre Julliard
parent 44e74969e3
commit f877cb9a89
2 changed files with 67 additions and 19 deletions

View File

@ -77,12 +77,16 @@ D3DVALUE WINAPI D3DRMColorGetRed(D3DCOLOR color)
/* Product of 2 quaternions */
LPD3DRMQUATERNION WINAPI D3DRMQuaternionMultiply(LPD3DRMQUATERNION q, LPD3DRMQUATERNION a, LPD3DRMQUATERNION b)
{
D3DRMQUATERNION temp;
D3DVECTOR cross_product;
D3DRMVectorCrossProduct(&cross_product, &a->v, &b->v);
q->s = a->s * b->s - D3DRMVectorDotProduct(&a->v, &b->v);
q->v.u1.x = a->s * b->v.u1.x + b->s * a->v.u1.x + cross_product.u1.x;
q->v.u2.y = a->s * b->v.u2.y + b->s * a->v.u2.y + cross_product.u2.y;
q->v.u3.z = a->s * b->v.u3.z + b->s * a->v.u3.z + cross_product.u3.z;
temp.s = a->s * b->s - D3DRMVectorDotProduct(&a->v, &b->v);
temp.v.u1.x = a->s * b->v.u1.x + b->s * a->v.u1.x + cross_product.u1.x;
temp.v.u2.y = a->s * b->v.u2.y + b->s * a->v.u2.y + cross_product.u2.y;
temp.v.u3.z = a->s * b->v.u3.z + b->s * a->v.u3.z + cross_product.u3.z;
*q = temp;
return q;
}
@ -149,27 +153,39 @@ LPD3DRMQUATERNION WINAPI D3DRMQuaternionSlerp(LPD3DRMQUATERNION q, LPD3DRMQUATER
/* Add Two Vectors */
LPD3DVECTOR WINAPI D3DRMVectorAdd(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DVECTOR s2)
{
d->u1.x=s1->u1.x + s2->u1.x;
d->u2.y=s1->u2.y + s2->u2.y;
d->u3.z=s1->u3.z + s2->u3.z;
D3DVECTOR temp;
temp.u1.x=s1->u1.x + s2->u1.x;
temp.u2.y=s1->u2.y + s2->u2.y;
temp.u3.z=s1->u3.z + s2->u3.z;
*d = temp;
return d;
}
/* Subtract Two Vectors */
LPD3DVECTOR WINAPI D3DRMVectorSubtract(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DVECTOR s2)
{
d->u1.x=s1->u1.x - s2->u1.x;
d->u2.y=s1->u2.y - s2->u2.y;
d->u3.z=s1->u3.z - s2->u3.z;
D3DVECTOR temp;
temp.u1.x=s1->u1.x - s2->u1.x;
temp.u2.y=s1->u2.y - s2->u2.y;
temp.u3.z=s1->u3.z - s2->u3.z;
*d = temp;
return d;
}
/* Cross Product of Two Vectors */
LPD3DVECTOR WINAPI D3DRMVectorCrossProduct(LPD3DVECTOR d, LPD3DVECTOR s1, LPD3DVECTOR s2)
{
d->u1.x=s1->u2.y * s2->u3.z - s1->u3.z * s2->u2.y;
d->u2.y=s1->u3.z * s2->u1.x - s1->u1.x * s2->u3.z;
d->u3.z=s1->u1.x * s2->u2.y - s1->u2.y * s2->u1.x;
D3DVECTOR temp;
temp.u1.x=s1->u2.y * s2->u3.z - s1->u3.z * s2->u2.y;
temp.u2.y=s1->u3.z * s2->u1.x - s1->u1.x * s2->u3.z;
temp.u3.z=s1->u1.x * s2->u2.y - s1->u2.y * s2->u1.x;
*d = temp;
return d;
}
@ -219,8 +235,10 @@ LPD3DVECTOR WINAPI D3DRMVectorRandom(LPD3DVECTOR d)
/* Reflection of a vector on a surface */
LPD3DVECTOR WINAPI D3DRMVectorReflect(LPD3DVECTOR r, LPD3DVECTOR ray, LPD3DVECTOR norm)
{
D3DVECTOR sca;
D3DRMVectorSubtract(r, D3DRMVectorScale(&sca, norm, 2.0*D3DRMVectorDotProduct(ray,norm)), ray);
D3DVECTOR sca, temp;
D3DRMVectorSubtract(&temp, D3DRMVectorScale(&sca, norm, 2.0*D3DRMVectorDotProduct(ray,norm)), ray);
*r = temp;
return r;
}
@ -246,8 +264,12 @@ LPD3DVECTOR WINAPI D3DRMVectorRotate(LPD3DVECTOR r, LPD3DVECTOR v, LPD3DVECTOR a
/* Scale a vector */
LPD3DVECTOR WINAPI D3DRMVectorScale(LPD3DVECTOR d, LPD3DVECTOR s, D3DVALUE factor)
{
d->u1.x=factor * s->u1.x;
d->u2.y=factor * s->u2.y;
d->u3.z=factor * s->u3.z;
D3DVECTOR temp;
temp.u1.x=factor * s->u1.x;
temp.u2.y=factor * s->u2.y;
temp.u3.z=factor * s->u3.z;
*d = temp;
return d;
}

View File

@ -130,26 +130,42 @@ static BOOL InitFunctionPtrs(void)
static void VectorTest(void)
{
D3DVALUE mod,par,theta;
D3DVECTOR e,r,u,v,w,axis,casnul,norm,ray;
D3DVECTOR e,r,u,v,w,axis,casnul,norm,ray,self;
U1(u).x=2.0f; U2(u).y=2.0f; U3(u).z=1.0f;
U1(v).x=4.0f; U2(v).y=4.0f; U3(v).z=0.0f;
/*______________________VectorAdd_________________________________*/
pD3DRMVectorAdd(&r,&u,&v);
U1(e).x=6.0f; U2(e).y=6.0f; U3(e).z=1.0f;
expect_vec(e,r);
U1(self).x=9.0f; U1(self).y=18.0f; U3(self).z=27.0f;
pD3DRMVectorAdd(&self,&self,&u);
U1(e).x=11.0f; U2(e).y=20.0f; U3(e).z=28.0f;
expect_vec(e,self);
/*_______________________VectorSubtract__________________________*/
pD3DRMVectorSubtract(&r,&u,&v);
U1(e).x=-2.0f; U2(e).y=-2.0f; U3(e).z=1.0f;
expect_vec(e,r);
U1(self).x=9.0f; U1(self).y=18.0f; U3(self).z=27.0f;
pD3DRMVectorSubtract(&self,&self,&u);
U1(e).x=7.0f; U2(e).y=16.0f; U3(e).z=26.0f;
expect_vec(e,self);
/*_______________________VectorCrossProduct_______________________*/
pD3DRMVectorCrossProduct(&r,&u,&v);
U1(e).x=-4.0f; U2(e).y=4.0f; U3(e).z=0.0f;
expect_vec(e,r);
U1(self).x=9.0f; U1(self).y=18.0f; U3(self).z=27.0f;
pD3DRMVectorCrossProduct(&self,&self,&u);
U1(e).x=-36.0f; U2(e).y=45.0f; U3(e).z=-18.0f;
expect_vec(e,self);
/*_______________________VectorDotProduct__________________________*/
mod=pD3DRMVectorDotProduct(&u,&v);
ok((mod == 16.0f), "Expected 16.0f, Got %f\n", mod);
@ -191,11 +207,21 @@ static void VectorTest(void)
U1(e).x=1.4f/sqrtf(2.0f); U2(e).y=0.2f/sqrtf(2.0f); U3(e).z=0.0f;
expect_vec(e,r);
theta=PI/8.0f;
pD3DRMVectorRotate(&self,&self,&axis,theta);
U1(e).x=0.989950; U2(e).y=0.141421f; U3(e).z=0.0f;
expect_vec(e,r);
/*_______________________VectorScale__________________________*/
par=2.5f;
pD3DRMVectorScale(&r,&v,par);
U1(e).x=10.0f; U2(e).y=10.0f; U3(e).z=0.0f;
expect_vec(e,r);
U1(self).x=9.0f; U1(self).y=18.0f; U3(self).z=27.0f;
pD3DRMVectorScale(&self,&self,2);
U1(e).x=18.0f; U2(e).y=36.0f; U3(e).z=54.0f;
expect_vec(e,self);
}
static void MatrixTest(void)