diff Indoor.cpp @ 1370:14695590d7a6

GetPortalScreenCoord fix
author Ritor1
date Mon, 15 Jul 2013 15:03:40 +0600
parents b99aeb077d4f
children 5572e7b02f45
line wrap: on
line diff
--- a/Indoor.cpp	Thu Jul 11 17:47:33 2013 +0600
+++ b/Indoor.cpp	Mon Jul 15 15:03:40 2013 +0600
@@ -6833,81 +6833,44 @@
 //----- (00424829) --------------------------------------------------------
 bool sub_424829(int pNumVertices, BspRenderer_stru2 *a2, BspRenderer_stru2 *a3, int uFaceID)
 {
-  //int v4; // edi@1
-  //BspRenderer_stru2 *v5; // ebx@1
   int v6; // eax@3
   int min_y; // esi@5
   int max_y; // edx@5
-  //int v9; // ecx@6
   int v10; // eax@12
-  //int v11; // edi@13
-  //int v12; // edx@18
   int v13; // eax@22
-  //int v14; // edi@28
   int v15; // ecx@29
-  //int v16; // edi@30
-  //int v17; // edx@35
   int v18; // eax@39
   int v19; // eax@44
   int v20; // ecx@44
-  //int v21; // edi@45
   int v22; // edi@46
-  //__int16 *v23; // ecx@47
   int v24; // edx@48
-  //int v25; // eax@50
   int v26; // eax@55
   signed int v27; // edi@55
-  //int v28; // edx@56
   int v29; // edx@57
-  //int v30; // eax@59
   int v31; // eax@64
   signed int v32; // edi@64
-  //int v33; // edx@65
   int v34; // eax@66
   int v35; // dx@66
   __int16 v36; // dx@67
   __int16 v37; // di@67
   __int16 v38; // dx@67
-  //BspRenderer_stru2 *v39; // ecx@69
-  //int v40; // edx@69
-  //int v41; // edi@70
-  //__int16 *v42; // eax@76
-  //__int16 *v43; // eax@81
-  //__int16 *v45; // eax@87
   int v46; // edx@87
-  //__int16 v47; // cx@88
-  //int v48; // eax@93
   int v49; // esi@93
-  //__int16 *v50; // ecx@94
-  //int v51; // eax@95
-  //int v52; // eax@97
   int v53; // [sp+Ch] [bp-34h]@44
   int v54; // [sp+10h] [bp-30h]@0
   int v55; // [sp+14h] [bp-2Ch]@12
-  //__int16 *v56; // [sp+14h] [bp-2Ch]@47
-  //__int16 v57; // [sp+14h] [bp-2Ch]@76
-  //__int16 v58; // [sp+14h] [bp-2Ch]@81
   int v59; // [sp+14h] [bp-2Ch]@87
-  //BspRenderer_stru2 *v60; // [sp+18h] [bp-28h]@1
   int v61; // [sp+1Ch] [bp-24h]@29
   int v62; // [sp+20h] [bp-20h]@0
   signed int v63; // [sp+24h] [bp-1Ch]@3
   signed int v64; // [sp+28h] [bp-18h]@3
   int v65; // [sp+2Ch] [bp-14h]@5
-  //int v66; // [sp+2Ch] [bp-14h]@39
-  //int v67; // [sp+30h] [bp-10h]@22
   int v68; // [sp+34h] [bp-Ch]@12
   int v69; // [sp+34h] [bp-Ch]@29
   int v70; // [sp+34h] [bp-Ch]@46
   int v71; // [sp+34h] [bp-Ch]@75
   int v72; // [sp+34h] [bp-Ch]@80
-  //int v73; // [sp+38h] [bp-8h]@11
-  //int v74; // [sp+3Ch] [bp-4h]@1
-  //int a3a; // [sp+48h] [bp+8h]@76
-  //int a3b; // [sp+48h] [bp+8h]@87
-
-  //try graphic engine with function returning 1 always, and without
-  //return true;
+
   if ( pNumVertices <= 1 )
     return false;
   min_y = PortalFace._screen_space_y[0];
@@ -7169,16 +7132,8 @@
   BLVFace *pFace; // ebx@1
   int pNextVertices; // edx@11
   int t; // ST28_4@12
-  signed int v13; // edx@12
-  signed __int64 v14; // qtt@12
-  signed int v17; // eax@14
-  signed __int64 v18; // qtt@14
-  signed int v20; // edx@17
-  int v25; // eax@22
   int pScreenX; // eax@22
-  int v31; // eax@27
   int pScreenY; // eax@27
-  int v35; // ST30_4@30
   signed int left_num_vertices; // edi@31
   signed int right_num_vertices; // ebx@41
   signed int top_num_vertices; // edi@51
@@ -7189,12 +7144,10 @@
   int v65; // ecx@83
   signed int v71; // [sp+14h] [bp-14h]@75
   bool current_vertices_flag; // [sp+18h] [bp-10h]@9
-  int thisb; // [sp+18h] [bp-10h]@12
   int thisf; // [sp+18h] [bp-10h]@74
   signed int depth_num_vertices; // [sp+1Ch] [bp-Ch]@9
   int v80; // [sp+1Ch] [bp-Ch]@76
   bool next_vertices_flag; // [sp+20h] [bp-8h]@10
-  signed int v90; // [sp+24h] [bp-4h]@51
 
   pFace = &pIndoor->pFaces[uFaceID];
   memset(&PortalFace, 0, sizeof(stru367));
@@ -7241,8 +7194,6 @@
         &PortalFace._view_transformed_z[i + 3], &PortalFace._view_transformed_x[i + 3], &PortalFace._view_transformed_y[i + 3], 0);
     }
   }
