changeset 1054:5520fdca7a74

m
author Ritor1
date Wed, 22 May 2013 22:22:36 +0600
parents 9318dd3f3711
children 010a844ef4a0
files Vis.cpp mm7_5.cpp
diffstat 2 files changed, 80 insertions(+), 123 deletions(-) [+]
line wrap: on
line diff
--- a/Vis.cpp	Tue May 14 23:16:10 2013 +0600
+++ b/Vis.cpp	Wed May 22 22:22:36 2013 +0600
@@ -366,6 +366,8 @@
     auto bmodel = &pOutdoor->pBModels[i];
     for (uint j = 0; j < bmodel->uNumFaces; ++j)
     {
+		if ( i == 77 && j == 17 )//
+		  __debugbreak();//
       auto face = &bmodel->pFaces[j];
       if (is_part_of_selection(face, filter))
       {
@@ -545,7 +547,7 @@
 {
   //BLVFace *v7; // ebx@1
   //bool result; // eax@1
-  double v9; // st7@3
+  double c2; // st7@3
   //__int16 v10; // fps@3
   //char v11; // c0@3
   //char v12; // c2@3
@@ -554,7 +556,8 @@
   //char v15; // c0@5
   //char v16; // c2@5
   //char v17; // c3@5
-  double v18; // st5@6
+  double c1; // st5@6
+  double v9;
   //__int16 v19; // fps@6
   //char v20; // c0@6
   //char v21; // c2@6
@@ -563,13 +566,13 @@
   //char v24; // c2@6
   //unsigned __int8 v25; // c3@6
   //char v26; // zf@6
-  double v27; // st6@10
+  double t2; // st6@10
   //__int16 v28; // fps@10
   //unsigned __int8 v29; // c0@10
   //char v30; // c2@10
   //unsigned __int8 v31; // c3@10
   //double v32; // st7@11
-  Vec2_short_ v33; // ST1E_4@11
+  //Vec2_short_ v33; // ST1E_4@11
   Vec3_short_ v34; // ST04_6@11
   //float a5a; // [sp+30h] [bp+18h]@10
   //float a5b; // [sp+30h] [bp+18h]@13
@@ -578,7 +581,7 @@
     return false;
 
   
-  int ray_dir_x = pRayEnd->vWorldPosition.x - pRayStart->vWorldPosition.x,
+  int ray_dir_x = pRayEnd->vWorldPosition.x - pRayStart->vWorldPosition.x,//вектор направления
       ray_dir_y = pRayEnd->vWorldPosition.y - pRayStart->vWorldPosition.y,
       ray_dir_z = pRayEnd->vWorldPosition.z - pRayStart->vWorldPosition.z;
 
@@ -600,11 +603,11 @@
 
 
   float dir_mag = sqrtf(ray_dir_x * ray_dir_x + ray_dir_y * ray_dir_y + ray_dir_z * ray_dir_z);
-  float ndir_x = ray_dir_x / dir_mag,
+  float ndir_x = ray_dir_x / dir_mag,//нормализованное направление
         ndir_y = ray_dir_y / dir_mag,
         ndir_z = ray_dir_z / dir_mag;
 
-  int face_center_x = (a5->pBounding.x1 + a5->pBounding.x2) / 2,
+  int face_center_x = (a5->pBounding.x1 + a5->pBounding.x2) / 2,//центр фейса
       face_center_y = (a5->pBounding.y1 + a5->pBounding.y2) / 2,
       face_center_z = (a5->pBounding.z1 + a5->pBounding.z2) / 2;
 
@@ -614,7 +617,7 @@
 
   float t = /*-a5->pFacePlane.dist*/ - (to_plane_x * a5->pFacePlane.vNormal.x + to_plane_y * a5->pFacePlane.vNormal.y + to_plane_y * a5->pFacePlane.vNormal.z) /
                    (ndir_x * a5->pFacePlane.vNormal.x + ndir_y * a5->pFacePlane.vNormal.y + ndir_z * a5->pFacePlane.vNormal.z);
-  if (t <= *pDepth)
+  /*if (t <= *pDepth)
   {
     int intersection_x = pRayStart->vWorldPosition.x + ndir_x * t,
         intersection_y = pRayStart->vWorldPosition.y + ndir_y * t,
@@ -630,78 +633,45 @@
   }
 
   
-  return false;
+  return false;*/
 
 //  v7 = a5;
   //result = a5->uAttributes;
-  v9 =   pRayEnd->vWorldPosition.z * a5->pFacePlane.vNormal.z
-           + pRayEnd->vWorldPosition.y * a5->pFacePlane.vNormal.y
-           + pRayEnd->vWorldPosition.x * a5->pFacePlane.vNormal.x;
-  if (v9 >= 0)   // ray faces face's normal ( > 0) or parallel ( == 0)
-    return false;
-  
-  a5->uAttributes |= 0x80000000;
-  return false;
+ 
+  //a5->uAttributes |= 0x80000000;
+  //return false;
 
-  v18 = -(a5->pFacePlane.vNormal.y * pRayStart->vWorldPosition.y
-        + pRayStart->vWorldPosition.x * a5->pFacePlane.vNormal.x
-        + pRayStart->vWorldPosition.z * a5->pFacePlane.vNormal.z
-        + a5->pFacePlane.dist);
-  if (v18 > 0)
-    return false;
-  //UNDEF(v19);
-  //v20 = v9 < 0.0;
-  //v21 = 0;
-  //v22 = v9 == 0.0;
-  //BYTE1(result) = HIBYTE(v19);
-  /*v23 = v18 < 0.0;
-  v24 = 0;
-  v25 = v18 == 0.0;
-  v26 = (BYTE1(result) & 0x41) == 0;
-  BYTE1(result) = HIBYTE(v19);
-  if ( v26 )
-  {
-    if ( v18 < 0.0 )
-      goto LABEL_12;
-  }
-  else
-  {
-    if ( !(v23 | v25) )
-    {
-LABEL_12:
-      LOBYTE(result) = 0;
-      return result;
-    }
-  }*/
-
-  //a5a = v18;
-  v27 = v18 / v9;
-  //HIWORD(result) = HIWORD(pDepth);
-  //UNDEF(v28);
-  //v29 = v27 < *pDepth;
-  //v30 = 0;
-  //v31 = v27 == *pDepth;
-  //BYTE1(result) = HIBYTE(v28);
-
-  if (v27 > *pDepth)
+  c1 = -a5->pFacePlane.dist -(a5->pFacePlane.vNormal.x * pRayStart->vWorldPosition.x 
+         + a5->pFacePlane.vNormal.y * pRayStart->vWorldPosition.y
+         + a5->pFacePlane.vNormal.z * pRayStart->vWorldPosition.z);
+  if (c1 > 0)
     return false;
 
-  a5->uAttributes |= 0x80000000;
+  c2 = a5->pFacePlane.vNormal.x * ray_dir_x  + a5->pFacePlane.vNormal.y *ray_dir_y + a5->pFacePlane.vNormal.z * ray_dir_z;
+  //if (v9 >= 0)   // ray faces face's normal ( > 0) or parallel ( == 0)
+    //return false;
+
+  //t = -d-(n * p0)/n * u
+  t2 = c1 / c2;
 
-  a4->vWorldPosition.x = v27 * pRayEnd->vWorldPosition.x + pRayStart->vWorldPosition.x;
-  a4->vWorldPosition.y = v27 * pRayEnd->vWorldPosition.y + pRayStart->vWorldPosition.y;
-  a4->vWorldPosition.z = v27 * pRayEnd->vWorldPosition.z + pRayStart->vWorldPosition.z;
-  v33.x = (signed __int64)a4->vWorldPosition.x;
-  v33.y = (signed __int64)a4->vWorldPosition.y;
-  v34.x = v33.x;
-  v34.y = 0;
+  if (t2 > *pDepth)
+    return false;
+
+  //a5->uAttributes |= 0x80000000;
+
+  a4->vWorldPosition.x = pRayStart->vWorldPosition.x + t2 * ray_dir_x;//12432 < X < 12656
+  a4->vWorldPosition.y = pRayStart->vWorldPosition.y + t2 * ray_dir_y;//-96 < Y < 1088
+  a4->vWorldPosition.z = pRayStart->vWorldPosition.z + t2 * ray_dir_z;//Z == 192
+
+  v34.x = (signed __int64)a4->vWorldPosition.x;
+  v34.y = (signed __int64)a4->vWorldPosition.y;
   v34.z = (signed __int64)a4->vWorldPosition.z;
         
-  if ( _4C1D2B(a5, v34, a6) == 0.0)
+  if ( !_4C1D2B(a5, v34, a6) )
     return false;
 
   //a5b = v27;
-  *pDepth = v27;
+  //*pDepth = t2;
   return true;
 }
 
@@ -723,11 +693,13 @@
   signed int v16; // [sp+18h] [bp-4h]@10
 
   v4 = pFace;
-  if (a2.z < pFace->pBounding.z1 || a2.z > pFace->pBounding.z2 ||
-      a2.x < pFace->pBounding.x1 || a2.x > pFace->pBounding.x2 ||
-      a2.y < pFace->pBounding.y1 || a2.y > pFace->pBounding.y2)
+  if (a2.x < pFace->pBounding.x1 || a2.x > pFace->pBounding.x2 ||
+      a2.y < pFace->pBounding.y1 || a2.y > pFace->pBounding.y2 ||
+      a2.z < pFace->pBounding.z1 || a2.z > pFace->pBounding.z2)
     return false;
 
+  pFace->uAttributes |= 0x80000000;
+  return true;
   if (uModelID != -1)
     _4C2186_BLV_IntersectBModel((int *)&pFace, (int *)&uModelID,
                                 word_F8BC48_displaced_face_intersect_plane_coords_a,
@@ -925,17 +897,17 @@
         v12 = a1a;
         a3[2 * a1a] = a6->pXInterceptDisplacements[a1a]
 //                    + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] + 12 * a6->pVertexIDs[a1a]);
-					  + pOutdoor->pBModels[v11].pVertices.pVertices[a6->pVertexIDs[a1a]].x;
+					  + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[a1a]].x;
         *(a5a - 1) = a6->pYInterceptDisplacements[v12]
 //                   + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] + 12 * a6->pVertexIDs[v12] + 4);
-					 + pOutdoor->pBModels[v11].pVertices.pVertices[a6->pVertexIDs[v12]].y;
+					 + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[v12]].y;
         *(__int16 *)((char *)a5a + (int)(char *)a3 - (char *)a4) = a6->pXInterceptDisplacements[v12 + 1]
 //                                                            + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11]
 //                                                                       + 12 * a6->pVertexIDs[v12 + 1]);
-		+ pOutdoor->pBModels[v11].pVertices.pVertices[a6->pVertexIDs[v12+1]].x;
+		+ pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[v12+1]].x;
         v13 = a6->pYInterceptDisplacements[v12 + 1]
 //            + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v11] + 12 * a6->pVertexIDs[v12 + 1] + 4);
