d3dx9: Handle NULL viewport in D3DXVec3Unproject.
Józef Kucia
joseph.kucia at gmail.com
Sun Oct 28 17:20:08 CDT 2012
---
dlls/d3dx9_36/math.c | 21 +++++++++++++--------
dlls/d3dx9_36/tests/math.c | 4 ++++
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/dlls/d3dx9_36/math.c b/dlls/d3dx9_36/math.c
index 5342bc9..117bb84 100644
--- a/dlls/d3dx9_36/math.c
+++ b/dlls/d3dx9_36/math.c
@@ -1928,22 +1928,27 @@ D3DXVECTOR3* WINAPI D3DXVec3TransformNormalArray(D3DXVECTOR3* out, UINT outstrid
D3DXVECTOR3* WINAPI D3DXVec3Unproject(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);
- if (pworld) {
+ if (pworld)
+ {
D3DXMatrixMultiply(&m, pworld, pview);
D3DXMatrixMultiply(&m, &m, pprojection);
- } else {
+ }
+ else
+ {
D3DXMatrixMultiply(&m, pview, pprojection);
}
D3DXMatrixInverse(&m, NULL, &m);
- out.x = 2.0f * ( pv->x - pviewport->X ) / pviewport->Width - 1.0f;
- out.y = 1.0f - 2.0f * ( pv->y - pviewport->Y ) / pviewport->Height;
- out.z = ( pv->z - pviewport->MinZ) / ( pviewport->MaxZ - pviewport->MinZ );
- D3DXVec3TransformCoord(&out, &out, &m);
- *pout = out;
+ *pout = *pv;
+ if (pviewport)
+ {
+ pout->x = 2.0f * ( pout->x - pviewport->X ) / pviewport->Width - 1.0f;
+ pout->y = 1.0f - 2.0f * ( pout->y - pviewport->Y ) / pviewport->Height;
+ pout->z = ( pout->z - pviewport->MinZ) / ( pviewport->MaxZ - pviewport->MinZ );
+ }
+ D3DXVec3TransformCoord(pout, pout, &m);
return pout;
}
diff --git a/dlls/d3dx9_36/tests/math.c b/dlls/d3dx9_36/tests/math.c
index 166b14a..a066ea8 100644
--- a/dlls/d3dx9_36/tests/math.c
+++ b/dlls/d3dx9_36/tests/math.c
@@ -1381,6 +1381,10 @@ static void D3DXVector3Test(void)
D3DXMatrixMultiply(&mat,&world,&view);
D3DXVec3Unproject(&gotvec,&u,&viewport,&projection,&mat,NULL);
expect_vec3(expectedvec,gotvec);
+ /* Viewport can be omitted */
+ expectedvec.x = -11.018396f; expectedvec.y = 3.218991f; expectedvec.z = 1.380329f;
+ D3DXVec3Unproject(&gotvec,&u,NULL,&projection,&view,&world);
+ expect_vec3(expectedvec,gotvec);
}
static void D3DXVector4Test(void)
--
1.7.12.4
More information about the wine-patches
mailing list