HRESULT InitTerrainRender() { HRESULT hr = S_OK; float fFinestLevelTriangError = g_fElevationSamplingInterval / 4.f; g_pTriangDataSource.reset( new CTriangDataSource ); CHAR str[MAX_PATH]; WideCharToMultiByte( CP_ACP, 0, g_strEncodedRQTTriangFile, -1, str, MAX_PATH, NULL, FALSE ); //hr = DXUTFindDXSDKMediaFileCch( str, MAX_PATH, g_strEncodedRQTTriangFile ); bool bCreateAdaptiveTriang = g_bForceRecreateTriang; if( !bCreateAdaptiveTriang ) { if( SUCCEEDED(hr) ) { // Try load triangulation data file hr = g_pTriangDataSource->LoadFromFile(str); if( SUCCEEDED(hr) ) { if( g_pTriangDataSource->GetNumLevelsInHierarchy() != g_pElevDataSource->GetNumLevelsInHierarchy() || g_pTriangDataSource->GetPatchSize() != g_pElevDataSource->GetPatchSize() ) bCreateAdaptiveTriang = true; // Incorrect parameters } else bCreateAdaptiveTriang = true; // Loading failed } else bCreateAdaptiveTriang = true; // File not found } // Init empty adaptive triangulation data source if file was not found or other problem occured if( bCreateAdaptiveTriang ) { g_pTriangDataSource->Init( g_pElevDataSource->GetNumLevelsInHierarchy(), g_pElevDataSource->GetPatchSize(), fFinestLevelTriangError ); } g_TerrainDX11Render.Init(g_TerrainRenderParams, g_DX11PatchRenderParams, g_pElevDataSource.get(), g_pTriangDataSource.get() ); // Create adaptive triangulation if file was not found or other problem occured if( bCreateAdaptiveTriang ) { g_TerrainDX11Render.ConstructPatchAdaptiveTriangulations(); hr = g_pTriangDataSource->SaveToFile(str); } SPatchBoundingBox TerrainAABB; g_TerrainDX11Render.GetTerrainBoundingBox(TerrainAABB); return S_OK; }
// Loads the selected scene HRESULT LoadScene() { memset( g_strRawDEMDataFile, 0, sizeof(g_strRawDEMDataFile) ); memset( g_strEncodedRQTTriangFile, 0, sizeof(g_strEncodedRQTTriangFile) ); // Get selected config file int iSelectedConfigFile = 0; // Parse the config file if( FAILED(ParseConfigurationFile( g_ConfigFiles[iSelectedConfigFile].c_str() )) ) { //LOG_ERROR(_T("Failed to load config file %s"), g_ConfigFiles[iSelectedConfigFile].c_str() ); return E_FAIL; } g_TerrainRenderParams.m_fElevationSamplingInterval = g_fElevationSamplingInterval; // Create data source try { g_pElevDataSource.reset( new CElevationDataSource(g_strRawDEMDataFile, g_iPatchSize) ); } catch(const std::exception &) { LOG_ERROR(_T("Failed to create elevation data source")); return E_FAIL; } g_TerrainRenderParams.m_iNumLevelsInPatchHierarchy = g_pElevDataSource->GetNumLevelsInHierarchy(); g_TerrainRenderParams.m_fGlobalMinElevation = g_pElevDataSource->GetGlobalMinElevation() * g_fElevationScale ; g_TerrainRenderParams.m_fGlobalMaxElevation = g_pElevDataSource->GetGlobalMaxElevation() * g_fElevationScale ; g_TerrainRenderParams.m_iPatchSize = g_pElevDataSource->GetPatchSize(); g_TerrainRenderParams.m_fElevationScale = g_fElevationScale; return S_OK; }