-		+ pOutdoor->pBModels[v11].pVertices.pVertices[a6->pVertexIDs[v12 + 1]].y;
+		+ pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[v12 + 1]].y;
         v14 = a5a;
         ++a1a;
         a5a += 2;
@@ -959,17 +931,17 @@
           v16 = a1a;
           a3[2 * a1a] = a6->pXInterceptDisplacements[a1a]
 //                      + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] + 12 * a6->pVertexIDs[a1a]);
-		  + pOutdoor->pBModels[v15].pVertices.pVertices[a6->pVertexIDs[a1a]].x;
+		  + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[a1a]].x;
           *(a5b - 1) = a6->pZInterceptDisplacements[v16]
 //                     + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] + 12 * a6->pVertexIDs[v16] + 8);
-		  + pOutdoor->pBModels[v15].pVertices.pVertices[a6->pVertexIDs[v16]].y;
+		  + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[v16]].y;
 		  *(__int16 *)((char *)a5b + (int)a3 - (int)a4) = a6->pXInterceptDisplacements[v16 + 1]
 //                                                              + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15]
 //                                                                         + 12 * a6->pVertexIDs[v16 + 1]);
-		  + pOutdoor->pBModels[v15].pVertices.pVertices[a6->pVertexIDs[v16+1]].x;
+		  + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[v16+1]].x;
           v17 = a6->pZInterceptDisplacements[v16 + 1]
 //              + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v15] + 12 * a6->pVertexIDs[v16 + 1] + 8);
