d3dx8: Implement D3DXMatrixTransformation.

This commit is contained in:
David Adam 2007-11-21 17:23:13 +01:00 committed by Alexandre Julliard
parent f1bc484947
commit cf443380ba
4 changed files with 96 additions and 3 deletions

View File

@ -33,7 +33,7 @@
@ stdcall D3DXMatrixRotationAxis(ptr ptr long)
@ stdcall D3DXMatrixRotationQuaternion(ptr ptr)
@ stdcall D3DXMatrixRotationYawPitchRoll(ptr long long long)
@ stub D3DXMatrixTransformation
@ stdcall D3DXMatrixTransformation(ptr ptr ptr ptr ptr ptr ptr)
@ stdcall D3DXMatrixAffineTransformation(ptr long ptr ptr ptr)
@ stdcall D3DXMatrixLookAtRH(ptr ptr ptr ptr)
@ stdcall D3DXMatrixLookAtLH(ptr ptr ptr ptr)

View File

@ -480,6 +480,86 @@ D3DXMATRIX* WINAPI D3DXMatrixShadow(D3DXMATRIX *pout, CONST D3DXVECTOR4 *plight,
return pout;
}
D3DXMATRIX* D3DXMatrixTransformation(D3DXMATRIX *pout, CONST D3DXVECTOR3 *pscalingcenter, CONST D3DXQUATERNION *pscalingrotation, CONST D3DXVECTOR3 *pscaling, CONST D3DXVECTOR3 *protationcenter, CONST D3DXQUATERNION *protation, CONST D3DXVECTOR3 *ptranslation)
{
D3DXMATRIX m1, m2, m3, m4, m5, m6, m7, p1, p2, p3, p4, p5;
D3DXQUATERNION prc;
D3DXVECTOR3 psc, pt;
if ( !pscalingcenter )
{
psc.x = 0.0f;
psc.y = 0.0f;
psc.z = 0.0f;
}
else
{
psc.x = pscalingcenter->x;
psc.y = pscalingcenter->y;
psc.z = pscalingcenter->z;
}
if ( !protationcenter )
{
prc.x = 0.0f;
prc.y = 0.0f;
prc.z = 0.0f;
}
else
{
prc.x = protationcenter->x;
prc.y = protationcenter->y;
prc.z = protationcenter->z;
}
if ( !ptranslation )
{
pt.x = 0.0f;
pt.y = 0.0f;
pt.z = 0.0f;
}
else
{
pt.x = ptranslation->x;
pt.y = ptranslation->y;
pt.z = ptranslation->z;
}
D3DXMatrixTranslation(&m1, -psc.x, -psc.y, -psc.z);
if ( !pscalingrotation )
{
D3DXMatrixIdentity(&m2);
D3DXMatrixIdentity(&m4);
}
else
{
D3DXMatrixRotationQuaternion(&m4, pscalingrotation);
D3DXMatrixInverse(&m2, NULL, &m4);
}
if ( !pscaling )
{
D3DXMatrixIdentity(&m3);
}
else
{
D3DXMatrixScaling(&m3, pscaling->x, pscaling->y, pscaling->z);
}
if ( !protation )
{
D3DXMatrixIdentity(&m6);
}
else
{
D3DXMatrixRotationQuaternion(&m6, protation);
}
D3DXMatrixTranslation(&m5, psc.x - prc.x, psc.y - prc.y, psc.z - prc.z);
D3DXMatrixTranslation(&m7, prc.x + pt.x, prc.y + pt.y, prc.z + pt.z);
D3DXMatrixMultiply(&p1, &m1, &m2);
D3DXMatrixMultiply(&p2, &p1, &m3);
D3DXMatrixMultiply(&p3, &p2, &m4);
D3DXMatrixMultiply(&p4, &p3, &m5);
D3DXMatrixMultiply(&p5, &p4, &m6);
D3DXMatrixMultiply(pout, &p5, &m7);
return pout;
}
D3DXMATRIX* WINAPI D3DXMatrixTranslation(D3DXMATRIX *pout, FLOAT x, FLOAT y, FLOAT z)
{
D3DXMatrixIdentity(pout);

View File

@ -164,8 +164,8 @@ static void D3DXMatrixTest(void)
D3DXMATRIX expectedmat, gotmat, mat, mat2, mat3;
LPD3DXMATRIX funcpointer;
D3DXPLANE plane;
D3DXQUATERNION q;
D3DXVECTOR3 at, axis, eye;
D3DXQUATERNION q, r;
D3DXVECTOR3 at, axis, eye, last, scaling;
D3DXVECTOR4 light;
BOOL expected, got;
FLOAT angle, determinant, expectedfloat, gotfloat;
@ -187,10 +187,13 @@ static void D3DXMatrixTest(void)
plane.a = -3.0f; plane.b = -1.0f; plane.c = 4.0f; plane.d = 7.0f;
q.x = 1.0f; q.y = -4.0f; q.z =7.0f; q.w = -11.0f;
r.x = 0.87f; r.y = 0.65f; r.z =0.43f; r.w= 0.21f;
at.x = -2.0f; at.y = 13.0f; at.z = -9.0f;
axis.x = 1.0f; axis.y = -3.0f; axis.z = 7.0f;
eye.x = 8.0f; eye.y = -5.0f; eye.z = 5.75f;
last.x = 9.7f; last.y = -8.6; last.z = 1.3f;
scaling.x = 0.03f; scaling.y =0.05f; scaling.z = 0.06f;
light.x = 9.6f; light.y = 8.5f; light.z = 7.4; light.w = 6.3;
@ -364,6 +367,7 @@ static void D3DXMatrixTest(void)
U(expectedmat).m[3][0] = 1.615385f; U(expectedmat).m[3][1] = 0.538462f; U(expectedmat).m[3][2] = -2.153846f; U(expectedmat).m[3][3] = 1.0f;
D3DXMatrixReflect(&gotmat,&plane);
expect_mat(expectedmat,gotmat);
/*____________D3DXMatrixRotationAxis_____*/
U(expectedmat).m[0][0] = 0.508475f; U(expectedmat).m[0][1] = 0.763805f; U(expectedmat).m[0][2] = 0.397563f; U(expectedmat).m[0][3] = 0.0f;
U(expectedmat).m[1][0] = -0.814652f; U(expectedmat).m[1][1] = 0.576271f; U(expectedmat).m[1][2] = -0.065219f; U(expectedmat).m[1][3] = 0.0f;
@ -428,6 +432,14 @@ static void D3DXMatrixTest(void)
D3DXMatrixShadow(&gotmat,&light,&plane);
expect_mat(expectedmat,gotmat);
/*____________D3DXMatrixTransformation______________*/
U(expectedmat).m[0][0] = -0.2148f; U(expectedmat).m[0][1] = 1.3116f; U(expectedmat).m[0][2] = 0.4752f; U(expectedmat).m[0][3] = 0.0f;
U(expectedmat).m[1][0] = 0.9504f; U(expectedmat).m[1][1] = -0.8836f; U(expectedmat).m[1][2] = 0.9244f; U(expectedmat).m[1][3] = 0.0f;
U(expectedmat).m[2][0] = 1.0212f; U(expectedmat).m[2][1] = 0.1936f; U(expectedmat).m[2][2] = -1.3588f; U(expectedmat).m[2][3] = 0.0f;
U(expectedmat).m[3][0] = 18.2985f; U(expectedmat).m[3][1] = -29.624001f; U(expectedmat).m[3][2] = 15.683499f; U(expectedmat).m[3][3] = 1.0f;
D3DXMatrixTransformation(&gotmat,&at,&q,NULL,&eye,&r,&last);
expect_mat(expectedmat,gotmat);
/*____________D3DXMatrixTranslation______________*/
U(expectedmat).m[0][0] = 1.0f; U(expectedmat).m[0][1] = 0.0f; U(expectedmat).m[0][2] = 0.0f; U(expectedmat).m[0][3] = 0.0f;
U(expectedmat).m[1][0] = 0.0; U(expectedmat).m[1][1] = 1.0f; U(expectedmat).m[1][2] = 0.0f; U(expectedmat).m[1][3] = 0.0f;

View File

@ -293,6 +293,7 @@ D3DXMATRIX* WINAPI D3DXMatrixRotationYawPitchRoll(D3DXMATRIX *pout, FLOAT yaw, F
D3DXMATRIX* WINAPI D3DXMatrixRotationZ(D3DXMATRIX *pout, FLOAT angle);
D3DXMATRIX* WINAPI D3DXMatrixScaling(D3DXMATRIX *pout, FLOAT sx, FLOAT sy, FLOAT sz);
D3DXMATRIX* WINAPI D3DXMatrixShadow(D3DXMATRIX *pout, CONST D3DXVECTOR4 *plight, CONST D3DXPLANE *pPlane);
D3DXMATRIX* D3DXMatrixTransformation(D3DXMATRIX *pout, CONST D3DXVECTOR3 *pscalingcenter, CONST D3DXQUATERNION *pscalingrotation, CONST D3DXVECTOR3 *pscaling, CONST D3DXVECTOR3 *protationcenter, CONST D3DXQUATERNION *protation, CONST D3DXVECTOR3 *ptranslation);
D3DXMATRIX* WINAPI D3DXMatrixTranslation(D3DXMATRIX *pout, FLOAT x, FLOAT y, FLOAT z);
D3DXMATRIX* WINAPI D3DXMatrixTranspose(D3DXMATRIX *pout, CONST D3DXMATRIX *pm);