[PATCH] Implement D3DXVec3Project with a test

David Adam David.Adam at math.cnrs.fr
Sun Nov 11 10:33:45 CST 2007


---
 dlls/d3dx8/d3dx8.spec   |    2 +-
 dlls/d3dx8/math.c       |   14 ++++++++++++++
 dlls/d3dx8/tests/math.c |   24 +++++++++++++++++++++++-
 include/d3dx8math.h     |    1 +
 4 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/dlls/d3dx8/d3dx8.spec b/dlls/d3dx8/d3dx8.spec
index 4b29b61..50d4cc3 100644
--- a/dlls/d3dx8/d3dx8.spec
+++ b/dlls/d3dx8/d3dx8.spec
@@ -12,7 +12,7 @@
 @ stdcall D3DXVec3Transform(ptr ptr ptr)
 @ stdcall D3DXVec3TransformCoord(ptr ptr ptr)
 @ stdcall D3DXVec3TransformNormal(ptr ptr ptr)
-@ stub D3DXVec3Project
+@ stdcall D3DXVec3Project(ptr ptr ptr ptr ptr ptr)
 @ stub D3DXVec3Unproject
 @ stdcall D3DXVec4Cross(ptr ptr ptr ptr)
 @ stdcall D3DXVec4Normalize(ptr ptr)
diff --git a/dlls/d3dx8/math.c b/dlls/d3dx8/math.c
index 6468867..ddc2df2 100644
--- a/dlls/d3dx8/math.c
+++ b/dlls/d3dx8/math.c
@@ -553,6 +553,20 @@ D3DXVECTOR3* WINAPI D3DXVec3Normalize(D3DXVECTOR3 *pout=
, CONST D3DXVECTOR3 *pv)
     return pout;
 }
