changeset 1045:d3f4c6584ada

Intersect_Ray_Face clean
author Ritor1
date Tue, 21 May 2013 16:13:43 +0600
parents a85f5cb295b7
children 5758ddc56127
files Vis.cpp mm7_5.cpp
diffstat 2 files changed, 25 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- a/Vis.cpp	Tue May 21 15:17:18 2013 +0600
+++ b/Vis.cpp	Tue May 21 16:13:43 2013 +0600
@@ -367,8 +367,6 @@
     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))
       {
@@ -547,101 +545,25 @@
 //----- (004C1C0C) --------------------------------------------------------
 bool Vis::Intersect_Ray_Face(RenderVertexSoft *pRayStart, RenderVertexSoft *pRayEnd, float *pDepth, RenderVertexSoft *Intersection, BLVFace *pFace, unsigned int pBModelID)
 {
-  //BLVFace *v7; // ebx@1
-  //bool result; // eax@1
-  double v9; // st7@3
-  //__int16 v10; // fps@3
-  //char v11; // c0@3
-  //char v12; // c2@3
-  //char v13; // c3@3
-  //__int16 v14; // fps@5
-  //char v15; // c0@5
-  //char v16; // c2@5
-  //char v17; // c3@5
-  double c1; // st5@6
-  //__int16 v19; // fps@6
-  //char v20; // c0@6
-  //char v21; // c2@6
-  //char v22; // c3@6
-  //unsigned __int8 v23; // c0@6
-  //char v24; // c2@6
-  //unsigned __int8 v25; // c3@6
-  //char v26; // zf@6
-  double v27; // st6@10
-  //__int16 v28; // fps@10
-  //unsigned __int8 v29; // c0@10
-  //char v30; // c2@10
-  //unsigned __int8 v31; // c3@10
-  double c2; // st7@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
+  float c1; // st5@6
+  float c2; // st7@11
+  Vec3_short_ IntersectPoint; // ST04_6@11
 
   if (pFace->Portal() || pFace->Invisible())
     return false;
 
-  int ray_dir_x = pRayEnd->vWorldPosition.x - pRayStart->vWorldPosition.x,//dir_x y z это вектор направления
-      ray_dir_y = pRayEnd->vWorldPosition.y - pRayStart->vWorldPosition.y,//точка В - точка А  = вектор из А в В
+  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;
 
-  /*v9 =   ray_dir_z * pFace->pFacePlane.vNormal.z
-           + ray_dir_y  * pFace->pFacePlane.vNormal.y//скалярное произведение направления луча и нормали к полигону
-           + ray_dir_x * pFace->pFacePlane.vNormal.x;//= косинус угла между двумя векторами
-  if (v9 >= 0)   // ray faces face's normal ( > 0) or parallel ( == 0)
-    return false;*/
-
-//ray   = t dir + start
-//plane = (p - vertex) normal = -d
-//
-//
-//(t dir + start - vertex) normal = -d
-//
-//      -d - (start - vertex) norm
-//t =       --------------------
-//               dir norm
-
-
-  /*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,//ndir - нормализованное направление
-        ndir_y = ray_dir_y / dir_mag,//В результате нормализации получается вектор, направление которого совпадает с исходным, а модуль равен единице (единичный вектор).
-        ndir_z = ray_dir_z / dir_mag;//Чтобы нормализовать произвольный вектор, достаточно разделить каждый компонент вектора на модуль вектора
-
-  int face_center_x = (pFace->pBounding.x1 + pFace->pBounding.x2) / 2,//усреднённые координаты баундинга
-      face_center_y = (pFace->pBounding.y1 + pFace->pBounding.y2) / 2,
-      face_center_z = (pFace->pBounding.z1 + pFace->pBounding.z2) / 2;
-
-  int to_plane_x = pRayStart->vWorldPosition.x - face_center_x,//вектор из глас к середине фейса
-      to_plane_y = pRayStart->vWorldPosition.y - face_center_y,
-      to_plane_z = pRayStart->vWorldPosition.z - face_center_z;*/
-
-  //float t = /*-pFace->pFacePlane.dist*/ - (to_plane_x * pFace->pFacePlane.vNormal.x + to_plane_y * pFace->pFacePlane.vNormal.y + to_plane_y * pFace->pFacePlane.vNormal.z) /
-            //       (ndir_x * pFace->pFacePlane.vNormal.x + ndir_y * pFace->pFacePlane.vNormal.y + ndir_z * pFace->pFacePlane.vNormal.z);//насколько сильно луч из камеры отклоняется от луча до центра фейса
-/*  if (t <= *pDepth)
-  {
-    int intersection_x = pRayStart->vWorldPosition.x + ndir_x * t,
-        intersection_y = pRayStart->vWorldPosition.y + ndir_y * t,
-        intersection_z = pRayStart->vWorldPosition.z + ndir_z * t;
-
-    if (intersection_x < pFace->pBounding.x1 || intersection_x > pFace->pBounding.x2 ||
-        intersection_y < pFace->pBounding.y1 || intersection_y > pFace->pBounding.y2 ||
-        intersection_z < pFace->pBounding.z1 || intersection_z > pFace->pBounding.z2)
-        return false;
-
-    pFace->uAttributes |= 0x80000000;
-    return true;
-  }
-
-  return false;*/
-
-
 //c1 = -d-(n*p0)
   c1 = -pFace->pFacePlane.dist -(pFace->pFacePlane.vNormal.x * pRayStart->vWorldPosition.x
         + pFace->pFacePlane.vNormal.y * pRayStart->vWorldPosition.y
         + pFace->pFacePlane.vNormal.z * pRayStart->vWorldPosition.z);
-  //if (c1 > 0)
-    //return false;
-#define EPSILON 0.000001
+  if (c1 > 0)
+    return false;
+  #define EPSILON 1e-6
+
 //c2 = n*u
   c2 = pFace->pFacePlane.vNormal.x * ray_dir_y
        + pFace->pFacePlane.vNormal.y * ray_dir_x 
@@ -650,28 +572,23 @@
     return false;
 
 //t = -d-(n*p0)/n*u
-  double t = c1 / c2;//точка соприкосновения
-
-  //if (t < 0 || t > 1)
-    //return false;
+  float t = c1 / c2;
 
-  // p(t) = p0 + tu;
-  // p(t) - вектор указывающий в точку на плоскости
-  // p0 -  начало вектора, точка наблюдателя, камеры
-  // t - 
-  // u - вектор направления
-  Intersection->vWorldPosition.x = pRayStart->vWorldPosition.x + t * ray_dir_y;//12432 < X < 12656
-  Intersection->vWorldPosition.y = pRayStart->vWorldPosition.y + t * ray_dir_x;//-96 < Y < 1088
-  Intersection->vWorldPosition.z = pRayStart->vWorldPosition.z + t * ray_dir_z;//Z == 192
-
-  v34.x = (signed __int64)Intersection->vWorldPosition.x;
-  v34.y = (signed __int64)Intersection->vWorldPosition.y;
-  v34.z = (signed __int64)Intersection->vWorldPosition.z;
-        
-  if ( !_4C1D2B(pFace, v34, pBModelID) )
+  if (t < 0 || t > 1)
     return false;
 
-  //a5b = v27;
+// p(t) = p0 + tu;
+  Intersection->vWorldPosition.x = pRayStart->vWorldPosition.x + t * ray_dir_y;
+  Intersection->vWorldPosition.y = pRayStart->vWorldPosition.y + t * ray_dir_x;
+  Intersection->vWorldPosition.z = pRayStart->vWorldPosition.z + t * ray_dir_z;
+
+  IntersectPoint.x = (signed __int64)Intersection->vWorldPosition.x;
+  IntersectPoint.y = (signed __int64)Intersection->vWorldPosition.y;
+  IntersectPoint.z = (signed __int64)Intersection->vWorldPosition.z;
+        
+  if ( !_4C1D2B(pFace, IntersectPoint, pBModelID) )
+    return false;
+
   //*pDepth = t;
   return true;
 }
@@ -971,7 +888,7 @@
   pStartR.x = pIndoorCamera->pos.x;
   pStartR.y = pIndoorCamera->pos.y;
   pRotX = pIndoorCamera->sRotationX + UnprojectY((signed __int64)fMouseY);
-  pDepth = fixpoint_from_float(fPickDepth);
+  pDepth = fixpoint_from_float(/*(int)&fMouseX, */fPickDepth);
   Vec3_int_::Rotate(pDepth, pRotY, pRotX, pStartR, &outx, &outy, &outz);
 
   v11[0].flt_2C = 0.0;
--- a/mm7_5.cpp	Tue May 21 15:17:18 2013 +0600
+++ b/mm7_5.cpp	Tue May 21 16:13:43 2013 +0600
@@ -5354,28 +5354,14 @@
 //----- (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(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),
        sinf_x = sinf(3.14159265f * sRotX / 1024.0f),
        cosf_y = cosf(3.14159265f * sRotY / 1024.0f),
        sinf_y = sinf(3.14159265f * sRotY / 1024.0f);
- //sDepth = 14000000;
+
  *outx = v.x + ((unsigned __int64)(sinf_y * (signed __int64)((unsigned __int64)(cosf_x * (signed __int64)sDepth)>> 16)));
  *outy = v.y + ((unsigned __int64)(cosf_y * (signed __int64)((unsigned __int64)(cosf_x * (signed __int64)sDepth)>> 16)));
  *outz = v.z + ((unsigned __int64)(sinf_x * (signed __int64)sDepth) >> 16);
-
 }
 
 //----- (0043AB61) --------------------------------------------------------