-  //х: 55681665, 55681665, 53050369, 47787777, 45156481, 45156481
-  //x: 0x0351 a281,0x0351 a281,0x0329 7c01,0x02d9 2f01,0x02b1 0881,0x02b1 0881
   //*****************************************************************************************************************************************
   //check vertices for the nearest plane(проверка вершин есть ли в области за ближайшей плоскостью)
   if ( pFace->uNumVertices <= 0 )
@@ -7287,11 +7238,8 @@
       {
         if ( next_vertices_flag )//следующая вершина за ближней границей
         {
-          v13 = 524288 - PortalFace._view_transformed_z[i + 2];
-          LODWORD(v14) = v13 << 16;
-          HIDWORD(v14) = v13 >> 16;
           //t = near_clip - v0.z / v1.z - v0.z
-          t = v14 / PortalFace._view_transformed_z[i + 3] - PortalFace._view_transformed_z[i + 2];
+          t = fixpoint_div(524288 - PortalFace._view_transformed_z[i + 2], PortalFace._view_transformed_z[i + 3] - PortalFace._view_transformed_z[i + 2]);
           //New_x = (v1.x - v0.x)*t + v0.x
           PortalFace._view_transformed_x[depth_num_vertices] = ((unsigned __int64)((PortalFace._view_transformed_x[i + 3]
                                                            - PortalFace._view_transformed_x[i + 2]) * t) >> 16) + PortalFace._view_transformed_x[i + 2];
@@ -7303,11 +7251,8 @@
         }
         else// текущая вершина за ближней границей
         {
-          v17 = 524288 - PortalFace._view_transformed_z[i + 3];
-          LODWORD(v18) = v17 << 16;
-          HIDWORD(v18) = v17 >> 16;
           //t = near_clip - v1.z / v0.z - v1.z
-          t = v18 / PortalFace._view_transformed_z[i + 2] - PortalFace._view_transformed_z[i + 3];
+          t = fixpoint_div(524288 - PortalFace._view_transformed_z[i + 3], PortalFace._view_transformed_z[i + 2] - PortalFace._view_transformed_z[i + 3]);
           //New_x = (v0.x - v1.x)*t + v1.x
           PortalFace._view_transformed_x[depth_num_vertices] = ((unsigned __int64)((PortalFace._view_transformed_x[i + 2]
                                                    - PortalFace._view_transformed_x[i + 3]) * t) >> 16) + PortalFace._view_transformed_x[i + 3];
@@ -7379,15 +7324,13 @@
     PortalFace._screen_space_x[i + 12] = pBLVRenderParams->uViewportCenterX - ((unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)pScreenX) >> 16);
     PortalFace._screen_space_y[i + 12] = pBLVRenderParams->uViewportCenterY - ((unsigned __int64)(SHIWORD(pBLVRenderParams->field_40) * (signed __int64)pScreenY) >> 16);
   }
