BOOL baiscobj::DisplayScene()
{ float speed=0.5f;
float x=g_eye[0],y=g_eye[2],z=g_eye[2];
if (KEY_DOWN(VK_SHIFT)) speed =speed*2;
if (KEY_DOWN(VK_LEFT)) g_Angle-=speed*2;
if (KEY_DOWN(VK_RIGHT)) g_Angle+=speed*2;
rad_xz = float (3.13149* g_Angle/180.0f);
if (KEY_DOWN(33)) g_elev +=speed;
if (KEY_DOWN(34)) g_elev -=speed;
if (g_elev<-360) g_elev =-360;
if (g_elev> 360) g_elev = 360;
if (KEY_DOWN(VK_UP))
{ g_eye[2]+=(float)sin(rad_xz)*speed;
g_eye[0]+=(float)cos(rad_xz)*speed;
}
if (KEY_DOWN(VK_DOWN))
{ g_eye[2]-=(float)sin(rad_xz)*speed;
g_eye[0]-=(float)cos(rad_xz)*speed;
}
if(g_eye[0]< MAP_SCALE) g_eye[0]= MAP_SCALE;
if(g_eye[0]> (MAP_W-2)*MAP_SCALE) g_eye[0]= (MAP_W-2)*MAP_SCALE;
if(g_eye[2]<-(MAP_W-2)*MAP_SCALE) g_eye[2]=-(MAP_W-2)*MAP_SCALE;
if(g_eye[2]> -MAP_SCALE) g_eye[2]= -MAP_SCALE;
g_eye[1] =GetHeight((float)g_eye[0],(float)g_eye[2])+gao;//gao=1.8
g_look[0] = (float)(g_eye[0] +100*cos(rad_xz));
g_look[2] = (float)(g_eye[2] +100*sin(rad_xz));
g_look[1] = g_eye[1] +g_elev;
gluLookAt(g_eye[0],g_eye[1],g_eye[2],
g_look[0],g_look[1],g_look[2],
0.0,1.0,0.0
);
return TRUE;
}
float baiscobj::GetHeight(float x, float z)
{ float CameraX = x/MAP_SCALE;//MAP_SCALE=24
float CameraZ =-z/MAP_SCALE;
int Col0 = int(CameraX);
int Row0 = int(CameraZ);
int Col1 = Col0 + 1;
int Row1 = Row0 + 1;
if (Col1 > MAP_W) Col1 = 0;//MAP_W=32
if (Row1 > MAP_W) Row1 = 0;
float h00=g_terrain[Col0 + Row0*MAP_W][1];
float h01=g_terrain[Col1 + Row0*MAP_W][1];
float h11=g_terrain[Col1 + Row1*MAP_W][1];
float h10=g_terrain[Col0 + Row1*MAP_W][1];
float tx =CameraX - int(CameraX);
float ty =CameraZ - int(CameraZ);
float txty = tx * ty;
return h00*(1.0f-ty-tx+txty)
+ h01*(tx-txty)
+ h11*txty
+ h10*(ty-txty);
}
看了半天不明白float baiscobj::GetHeight(float x, float z)这个函数是做什么用的,请帮助看看,谢谢