BVB Source Codes

CRYENGINE Show terrain_sector.cpp Source code

Return Download CRYENGINE: download terrain_sector.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   terrain_sector.cpp
  5. //  Version:     v1.00
  6. //  Created:     28/5/2001 by Vladimir Kajalin
  7. //  Compilers:   Visual Studio.NET
  8. //  Description: sector initialiazilation, objects rendering
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13.  
  14. #include "StdAfx.h"
  15. #include "terrain_sector.h"
  16. #include "terrain.h"
  17. #include "ObjMan.h"
  18.  
  19. int CTerrainNode::GetMML(int nDist, int mmMin, int mmMax)
  20. {
  21.         const int nStep = 48;
  22.  
  23.         for (int i = mmMin; i < mmMax; i++)
  24.                 if (nStep << i > nDist)
  25.                         return i;
  26.  
  27.         return mmMax;
  28. }
  29.  
  30. void CTerrainNode::FillSectorHeightMapTextureData(Array2d<float> &arrHmData)
  31. {
  32.         FUNCTION_PROFILER_3DENGINE;
  33.  
  34.         int nTexSize = m_pTerrain->m_texCache[2].m_nDim;
  35.         float fBoxSize = GetBBox().GetSize().x;
  36.         arrHmData.Allocate(nTexSize);
  37.         for (int x = 0; x < nTexSize; x++) for (int y = 0; y < nTexSize; y++)
  38.         {
  39.                 arrHmData[x][y] = m_pTerrain->GetZApr(
  40.                         (float)m_nOriginX + fBoxSize * float(x) / nTexSize * (1.f + 1.f / (float)nTexSize),
  41.                         (float)m_nOriginY + fBoxSize * float(y) / nTexSize * (1.f + 1.f / (float)nTexSize), 0);
  42.         }
  43. }
  44.  
  45. void CTerrainNode::SetLOD(const SRenderingPassInfo& passInfo)
  46. {
  47.         // Calculate geometry LOD
  48.         const float fDist = m_arrfDistance[passInfo.GetRecursiveLevel()];
  49.  
  50.         if (fDist < CTerrain::GetSectorSize() + (CTerrain::GetSectorSize() >> 2))
  51.                 m_cNewGeomMML = 0;
  52.         else
  53.         {
  54.                 float fAllowedError = (passInfo.GetZoomFactor() * GetCVars()->e_TerrainLodRatio * fDist) / 180.f * 2.5f;
  55.  
  56.                 int nGeomMML;
  57.                 for (nGeomMML = GetTerrain()->m_nUnitsToSectorBitShift - 1; nGeomMML > m_rangeInfo.nUnitBitShift; nGeomMML--)
  58.                         if (m_pGeomErrors[nGeomMML] < fAllowedError)
  59.                                 break;
  60.  
  61.                 m_cNewGeomMML = min(nGeomMML, int(fDist / 32));
  62.         }
  63.  
  64.         // Calculate Texture LOD
  65.         if (passInfo.IsGeneralPass())
  66.                 m_cNodeNewTexMML = GetTextureLOD(fDist, passInfo);
  67. }
  68.  
  69. uint8 CTerrainNode::GetTextureLOD(float fDistance, const SRenderingPassInfo& passInfo)
  70. {
  71.         int nDiffTexDim = GetTerrain()->m_arrBaseTexInfos[m_nSID].m_TerrainTextureLayer[0].nSectorSizePixels;
  72.  
  73.         float fTexSizeK = nDiffTexDim ? float(nDiffTexDim) / float(GetTerrain()->GetTerrainTextureNodeSizeMeters()) : 1.f;
  74.  
  75.         uint8 cNodeNewTexMML = GetMML(int(fTexSizeK * 0.05f * (fDistance * passInfo.GetZoomFactor()) * GetFloatCVar(e_TerrainTextureLodRatio)), 0,
  76.                                       m_bMergeNotAllowed ? 0 : GetTerrain()->GetParentNode(m_nSID)->m_nTreeLevel);
  77.  
  78.         return cNodeNewTexMML;
  79. }
  80.  
  81. int CTerrainNode::GetSecIndex()
  82. {
  83.         int nSectorSize = CTerrain::GetSectorSize() << m_nTreeLevel;
  84.         int nSectorsTableSize = CTerrain::GetSectorsTableSize(m_nSID) >> m_nTreeLevel;
  85.         return (m_nOriginX / nSectorSize) * nSectorsTableSize + (m_nOriginY / nSectorSize);
  86. }
downloadterrain_sector.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top