-		  + pOutdoor->pBModels[v15].pVertices.pVertices[a6->pVertexIDs[v16+1]].z;
+		  + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[v16+1]].z;
           v18 = a5b;
           ++a1a;
           a5b += 2;
@@ -991,18 +963,18 @@
           v20 = a1a;
           a3[2 * a1a] = a6->pYInterceptDisplacements[a1a]
 //                      + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] + 12 * a6->pVertexIDs[a1a] + 4);
-		  + pOutdoor->pBModels[v19].pVertices.pVertices[a6->pVertexIDs[a1a]].y;
+		  + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[a1a]].y;
           *(a5c - 1) = a6->pZInterceptDisplacements[v20]
 //                     + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] + 12 * a6->pVertexIDs[v20] + 8);
-		  + pOutdoor->pBModels[v19].pVertices.pVertices[a6->pVertexIDs[a1a]].z;
+		  + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[a1a]].z;
           *(__int16 *)((char *)a5c + (int)(char *)a3 - (char *)a4) = a6->pYInterceptDisplacements[v20 + 1]
 //                                                              + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19]
 //                                                                         + 12 * a6->pVertexIDs[v20 + 1]
 //                                                                         + 4);
-		  + pOutdoor->pBModels[v19].pVertices.pVertices[a6->pVertexIDs[v20+1]].y;
+		  + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[v20+1]].y;
 		  v21 = a6->pZInterceptDisplacements[v20 + 1]
 //              + *(short *)(*(int *)&pOutdoor->pBModels->pModelName[v19] + 12 * a6->pVertexIDs[v20 + 1] + 8);
