diff Render.cpp @ 2320:847aba0b7f82

draw terrain distance
author Ritor1
date Fri, 21 Mar 2014 01:12:52 +0600
parents 133882370e83
children 53c9d34024d6
line wrap: on
line diff
--- a/Render.cpp	Thu Mar 20 18:44:27 2014 +0600
+++ b/Render.cpp	Fri Mar 21 01:12:52 2014 +0600
@@ -359,8 +359,8 @@
         norm = 0;
       else
         norm = &pTerrainNormals[norm_idx];
-      pGame->pLightmapBuilder->StackLights_TerrainFace(norm, &a3a, array_50AC10, 4, 1);//Ritor1: slows
-      pDecalBuilder->_49BE8A(pTilePolygon, norm, &a3a, array_50AC10, 4, 1);
+      //pGame->pLightmapBuilder->StackLights_TerrainFace(norm, &a3a, array_50AC10, 4, 1);//Ritor1: slows
+      //pDecalBuilder->_49BE8A(pTilePolygon, norm, &a3a, array_50AC10, 4, 1);
 //-----------------------------------------------------------------------------------------------
 
       ++pODMRenderParams->uNumPolygons;
@@ -376,7 +376,9 @@
         array_50AC10[k]._rhw = 1.0 / (array_73D150[k].vWorldViewPosition.x + 0.0000001000000011686097);
       }
 //---------Draw distance(Дальность отрисовки)-------------------------------
-      pODMRenderParams->shading_dist_mist = 0x5000;
+      int temp =  pODMRenderParams->shading_dist_mist;
+      if ( draw_terrain_dist_mist )
+        pODMRenderParams->shading_dist_mist = 0x5000;
       bool neer_clip = array_73D150[0].vWorldViewPosition.x < 8.0
                     || array_73D150[1].vWorldViewPosition.x < 8.0
                     || array_73D150[2].vWorldViewPosition.x < 8.0
@@ -390,16 +392,15 @@
         if ( neer_clip )
         {
           pTilePolygon->uNumVertices = ODM_NearClip(pTilePolygon->uNumVertices);
-          //ODM_Project(pTilePolygon->uNumVertices);
+          ODM_Project(pTilePolygon->uNumVertices);
         }
         if ( far_clip )
         {
-
           pTilePolygon->uNumVertices = ODM_FarClip(pTilePolygon->uNumVertices);
-          //ODM_Project(pTilePolygon->uNumVertices);
+          ODM_Project(pTilePolygon->uNumVertices);
         }
       }
-      pODMRenderParams->shading_dist_mist = 0x2000;
+      pODMRenderParams->shading_dist_mist = temp;
 
 // check the transparency and texture (tiles) mapping (проверка прозрачности и наложение текстур (тайлов))----------------------
       bool transparent = false;
@@ -8524,16 +8525,38 @@
   bool current_vertices_flag; // edi@1
   bool next_vertices_flag; // [sp+Ch] [bp-24h]@6
   double t; // st6@10
-  //int pNextVertices;
+  bool bFound;
+
+  bFound = false;
 
   if (!num_vertices)
     return 0;
+  for (uint i = 0; i < num_vertices; ++i)// есть ли пограничные вершины
+  {
+    if ( array_50AC10[i].vWorldViewPosition.x > 8.0 )
+    {
+      bFound = true;
+      break;
+    }
+  }
+  if ( !bFound )
+    return 0;
 
   memcpy(&array_50AC10[num_vertices], &array_50AC10[0], sizeof(array_50AC10[0]));
   current_vertices_flag = false;
   next_vertices_flag = false;
   if ( array_50AC10[0].vWorldViewPosition.x <= 8.0 )
     current_vertices_flag = true;
+  //check for near clip plane(проверка по ближней границе)
+  //   
+  // v3.__________________. v0
+  //   |                  |
+  //   |                  |
+  //   |                  |
+  //  ----------------------- 8.0(near_clip - 8.0)
+  //   |                  |
+  //   .__________________.
+  //  v2                     v1
 
   int out_num_vertices = 0;
   for (int i = 0; i < num_vertices; ++i)
@@ -8581,7 +8604,6 @@
   bool next_vertices_flag; // edi@1
   double t; // st6@10
   signed int depth_num_vertices; // [sp+18h] [bp-1Ch]@1
-  //int pNextVertices;
   bool bFound;
   //Доп инфо "Программирование трёхмерных игр для windows" Ламот стр 910
 