-  //х -34, 4, 61, 83, 83, -34
-  //y 211, 152, 172, 216, 273, 293
   // результат: при повороте камеры, когда граница портала сдвигается к краю экрана, портал остается прозрачным(видимым)
   //******************************************************************************************************************************************
   //check for left_clip plane(порверка по левой границе)
   left_num_vertices = 0;
   PortalFace._screen_space_x[depth_num_vertices + 12] = PortalFace._screen_space_x[12];
   PortalFace._screen_space_y[depth_num_vertices + 12] = PortalFace._screen_space_y[12];
-  current_vertices_flag = PortalFace._screen_space_x[12] >= (signed int)pBLVRenderParams->uViewportX;
+  current_vertices_flag = PortalFace._screen_space_x[12] >= (signed int)pBLVRenderParams->uViewportX;//8.0
   if ( depth_num_vertices < 1 )
     return 0;
   for ( uint i = 1; i <= depth_num_vertices; ++i )
@@ -7398,22 +7341,20 @@
       if ( next_vertices_flag )
       {
         //t = left_clip - v0.x / v1.x - v0.x
-        t = (signed __int64)(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 11])
-                          / (PortalFace._screen_space_x[i + 12] - PortalFace._screen_space_x[i + 11]);
+        t = fixpoint_div(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 11], PortalFace._screen_space_x[i + 12] - PortalFace._screen_space_x[i + 11]);
         //New_y = (v1.y - v0.y)*t + v0.y
-        PortalFace._screen_space_y[left_num_vertices + 9] = (signed int)(PortalFace._screen_space_y[i + 12]- PortalFace._screen_space_y[i + 11])
-                                                            * t + PortalFace._screen_space_y[i + 11];
+        PortalFace._screen_space_y[left_num_vertices + 9] = ((signed int)((PortalFace._screen_space_y[i + 12]- PortalFace._screen_space_y[i + 11])
+                                                            * t) >> 16) + PortalFace._screen_space_y[i + 11];
         //New_x = left_clip
         PortalFace._screen_space_x[left_num_vertices + 9] = pBLVRenderParams->uViewportX;
       }
       else
       {
         //t = left_clip - v1.x / v0.x - v1.x
-        t = (signed __int64)(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 12])
-                          / (PortalFace._screen_space_x[i + 11] - PortalFace._screen_space_x[i + 12]);
+        t = fixpoint_div(pBLVRenderParams->uViewportX - PortalFace._screen_space_x[i + 12], PortalFace._screen_space_x[i + 11] - PortalFace._screen_space_x[i + 12]);
         //New_y = (v0.y - v1.y)*t + v1.y
-        PortalFace._screen_space_y[left_num_vertices + 9] = (signed int)( PortalFace._screen_space_y[i + 11] - PortalFace._screen_space_y[i + 12])
-                                                            * t + PortalFace._screen_space_y[i + 12];
+        PortalFace._screen_space_y[left_num_vertices + 9] = ((signed int)(( PortalFace._screen_space_y[i + 11] - PortalFace._screen_space_y[i + 12])
+                                                            * t) >> 16) + PortalFace._screen_space_y[i + 12];
         //New_x = left_clip
         PortalFace._screen_space_x[left_num_vertices + 9] = pBLVRenderParams->uViewportX;
       }
@@ -7432,7 +7373,7 @@
   right_num_vertices = 0;
   PortalFace._screen_space_x[left_num_vertices + 9] = PortalFace._screen_space_x[9];
   PortalFace._screen_space_y[left_num_vertices + 9] = PortalFace._screen_space_y[9];
-  current_vertices_flag = PortalFace._screen_space_x[9] <= (signed int)pBLVRenderParams->uViewportZ;
+  current_vertices_flag = PortalFace._screen_space_x[9] <= (signed int)pBLVRenderParams->uViewportZ;//468.0
   if (left_num_vertices < 1)
     return 0;
   for ( uint i = 1; i <= left_num_vertices; ++i )