-		  + pOutdoor->pBModels[v19].pVertices.pVertices[a6->pVertexIDs[v20+1]].z;
+		  + pOutdoor->pBModels[uModelID].pVertices.pVertices[a6->pVertexIDs[v20+1]].z;
           v22 = a5c;
           ++a1a;
           a5c += 2;
@@ -1019,39 +991,30 @@
 //----- (004C248E) --------------------------------------------------------
 void Vis::CastPickRay(RenderVertexSoft *pRay, float fMouseX, float fMouseY, float fPickDepth)
 {
-  int v5; // ebx@1
-  int v6; // edi@1
-  int v7; // esi@1
+  int pRotX; // esi@1
   Vec3_int_ v8; // ST08_12@1
-  int v9; // ST04_4@1
-  int v10; // eax@1
+  int pRotY; // ST04_4@1
+  int pDepth; // eax@1
   RenderVertexSoft v11[2]; // [sp+2Ch] [bp-74h]@1
-  int v12; // [sp+8Ch] [bp-14h]@1
-  int v13; // [sp+90h] [bp-10h]@1
+  int outx;
   int outz; // [sp+94h] [bp-Ch]@1
   int outy; // [sp+98h] [bp-8h]@1
-  int v16; // [sp+9Ch] [bp-4h]@1
 
-  v5 = pIndoorCamera->pos.y;
-  v6 = pIndoorCamera->pos.x;
-  v13 = pIndoorCamera->pos.x;
-  v12 = pIndoorCamera->pos.y;
-  v16 = pIndoorCamera->pos.z;
-  v7 = pIndoorCamera->sRotationY + UnprojectX((signed __int64)fMouseX);
-  v8.z = v16;
-  v8.x = v6;
-  v8.y = v5;
-  v9 = pIndoorCamera->sRotationX + UnprojectY((signed __int64)fMouseY);
-  v10 = _48B561_mess_with_scaling_along_z(/*(int)&fMouseX, */fPickDepth);
-  Vec3_int_::Rotate(v10, v7, v9, v8, (int *)&fMouseX, &outy, &outz);
+  pRotX = pIndoorCamera->sRotationY + UnprojectX((signed __int64)fMouseX);
+  v8.z = pIndoorCamera->pos.z;
+  v8.x = pIndoorCamera->pos.x;
+  v8.y = pIndoorCamera->pos.y;
+  pRotY = pIndoorCamera->sRotationX + UnprojectY((signed __int64)fMouseY);
+  pDepth = _48B561_mess_with_scaling_along_z(/*(int)&fMouseX, */fPickDepth);
+  Vec3_int_::Rotate(pDepth, pRotX, pRotY, v8, &outx, &outy, &outz);
   v11[0].flt_2C = 0.0;
-  v11[0].vWorldPosition.x = (double)SLODWORD(fMouseX);
+  v11[0].vWorldPosition.x = (double)outx;
   v11[0].vWorldPosition.y = (double)outy;
   v11[0].vWorldPosition.z = (double)outz;
   v11[1].flt_2C = 0.0;
-  v11[1].vWorldPosition.x = (double)v13;
-  v11[1].vWorldPosition.y = (double)v12;
-  v11[1].vWorldPosition.z = (double)v16;
+  v11[1].vWorldPosition.x = (double)pIndoorCamera->pos.x;
+  v11[1].vWorldPosition.y = (double)pIndoorCamera->pos.y;
+  v11[1].vWorldPosition.z = (double)pIndoorCamera->pos.z;
   memcpy(pRay, &v11[1], 0x30u);
   memcpy(&pRay[1], v11, sizeof(pRay[1]));
 }
