diff Render.cpp @ 1908:cb1cbb969fce

Merge
author Grumpy7
date Mon, 21 Oct 2013 23:20:29 -0700
parents 1a1c4040bee4
children af38275939cc
line wrap: on
line diff
--- a/Render.cpp	Mon Oct 21 23:19:30 2013 -0700
+++ b/Render.cpp	Mon Oct 21 23:20:29 2013 -0700
@@ -8727,9 +8727,61 @@
     break;
   }
 }
-
+//----- (00424CD7) --------------------------------------------------------
+int ODM_NearClip(unsigned int num_vertices)
+{
+  bool current_vertices_flag; // edi@1
+  bool next_vertices_flag; // [sp+Ch] [bp-24h]@6
+  double t; // st6@10
+  int pNextVertices;
+
+  if (!num_vertices)
+    return 0;
+
+  memcpy(&array_50AC10[num_vertices], array_50AC10, sizeof(array_50AC10[0]));
+  current_vertices_flag = 0;
+  if ( array_50AC10[0].vWorldViewPosition.x >= 8.0 )
+    current_vertices_flag = 1;
+
+  int out_num_vertices = 0;
+  for (int i = 0; i < num_vertices; ++i)
+  {
+    next_vertices_flag = array_50AC10[i + 1].vWorldViewPosition.x >= 8.0;
+    if ( current_vertices_flag != next_vertices_flag )
+    {
+      if ( next_vertices_flag )
+      {
+        //t = neer_clip - v0.x / v1.x - v0.x    (формула получения точки пересечения отрезка с плоскостью)
+        t = (8.0 - array_50AC10[i].vWorldViewPosition.x) / (array_50AC10[i + 1].vWorldViewPosition.x - array_50AC10[i].vWorldViewPosition.x);
+        array_507D30[out_num_vertices].vWorldViewPosition.y = (array_50AC10[i + 1].vWorldViewPosition.y - array_50AC10[i].vWorldViewPosition.y) * t + array_50AC10[i].vWorldViewPosition.y;
+        array_507D30[out_num_vertices].vWorldViewPosition.z = (array_50AC10[i + 1].vWorldViewPosition.z - array_50AC10[i].vWorldViewPosition.z) * t + array_50AC10[i].vWorldViewPosition.z;
+        array_507D30[out_num_vertices].u = (array_50AC10[i + 1].u - array_50AC10[i].u) * t + array_50AC10[i].u;
+        array_507D30[out_num_vertices].v = (array_50AC10[i + 1].v - array_50AC10[i].v) * t + array_50AC10[i].v;
+      }
+      else
+      {
+        t = (8.0 - array_50AC10[i + 1].vWorldViewPosition.x) / (array_50AC10[i].vWorldViewPosition.x - array_50AC10[i + 1].vWorldViewPosition.x);
+        array_507D30[out_num_vertices].vWorldViewPosition.y = (array_50AC10[i].vWorldViewPosition.y - array_50AC10[i + 1].vWorldViewPosition.y) * t + array_50AC10[i + 1].vWorldViewPosition.y;
+        array_507D30[out_num_vertices].vWorldViewPosition.z = (array_50AC10[i].vWorldViewPosition.z - array_50AC10[i + 1].vWorldViewPosition.z) * t + array_50AC10[i + 1].vWorldViewPosition.z;
+        array_507D30[out_num_vertices].u = (array_50AC10[i].u - array_50AC10[i + 1].u) * t + array_50AC10[i + 1].u;
+        array_507D30[out_num_vertices].v = (array_50AC10[i].v - array_50AC10[i + 1].v) * t + array_50AC10[i + 1].v;
+      }
+      array_507D30[out_num_vertices].vWorldViewPosition.x = 8.0;
+      array_507D30[out_num_vertices]._rhw = 1.0 / 8.0;
+      //array_507D30[out_num_vertices]._rhw = 0x3E000000u;
+      ++out_num_vertices;
+    }
+    if ( next_vertices_flag )
+    {
+      pNextVertices = out_num_vertices++;
+      memcpy(&array_507D30[pNextVertices], &array_50AC10[i + 1], 0x30);
+    }
+    current_vertices_flag = next_vertices_flag;
+  }
+  return out_num_vertices >= 3 ? out_num_vertices : 0;
+}
 //----- (00424EE0) --------------------------------------------------------
-int BuildingVerticesClipping(unsigned int uNumVertices)
+int ODM_FarClip(unsigned int uNumVertices)
 {
   signed int previous_vertices_flag; // edi@1
   double t; // st6@10
@@ -8960,13 +9012,13 @@
                 pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &static_RenderBuildingsD3D_stru_73C834, uNumVertices, array_50AC10, 0, (char)v31);
               if ( v50 )
               {
-                array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices = sr_424CD7(pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices);
+                array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices = ODM_NearClip(pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices);
                 uNumVertices = array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices;
                 ODM_Project(array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices);
               }
               if ( v49 )
               {
-                array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices = BuildingVerticesClipping(pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices);
+                array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices = ODM_FarClip(pOutdoor->pBModels[model_id].pFaces[face_id].uNumVertices);
                 uNumVertices = array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices;
                 ODM_Project(array_77EC08[pODMRenderParams->uNumPolygons].uNumVertices);
               }