=?UTF-8?Q?J=C3=B3zef=20Kucia=20?=: d3dx9: Handle NULL viewport in D3DXVec3Unproject.

Alexandre Julliard julliard at winehq.org
Mon Oct 29 13:52:51 CDT 2012


Module: wine
Branch: master
Commit: 7bfd634286bd3a9afdcd790fee3af3050671b6e2
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=7bfd634286bd3a9afdcd790fee3af3050671b6e2

Author: Józef Kucia <joseph.kucia at gmail.com>
Date:   Sun Oct 28 23:20:08 2012 +0100

d3dx9: Handle NULL viewport in D3DXVec3Unproject.

---

 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)




More information about the wine-cvs mailing list