From 48d8ff42e12fa50b8df53af586d22aefa4b3aa09 Mon Sep 17 00:00:00 2001
From: Christian Costa <titan.costa@wanadoo.fr>
Date: Fri, 27 Sep 2002 22:01:28 +0000
Subject: [PATCH] Remove wrong and useless transformation of z projected
 coordinates. Add normals world transformation.

---
 dlls/ddraw/d3dexecutebuffer.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/dlls/ddraw/d3dexecutebuffer.c b/dlls/ddraw/d3dexecutebuffer.c
index bec04092e91..ed635675a49 100644
--- a/dlls/ddraw/d3dexecutebuffer.c
+++ b/dlls/ddraw/d3dexecutebuffer.c
@@ -227,12 +227,6 @@ static void execute(LPDIRECT3DEXECUTEBUFFER lpBuff,
 
     case D3DOP_TRIANGLE: {
       int i;
-      float z_inv_matrix[16] = {
-	1.0, 0.0,  0.0, 0.0,
-	0.0, 1.0,  0.0, 0.0,
-	0.0, 0.0, -1.0, 0.0,
-	0.0, 0.0,  1.0, 1.0
-      };
 
       OGL_Vertex  *vx    = (OGL_Vertex  *) ilpBuff->vertex_data;
       OGL_LVertex *l_vx  = (OGL_LVertex *) ilpBuff->vertex_data;
@@ -255,9 +249,11 @@ static void execute(LPDIRECT3DEXECUTEBUFFER lpBuff,
 	TRACE("  View       Matrix : (%p)\n", odev->view_mat);
 	dump_mat(odev->view_mat);
 
-	glLoadMatrixf((float *) z_inv_matrix);
-	glMultMatrixf((float *) odev->proj_mat);
-      glMultMatrixf((float *) odev->view_mat);
+	/* Although z axis is inverted between OpenGL and Direct3D, the z projected coordinates
+	   are always 0.0 at the front viewing volume and 1.0 at the back with Direct 3D and with
+	   the default behaviour of OpenGL. So, no additional transformation is required. */
+	glLoadMatrixf((float *) odev->proj_mat);
+	glMultMatrixf((float *) odev->view_mat);
 	break;
 
       case D3DVT_LVERTEX:
@@ -275,8 +271,10 @@ static void execute(LPDIRECT3DEXECUTEBUFFER lpBuff,
 	TRACE("  View       Matrix : (%p)\n", odev->view_mat);
 	dump_mat(odev->view_mat);
 
-	glLoadMatrixf((float *) z_inv_matrix);
-	glMultMatrixf((float *) odev->proj_mat);
+	/* Although z axis is inverted between OpenGL and Direct3D, the z projected coordinates
+	   are always 0 at the front viewing volume and 1 at the back with Direct 3D and with
+	   the default behaviour of OpenGL. So, no additional transformation is required. */
+	glLoadMatrixf((float *) odev->proj_mat);
 	glMultMatrixf((float *) odev->view_mat);
 	break;
 
@@ -554,9 +552,9 @@ static void execute(LPDIRECT3DEXECUTEBUFFER lpBuff,
 
 	  for (nb = 0; nb < ci->dwCount; nb++) {
 	    /* For the moment, no normal transformation... */
-	    dst->nx = src->u4.nx;
-	    dst->ny = src->u5.ny;
-	    dst->nz = src->u6.nz;
+	    dst->nx = (src->u4.nx * mat->_11) + (src->u5.ny * mat->_21) + (src->u6.nz * mat->_31);
+	    dst->ny = (src->u4.nx * mat->_12) + (src->u5.ny * mat->_22) + (src->u6.nz * mat->_32);
+	    dst->nz = (src->u4.nx * mat->_13) + (src->u5.ny * mat->_23) + (src->u6.nz * mat->_33);
 
 	    dst->u  = src->u7.tu;
 	    dst->v  = src->u8.tv;
-- 
GitLab