--- a/mm7_5.cpp	Tue May 14 23:16:10 2013 +0600
+++ b/mm7_5.cpp	Wed May 22 22:22:36 2013 +0600
@@ -5393,29 +5393,23 @@
 //----- (0043AA99) --------------------------------------------------------
 void __fastcall Vec3_int_::Rotate(int sDepth, int sRotY, int sRotX, Vec3_int_ v, int *outx, int *outy, int *outz)
 {
-/*  int v7; // ebx@1
-  int v8; // ST14_4@1
-  int v9; // edi@1
   int anglea; // [sp+20h] [bp+8h]@1
-  v7 = sRotX;
-  v8 = sDepth;
-  v9 = sRotY;
-  anglea = (unsigned __int64)(stru_5C6E00->SinCos(sRotX) * (signed __int64)sDepth) >> 16;
-  *outx = v.x + ((unsigned __int64)(stru_5C6E00->SinCos(v9) * (signed __int64)anglea) >> 16);
-  *outy = v.y
-        + ((unsigned __int64)(stru_5C6E00->SinCos(v9 - stru_5C6E00->uIntegerHalfPi)
-                            * (signed __int64)anglea) >> 16);
-  *outz = v.z
-        + ((unsigned __int64)(stru_5C6E00->SinCos(v7 - stru_5C6E00->uIntegerHalfPi) * (signed __int64)v8) >> 16);*/
+
+/*  anglea = (unsigned __int64)(stru_5C6E00->SinCos(sRotX) * (signed __int64)sDepth) >> 16;
+  *outx = v.x + ((unsigned __int64)(stru_5C6E00->SinCos(sRotY) * (signed __int64)anglea) >> 16);
+  *outy = v.y + ((unsigned __int64)(stru_5C6E00->SinCos(sRotY - stru_5C6E00->uIntegerHalfPi) * (signed __int64)anglea) >> 16);
+  *outz = v.z + ((unsigned __int64)(stru_5C6E00->SinCos(sRotX - stru_5C6E00->uIntegerHalfPi) * (signed __int64)sDepth) >> 16);*/
 
  float cosf_x = cosf(3.14159265f * sRotX / 1024.0f),
        cosf_y = cosf(3.14159265f * sRotY / 1024.0f),
        sinf_x = sinf(3.14159265f * sRotX / 1024.0f),
        sinf_y = sinf(3.14159265f * sRotY / 1024.0f);
 
- *outx = v.x + ((unsigned __int64)((double)sDepth * cosf_y * cosf_x) >> 16);
- *outy = v.y + ((unsigned __int64)((double)sDepth * sinf_y * cosf_x) >> 16);
- *outz = v.z + ((unsigned __int64)((double)sDepth * sinf_x) >> 16);
+ sDepth = 14000000;
+ anglea = (unsigned __int64)(cosf_x * (signed __int64)sDepth) >> 16;
+ *outx = v.x + (unsigned __int64)(sinf_y * (signed __int64)anglea);
+ *outy = v.y + (unsigned __int64)(cosf_y * (signed __int64)anglea);
+ *outz = v.z + ((unsigned __int64)(sinf_x * (signed __int64)sDepth) >> 16);
 
 }