diff mm7_4.cpp @ 734:2f4e33c1ed24

stru154
author Nomad
date Fri, 22 Mar 2013 16:16:40 +0200
parents de482c901171
children 6daaa2f18d0d cd9ae9a2c99c
line wrap: on
line diff
--- a/mm7_4.cpp	Fri Mar 22 13:24:12 2013 +0200
+++ b/mm7_4.cpp	Fri Mar 22 16:16:40 2013 +0200
@@ -4770,204 +4770,134 @@
 
 
 //----- (0049B04D) --------------------------------------------------------
-int stru154::_49B04D(ODMFace *a2, BSPVertexBuffer *a3)
+void stru154::GetFacePlaneAndClassify(ODMFace *a2, BSPVertexBuffer *a3)
 {
-  stru154 *v3; // edi@1
-  signed int v4; // eax@1
-  signed int result; // eax@9
-  signed int v6; // [sp-8h] [bp-18h]@8
+  //stru154 *v3; // edi@1
+  //signed int v4; // eax@1
+  //signed int result; // eax@9
+  //signed int v6; // [sp-8h] [bp-18h]@8
   Vec3_float_ v; // [sp+4h] [bp-Ch]@1
+  float v7;
 
   v.x = 0.0;
-  v3 = this;
   v.y = 0.0;
   v.z = 0.0;
-  _49B13D(a2, a3, &v, (float *)&a3);
-  v4 = 2;
-  if ( a2->pFacePlane.vNormal.z )
-  {
-    if ( !a2->pFacePlane.vNormal.x && !a2->pFacePlane.vNormal.y )
-      v4 = 1;
-  }
+  GetFacePlane(a2, a3, &v, &v7);
+
+  if (fabsf(a2->pFacePlane.vNormal.z) < 1e-6f)
+    polygonType = POLYGON_VerticalWall;
+  else if (fabsf(a2->pFacePlane.vNormal.x) < 1e-6f &&
+           fabsf(a2->pFacePlane.vNormal.y) < 1e-6f)
+    polygonType = POLYGON_Floor;
   else
-  {
-    v4 = 0;
-  }
-  if ( v4 )
-  {
-    if ( v4 == 1 )
-      v6 = 3;
-    else
-      v6 = 4;
-    result = v6;
-  }
-  else
-  {
-    result = 1;
-  }
-  v3->face_plane.vNormal.x = v.x;
-  v3->face_plane.vNormal.y = v.y;
-  v3->face_plane.vNormal.z = v.z;
-  v3->face_plane.dist = *(float *)&a3;
-  v3->polygonType = (PolygonType)result;
-  return result;
+    polygonType = POLYGON_InBetweenFloorAndWall;
+
+  face_plane.vNormal.x = v.x;
+  face_plane.vNormal.y = v.y;
+  face_plane.vNormal.z = v.z;
+  face_plane.dist = v7;
 }
 
 //----- (0049B0C9) --------------------------------------------------------
-int stru154::_49B0C9(Vec3_float_ *pNormal, float dist)
+void stru154::ClassifyPolygon(Vec3_float_ *pNormal, float dist)
 {
-  signed int v3; // esi@1
-  signed int result; // eax@9
-  double v5; // st7@12
-  double v6; // st6@12
-  double v7; // st5@12
-  signed int v8; // [sp+0h] [bp-4h]@8
-
-  v3 = 2;
-  if ( pNormal->z == 0.0 )
-  {
-    v3 = 0;
-  }
+  if (fabsf(pNormal->z) < 1e-6f)
+    polygonType = POLYGON_VerticalWall;
+  else if (fabsf(pNormal->x) < 1e-6f &&
+           fabsf(pNormal->y) < 1e-6f)
+    polygonType = POLYGON_Floor;
   else
-  {
-    if ( pNormal->x == 0.0 && pNormal->y == 0.0 )
-      v3 = 1;
-  }
-  if ( v3 )
-  {
-    if ( v3 == 1 )
-      v8 = 3;
-    else
-      v8 = 4;
-    result = v8;
-  }
-  else
-  {
-    result = 1;
-  }
-  v5 = pNormal->z;
-  v6 = pNormal->y;
-  v7 = pNormal->x;
-  this->polygonType = (PolygonType)result;
-  this->face_plane.vNormal.x = v7;
-  this->face_plane.dist = dist;
-  this->face_plane.vNormal.y = v6;
-  this->face_plane.vNormal.z = v5;
-  return result;
+    polygonType = POLYGON_InBetweenFloorAndWall;
+
+  face_plane.vNormal.x = pNormal->x;
+  face_plane.dist = dist;
+  face_plane.vNormal.y = pNormal->y;
+  face_plane.vNormal.z = pNormal->z;
 }
 
 //----- (0049B13D) --------------------------------------------------------
