diff IndoorCameraD3D.cpp @ 1638:ccde94f02b75

class IndoorCamera split into BLVRenderParams and ODMRenderParams
author Nomad
date Tue, 17 Sep 2013 15:40:09 +0200
parents 2c71fa8913d2
children afc1c3514dd5
line wrap: on
line diff
--- a/IndoorCameraD3D.cpp	Tue Sep 17 14:10:41 2013 +0200
+++ b/IndoorCameraD3D.cpp	Tue Sep 17 15:40:09 2013 +0200
@@ -3,7 +3,6 @@
 #include "Game.h"
 #include "Indoor.h"
 #include "Viewport.h"
-#include "IndoorCamera.h"
 #include "Outdoor_stuff.h"
 #include "Render.h"
 #include "LOD.h"
@@ -204,20 +203,61 @@
   return is_face_faced_to_camera(pFace, &v);
 }
 
+
+
+//----- (00481CCE) --------------------------------------------------------
+float ViewTransform_ODM(RenderVertexSoft *a1)
+{
+  float result; // eax@1
+  double vCamToVertexZ; // st7@1
+  double v3; // st6@1
+  double v4; // st5@1
+  double v5; // st4@1
+  float v6; // ST04_4@3
+  float v7; // [sp+0h] [bp-14h]@1
+  float v8; // [sp+8h] [bp-Ch]@1
+  float vCamToVertexX; // [sp+Ch] [bp-8h]@1
+  float vCamToVertexY; // [sp+10h] [bp-4h]@1
+
+  v8 = pODMRenderParams->fRotationXCosine;
+  result = pODMRenderParams->fRotationXSine;
+  v7 = pODMRenderParams->fRotationXSine;
+  vCamToVertexX = a1->vWorldPosition.x - (double)pODMRenderParams->vPartyPos.x;
+  vCamToVertexY = a1->vWorldPosition.y - (double)pODMRenderParams->vPartyPos.y;
+  vCamToVertexZ = a1->vWorldPosition.z - (double)pODMRenderParams->vPartyPos.z;
+  v3 = pODMRenderParams->fRotationYCosine;
+  v4 = pODMRenderParams->fRotationYSine;
+  v5 = vCamToVertexY * pODMRenderParams->fRotationYSine + pODMRenderParams->fRotationYCosine * vCamToVertexX;
+  if (pODMRenderParams->rotation_x)
+  {
+    v6 = vCamToVertexY * pODMRenderParams->fRotationYSine + pODMRenderParams->fRotationYCosine * vCamToVertexX;
+    a1->vWorldViewPosition.x = v5 * pODMRenderParams->fRotationXCosine + pODMRenderParams->fRotationXSine * vCamToVertexZ;
+    a1->vWorldViewPosition.y = v3 * vCamToVertexY - v4 * vCamToVertexX;
+    a1->vWorldViewPosition.z = v8 * vCamToVertexZ - v6 * v7;
+  }
+  else
+  {
+    a1->vWorldViewPosition.x = vCamToVertexY * pODMRenderParams->fRotationYSine + pODMRenderParams->fRotationYCosine * vCamToVertexX;
+    a1->vWorldViewPosition.y = v3 * vCamToVertexY - v4 * vCamToVertexX;
+    a1->vWorldViewPosition.z = vCamToVertexZ;
+  }
+  return result;
+}
+
 //----- (00436523) --------------------------------------------------------
 void IndoorCameraD3D::ViewTransform(RenderVertexSoft *a1a, unsigned int uNumVertices)
 {
   if (byte_4D864C && pGame->uFlags & 0x80 ||
       uCurrentlyLoadedLevelType == LEVEL_Indoor)
   {
-    float sin_x = pIndoorCamera->fRotationXSine,
-          cos_x = pIndoorCamera->fRotationXCosine;
-    float sin_y = pIndoorCamera->fRotationYSine,
-          cos_y = pIndoorCamera->fRotationYCosine;
+    float sin_x = pBLVRenderParams->fRotationXSine,
+          cos_x = pBLVRenderParams->fRotationXCosine;
+    float sin_y = pBLVRenderParams->fRotationYSine,
+          cos_y = pBLVRenderParams->fRotationYCosine;
 
     //v4 = uNumVertices;
     //v7 = pIndoorCamera->fRotationXSine;
-    if ( pIndoorCamera->sRotationX )
+    if (pBLVRenderParams->sPartyRotX)
     {
 
         //_EAX = a1a;
@@ -264,9 +304,9 @@
                                          // 4[pIndoorCamera->fRotationYSine]
                                          // 5[pIndoorCamera->fRotationYCosine]
             }*/
-            st0 = sin_y * (a1a[i].vWorldPosition.x - pIndoorCamera->pos.x) - cos_y * (a1a[i].vWorldPosition.y - pIndoorCamera->pos.y);
-            st1 = cos_y * (a1a[i].vWorldPosition.x - pIndoorCamera->pos.x) + sin_y * (a1a[i].vWorldPosition.y - pIndoorCamera->pos.y);
-            st2 = (a1a[i].vWorldPosition.z - pIndoorCamera->pos.z);
+            st0 = sin_y * (a1a[i].vWorldPosition.x - pBLVRenderParams->vPartyPos.x) - cos_y * (a1a[i].vWorldPosition.y - pBLVRenderParams->vPartyPos.y);
+            st1 = cos_y * (a1a[i].vWorldPosition.x - pBLVRenderParams->vPartyPos.x) + sin_y * (a1a[i].vWorldPosition.y - pBLVRenderParams->vPartyPos.y);
+            st2 = (a1a[i].vWorldPosition.z - pBLVRenderParams->vPartyPos.z);
           }
           else
           {
@@ -332,9 +372,9 @@
                                          // 4[pIndoorCamera->fRotationYSine]
                                          // 5[pIndoorCamera->fRotationYCosine]
             }*/
-            st0 = cos_y * (a1a[i].vWorldPosition.y - pIndoorCamera->pos.y) + sin_y * (a1a[i].vWorldPosition.x - pIndoorCamera->pos.x);
-            st1 = cos_y * (a1a[i].vWorldPosition.x - pIndoorCamera->pos.x) - sin_y * (a1a[i].vWorldPosition.y - pIndoorCamera->pos.y);
-            st2 = (a1a[i].vWorldPosition.z - pIndoorCamera->pos.z);
+            st0 = cos_y * (a1a[i].vWorldPosition.y - pBLVRenderParams->vPartyPos.y) + sin_y * (a1a[i].vWorldPosition.x - pBLVRenderParams->vPartyPos.x);
+            st1 = cos_y * (a1a[i].vWorldPosition.x - pBLVRenderParams->vPartyPos.x) - sin_y * (a1a[i].vWorldPosition.y - pBLVRenderParams->vPartyPos.y);
+            st2 = (a1a[i].vWorldPosition.z - pBLVRenderParams->vPartyPos.z);
           }
 
           a1a[i].vWorldViewPosition.x = st1*cos_x - st2*sin_x;
