diff Outdoor.cpp @ 2368:91b6c0a338ad

ODMFace::IsBackfaceCulled to ODMFace::IsBackfaceNotCulled, cleaned up a bit
author Grumpy7
date Mon, 12 May 2014 00:13:39 +0200
parents 7942b5727708
children bddcaf5d5db2
line wrap: on
line diff
--- a/Outdoor.cpp	Sun May 11 23:17:23 2014 +0200
+++ b/Outdoor.cpp	Mon May 12 00:13:39 2014 +0200
@@ -576,20 +576,13 @@
 }
 
 //----- (00482170) --------------------------------------------------------
-bool ODMFace::IsBackfaceCulled(RenderVertexSoft *a2, struct Polygon *polygon)
+bool ODMFace::IsBackfaceNotCulled(RenderVertexSoft *a2, struct Polygon *polygon)
 {
-  unsigned int v5; // edx@1
-  RenderVertexSoft *v6; // ecx@2
+  unsigned int numOfVertices; // edx@1
+  RenderVertexSoft *currVertex; // ecx@2
   double v7; // st7@5
   double v8; // st6@5
   double v9; // st5@5
-  double v10; // st6@9
-  double v11; // st5@9
-  double v12; // st4@9
-  double v14; // ST2C_8@17
-  double v15; // ST20_8@17
-  double v16; // ST0C_8@17
-  double v17; // ST0C_8@17
   float v18; // [sp+8h] [bp-38h]@5
   float v19; // [sp+10h] [bp-30h]@5
   float v20; // [sp+14h] [bp-2Ch]@5
@@ -607,69 +600,54 @@
   float a3d; // [sp+48h] [bp+8h]@17
   float a3e; // [sp+48h] [bp+8h]@17
 
-  v5 = polygon->uNumVertices;
-  if ( (signed int)v5 < 3 )
-      return false;
-  v6 = &a2[v5 - 1];
-  if ( a2->vWorldPosition.z == a2[1].vWorldPosition.z && a2[1].vWorldPosition.z == v6->vWorldPosition.z )
-    *(int *)&polygon->flags |= 0x10u;
-  v19 = a2[1].vWorldViewPosition.x - a2->vWorldViewPosition.x;
-  v18 = a2[1].vWorldViewPosition.y - a2->vWorldViewPosition.y;
-  v20 = a2[1].vWorldViewPosition.z - a2->vWorldViewPosition.z;
-  v21 = v6->vWorldViewPosition.x - a2->vWorldViewPosition.x;
-  v22 = v6->vWorldViewPosition.y - a2->vWorldViewPosition.y;
-  v23 = v6->vWorldViewPosition.z - a2->vWorldViewPosition.z;
+  numOfVertices = polygon->uNumVertices;
+  if ( numOfVertices < 3 )
+    return false;
+  currVertex = &a2[numOfVertices - 1];
+  if ( a2->vWorldPosition.z == a2[1].vWorldPosition.z && a2[1].vWorldPosition.z == currVertex->vWorldPosition.z )
+    polygon->flags |= 0x10u;
+
   v28 = a2[1].vWorldPosition.x - a2->vWorldPosition.x;
   v27 = a2[1].vWorldPosition.y - a2->vWorldPosition.y;
   a3a = a2[1].vWorldPosition.z - a2->vWorldPosition.z;
-  v7 = v6->vWorldPosition.x - a2->vWorldPosition.x;
-  v8 = v6->vWorldPosition.y - a2->vWorldPosition.y;
-  v9 = v6->vWorldPosition.z - a2->vWorldPosition.z;
-  v26 = v27 * v9 - v8 * a3a;
-  v24 = v7 * a3a - v9 * v28;
-  v25 = v8 * v28 - v7 * v27;
-  if ( v26 == 0.0 && v24 == 0.0 && v25 == 0.0 )
+
+
+  for (int i = 0; i < numOfVertices; i++)
   {
-    while ( 1 )
-    {
-      --v5;
-      if ( (signed int)v5 < 2 )
-        break;
-      v10 = v6->vWorldPosition.x - a2->vWorldPosition.x;
-      v11 = v6->vWorldPosition.y - a2->vWorldPosition.y;
-      v12 = v6->vWorldPosition.z - a2->vWorldPosition.z;
-      v26 = v27 * v12 - v11 * a3a;
-      v24 = v10 * a3a - v12 * v28;
-      v25 = v11 * v28 - v10 * v27;
-      if ( v26 != 0.0 )
-        break;
-      if ( v24 != 0.0 || v25 != 0.0 )
-        break;
-      --v6;
-    }
-    v21 = v6->vWorldViewPosition.x - a2->vWorldViewPosition.x;
-    v22 = v6->vWorldViewPosition.y - a2->vWorldViewPosition.y;
-    v23 = v6->vWorldViewPosition.z - a2->vWorldViewPosition.z;
+    v7 = currVertex->vWorldPosition.x - a2->vWorldPosition.x;
+    v8 = currVertex->vWorldPosition.y - a2->vWorldPosition.y;
+    v9 = currVertex->vWorldPosition.z - a2->vWorldPosition.z;
+    v26 = v27 * v9 - v8 * a3a;
+    v24 = v7 * a3a - v9 * v28;
+    v25 = v8 * v28 - v7 * v27;
+    if ( v24 != 0.0 || v25 != 0.0 || v26 != 0.0 )
+      break;
+    currVertex--;
   }
+
   if ( ((double)pGame->pIndoorCameraD3D->vPartyPos.x - a2->vWorldPosition.x) * v26
-     + ((double)pGame->pIndoorCameraD3D->vPartyPos.z - a2->vWorldPosition.z) * v25
-     + ((double)pGame->pIndoorCameraD3D->vPartyPos.y - a2->vWorldPosition.y) * v24 > 0.0 )
+    + ((double)pGame->pIndoorCameraD3D->vPartyPos.z - a2->vWorldPosition.z) * v25
+    + ((double)pGame->pIndoorCameraD3D->vPartyPos.y - a2->vWorldPosition.y) * v24 > 0.0 )
   {
+
+    v19 = a2[1].vWorldViewPosition.x - a2->vWorldViewPosition.x;
+    v18 = a2[1].vWorldViewPosition.y - a2->vWorldViewPosition.y;
+    v20 = a2[1].vWorldViewPosition.z - a2->vWorldViewPosition.z;
+    v21 = currVertex->vWorldViewPosition.x - a2->vWorldViewPosition.x;
+    v22 = currVertex->vWorldViewPosition.y - a2->vWorldViewPosition.y;
+    v23 = currVertex->vWorldViewPosition.z - a2->vWorldViewPosition.z;
+
     a3b = v23 * v18 - v22 * v20;
-    v14 = a3b + 6.7553994e15;
-    polygon->v_18.x = LODWORD(v14);
+    polygon->v_18.x = bankersRounding(a3b);
     a3c = v21 * v20 - v23 * v19;
-    v15 = a3c + 6.7553994e15;
-    polygon->v_18.y = LODWORD(v15);
+    polygon->v_18.y = bankersRounding(a3c);
     a3d = v22 * v19 - v21 * v18;
-    v16 = a3d + 6.7553994e15;
-    polygon->v_18.z = LODWORD(v16);
+    polygon->v_18.z = bankersRounding(a3d);
     polygon->_normalize_v_18();
     a3e = -((double)polygon->v_18.x * a2->vWorldViewPosition.x)
-        - (double)polygon->v_18.y * a2->vWorldViewPosition.y
-        - (double)polygon->v_18.z * a2->vWorldViewPosition.z;
-    v17 = a3e + 6.7553994e15;
-    polygon->field_24 = LODWORD(v17);
+      - (double)polygon->v_18.y * a2->vWorldViewPosition.y
+      - (double)polygon->v_18.z * a2->vWorldViewPosition.z;
+    polygon->field_24 = bankersRounding(a3e);
     return true;
   }
   else