예제 #1
0
// 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;
}
예제 #2
0
void App::UpdateSNBTerrain()
{	
	if (!terrainload_) return;
	
	ActiveCam_->getFrom((float*)g_CameraPos);
	ActiveCam_->getTo((float*)g_CameraLookAt);

	// Currently intersections with the base mesh are not supported
	D3DXVECTOR3 StartPoint;
	StartPoint.x = g_CameraPos.x;
	StartPoint.y = g_pElevDataSource->GetGlobalMinElevation()*g_fElevationScale - g_fElevationSamplingInterval;
	StartPoint.z = g_CameraPos.z;
	float DistToSurface = 0.f;
	g_TerrainDX11Render.RayCast(StartPoint, D3DXVECTOR3(0,1,0), &DistToSurface);
	float fTerrainHeightUnderCamera = StartPoint.y + DistToSurface;

	float fMinimalDistToSurfae = max(ActiveCam_->GetNear() *2, g_fElevationSamplingInterval * 5.f);
	fTerrainHeightUnderCamera += fMinimalDistToSurfae;
	if( g_CameraPos.y < fTerrainHeightUnderCamera )
	{
		g_CameraPos.y = Min(3000.f, fTerrainHeightUnderCamera);
		D3DXVECTOR3 dir;
		ActiveCam_->getDir((float*)dir);
		g_CameraLookAt = g_CameraPos + dir;
		//g_Camera.SetViewParams( &g_CameraPos, &g_CameraLookAt );	
		
		ActiveCam_->setFrom((float*)g_CameraPos);
		ActiveCam_->setTo((float*)g_CameraLookAt);
		
		ActiveCam_->computeModelView();		
	}
	
	BaseCamera* pCam = GetApp()->ActiveCam_;
	//D3DXMATRIX mProj;
	//D3DXMATRIX mView;

	//const unsigned int size16 = sizeof(float) * 16;		 
	//memcpy(&mView, pCam->getViewMatrix(), size16);
	//memcpy(&mProj, pCam->getProjectionMatrix(), size16);

	g_TerrainDX11Render.UpdateModel( g_CameraPos, pCam->getProjectionMatrix() );
}