-int stru154::_49B13D(ODMFace *pFace, BSPVertexBuffer *pVertices, Vec3_float_ *a3, float *a4)
+void stru154::GetFacePlane(ODMFace *pFace, BSPVertexBuffer *pVertices, Vec3_float_ *pOutNormal, float *pOutDist)
 {
   ODMFace *v5; // ebx@1
-  int v6; // eax@1
-  unsigned __int16 *v7; // ebx@2
-  Vec3_int_ *v8; // eax@3
+  //int v6; // eax@1
+  //unsigned __int16 *v7; // ebx@2
+  //Vec3_int_ *v8; // eax@3
   Vec3_int_ *v9; // ecx@3
-  double v10; // st7@3
-  int v11; // ecx@3
+  //double v10; // st7@3
+  //int v11; // ecx@3
   Vec3_int_ *v12; // ecx@3
-  double v13; // st7@3
-  double v14; // st6@3
-  double v15; // st5@3
-  int v16; // ecx@3
+  //double v13; // st7@3
+  //double v14; // st6@3
+  //double v15; // st5@3
+  //int v16; // ecx@3
   Vec3_int_ *v17; // eax@3
-  double v18; // st5@3
+  //double v18; // st5@3
   Vec3_float_ *v19; // eax@3
-  int result; // eax@8
-  float v21; // ecx@10
-  double v22; // st7@10
-  double v23; // st6@10
+  //int result; // eax@8
+  //float v21; // ecx@10
+  //double v22; // st7@10
+  //double v23; // st6@10
   Vec3_float_ v2; // [sp+4h] [bp-64h]@3
-  float v25; // [sp+18h] [bp-50h]@3
+  //float v25; // [sp+18h] [bp-50h]@3
   float v26; // [sp+1Ch] [bp-4Ch]@3
   float v27; // [sp+20h] [bp-48h]@3
   float v28; // [sp+24h] [bp-44h]@3
-  float v29; // [sp+2Ch] [bp-3Ch]@3
-  float v30; // [sp+30h] [bp-38h]@3
-  float v31; // [sp+34h] [bp-34h]@3
-  float v32; // [sp+38h] [bp-30h]@3
-  float v33; // [sp+3Ch] [bp-2Ch]@3
+  //float v29; // [sp+2Ch] [bp-3Ch]@3
+  //float v30; // [sp+30h] [bp-38h]@3
+  //float v31; // [sp+34h] [bp-34h]@3
+  //float v32; // [sp+38h] [bp-30h]@3
+  //float v33; // [sp+3Ch] [bp-2Ch]@3
   Vec3_float_ v1; // [sp+40h] [bp-28h]@1
-  float v35; // [sp+4Ch] [bp-1Ch]@3
-  float v36; // [sp+50h] [bp-18h]@3
-  float v37; // [sp+54h] [bp-14h]@3
+  //float v35; // [sp+4Ch] [bp-1Ch]@3
+  //float v36; // [sp+50h] [bp-18h]@3
+  //float v37; // [sp+54h] [bp-14h]@3
   Vec3_float_ v38; // [sp+58h] [bp-10h]@3
-  int v39; // [sp+64h] [bp-4h]@1
-
-  v39 = 0;
+  //int v39; // [sp+64h] [bp-4h]@1
+
+  //v39 = 0;
   v1.x = 0.0;
   v5 = pFace;
-  v6 = pFace->uNumVertices;
+  //v6 = pFace->uNumVertices;
   v1.y = 0.0;
   v1.z = 0.0;
-  if ( v6 - 1 <= 0 )
-  {
-LABEL_8:
-    a3->x = (double)(v5->pFacePlane.vNormal.x & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.x >> 16);
-    a3->y = (double)(v5->pFacePlane.vNormal.y & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.y >> 16);
-    a3->z = (double)(v5->pFacePlane.vNormal.z & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.vNormal.z >> 16);
-    result = (int)a4;
-    *a4 = (double)(v5->pFacePlane.dist & 0xFFFF) * 0.000015259022 + (double)(v5->pFacePlane.dist >> 16);
-  }
-  else
-  {
-    v7 = &pFace->pVertexIDs[1];
-    while ( 1 )
-    {
-      v8 = pVertices->pVertices;
-      v9 = &v8[*(v7 - 1)];
-      v35 = (double)v9->x;
-      v36 = (double)v9->y;
-      v10 = (double)v9->z;
-      v11 = *v7;
-      v37 = v10;
-      v12 = &v8[v11];
-      v13 = (double)v12->x;
-      v14 = (double)v12->y;
-      v15 = (double)v12->z;
-      v16 = v7[1];
-      v25 = v15;
-      v17 = &v8[v16];
-      v18 = (double)v17->x;
-      v29 = (double)v17->y;
-      v30 = (double)v17->z;
-      v31 = v13 - v35;
-      v32 = v14 - v36;
-      v33 = v25 - v37;
-      v1.x = v31;
-      v26 = v18 - v13;
-      v1.y = v32;
-      v27 = v29 - v14;
-      v1.z = v33;
-      v28 = v30 - v25;
+
+  if (pFace->uNumVertices >= 2)
+  {
+    int i = 0;
+    while ( i < pFace->uNumVertices - 2 )
+    {
+      v9 = &pVertices->pVertices[pFace->pVertexIDs[i]];
+      v12 = &pVertices->pVertices[pFace->pVertexIDs[i + 1]];
+      v17 = &pVertices->pVertices[pFace->pVertexIDs[i + 2]];
+
+      v1.x = v12->x - v9->x;
+      v26 = v17->x - v12->x;
+      v1.y = v12->y - v9->y;
+      v27 = v17->y - v12->y;
+      v1.z = v12->z - v9->z;
+      v28 = v17->z - v12->z;
       v19 = Vec3_float_::Cross(&v1, &v2, v26, v27, v28);
       v38.x = v19->x;
       v38.y = v19->y;
       v38.z = v19->z;
-      if ( v38.x != 0.0 )
-        break;
-      if ( v38.y != 0.0 || v38.z != 0.0 )
-        break;
-      ++v39;
-      ++v7;
-      if ( v39 >= pFace->uNumVertices - 1 )
-      {
-        v5 = pFace;
-        goto LABEL_8;
-      }
-    }
-    v38.Normalize();
-    v21 = v38.y;
-    a3->x = v38.x;
-    v22 = v37 * v38.z;
-    v23 = v36 * v38.y;
-    a3->y = v21;
-    a3->z = v38.z;
-    result = (int)a4;
-    *a4 = -(v22 + v23 + v35 * v38.x);
-  }
-  return result;
+      if ( v38.x != 0.0  || v38.y != 0.0 || v38.z != 0.0)
+      {
+        v38.Normalize();
+
+        pOutNormal->x = v38.x;
+        pOutNormal->y = v38.y;
+        pOutNormal->z = v38.z;
+
+        *pOutDist = -(v9->x * v38.x + v9->y * v38.y + v9->z * v38.z);
+        return;
+      }
+    }
+  }
+
+  pOutNormal->x = (double)(v5->pFacePlane.vNormal.x & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.vNormal.x >> 16);
+  pOutNormal->y = (double)(v5->pFacePlane.vNormal.y & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.vNormal.y >> 16);
+  pOutNormal->z = (double)(v5->pFacePlane.vNormal.z & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.vNormal.z >> 16);
+  *pOutDist = (double)(v5->pFacePlane.dist & 0xFFFF) / 65535.0f + (double)(v5->pFacePlane.dist >> 16);
 }