@@ -7443,22 +7384,20 @@
       if ( next_vertices_flag )
       {
         //t = right_clip - v1.x / v0.x - v1.x
-        t = (signed __int64)(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 9])
-                          / (PortalFace._screen_space_x[i + 8] - PortalFace._screen_space_x[i + 9]);
+        t = fixpoint_div(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 8], PortalFace._screen_space_x[i + 9] - PortalFace._screen_space_x[i + 8]);
         //New_y = (v0.y - v1.y)*t + v1.y
-        PortalFace._screen_space_y[right_num_vertices + 6] = (signed int)(PortalFace._screen_space_y[i + 8] - PortalFace._screen_space_y[i + 9])
-                                                           * t + PortalFace._screen_space_y[i + 9];
+        PortalFace._screen_space_y[right_num_vertices + 6] = ((signed int)((PortalFace._screen_space_y[i + 9] - PortalFace._screen_space_y[i + 8])
+                                                           * t) >> 16) + PortalFace._screen_space_y[i + 8];
         //New_x = right_clip
         PortalFace._screen_space_x[right_num_vertices + 6] = pBLVRenderParams->uViewportZ;
       }
       else
       {
         //t = right_clip - v0.x / v1.x - v0.x
-        t = (signed __int64)(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 8])
-                          / (PortalFace._screen_space_x[i + 9] - PortalFace._screen_space_x[i + 8]);
+        t = fixpoint_div(pBLVRenderParams->uViewportZ - PortalFace._screen_space_x[i + 9], PortalFace._screen_space_x[i + 8] - PortalFace._screen_space_x[i + 9]);
         //New_y = (v1.y - v0.y)*t + v0.y
-        PortalFace._screen_space_y[right_num_vertices + 6] = (signed int)(PortalFace._screen_space_y[i + 9] - PortalFace._screen_space_y[i + 8])
-                                                           * t + PortalFace._screen_space_y[i + 8];
+        PortalFace._screen_space_y[right_num_vertices + 6] = ((signed int)((PortalFace._screen_space_y[i + 8] - PortalFace._screen_space_y[i + 9])
+                                                           * t) >> 16) + PortalFace._screen_space_y[i + 9];
         //New_x = right_clip
         PortalFace._screen_space_x[right_num_vertices + 6] = pBLVRenderParams->uViewportZ;
       }
@@ -7478,7 +7417,7 @@
   PortalFace._screen_space_x[right_num_vertices + 6] = PortalFace._screen_space_x[6];
   PortalFace._screen_space_y[right_num_vertices + 6] = PortalFace._screen_space_y[6];
 
-  current_vertices_flag = PortalFace._screen_space_y[6] >= (signed int)pBLVRenderParams->uViewportY;
+  current_vertices_flag = PortalFace._screen_space_y[6] >= (signed int)pBLVRenderParams->uViewportY;//8.0
   if ( right_num_vertices < 1 )
     return 0;
   for ( uint i = 1; i <= right_num_vertices; ++i )
