www.pudn.com > roam.rar > RoamTerrain.cpp
// RoamTerrain.cpp: implementation of the CRoamTerrain class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ROAM.h"
#include "RoamTerrain.h"
#include "fstream.h"
#include "math.h"
#include "landscape.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
double *gHeightMaster;
extern void SetMinMaxElevation(float zmin,float zmax);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRoamTerrain::CRoamTerrain()
{
LoadTerrainData();
// loadTerrain(1024, &heightMap);
gLand.Init(heightMap);
}
CRoamTerrain::~CRoamTerrain()
{
if(heightMap)
free(heightMap);
}
/////////////////////////////////////////////
////// 读入grid格式高程数据 ///////////////
/////////////////////////////////////////////
BOOL CRoamTerrain::LoadTerrainData()
{
char szValue[409600];
float zmin;
float zmax;
int i = 0;
int j = 0;
BOOL status = FALSE;
ifstream is("test.grd"); //读入grid文件
is.getline(szValue,sizeof(szValue));//读入dsaa
is.getline(szValue,sizeof(szValue));//读入row&col
char seps[] = " ";
char *token;
token = strtok(szValue, seps );
row = atoi(szValue);
token = strtok(NULL, seps );
col = atoi(token);
is.getline(szValue,sizeof(szValue));//读入xmin.xmax
is.getline(szValue,sizeof(szValue));//读入ymin.ymax
is.getline(szValue,sizeof(szValue));//读入zmin.zmax
token = strtok(szValue, seps );
zmin = (float)atof(token);
token = strtok(NULL, seps);
zmax = (float)atof(token);
SetMinMaxElevation(zmin,zmax);
heightMap = (double*)malloc(row*col*sizeof(double));
i=0;
while(is.eof()==false)
{
is.getline(szValue,sizeof(szValue));////读入高程数据
token = strtok(szValue, seps );
while(token!=NULL)
{
heightMap[i] = (double)atof(token);
token = strtok(NULL,seps);
i++;
}
}
is.close();
status = TRUE;
return status;
}
void CRoamTerrain::RoamDrawScene(int viewPosX,int viewPosY)
{
// Perform all the functions needed to render one frame.
gLand.Reset(viewPosX,viewPosY);
gLand.Tessellate();
gLand.Render();
}