@@ -398,9 +438,9 @@
               fstp    dword ptr [eax+10h]
               fstp    dword ptr [eax+14h]
             }*/
-            a1a[i].vWorldViewPosition.x = cos_y * (a1a[i].vWorldPosition.x - pIndoorCamera->pos.x) + sin_y * (a1a[i].vWorldPosition.y - pIndoorCamera->pos.y);
-            a1a[i].vWorldViewPosition.y = sin_y * (a1a[i].vWorldPosition.x - pIndoorCamera->pos.x) - cos_y * (a1a[i].vWorldPosition.y - pIndoorCamera->pos.y);
-            a1a[i].vWorldViewPosition.z = (a1a[i].vWorldPosition.z - pIndoorCamera->pos.z);
+            a1a[i].vWorldViewPosition.x = cos_y * (a1a[i].vWorldPosition.x - pBLVRenderParams->vPartyPos.x) + sin_y * (a1a[i].vWorldPosition.y - pBLVRenderParams->vPartyPos.y);
+            a1a[i].vWorldViewPosition.y = sin_y * (a1a[i].vWorldPosition.x - pBLVRenderParams->vPartyPos.x) - cos_y * (a1a[i].vWorldPosition.y - pBLVRenderParams->vPartyPos.y);
+            a1a[i].vWorldViewPosition.z = (a1a[i].vWorldPosition.z - pBLVRenderParams->vPartyPos.z);
           }
           else
           {
@@ -427,9 +467,11 @@
     }
   }
   else for (uint i = 0; i < uNumVertices; ++i)
-    pIndoorCamera->ViewTransform(a1a + i);
+    //pIndoorCamera->ViewTransform_ODM(a1a + i);
+    ViewTransform_ODM(a1a + i);
 }
 
