d3dx9: Handle NULL arguments in D3DXVec3Project.

This commit is contained in:
Józef Kucia 2012-11-08 13:45:54 +01:00 committed by Alexandre Julliard
parent dff501236a
commit a5d5650730
2 changed files with 39 additions and 14 deletions

View File

@ -1809,17 +1809,22 @@ D3DXVECTOR3* WINAPI D3DXVec3Normalize(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv)
D3DXVECTOR3* WINAPI D3DXVec3Project(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *pv, CONST D3DVIEWPORT9 *pviewport, CONST D3DXMATRIX *pprojection, CONST D3DXMATRIX *pview, CONST D3DXMATRIX *pworld)
{
D3DXMATRIX m;
D3DXVECTOR3 out;
TRACE("(%p, %p, %p, %p, %p, %p)\n", pout, pv, pviewport, pprojection, pview, pworld);
D3DXMatrixMultiply(&m, pworld, pview);
D3DXMatrixMultiply(&m, &m, pprojection);
D3DXVec3TransformCoord(&out, pv, &m);
out.x = pviewport->X + ( 1.0f + out.x ) * pviewport->Width / 2.0f;
out.y = pviewport->Y + ( 1.0f - out.y ) * pviewport->Height / 2.0f;
out.z = pviewport->MinZ + out.z * ( pviewport->MaxZ - pviewport->MinZ );
*pout = out;
D3DXMatrixIdentity(&m);
if (pworld) D3DXMatrixMultiply(&m, &m, pworld);
if (pview) D3DXMatrixMultiply(&m, &m, pview);
if (pprojection) D3DXMatrixMultiply(&m, &m, pprojection);
D3DXVec3TransformCoord(pout, pv, &m);
if (pviewport)
{
pout->x = pviewport->X + ( 1.0f + pout->x ) * pviewport->Width / 2.0f;
pout->y = pviewport->Y + ( 1.0f - pout->y ) * pviewport->Height / 2.0f;
pout->z = pviewport->MinZ + pout->z * ( pviewport->MaxZ - pviewport->MinZ );
}
return pout;
}

View File

@ -1331,12 +1331,6 @@ static void D3DXVector3Test(void)
D3DXVec3Normalize(&gotvec,&nul);
expect_vec3(expectedvec,gotvec);
/*_______________D3DXVec3Project_________________________*/
expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
expect_vec3(expectedvec,gotvec);
/*_______________D3DXVec3Scale____________________________*/
expectedvec.x = -58.5f; expectedvec.y = -39.0f; expectedvec.z = -13.0f;
D3DXVec3Scale(&gotvec,&u,scale);
@ -1372,6 +1366,32 @@ static void D3DXVector3Test(void)
D3DXVec3TransformNormal(&gotvec,&u,&mat);
expect_vec3(expectedvec,gotvec);
/*_______________D3DXVec3Project_________________________*/
expectedvec.x = 1135.721924f; expectedvec.y = 147.086914f; expectedvec.z = 0.153412f;
D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);
D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
expect_vec3(expectedvec,gotvec);
/* World matrix can be omitted */
D3DXMatrixMultiply(&mat,&world,&view);
D3DXVec3Project(&gotvec,&u,&viewport,&projection,&mat,NULL);
expect_vec3(expectedvec,gotvec);
/* Projection matrix can be omitted */
D3DXMatrixMultiply(&mat,&view,&projection);
D3DXVec3Project(&gotvec,&u,&viewport,NULL,&mat,&world);
expect_vec3(expectedvec,gotvec);
/* View matrix can be omitted */
D3DXMatrixMultiply(&mat,&world,&view);
D3DXVec3Project(&gotvec,&u,&viewport,&projection,NULL,&mat);
expect_vec3(expectedvec,gotvec);
/* All matrices can be omitted */
expectedvec.x = 4010.000000f; expectedvec.y = -1695.000000f; expectedvec.z = 1.600000f;
D3DXVec3Project(&gotvec,&u,&viewport,NULL,NULL,NULL);
expect_vec3(expectedvec,gotvec);
/* Viewport can be omitted */
expectedvec.x = 1.814305f; expectedvec.y = 0.582097f; expectedvec.z = -0.066555f;
D3DXVec3Project(&gotvec,&u,NULL,&projection,&view,&world);
expect_vec3(expectedvec,gotvec);
/*_______________D3DXVec3Unproject_________________________*/
expectedvec.x = -2.913411f; expectedvec.y = 1.593215f; expectedvec.z = 0.380724f;
D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,1000.0f);