@@ -7488,18 +7427,16 @@
     {
       if ( next_vertices_flag )
       {
-        t = (signed __int64)(pBLVRenderParams->uViewportY  - PortalFace._screen_space_y[i + 5])
-                          / (PortalFace._screen_space_y[i + 6] - PortalFace._screen_space_y[i + 5]);
-        PortalFace._screen_space_x[top_num_vertices + 3] = (signed int)(PortalFace._screen_space_x[i + 6] - PortalFace._screen_space_x[i + 5])
-            * t + PortalFace._screen_space_x[i + 5];
+        t = fixpoint_div(pBLVRenderParams->uViewportY  - PortalFace._screen_space_y[i + 5], PortalFace._screen_space_y[i + 6] - PortalFace._screen_space_y[i + 5]);
+        PortalFace._screen_space_x[top_num_vertices + 3] = ((signed int)((PortalFace._screen_space_x[i + 6] - PortalFace._screen_space_x[i + 5])
+            * t) >> 16) + PortalFace._screen_space_x[i + 5];
         PortalFace._screen_space_y[top_num_vertices + 3] = pBLVRenderParams->uViewportY;
       }
       else
       {
-        t = (signed __int64)(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 6])
-                          / (PortalFace._screen_space_y[i + 5] - PortalFace._screen_space_y[i + 6]);
-        PortalFace._screen_space_x[top_num_vertices + 3] = (signed int)(PortalFace._screen_space_x[i + 5]- PortalFace._screen_space_x[i + 6])
-            * t + PortalFace._screen_space_x[i + 6];
+        t = fixpoint_div(pBLVRenderParams->uViewportY - PortalFace._screen_space_y[i + 6], PortalFace._screen_space_y[i + 5] - PortalFace._screen_space_y[i + 6]);
+        PortalFace._screen_space_x[top_num_vertices + 3] = ((signed int)((PortalFace._screen_space_x[i + 5]- PortalFace._screen_space_x[i + 6])
+            * t) >> 16) + PortalFace._screen_space_x[i + 6];
         PortalFace._screen_space_y[top_num_vertices + 3] = pBLVRenderParams->uViewportY;
       }
       top_num_vertices++;
@@ -7517,7 +7454,7 @@
   bottom_num_vertices = 0;
   PortalFace._screen_space_x[top_num_vertices + 3] = PortalFace._screen_space_x[3];
   PortalFace._screen_space_y[top_num_vertices + 3] = PortalFace._screen_space_y[3];
-  current_vertices_flag = PortalFace._screen_space_y[3] <= (signed int)pBLVRenderParams->uViewportW;
+  current_vertices_flag = PortalFace._screen_space_y[3] <= (signed int)pBLVRenderParams->uViewportW;//351.0
   if ( top_num_vertices < 1 )
     return 0;
   for ( uint i =1; i <= top_num_vertices; ++i )
@@ -7527,18 +7464,16 @@
     {
       if ( next_vertices_flag )
       {
-        t = (signed __int64)(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 3])
-                          / (PortalFace._screen_space_y[i + 2] - PortalFace._screen_space_y[i + 3]);
-        PortalFace._screen_space_x[bottom_num_vertices] = (signed int)(PortalFace._screen_space_x[i + 2] - PortalFace._screen_space_x[i + 3])
-            * t + PortalFace._screen_space_x[i + 3];
+        t = fixpoint_div(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 2], PortalFace._screen_space_y[i + 3] - PortalFace._screen_space_y[i + 2]);
+        PortalFace._screen_space_x[bottom_num_vertices] = ((signed int)((PortalFace._screen_space_x[i + 3] - PortalFace._screen_space_x[i + 2])
+            * t) >> 16) + PortalFace._screen_space_x[i + 2];
         PortalFace._screen_space_y[bottom_num_vertices] = pBLVRenderParams->uViewportW;
       }
       else
       {
-        t = (signed __int64)(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 2])
-                          / (PortalFace._screen_space_y[i + 3] - PortalFace._screen_space_y[i + 2]);
-        PortalFace._screen_space_x[bottom_num_vertices] = (signed int)(PortalFace._screen_space_x[i + 3] - PortalFace._screen_space_x[i + 2])
-            * t + PortalFace._screen_space_x[i + 2];
+        t = fixpoint_div(pBLVRenderParams->uViewportW - PortalFace._screen_space_y[i + 3], PortalFace._screen_space_y[i + 2] - PortalFace._screen_space_y[i + 3]);
+        PortalFace._screen_space_x[bottom_num_vertices] = ((signed int)((PortalFace._screen_space_x[i + 2] - PortalFace._screen_space_x[i + 3])
+            * t) >> 16) + PortalFace._screen_space_x[i + 3];
         PortalFace._screen_space_y[bottom_num_vertices] = pBLVRenderParams->uViewportW;
       }
       bottom_num_vertices++;
@@ -7551,8 +7486,6 @@
     }
     current_vertices_flag = next_vertices_flag;
   }
-  //out_x: 83,8,8,61,83
-  //out_y: 273,293,152,172,216
 //***************************************************************************************************************************************
 
   if ( !bottom_num_vertices )