+
 //----- (00436932) --------------------------------------------------------
 bool IndoorCameraD3D::GetFacetOrientation(char polyType, Vec3_float_ *a2, Vec3_float_ *a3, Vec3_float_ *a4)
 {
@@ -498,10 +540,24 @@
   if (pFace->Portal())
     return false;
 
+  float pos_x, pos_y, pos_z;
+  if (uCurrentlyLoadedLevelType == LEVEL_Indoor)
+  {
+    pos_x = pBLVRenderParams->vPartyPos.x;
+    pos_y = pBLVRenderParams->vPartyPos.y;
+    pos_z = pBLVRenderParams->vPartyPos.z;
+  }
+  else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor)
+  {
+    pos_x = pODMRenderParams->vPartyPos.x;
+    pos_y = pODMRenderParams->vPartyPos.y;
+    pos_z = pODMRenderParams->vPartyPos.z;
+  }
+
   //really strange cull; dot(to_cam, normal) < 0 means we see the BACK face, not font %_%
-  if ( (a2->vWorldPosition.z - (double)pIndoorCamera->pos.z) * (double)pFace->pFacePlane_old.vNormal.z
-     + (a2->vWorldPosition.y - (double)pIndoorCamera->pos.y) * (double)pFace->pFacePlane_old.vNormal.y
-     + (a2->vWorldPosition.x - (double)pIndoorCamera->pos.x) * (double)pFace->pFacePlane_old.vNormal.x < 0.0)
+  if ( (a2->vWorldPosition.z - (double)pos_z) * (double)pFace->pFacePlane_old.vNormal.z
+     + (a2->vWorldPosition.y - (double)pos_y) * (double)pFace->pFacePlane_old.vNormal.y
+     + (a2->vWorldPosition.x - (double)pos_x) * (double)pFace->pFacePlane_old.vNormal.x < 0.0)
     return false;
 
   return true;
@@ -855,15 +911,15 @@
   m5._21 = -sinf(0);        m5._22 = cosf(0);        m5._23 = 0;
   m5._31 = 0;               m5._32 = 0;              m5._33 = 1;
 
-  float cos_x1 = pIndoorCamera->fRotationXCosine,
-        sin_x1 = pIndoorCamera->fRotationXSine;
+  float cos_x1 = uCurrentlyLoadedLevelType == LEVEL_Indoor ? pBLVRenderParams->fRotationXCosine : pODMRenderParams->fRotationXCosine,
+        sin_x1 = uCurrentlyLoadedLevelType == LEVEL_Indoor ? pBLVRenderParams->fRotationXSine   : pODMRenderParams->fRotationXSine;
  //RotationX(x)
   m4._11 = 1;               m4._12 = 0;              m4._13 = 0;
   m4._21 = 0;               m4._22 = cos_x1;         m4._23 = sin_x1;
   m4._31 = 0;               m4._32 = -sin_x1;        m4._33 = cos_x1;
   
-  float cos_y1 = pIndoorCamera->fRotationYCosine,
-        sin_y1 = pIndoorCamera->fRotationYSine;
+  float cos_y1 = uCurrentlyLoadedLevelType == LEVEL_Indoor ? pBLVRenderParams->fRotationYCosine : pODMRenderParams->fRotationYCosine,
+        sin_y1 = uCurrentlyLoadedLevelType == LEVEL_Indoor ? pBLVRenderParams->fRotationYSine   : pODMRenderParams->fRotationYSine;
  //RotationY(some_angle)
   m3._11 = cos_y1;          m3._12 = 0;              m3._13 = -sin_y1;
   m3._21 = 0;               m3._22 = 1;              m3._23 = 0;
@@ -904,9 +960,9 @@
   double v4; // st7@1
   IndoorCameraD3D_Vec3 v8; // [sp+8h] [bp-1Ch]@1
 
-  v8.x = (double)pIndoorCamera->pos.x;
-  v8.y = (double)pIndoorCamera->pos.y;
-  v8.z = (double)pIndoorCamera->pos.z;
+  v8.x = (double)(uCurrentlyLoadedLevelType == LEVEL_Indoor ? pBLVRenderParams->vPartyPos.x : pODMRenderParams->vPartyPos.x);
+  v8.y = (double)(uCurrentlyLoadedLevelType == LEVEL_Indoor ? pBLVRenderParams->vPartyPos.y : pODMRenderParams->vPartyPos.y);
+  v8.z = (double)(uCurrentlyLoadedLevelType == LEVEL_Indoor ? pBLVRenderParams->vPartyPos.z : pODMRenderParams->vPartyPos.z);
   Vec3Transform(a1, a2);
 
   v4 = v8.x * a2->x + v8.y * a2->y + v8.z * a2->z;