=20
+D3DXVECTOR3* WINAPI D3DXVec3Project(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *p=
v, CONST D3DVIEWPORT8 *pviewport, CONST D3DXMATRIX *pprojection, CONST D3DXM=
ATRIX *pview, CONST D3DXMATRIX *pworld)
+{
+    D3DXMATRIX m1, m2;
+    D3DXVECTOR3 vec;
+
+    D3DXMatrixMultiply(&m1, pworld, pview);
+    D3DXMatrixMultiply(&m2, &m1, pprojection);
+    D3DXVec3TransformCoord(&vec, pv, &m2);
+    pout->x =3D pviewport->X +  ( 1.0f + vec.x ) * pviewport->Width / 2.0f;
+    pout->y =3D pviewport->Y +  ( 1.0f - vec.y ) * pviewport->Height / 2.0f=
;
+    pout->z =3D pviewport->MinZ + vec.z * ( pviewport->MaxZ - pviewport->Mi=
nZ );
+    return pout;
+}
+
 D3DXVECTOR4* WINAPI D3DXVec3Transform(D3DXVECTOR4 *pout, CONST D3DXVECTOR3 =
*pv, CONST D3DXMATRIX *pm)
 {
     pout->x =3D pm->u.m[0][0] * pv->x + pm->u.m[1][0] * pv->y + pm->u.m[2][=
0] * pv->z + pm->u.m[3][0];
diff --git a/dlls/d3dx8/tests/math.c b/dlls/d3dx8/tests/math.c
index 6a20a30..70e5240 100644
--- a/dlls/d3dx8/tests/math.c
+++ b/dlls/d3dx8/tests/math.c
@@ -692,10 +692,11 @@ static void D3X8Vector2Test(void)
=20
 static void D3X8Vector3Test(void)
 {
+    D3DVIEWPORT8 viewport;
     D3DXVECTOR3 expectedvec, gotvec, nul, nulproj, u, v, w, x;
     LPD3DXVECTOR3 funcpointer;
     D3DXVECTOR4 expectedtrans, gottrans;
-    D3DXMATRIX mat;
+    D3DXMATRIX mat, projection, view, world;
     FLOAT coeff1, coeff2, expected, got, scale;
=20
     nul.x =3D 0.0f; nul.y =3D 0.0f; nul.z =3D 0.0f;
@@ -704,11 +705,26 @@ static void D3X8Vector3Test(void)
     w.x =3D 3.0f; w.y =3D -5.0f; w.z =3D 7.0f;
     x.x =3D 4.0f; x.y =3D 1.0f; x.z =3D 11.0f;
=20
+    viewport.Width =3D 800; viewport.MinZ =3D 0.2f; viewport.X =3D 10;
+    viewport.Height =3D 680; viewport.MaxZ =3D 0.9f; viewport.Y =3D 5;
+
     U(mat).m[0][0] =3D 1.0f; U(mat).m[0][1] =3D 2.0f; U(mat).m[0][2] =3D 3.=
0f; U(mat).m[0][3] =3D 4.0f;
     U(mat).m[1][0] =3D 5.0f; U(mat).m[1][1] =3D 6.0f; U(mat).m[1][2] =3D 7.=
0f; U(mat).m[1][3] =3D 8.0f;
     U(mat).m[2][0] =3D 9.0f; U(mat).m[2][1] =3D 10.0f; U(mat).m[2][2] =3D 1=
1.0f; U(mat).m[2][3] =3D 12.0f;
     U(mat).m[3][0] =3D 13.0f; U(mat).m[3][1] =3D 14.0f; U(mat).m[3][2] =3D =
15.0f; U(mat).m[3][3] =3D 16.0f;
=20
+    view.m[0][1] =3D 5.0f; view.m[0][2] =3D 7.0f; view.m[0][3] =3D 8.0f;
+    view.m[1][0] =3D 11.0f; view.m[1][2] =3D 16.0f; view.m[1][3] =3D 33.0f;
+    view.m[2][0] =3D 19.0f; view.m[2][1] =3D -21.0f; view.m[2][3] =3D 43.0f=
;
+    view.m[3][0] =3D 2.0f; view.m[3][1] =3D 3.0f; view.m[3][2] =3D -4.0f;
+    view.m[0][0] =3D 10.0f; view.m[1][1] =3D 20.0f; view.m[2][2] =3D 30.0f;
+    view.m[3][3] =3D -40.0f;
+
+    world.m[0][0] =3D 21.0f; world.m[0][1] =3D 2.0f; world.m[0][2] =3D 3.0f=
; world.m[0][3] =3D 4.0;
+    world.m[1][0] =3D 5.0f; world.m[1][1] =3D 23.0f; world.m[1][2] =3D 7.0f=
; world.m[1][3] =3D 8.0f;
+    world.m[2][0] =3D -8.0f; world.m[2][1] =3D -7.0f; world.m[2][2] =3D 25.=
0f; world.m[2][3] =3D -5.0f;
+    world.m[3][0] =3D -4.0f; world.m[3][1] =3D -3.0f; world.m[3][2] =3D -2.=
0f; world.m[3][3] =3D 27.0f;
+
     coeff1 =3D 2.0f; coeff2 =3D 5.0f;
     scale =3D -6.5f;
=20
@@ -817,6 +833,12 @@ static void D3X8Vector3Test(void)
     D3DXVec3Normalize(&gotvec,&nul);
     expect_vec3(expectedvec,gotvec);
=20
+/*_______________D3DXVec3Project_________________________*/
+    expectedvec.x =3D 1135.721924f; expectedvec.y =3D 147.086914f; expected=
vec.z =3D 0.153412f;
+    D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4.0f,20.0f/17.0f,1.0f,10=
00.0f);
+    D3DXVec3Project(&gotvec,&u,&viewport,&projection,&view,&world);
+    expect_vec3(expectedvec,gotvec);
+
 /*_______________D3DXVec3Scale____________________________*/
     expectedvec.x =3D -58.5f; expectedvec.y =3D -39.0f; expectedvec.z =3D -=
13.0f;
     D3DXVec3Scale(&gotvec,&u,scale);
diff --git a/include/d3dx8math.h b/include/d3dx8math.h
index f9a9563..a30d19f 100644
--- a/include/d3dx8math.h
+++ b/include/d3dx8math.h
@@ -99,6 +99,7 @@ D3DXVECTOR3* WINAPI D3DXVec3BaryCentric(D3DXVECTOR3 *pout,=
 CONST D3DXVECTOR3 *pv
 D3DXVECTOR3* WINAPI D3DXVec3CatmullRom( D3DXVECTOR3 *pout, CONST D3DXVECTOR=
3 *pv0, CONST D3DXVECTOR3 *pv1, CONST D3DXVECTOR3 *pv2, CONST D3DXVECTOR3 *p=
v3, FLOAT s);
 D3DXVECTOR3* WINAPI D3DXVec3Hermite(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *p=
v1, CONST D3DXVECTOR3 *pt1, CONST D3DXVECTOR3 *pv2, CONST D3DXVECTOR3 *pt2, =
FLOAT s);
 D3DXVECTOR3* WINAPI D3DXVec3Normalize(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 =
*pv);
+D3DXVECTOR3* WINAPI D3DXVec3Project(D3DXVECTOR3 *pout, CONST D3DXVECTOR3 *p=
v, CONST D3DVIEWPORT8 *pviewport, CONST D3DXMATRIX *pprojection, CONST D3DXM=
ATRIX *pview, CONST D3DXMATRIX *pworld);
 D3DXVECTOR4* WINAPI D3DXVec3Transform(D3DXVECTOR4 *pout, CONST D3DXVECTOR3 =
*pv, CONST D3DXMATRIX *pm);
 D3DXVECTOR3* WINAPI D3DXVec3TransformCoord(D3DXVECTOR3 *pout, CONST D3DXVEC=
TOR3 *pv, CONST D3DXMATRIX *pm);
 D3DXVECTOR3* WINAPI D3DXVec3TransformNormal(D3DXVECTOR3 *pout, CONST D3DXVE=
CTOR3 *pv, CONST D3DXMATRIX *pm);
--=20
1.5.3.2


--=_1242e0lygt9w--



More information about the wine-patches mailing list