@@ -8623,14 +8645,14 @@
       if ( next_vertices_flag )//следующая вершина больше границы видимости(настоящая вершина меньше границы видимости) - v3
       {
         //t = far_clip - v2.x / v3.x - v2.x (формула получения точки пересечения отрезка с плоскостью)
-        t = (pODMRenderParams->shading_dist_mist - array_50AC10[i].vWorldViewPosition.x) / (array_50AC10[i + 1].vWorldViewPosition.x - array_50AC10[i].vWorldViewPosition.x);
+        t = (pODMRenderParams->shading_dist_mist - array_50AC10[i].vWorldViewPosition.x) / (array_50AC10[i].vWorldViewPosition.x - array_50AC10[i + 1].vWorldViewPosition.x);
         array_507D30[depth_num_vertices].vWorldViewPosition.x = pODMRenderParams->shading_dist_mist;
         //New_y = v2.y + (v3.y - v2.y)*t
-        array_507D30[depth_num_vertices].vWorldViewPosition.y = array_50AC10[i].vWorldViewPosition.y + (array_50AC10[i + 1].vWorldViewPosition.y - array_50AC10[i].vWorldViewPosition.y) * t;
+        array_507D30[depth_num_vertices].vWorldViewPosition.y = array_50AC10[i].vWorldViewPosition.y + (array_50AC10[i].vWorldViewPosition.y - array_50AC10[i + 1].vWorldViewPosition.y) * t;
         //New_z = v2.z + (v3.z - v2.z)*t
-        array_507D30[depth_num_vertices].vWorldViewPosition.z = array_50AC10[i].vWorldViewPosition.z + (array_50AC10[i + 1].vWorldViewPosition.z - array_50AC10[i].vWorldViewPosition.z) * t;
-        array_507D30[depth_num_vertices].u = array_50AC10[i].u + (array_50AC10[i + 1].u - array_50AC10[i].u) * t;
-        array_507D30[depth_num_vertices].v = array_50AC10[i].v + (array_50AC10[i + 1].v - array_50AC10[i].v) * t;
+        array_507D30[depth_num_vertices].vWorldViewPosition.z = array_50AC10[i].vWorldViewPosition.z + (array_50AC10[i].vWorldViewPosition.z - array_50AC10[i + 1].vWorldViewPosition.z) * t;
+        array_507D30[depth_num_vertices].u = array_50AC10[i].u + (array_50AC10[i].u - array_50AC10[i + 1].u) * t;
+        array_507D30[depth_num_vertices].v = array_50AC10[i].v + (array_50AC10[i].v - array_50AC10[i + 1].v) * t;
         array_507D30[depth_num_vertices]._rhw = 1.0 / pODMRenderParams->shading_dist_mist;
       }
       else//настоящая вершина больше границы видимости(следующая вершина меньше границы видимости) - v0
@@ -8639,11 +8661,11 @@
         t = (pODMRenderParams->shading_dist_mist - array_50AC10[i].vWorldViewPosition.x) / (array_50AC10[i + 1].vWorldViewPosition.x - array_50AC10[i].vWorldViewPosition.x);
         array_507D30[depth_num_vertices].vWorldViewPosition.x = pODMRenderParams->shading_dist_mist;
         //New_y = (v0.y - v1.y)*t + v1.y
-        array_507D30[depth_num_vertices].vWorldViewPosition.y = array_50AC10[i + 1].vWorldViewPosition.y + (array_50AC10[i].vWorldViewPosition.y - array_50AC10[i + 1].vWorldViewPosition.y) * t;
+        array_507D30[depth_num_vertices].vWorldViewPosition.y = array_50AC10[i].vWorldViewPosition.y + (array_50AC10[i + 1].vWorldViewPosition.y - array_50AC10[i].vWorldViewPosition.y) * t;
         //New_z = (v0.z - v1.z)*t + v1.z
-        array_507D30[depth_num_vertices].vWorldViewPosition.z = array_50AC10[i + 1].vWorldViewPosition.z + (array_50AC10[i].vWorldViewPosition.z - array_50AC10[i + 1].vWorldViewPosition.z) * t;
-        array_507D30[depth_num_vertices].u = array_50AC10[i + 1].u + (array_50AC10[i].u - array_50AC10[i + 1].u) * t;
-        array_507D30[depth_num_vertices].v = array_50AC10[i + 1].v + (array_50AC10[i].v - array_50AC10[i + 1].v) * t;
+        array_507D30[depth_num_vertices].vWorldViewPosition.z = array_50AC10[i].vWorldViewPosition.z + (array_50AC10[i + 1].vWorldViewPosition.z - array_50AC10[i].vWorldViewPosition.z) * t;
+        array_507D30[depth_num_vertices].u = array_50AC10[i].u + (array_50AC10[i + 1].u - array_50AC10[i].u) * t;
+        array_507D30[depth_num_vertices].v = array_50AC10[i].v + (array_50AC10[i + 1].v - array_50AC10[i].v) * t;
         array_507D30[depth_num_vertices]._rhw = 1.0 / pODMRenderParams->shading_dist_mist;
       }
       ++depth_num_vertices;
@@ -8655,13 +8677,6 @@
     }
     current_vertices_flag = next_vertices_flag;
   }
-  for (uint i = 0; i < depth_num_vertices; ++i)// есть ли пограничные вершины
-  {
-    if ( array_507D30[i].vWorldViewPosition.x > pODMRenderParams->shading_dist_mist )
-    {
-      __debugbreak();
-    }
-  }
   return depth_num_vertices >= 3 ? depth_num_vertices : 0;
 }