BAISCOBJ.CPP
Upload User: xuczgm
Upload Date: 2022-04-25
Package Size: 8601k
Code Size: 62k
Category:

Special Effects

Development Platform:

Visual C++

  1. // 学程序编游戏系列丛书
  2. // 唐明理 E_mail: cqtmL@163.com
  3. //====================================================================
  4. #include "stdafx.h"
  5. #include "baiscobj.h"
  6. #include "../include/BITMAP.H"
  7. #define PLANE_FLY_SPEED 1.0f //liuying
  8. #define PLANE_MAX_SPEED 6.0f //liuying
  9. #define CHANGE 3.13149/180.0f //liuying
  10. extern GLfloat r;       //飞机盘旋角度
  11. float gao=0.8f;
  12. extern CString test;    //场景信息
  13. //////////////////////////////////////////////////////////////////////
  14. baiscobj::baiscobj()
  15. {
  16. g_eye[0]=250; //2*MAP-2*MAP_SCALE;//
  17. g_eye[2]=-260;//
  18. g_Angle=60;//
  19. g_elev=-0;//
  20. char charTemp[200];
  21. ::GetCurrentDirectory(200,charTemp);
  22. m_strFolderName = (CString)charTemp;
  23. for(int i=0;i<9;i++)
  24. {
  25. GetDEMList[i]= new CGetDEMList;
  26. }
  27. m_bGetDataStatus=false;
  28. ////////////////////////////////////////////////////////////////////////
  29. LoadT8("data/images/sand3.bmp",  g_cactus[0]); //地面帖图
  30. LoadT8("data/images/3RBack.bmp",g_cactus[2]); //天空贴图后
  31. LoadT8("data/images/3Front.bmp",g_cactus[3]); //天空贴图前
  32. LoadT8("data/images/3Top.bmp",  g_cactus[4]); //天空贴图顶
  33. LoadT8("data/images/3Left.bmp", g_cactus[5]); //天空贴图左
  34. LoadT8("data/images/3Right.bmp",g_cactus[6]); //天空贴图右
  35. InitTerrain(5);//初始化地面
  36. m_3ds=new CLoad3DS();
  37. load3dobj("data/3ds/","飞机歼击1.3ds",1);
  38. //战斗机状态初始化
  39. plane_x=250,plane_y=2,plane_z=-250; //初始化战斗机位置
  40. plane_x_angle=0,plane_y_angle=0,plane_z_angle=0; //初始化战斗机旋转的角度
  41. plane_speed=0; //初始化战斗机速度
  42. plane_can_fly=false;
  43. plane_left_right_sign=0;
  44. cameratype=0; //摄象机角度类型初始化
  45. glEnable(GL_TEXTURE_2D);
  46. ///////////////////////////////////////爆炸碎片初始化
  47. InitData();
  48. }
  49. baiscobj::~baiscobj()
  50. {
  51. for(int i=0;i<9;i++)
  52. {
  53. delete GetDEMList[i];
  54. glDeleteTextures(1,&textureID[i]);
  55. }
  56. //注记
  57. for(i=0;i<m_iTextureObjectNum;i++)//纹理物体
  58. {
  59. glDeleteLists(m_pTextureObject[i].m_ilid,1);
  60. glDeleteTextures(1,&(m_pTextureObject[i].m_iTextureObjectID));
  61. if(m_pTextureObject[i].m_iDrawNum!=0)
  62. delete []m_pTextureObject[i].m_pTextureObjectCoordinate;
  63. }
  64. if(m_iTextureObjectNum!=0)
  65. delete []m_pTextureObject;
  66.     //天空
  67. glDeleteLists(listsky,1);
  68. glDeleteTextures(1,&textureIDsky);
  69. for(i=0;i<16;i++) glDeleteTextures(1, &g_cactus[i]);
  70. glDisableClientState(GL_VERTEX_ARRAY);
  71. glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  72. }
  73. //场景===========================================================
  74. void baiscobj::light0()
  75. {
  76. GLfloat light_position[] = {1.0,5.0,1.0,1.0};
  77. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  78. glEnable(GL_LIGHTING);
  79. glEnable(GL_LIGHT0);
  80. glEnable(GL_DEPTH_TEST);
  81. glEnable(GL_COLOR_MATERIAL);
  82. }
  83. BOOL baiscobj::DisplayScene()//摄像漫游
  84. float speed=0.5f; //步长
  85.   float x=g_eye[0],y=g_eye[1],z=g_eye[2]; //保存上一步
  86.   if (KEY_DOWN(VK_SHIFT))  speed   =speed*2;//按SHIFT时的加速true
  87.   if (KEY_DOWN(VK_LEFT))   g_Angle-=speed*2;//左转,方位角-
  88.   if (KEY_DOWN(VK_RIGHT))  g_Angle+=speed*2;//右转,方位角+
  89.   rad_xz = float (3.13149* g_Angle/180.0f); //计算左右旋转角度
  90.   if (KEY_DOWN(VK_F1))   gao+=0.5f; //升高
  91.   if (KEY_DOWN(VK_F2))   gao-=0.5f; //降低
  92.   g_eye[1]=gao;
  93.   if (KEY_DOWN(33))    g_elev +=speed; //Page UP  键
  94.   if (KEY_DOWN(34))    g_elev -=speed; //Page Down键
  95.   if (g_elev<-360)    g_elev  =-360; //仰俯角
  96.   if (g_elev> 360)    g_elev  = 360; //仰俯角
  97.   if (KEY_DOWN(VK_UP)) //前进
  98.   { g_eye[2]+=(float)sin(rad_xz)*speed; //视点的x分量
  99.     g_eye[0]+=(float)cos(rad_xz)*speed; //视点的Z分量
  100.   }
  101.   if (KEY_DOWN(VK_DOWN)) //后退
  102.   { g_eye[2]-=(float)sin(rad_xz)*speed; //视点的x分量
  103.     g_eye[0]-=(float)cos(rad_xz)*speed; //视点的Z分量
  104.   }
  105.   if (KEY_DOWN(49))    cameratype=0; //Page UP  键
  106.   if (KEY_DOWN(50))    cameratype=1; //Page Down键
  107.   if (KEY_DOWN(51))    cameratype=2; //Page Down键
  108.  
  109.   //摄像机的方向
  110.   g_look[0] = (float)(g_eye[0] +100*cos(rad_xz)); //目标点X分量
  111.   g_look[2] = (float)(g_eye[2] +100*sin(rad_xz)); //目标点Z分量
  112.   g_look[1] = g_eye[1] +g_elev; //目标点Y分量
  113.   //建立modelview矩阵方向
  114.   switch(cameratype)
  115.   {
  116.   case 0:
  117.   gluLookAt(g_eye[0],g_eye[1],g_eye[2],
  118. plane_x,plane_y,plane_z, //目标点
  119. 0.0,1.0,0.0 //视点方向
  120.    ); //观察员的视角
  121. break;
  122. case 1:
  123.   gluLookAt(plane_x-cos(plane_y_angle*CHANGE)*25,
  124.   plane_y,
  125.   plane_z+sin(plane_y_angle*CHANGE)*25,
  126. plane_x,plane_y,plane_z, //目标点
  127. 0.0,1.0,0.0 //视点方向
  128.    ); //驾驶员的视角
  129. break;
  130. case 2:
  131. gluLookAt(g_eye[0],g_eye[1],g_eye[2],
  132. g_look[0],g_look[1],g_look[2], //目标点
  133. 0.0,1.0,0.0 //视点方向
  134.    ); //自由人的视点
  135. break;
  136. }
  137.   ////////////////////////////////////////////////////////////////
  138. //  int r0=abs((int)g_Angle);
  139. test.Format("[速度=%3.1f 高度=%3.0f x=%3.0f,z=%3.0f]",plane_speed,plane_y,plane_x,plane_z);
  140. return TRUE;
  141. }
  142. //==========================================================================
  143. void baiscobj::InitTerrain(float h)//建立地域数组
  144. { int index = 0;
  145.   int Vertex;
  146.   for (int z = 0; z < MAP_W; z++)
  147.    for (int x = 0; x < MAP_W; x++)
  148.     { Vertex = z * MAP_W + x;
  149.       g_terrain [Vertex][0] = float(x)*MAP_SCALE; //地域数据X分量
  150. //      g_terrain [Vertex][1] = (float)(g_imageData[(z*MAP_W+x)*3]/3);//Y分量,山的高度
  151.   g_terrain [Vertex][1] = 0; //Y分量,随机产生山的高度
  152.       g_terrain [Vertex][2] = -float(z)*MAP_SCALE; //地域数据Z分量
  153.       g_texcoord[Vertex][0] = (float) x; //索引数组x
  154.      g_texcoord[Vertex][1] = (float) z; //索引数组z
  155.      g_index [index++] = Vertex; //顶点数组1维
  156.      g_index [index++] = Vertex+ MAP_W;
  157.    }
  158.   glEnableClientState(GL_VERTEX_ARRAY); //允许使用地域数组
  159.   glVertexPointer    (3,GL_FLOAT,0,g_terrain); //装入地域数据
  160.   glEnableClientState(GL_TEXTURE_COORD_ARRAY); //允许使用索引数组
  161.   glTexCoordPointer  (2,GL_FLOAT,0,g_texcoord); //装入索引数组
  162. }
  163. void baiscobj::DrawSand()//显示随机山势
  164. {
  165. glBindTexture(GL_TEXTURE_2D, g_cactus[0]);//地贴图
  166.   glTexEnvf    (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  167.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//放大采用线性滤波
  168.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  169.   for (int z = 0; z < MAP_W-1; z++)
  170.     glDrawElements(GL_TRIANGLE_STRIP,MAP_W*2,GL_UNSIGNED_INT,&g_index[z*MAP_W*2]);
  171. //显示由顶点数组指定的面。
  172. }
  173. float baiscobj::GetHeight(float x, float z)// 取地面高度
  174. {  float CameraX = x/MAP_SCALE;              //计算在那一块
  175. float CameraZ =-z/MAP_SCALE;              //计算在那一块
  176. int Col0 = int(CameraX);                  //块的列号
  177. int Row0 = int(CameraZ);                  //块的行号
  178. int Col1 = Col0 + 1;                      //相邻列
  179. int Row1 = Row0 + 1;                      //相邻行
  180. if (Col1 > MAP_W) Col1 = 0;             //相邻列大于地块数,取首列
  181. if (Row1 > MAP_W) Row1 = 0;             //相邻行大于地块数,取首行
  182. float h00=g_terrain[Col0 + Row0*MAP_W][1];//获取块四角的高度
  183. float h01=g_terrain[Col1 + Row0*MAP_W][1];
  184. float h11=g_terrain[Col1 + Row1*MAP_W][1];
  185. float h10=g_terrain[Col0 + Row1*MAP_W][1];
  186. float tx =CameraX - int(CameraX);         //求块内X偏移位置
  187. float ty =CameraZ - int(CameraZ);         //求块内Z偏移位置
  188. float txty = tx * ty;                     //以下为双线性插值(内插)计算
  189. return h00*(1.0f-ty-tx+txty) 
  190. + h01*(tx-txty)
  191. + h11*txty
  192. + h10*(ty-txty);                  //返回插值计算值,为所求点的高度。
  193. }
  194. void baiscobj::CreateSkyBox(int a,int wi,int he,int le)//显示天空
  195. { float width =MAP*wi; // 天空盒宽
  196. float height=MAP*he; // 天空盒高
  197. float length=MAP*le; // 天空盒长
  198. float x = MAP  -width /2; // 天空的位置x
  199. float y = MAP/a-height/2; // 天空的位置y
  200. float z = -MAP -length/2; // 天空的位置z
  201. ///////////////////////////////////////////////////////////////////////////////
  202. texture(g_cactus[2]); // 设置BACK贴图左
  203. glBegin(GL_QUADS); // 多组独立填充四边形
  204. glTexCoord2f(1.0f,0.0f); glVertex3f(x+width,y,  z);
  205. glTexCoord2f(1.0f,1.0f); glVertex3f(x+width,y+height,z); 
  206. glTexCoord2f(0.0f,1.0f); glVertex3f(x, y+height,z);
  207. glTexCoord2f(0.0f,0.0f); glVertex3f(x, y,  z);
  208. glEnd();
  209. texture(g_cactus[3]); // 设置FRONT贴图右
  210. glBegin(GL_QUADS); // 多组独立填充四边形
  211. glTexCoord2f(1.0f,0.0f); glVertex3f(x, y,  z+length);
  212. glTexCoord2f(1.0f,1.0f); glVertex3f(x, y+height,z+length);
  213. glTexCoord2f(0.0f,1.0f); glVertex3f(x+width,y+height,z+length); 
  214. glTexCoord2f(0.0f,0.0f); glVertex3f(x+width,y,  z+length);
  215. glEnd();
  216. texture(g_cactus[4]); // 设置TOP贴图顶
  217. glBegin(GL_QUADS); // 多组独立填充四边形
  218. glTexCoord2f(0.0f,1.0f); glVertex3f(x+width,y+height,z);
  219. glTexCoord2f(0.0f,0.0f); glVertex3f(x+width,y+height,z+length); 
  220. glTexCoord2f(1.0f,0.0f); glVertex3f(x, y+height,z+length);
  221. glTexCoord2f(1.0f,1.0f); glVertex3f(x, y+height,z);
  222. glEnd();
  223. texture(g_cactus[5]); // 设置LEFT贴图前
  224. glBegin(GL_QUADS); // 多组独立填充四边形
  225. glTexCoord2f(1.0f,1.0f); glVertex3f(x, y+height,z);
  226. glTexCoord2f(0.0f,1.0f); glVertex3f(x, y+height,z+length); 
  227. glTexCoord2f(0.0f,0.0f); glVertex3f(x, y,  z+length);
  228. glTexCoord2f(1.0f,0.0f); glVertex3f(x, y,  z);
  229. glEnd();
  230. texture(g_cactus[6]); // 设置RIGHT贴图后
  231. glBegin(GL_QUADS); // 多组独立填充四边形
  232. glTexCoord2f(0.0f,0.0f); glVertex3f(x+width,y,  z);
  233. glTexCoord2f(1.0f,0.0f); glVertex3f(x+width,y,  z+length);
  234. glTexCoord2f(1.0f,1.0f); glVertex3f(x+width,y+height,z+length); 
  235. glTexCoord2f(0.0f,1.0f); glVertex3f(x+width,y+height,z);
  236. glEnd();
  237. }
  238. void baiscobj::texture(UINT textur)//设置贴图滤波
  239. { glBindTexture  (GL_TEXTURE_2D, textur);// 设置贴图
  240. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  241. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  242. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); //缩小采用线性滤波
  243.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//放大采用线性滤波
  244. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  245. }
  246. //组合图形=================================================================
  247. bool baiscobj::LoadT8(char *filename, GLuint &texture)//调8位贴图
  248. { AUX_RGBImageRec *pImage = NULL;
  249. pImage = auxDIBImageLoad(filename);  // 装入位图
  250. if(pImage == NULL) return false;  // 位图没装入返回错误
  251. glGenTextures(1, &texture);  // 生成贴图(纹理)
  252. glBindTexture    (GL_TEXTURE_2D,texture);// 捆绑贴图(纹理)
  253. gluBuild2DMipmaps(GL_TEXTURE_2D,4,   //
  254.   pImage->sizeX,     // 图形宽
  255.   pImage->sizeY,     // 图形高
  256.   GL_RGB, GL_UNSIGNED_BYTE,
  257.   pImage->data       // 图形数据
  258.  );
  259. free(pImage->data);                  // 释放位图数据占据的内存资源
  260. free(pImage);
  261. return true;                         // 返回成功
  262. }
  263. void baiscobj::LoadT16(char *filename, GLuint &texture)//调帖图
  264. { glGenTextures(1, &texture);            //获取1个未使用的贴图名称
  265.   glBindTexture(GL_TEXTURE_2D, texture); //选择要绑定的贴图(纹理)
  266.   BITMAPINFOHEADER bitHeader;  //定义位图结构
  267.   unsigned char *buffer;                 //定义位图指针
  268.   buffer=LoadBitmapFileWithAlpha(filename,&bitHeader); //调入位图
  269.   gluBuild2DMipmaps ( GL_TEXTURE_2D,     // 创建一个 2D贴图(纹理)
  270.   4,                 // 使用3种颜色(RGB)+ 颜色深度
  271.   bitHeader.biWidth, // 图像宽
  272.   bitHeader.biHeight,// 图像高
  273.   GL_RGBA,           // 红绿蓝顺序
  274.   GL_UNSIGNED_BYTE,  // 图像的数据类型是字节
  275.   buffer             // 指定贴图(纹理)数据
  276. );                   // 创建贴图(纹理)
  277.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  278.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  279.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); //缩小采用三线性滤波
  280.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//放大采用线性滤波
  281.   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
  282.   free(buffer);                                // 释放位图数据
  283. }
  284. unsigned char * baiscobj::LoadBit(char *filename, BITMAPINFOHEADER *bitmap)
  285. { FILE *filePtr;                        // 定义文件句柄
  286.   BITMAPFILEHEADER  Header;   // 定义位图指针
  287.   unsigned char    *Image;        // 位图数据区
  288.   unsigned int      imageIdx = 0;       // 图形索引
  289.   unsigned char     tempRGB;            // 交换变量
  290.   filePtr = fopen(filename, "rb");// 读文件
  291.   if (filePtr == NULL)    return NULL;// 读文件出错返回
  292.   fread(&Header, sizeof(BITMAPFILEHEADER), 1, filePtr);
  293.   if (Header.bfType != BITMAP_ID)
  294.   { fclose(filePtr);
  295.     return NULL;
  296.   }
  297.   fread(bitmap, sizeof(BITMAPINFOHEADER), 1, filePtr);
  298.   fseek(filePtr, Header.bfOffBits, SEEK_SET);
  299.   Image = (unsigned char*)malloc(bitmap->biSizeImage);
  300.   if (!Image)
  301.   { free(Image);
  302.     fclose(filePtr);
  303.     return NULL;
  304.   }
  305.   fread(Image, 1, bitmap->biSizeImage, filePtr);//将图形数据读入
  306.   if (Image == NULL)
  307.   { fclose(filePtr);
  308.     return NULL;
  309.   }
  310.   for (imageIdx = 0; imageIdx < bitmap->biSizeImage; imageIdx+=3)
  311.   { tempRGB = Image[imageIdx];
  312.     Image[imageIdx] = Image[imageIdx + 2];
  313.     Image[imageIdx + 2] = tempRGB;
  314.   }
  315.   fclose(filePtr);
  316.   return Image;
  317. }
  318. /////////////////////////////////////////////////////////////////////////////
  319. void baiscobj::load3dobj(char* dir,char* cn,int a)
  320. { char appdir[256];
  321. GetCurrentDirectory(256,appdir);
  322. SetCurrentDirectory(dir);
  323. m_3ds->Init(cn,a);
  324. SetCurrentDirectory(appdir);
  325. }
  326. void baiscobj::Scene(int obj,float x,float y,float z,float rx,float ry,float rz,float size)//显示对象
  327. {                //序号obj,位置  x,高度  h,位置  z,角度re,大小  size
  328.  glPushMatrix();
  329. //  int y=GetHeight(x,z)+h;
  330.  glTranslatef(x,y,z); //飞机定位
  331.  
  332.  glRotatef(ry, 0.0, 1.0, 0.0); //飞机的旋转
  333.  glRotatef(rz, 0.0, 0.0, 1.0); //飞机的旋转
  334.  glRotatef(rx, 1.0, 0.0, 0.0); //飞机的旋转
  335. //  if(obj>0) glRotatef(-20, 1.0, 0.0, 0.0); //飞机的斜角
  336.  m_3ds->show3ds(obj,0,0,0,size);//显示3ds模型飞机运行半径的定位
  337.  glPopMatrix();
  338. }
  339. //---------------------------------------------------------------------------------------
  340. //DEL void baiscobj::zangan(float x,float z)//碰撞绕行
  341. //DEL { float pp,qq;
  342. //DEL   for(int i=0;i<TREESL;i++) //障碍检测
  343. //DEL    for(int j=0;j<TREESL;j++) //障碍检测
  344. //DEL   { if(iftf(i,j)) //有障碍
  345. //DEL  {pp=g_eye[0];g_eye[0]=x; //X方向回原点 
  346. //DEL   if(!iftf(i,j))  continue; //没障碍,绕行。
  347. //DEL   else g_eye[0]=pp; //有障碍,X方向不变
  348. //DEL   ///////////////////////////////////////////
  349. //DEL      qq=g_eye[2];g_eye[2]=z; //Y方向回原点   
  350. //DEL   if(!iftf(i,j))  continue; //没障碍了,绕行。
  351. //DEL   else g_eye[2]=qq; //有障碍,Y方向不变
  352. //DEL   ///////////////////////////////////////////
  353. //DEL  }
  354. //DEL   }
  355. //DEL  return;
  356. //DEL }
  357. //----------------------------------------------------------------------------------------
  358. BOOL baiscobj::iftf(int i,int j)//判断障碍
  359. {
  360. if(objposi[i][j].exist==false)return false; //没遇到
  361. else
  362. {
  363. if(fabs(g_eye[0]-objposi[i][j].x)<20&&
  364. fabs(g_eye[2]-objposi[i][j].z)<20)
  365. return TRUE; //遇到障碍
  366. else return FALSE; //没遇到
  367. }
  368. }
  369. //----------------------------------------------------------------------------------------
  370. void baiscobj::caculate()
  371. {
  372.   ////////////////////战斗机的键盘控制/////////////////////////////////////////////
  373.   if (KEY_DOWN(70)||KEY_DOWN(102))   plane_speed+=0.02f; //战斗机加速,F键
  374.   if (KEY_DOWN(67)||KEY_DOWN(99))   plane_speed-=0.02f; //战斗机减速,C键
  375.   if (KEY_DOWN(65)||KEY_DOWN(97))
  376.   {
  377.   plane_y_angle++;
  378.   plane_left_right_sign=-1;
  379.   } //左转向,A键 
  380.   if (KEY_DOWN(68)||KEY_DOWN(100))
  381.   {
  382.   plane_y_angle--;
  383.   plane_left_right_sign=1;   
  384.   } //右转向,D键
  385.   if (KEY_DOWN(87)||KEY_DOWN(119)) plane_z_angle++; //爬升,W键
  386.   if (KEY_DOWN(83)||KEY_DOWN(115)) plane_z_angle--; //俯冲,S键
  387. //////////////////////////飞行速度优化////////////////////////////////////
  388.   if(plane_speed<0.6f&&plane_y>2)
  389.   plane_speed=0.6f;
  390. if(plane_speed<0)
  391. plane_speed=0;
  392. else if(plane_speed>PLANE_MAX_SPEED)
  393. plane_speed=PLANE_MAX_SPEED;
  394. //限制飞机飞行的速度
  395. if(plane_speed>PLANE_FLY_SPEED)
  396. plane_can_fly=true;
  397. else
  398. plane_can_fly=false;
  399. //判断飞机是否达到起飞的速度
  400. //////////////////////////飞机俯冲、爬升角度优化///////////////////////////
  401. if(plane_z_angle>0)
  402. plane_z_angle-=0.5f;
  403. else if(plane_z_angle<0)
  404. plane_z_angle+=0.5f;
  405. //飞机的俯仰角度回复代码
  406. if(plane_y==2)
  407. {
  408. if(plane_speed<PLANE_FLY_SPEED)
  409. plane_z_angle=0;
  410. if((plane_z_angle>180&&plane_z_angle<360)||(plane_z_angle>-180&&plane_z_angle<0))
  411. plane_z_angle=0;
  412. }
  413. //////////////////////////飞机左右转弯优化/////////////////////////////////
  414. if(plane_y>5)
  415. {
  416. if(plane_left_right_sign==0)
  417. {
  418. if(plane_x_angle>0)
  419. plane_x_angle-=1.5f;
  420. else if(plane_x_angle<0)
  421. plane_x_angle+=1.5f;
  422. }
  423. else if(plane_left_right_sign==-1)
  424. {
  425. plane_x_angle-=0.5f;
  426. plane_left_right_sign=0;
  427. }
  428. else if(plane_left_right_sign==1)
  429. {
  430. plane_x_angle+=0.5f;
  431. plane_left_right_sign=0;
  432. }
  433. //控制飞机左右旋转时的细节动作
  434. if(plane_x_angle>90)
  435. plane_x_angle=90;
  436. else if(plane_x_angle<-90)
  437. plane_x_angle=-90;
  438. //控制飞机细节动作的范围
  439. }
  440. else
  441. plane_x_angle=0;
  442. ////////////////////////////////飞行路线优化////////////////////////////////
  443. if(plane_z_angle>360)
  444. plane_z_angle-=360;
  445. else if(plane_z_angle<-360)
  446. plane_z_angle+=360;
  447. //控制飞机俯仰角度的范围
  448. if(plane_can_fly==true)
  449. {
  450. if((plane_z_angle>0&&plane_z_angle<180)||(plane_z_angle>-360&&plane_z_angle<-180))
  451. plane_y=plane_y+sin(plane_z_angle*CHANGE)*(plane_speed-PLANE_FLY_SPEED);
  452. else if((plane_z_angle>180&&plane_z_angle<360)||(plane_z_angle>-180&&plane_z_angle<0))
  453. plane_y=plane_y+sin(plane_z_angle*CHANGE)*(plane_speed+PLANE_FLY_SPEED);
  454. }
  455. else if(plane_can_fly==false)
  456. plane_y=plane_y-(PLANE_FLY_SPEED-plane_speed);
  457. //y轴的升高与降低控制,(!!没有考虑)升高时的减速与降低时的加速
  458. plane_x=plane_x+cos(plane_z_angle*CHANGE)*cos(plane_y_angle*CHANGE)*plane_speed;
  459. plane_z=plane_z-cos(plane_z_angle*CHANGE)*sin(plane_y_angle*CHANGE)*plane_speed;
  460. //飞行路线的产生
  461. if(plane_y<2)
  462. {
  463. plane_y=2;
  464. if(plane_speed>2.5||plane_z_angle<-15) //触发爆炸的条件
  465. explode=true;
  466. }
  467. //控制飞行的范围
  468. }
  469. void baiscobj::InitData()
  470. {
  471. int t;
  472. for(t=0;t<MAXFRAGMENT;t++)
  473. {
  474. // fragment[t].x=(float)(rand()%100-rand()%100)/1000;
  475. fragment[t].x=0;
  476. fragment[t].y=0;
  477. fragment[t].z=0;
  478. fragment[t].active=true;
  479. fragment[t].anx=(float)(rand()%360);
  480. fragment[t].any=0;
  481. fragment[t].anz=(float)(rand()%360);
  482. fragment[t].dim=(float)(rand()%100)/200;
  483. fragment[t].ddim=(float)(rand()%3);
  484. fragment[t].r=1;
  485. fragment[t].g=1;
  486. fragment[t].b=1;
  487. // fragment[t].dx=(float)(rand()%100-rand()%100)/50;
  488. // fragment[t].dy=(float)(rand()%100-rand()%100)/50;
  489. // fragment[t].dz=0.1+(float)(rand()%100)/200;
  490. fragment[t].dx=(float)(rand()%100-rand()%100)/50;
  491. fragment[t].dy=(float)(rand()%100-rand()%100)/50;
  492. fragment[t].dz=(float)(rand()%100-rand()%100)/50;
  493. }
  494. fine=false;
  495. explode=false;
  496. }
  497. void baiscobj::CalFragment()
  498. {
  499. int t,k=false;
  500. for(t=0;t<MAXFRAGMENT;t++)
  501. {
  502. if(fragment[t].active==true)
  503. {
  504. k=true;
  505. fragment[t].anx+=4;
  506. fragment[t].anz+=3;
  507. fragment[t].x+=fragment[t].dx;
  508. fragment[t].y+=fragment[t].dy;
  509. fragment[t].z+=fragment[t].dz;
  510. if(fragment[t].y<-4)
  511. {
  512. fragment[t].dy/=2;
  513. fragment[t].dy=-fragment[t].dy;
  514. fragment[t].y+=fragment[t].dy;
  515. fragment[t].ddim--;
  516. if(fragment[t].ddim<=0)
  517. fragment[t].active=false;
  518. }
  519. fragment[t].dy-=0.01f;
  520. }
  521. }
  522. if(k==false)
  523. fine=true;
  524. }
  525. void baiscobj::DrawFragment(float x, float y, float z)
  526. {
  527. int t;
  528. glColor3f(1,1,1);
  529. for(t=0;t<MAXFRAGMENT;t++)
  530. {
  531. if(fragment[t].active==true)
  532. {
  533. glPushMatrix();
  534. glTranslatef(fragment[t].x+x,fragment[t].y+y,fragment[t].z+z);
  535. glRotatef(fragment[t].anx,1,0,0);
  536. glRotatef(fragment[t].anz,0,0,1);
  537. glBegin(GL_TRIANGLES);
  538. glVertex3f(0,0,1.0f);
  539. glVertex3f(1.0f,0,-1.0f);
  540. glVertex3f(-1.0f,0,-1.0f);
  541. glEnd();
  542. glPopMatrix();
  543. }
  544. }
  545. }
  546. void baiscobj::CreateTexture(UINT textureArray[], LPSTR strFileName, int textureID)
  547. {
  548. AUX_RGBImageRec *pBitmap = NULL;
  549. if(!strFileName) // 如果无此文件,则直接返回
  550. return;
  551.     CString a,b="HnFlyData\modle\";
  552. a=b+strFileName;
  553. pBitmap = auxDIBImageLoad(a); //strFileName // 装入位图,并保存数据
  554. if(pBitmap == NULL) // 如果装入位图失败,则退出
  555. {
  556. AfxMessageBox("目录下没有 "+a+" 位图!");
  557. return;//exit(0);
  558. }
  559. // 生成纹理
  560. glGenTextures(1, &textureArray[textureID]);
  561. // 设置像素对齐格式
  562. glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
  563. glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
  564. gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);
  565. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
  566. glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
  567. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  568. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  569. // glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);/////去除其他立体效果 () GL_DECAL
  570. if (pBitmap) // 释放位图占用的资源
  571. {
  572. if (pBitmap->data)
  573. {
  574. free(pBitmap->data);
  575. }
  576. free(pBitmap);
  577. }
  578. }
  579. void baiscobj::DrawObject(t3DModel g_3DModel, UINT tex[], double ratio)
  580. {
  581. // 遍历模型中所有的对象
  582. for(int i = 0; i < g_3DModel.numOfObjects; i++)
  583. {
  584. // 如果对象的大小小于0,则退出
  585. if(g_3DModel.pObject.size() <= 0) break;
  586. // 获得当前显示的对象
  587. t3DObject *pObject = &g_3DModel.pObject[i];
  588. // 判断该对象是否有纹理映射
  589. if(pObject->bHasTexture) 
  590. {
  591. // 打开纹理映射
  592. glEnable(GL_TEXTURE_2D);
  593. glColor3ub(255, 255, 255);
  594. glBindTexture(GL_TEXTURE_2D, tex[pObject->materialID]);
  595. }
  596. else
  597. {
  598. // 关闭纹理映射
  599. glDisable(GL_TEXTURE_2D);
  600. glColor3ub(255, 255, 255);
  601. }
  602. //////////////////////////////////////////////////////////////////////////
  603. // 初始化名称堆栈
  604. glInitNames();
  605. glPushName(0);
  606. glPushMatrix();
  607. glLoadName(i+1);
  608. glTranslatef(0.0f,-0.025f,0.0f);
  609. glBegin(GL_TRIANGLES);
  610. // 遍历所有的面
  611. for(int j = 0; j < pObject->numOfFaces; j++)
  612. {
  613. // 遍历三角形的所有点
  614. for(int whichVertex = 0; whichVertex < 3; whichVertex++)
  615. {
  616. // 获得面对每个点的索引
  617. int index = pObject->pFaces[j].vertIndex[whichVertex];
  618. // 给出法向量
  619. glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z);
  620. // 如果对象具有纹理
  621. if(pObject->bHasTexture) 
  622. {
  623. // 确定是否有UVW纹理坐标
  624. if(pObject->pTexVerts) 
  625. {
  626. glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
  627. }
  628. else 
  629. {
  630. if(g_3DModel.pMaterials.size() && pObject->materialID >= 0) 
  631. {
  632. BYTE *pColor = g_3DModel.pMaterials[pObject->materialID].color;
  633. glColor3ub(pColor[0], pColor[1], pColor[2]);
  634. }
  635. }
  636. glVertex3f(pObject->pVerts[ index ].x*ratio, pObject->pVerts[ index ].y*ratio, pObject->pVerts[ index ].z*ratio);
  637. }
  638. }
  639. glEnd();// 绘制结束
  640. glPopMatrix();
  641. glPopName();
  642. // DrawObjectBox(g_3DModel,ratio);
  643. }
  644. }
  645. void baiscobj::ShowMap()
  646. {
  647. ClearScreen();
  648. SetModelView();
  649. // SetLight();
  650. glMatrixMode(GL_PROJECTION);//设置矩阵模式
  651. glLoadIdentity();//给投影变换赋单位矩阵
  652. gluPerspective (cameratype,           // Field-of-view angle
  653. 1024/768,      // Aspect ratio of viewing volume
  654.         10,            // Distance to near clipping plane
  655.         10000);   
  656. glMatrixMode(GL_MODELVIEW);//矩阵模式还原成视模变换模式
  657. CGetDEMList GetDEMList;
  658. //天空
  659. listsky=GetDEMList.GetSkyList(m_strFolderName+"\HnFlyData\SKY\Sky.bmp",112.5,0,-33.0,3000,-6000);
  660. textureIDsky=GetDEMList.m_iSkyTextureObjectID;
  661. //天空
  662. // if(!fog_flag)
  663. glCallList(listsky);
  664. SetProjection();
  665. ShowLand();
  666. //注记
  667. glDepthMask(GL_FALSE);
  668. for(int i=0;i<m_iTextureObjectNum;i++)//有几类注记
  669. {
  670. GLfloat fTextureObjectX,fTextureObjectY,fTextureObjectZ;//实际位置
  671. GLdouble angle;//所需旋转角度
  672. GLdouble dx,dz;//计算角度所需
  673. for(int j=0;j<m_pTextureObject[i].m_iDrawNum;j++)//每类注记画几次
  674. {
  675. fTextureObjectX=(m_pTextureObject[i].m_pTextureObjectCoordinate)[j].x;
  676. fTextureObjectY=(m_pTextureObject[i].m_pTextureObjectCoordinate)[j].y;
  677. fTextureObjectZ=(m_pTextureObject[i].m_pTextureObjectCoordinate)[j].z;
  678. dx=(GLdouble)(g_eye [0]-g_eye [0]);
  679. dz=(GLdouble)(g_eye [2]-g_eye [2]);
  680. if(dx>0&&dz>0)
  681. angle=atan(dx/dz)*180.0/PI;
  682. if(dx<0&&dz>0)
  683. angle=-atan(-dx/dz)*180.0/PI;
  684. if(dx<0&&dz<0)
  685. angle=-(90.0+atan(dz/dx)*180.0/PI);
  686. if(dx>0&&dz<0)
  687. angle=90.0+atan(-dz/dx)*180.0/PI;
  688. if(dx==0&&dz!=0)
  689. if(dz>0)
  690. angle=0.0;
  691. else
  692. angle=180.0;
  693. if(dx!=0&&dz==0)
  694. if(dx>0)
  695. angle=90.0;
  696. else
  697. angle=-90.0;
  698. if(dx==0&&dz==0)
  699. break;
  700. glPushMatrix();
  701. glTranslatef(fTextureObjectX,fTextureObjectY,fTextureObjectZ);
  702. glRotatef((GLfloat)angle,0.0,1.0,0.0);
  703. glCallList(m_pTextureObject[i].m_ilid);
  704. glPopMatrix();
  705. }
  706. }
  707. glDepthMask(GL_TRUE);
  708. SwapBuffers(wglGetCurrentDC());
  709. }
  710. void baiscobj::SetModelView()
  711. {
  712. glLoadIdentity();//给视模变换赋单位矩阵
  713. gluLookAt(g_eye[0],g_eye[1],g_eye[2],
  714. g_look[0],g_look[1],g_look[2],
  715. 0.0,1.0,0.0); 
  716. }
  717. void baiscobj::ClearScreen()
  718. {
  719. float fog_r = 170.f/255.f;
  720. float fog_g = 203.f/255.f;
  721. float fog_b = 245.f/255.f;
  722. glClearColor(fog_r,fog_g,fog_b,1.0f);//清屏颜色
  723. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//颜色,深缓清屏
  724. //在其它颜色启动前所有未指定颜色物体为白色
  725. glColor3f(1.0f, 1.0f, 1.0f);
  726. glEnable (GL_DEPTH_TEST);    
  727.     glEnable(GL_CULL_FACE);//使能够剔除
  728. glCullFace(GL_BACK);//剔除背面
  729. }
  730. void baiscobj::SetProjection()
  731. {
  732. glMatrixMode(GL_PROJECTION);//设置矩阵模式
  733. glLoadIdentity();//给投影变换赋单位矩阵
  734. gluPerspective (cameratype,           // Field-of-view angle
  735. 1024/768,      // Aspect ratio of viewing volume
  736.         0.005,            // Distance to near clipping plane
  737.         10000);   
  738. glMatrixMode(GL_MODELVIEW);//矩阵模式还原成视模变换模式
  739. }
  740. void baiscobj::ShowLand()
  741. {
  742. SetFog();
  743. CString strPath=m_strFolderName+"\HnFlyData\DEM\";
  744. if(!m_bGetDataStatus)//第一次进来
  745. {
  746. GetCircumsphereInfo();
  747. m_strMapID=CalculateFiftyThousandMapSheetNumber(m_fSphereX,-m_fSphereZ);
  748. // BeginWaitCursor();
  749. //DEM
  750. CString strLeftMapID=GetLeftMapID("50000",m_strMapID);
  751. CString strRightMapID=GetRightMapID("50000",m_strMapID);
  752. CString strTopMapID=GetTopMapID("50000",m_strMapID);
  753. CString strBottomMapID=GetBottomMapID("50000",m_strMapID);
  754. CString strLeftBottomMapID=GetLeftMapID("50000",strBottomMapID);
  755. CString strRightBottomMapID=GetRightMapID("50000",strBottomMapID);
  756. CString strLeftTopMapID=GetLeftMapID("50000",strTopMapID);
  757. CString strRightTopMapID=GetRightMapID("50000",strTopMapID);
  758. m_old_strLeftTopMapID = strLeftTopMapID;
  759. m_old_strTopMapID = strTopMapID;
  760. m_old_strRightTopMapID = strRightTopMapID;
  761. m_old_strLeftMapID = strLeftMapID;
  762. m_old_strMapID = m_strMapID;
  763. m_old_strRightMapID = strRightMapID;
  764. m_old_strLeftBottomMapID = strLeftBottomMapID;
  765. m_old_strBottomMapID = strBottomMapID;
  766. m_old_strRightBottomMapID = strRightBottomMapID;
  767. double L,B,LS,BS;
  768. //下
  769. if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
  770. {
  771. GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
  772. //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
  773. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  774. }
  775. if(GetDEMList[1]->OpenDEMFile(strPath+strBottomMapID+".dem",m_dHeightScale))
  776. {
  777. GetDEMList[1]->LoadGridTexture(strPath+"\3\"+strBottomMapID+".bmp",&textureID[1]);
  778. //textureID[1]=GetDEMList[1]->m_iDEMTextureObjectID;
  779. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  780. }
  781. if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
  782. {
  783. GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
  784. //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
  785. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  786. }
  787. //中
  788. if(GetDEMList[3]->OpenDEMFile(strPath+strLeftMapID+".dem",m_dHeightScale))
  789. {
  790. GetDEMList[3]->LoadGridTexture(strPath+"\3\"+strLeftMapID+".bmp",&textureID[3]);
  791. //textureID[3]=GetDEMList[3]->m_iDEMTextureObjectID;
  792. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  793. }
  794. if(GetDEMList[4]->OpenDEMFile(strPath+m_strMapID+".dem",m_dHeightScale))
  795. {
  796. GetDEMList[4]->LoadGridTexture(strPath+m_strMapID+".bmp",&textureID[4]);
  797. //textureID[4]=GetDEMList[4]->m_iDEMTextureObjectID;
  798. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  799. }
  800. if(GetDEMList[5]->OpenDEMFile(strPath+strRightMapID+".dem",m_dHeightScale))
  801. {
  802. GetDEMList[5]->LoadGridTexture(strPath+"\3\"+strRightMapID+".bmp",&textureID[5]);
  803. //textureID[5]=GetDEMList[5]->m_iDEMTextureObjectID;
  804. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  805. }
  806. //上
  807. if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
  808. {
  809. GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
  810. //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
  811. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  812. }
  813. if(GetDEMList[7]->OpenDEMFile(strPath+strTopMapID+".dem",m_dHeightScale))
  814. {
  815. GetDEMList[7]->LoadGridTexture(strPath+"\3\"+strTopMapID+".bmp",&textureID[7]);
  816. //textureID[7]=GetDEMList[7]->m_iDEMTextureObjectID;
  817. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  818. }
  819. if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
  820. {
  821. GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
  822. //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
  823. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  824. }
  825. //注记
  826. CGetDEMList GetNoteList;
  827. InputTextureObjectData(m_strFolderName+"\HnFlyData\NOTE\Note.zzp3",m_strFolderName+"\HnFlyData\NOTE\");
  828. for(int i=0;i<m_iTextureObjectNum;i++)//有几个纹理物体就建立几个显示列表
  829. {
  830. m_pTextureObject[i].m_ilid=GetNoteList.GetTextureObjectList(
  831. m_pTextureObject[i].m_cTexturePath,m_pTextureObject[i].m_fXLong*0.4,
  832. m_pTextureObject[i].m_fYLong*0.4);
  833. m_pTextureObject[i].m_iTextureObjectID=GetNoteList.m_iTextureObjectTextureObjectID;
  834. }
  835. //模型
  836. // EndWaitCursor();
  837. }
  838. else
  839. {
  840. CString strMapID;
  841. strMapID=m_strMapID;
  842. GetCircumsphereInfo();
  843. m_strMapID=CalculateFiftyThousandMapSheetNumber(m_fSphereX,-m_fSphereZ);
  844. CString strOldLeftMapID=GetLeftMapID("50000",strMapID);
  845. CString strOldRightMapID=GetRightMapID("50000",strMapID);
  846. CString strOldTopMapID=GetTopMapID("50000",strMapID);
  847. CString strOldBottomMapID=GetBottomMapID("50000",strMapID);
  848. CString strOldLeftBottomMapID=GetLeftMapID("50000",strOldBottomMapID);
  849. CString strOldRightBottomMapID=GetRightMapID("50000",strOldBottomMapID);
  850. CString strOldLeftTopMapID=GetLeftMapID("50000",strOldTopMapID);
  851. CString strOldRightTopMapID=GetRightMapID("50000",strOldTopMapID);
  852. //DEM
  853. CString strLeftMapID=GetLeftMapID("50000",m_strMapID);
  854. CString strRightMapID=GetRightMapID("50000",m_strMapID);
  855. CString strTopMapID=GetTopMapID("50000",m_strMapID);
  856. CString strBottomMapID=GetBottomMapID("50000",m_strMapID);
  857. CString strLeftBottomMapID=GetLeftMapID("50000",strBottomMapID);
  858. CString strRightBottomMapID=GetRightMapID("50000",strBottomMapID);
  859. CString strLeftTopMapID=GetLeftMapID("50000",strTopMapID);
  860. CString strRightTopMapID=GetRightMapID("50000",strTopMapID);
  861. double L,B,LS,BS;
  862. if(m_strMapID==strOldTopMapID)
  863. {
  864. delete GetDEMList[0];delete GetDEMList[1];delete GetDEMList[2];
  865. glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[1]);glDeleteTextures(1,&textureID[2]);
  866. GetDEMList[0]=GetDEMList[3];
  867. GetDEMList[1]=GetDEMList[4];
  868. GetDEMList[2]=GetDEMList[5];
  869. textureID[0]=textureID[3];
  870. textureID[1]=textureID[4];
  871. textureID[2]=textureID[5];
  872. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  873. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  874. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  875. GetDEMList[3]=GetDEMList[6];
  876. GetDEMList[4]=GetDEMList[7];
  877. GetDEMList[5]=GetDEMList[8];
  878. textureID[3]=textureID[6];
  879. textureID[4]=textureID[7];
  880. textureID[5]=textureID[8];
  881. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  882. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  883. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  884. GetDEMList[6]=new CGetDEMList;
  885. GetDEMList[7]=new CGetDEMList;
  886. GetDEMList[8]=new CGetDEMList;
  887. if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
  888. {
  889. GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
  890. //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
  891. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  892. }
  893. if(GetDEMList[7]->OpenDEMFile(strPath+strTopMapID+".dem",m_dHeightScale))
  894. {
  895. GetDEMList[7]->LoadGridTexture(strPath+"\3\"+strTopMapID+".bmp",&textureID[7]);
  896. //textureID[7]=GetDEMList[7]->m_iDEMTextureObjectID;
  897. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  898. }
  899. if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
  900. {
  901. GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
  902. //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
  903. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  904. }
  905. }
  906. else if(m_strMapID==strOldBottomMapID)
  907. {
  908. delete GetDEMList[6];delete GetDEMList[7];delete GetDEMList[8];
  909. glDeleteTextures(1,&textureID[6]);glDeleteTextures(1,&textureID[7]);glDeleteTextures(1,&textureID[8]);
  910. GetDEMList[6]=GetDEMList[3];
  911. GetDEMList[7]=GetDEMList[4];
  912. GetDEMList[8]=GetDEMList[5];
  913. textureID[6]=textureID[3];
  914. textureID[7]=textureID[4];
  915. textureID[8]=textureID[5];
  916. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  917. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  918. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  919. GetDEMList[3]=GetDEMList[0];
  920. GetDEMList[4]=GetDEMList[1];
  921. GetDEMList[5]=GetDEMList[2];
  922. textureID[3]=textureID[0];
  923. textureID[4]=textureID[1];
  924. textureID[5]=textureID[2];
  925. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  926. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  927. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  928. GetDEMList[0]=new CGetDEMList;
  929. GetDEMList[1]=new CGetDEMList;
  930. GetDEMList[2]=new CGetDEMList;
  931. if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
  932. {
  933. GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
  934. //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
  935. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  936. }
  937. if(GetDEMList[1]->OpenDEMFile(strPath+strBottomMapID+".dem",m_dHeightScale))
  938. {
  939. GetDEMList[1]->LoadGridTexture(strPath+"\3\"+strBottomMapID+".bmp",&textureID[1]);
  940. //textureID[1]=GetDEMList[1]->m_iDEMTextureObjectID;
  941. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  942. }
  943. if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
  944. {
  945. GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
  946. //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
  947. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  948. }
  949. }
  950. else if(m_strMapID==strOldLeftMapID)
  951. {
  952. delete GetDEMList[2];delete GetDEMList[5];delete GetDEMList[8];
  953. glDeleteTextures(1,&textureID[2]);glDeleteTextures(1,&textureID[5]);glDeleteTextures(1,&textureID[8]);
  954. GetDEMList[2]=GetDEMList[1];
  955. GetDEMList[5]=GetDEMList[4];
  956. GetDEMList[8]=GetDEMList[7];
  957. textureID[2]=textureID[1];
  958. textureID[5]=textureID[4];
  959. textureID[8]=textureID[7];
  960. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  961. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  962. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  963. GetDEMList[1]=GetDEMList[0];
  964. GetDEMList[4]=GetDEMList[3];
  965. GetDEMList[7]=GetDEMList[6];
  966. textureID[1]=textureID[0];
  967. textureID[4]=textureID[3];
  968. textureID[7]=textureID[6];
  969. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  970. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  971. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  972. GetDEMList[0]=new CGetDEMList;
  973. GetDEMList[3]=new CGetDEMList;
  974. GetDEMList[6]=new CGetDEMList;
  975. if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
  976. {
  977. GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
  978. //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
  979. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  980. }
  981. if(GetDEMList[3]->OpenDEMFile(strPath+strLeftMapID+".dem",m_dHeightScale))
  982. {
  983. GetDEMList[3]->LoadGridTexture(strPath+"\3\"+strLeftMapID+".bmp",&textureID[3]);
  984. //textureID[3]=GetDEMList[3]->m_iDEMTextureObjectID;
  985. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  986. }
  987. if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
  988. {
  989. GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
  990. //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
  991. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  992. }
  993. }
  994. else if(m_strMapID==strOldRightMapID)
  995. {
  996. delete GetDEMList[0];delete GetDEMList[3];delete GetDEMList[6];
  997. glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[3]);glDeleteTextures(1,&textureID[6]);
  998. GetDEMList[0]=GetDEMList[1];
  999. GetDEMList[3]=GetDEMList[4];
  1000. GetDEMList[6]=GetDEMList[7];
  1001. textureID[0]=textureID[1];
  1002. textureID[3]=textureID[4];
  1003. textureID[6]=textureID[7];
  1004. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  1005. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  1006. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  1007. GetDEMList[1]=GetDEMList[2];
  1008. GetDEMList[4]=GetDEMList[5];
  1009. GetDEMList[7]=GetDEMList[8];
  1010. textureID[1]=textureID[2];
  1011. textureID[4]=textureID[5];
  1012. textureID[7]=textureID[8];
  1013. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  1014. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  1015. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  1016. GetDEMList[2]=new CGetDEMList;
  1017. GetDEMList[5]=new CGetDEMList;
  1018. GetDEMList[8]=new CGetDEMList;
  1019. if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
  1020. {
  1021. GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
  1022. //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
  1023. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  1024. }
  1025. if(GetDEMList[5]->OpenDEMFile(strPath+strRightMapID+".dem",m_dHeightScale))
  1026. {
  1027. GetDEMList[5]->LoadGridTexture(strPath+"\3\"+strRightMapID+".bmp",&textureID[5]);
  1028. //textureID[5]=GetDEMList[5]->m_iDEMTextureObjectID;
  1029. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  1030. }
  1031. if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
  1032. {
  1033. GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
  1034. //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
  1035. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  1036. }
  1037. }
  1038. else if(m_strMapID==strOldLeftTopMapID)
  1039. {
  1040. delete GetDEMList[0];delete GetDEMList[1];delete GetDEMList[2];
  1041. delete GetDEMList[5];delete GetDEMList[8];
  1042. glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[1]);
  1043. glDeleteTextures(1,&textureID[2]);glDeleteTextures(1,&textureID[5]);
  1044. glDeleteTextures(1,&textureID[8]);
  1045. GetDEMList[1]=GetDEMList[3];
  1046. GetDEMList[2]=GetDEMList[4];
  1047. GetDEMList[4]=GetDEMList[6];
  1048. GetDEMList[5]=GetDEMList[7];
  1049. textureID[1]=textureID[3];
  1050. textureID[2]=textureID[4];
  1051. textureID[4]=textureID[6];
  1052. textureID[5]=textureID[7];
  1053. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  1054. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  1055. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  1056. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  1057. GetDEMList[0]=new CGetDEMList;
  1058. GetDEMList[3]=new CGetDEMList;
  1059. GetDEMList[6]=new CGetDEMList;
  1060. GetDEMList[7]=new CGetDEMList;
  1061. GetDEMList[8]=new CGetDEMList;
  1062. if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
  1063. {
  1064. GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
  1065. //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
  1066. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  1067. }
  1068. if(GetDEMList[3]->OpenDEMFile(strPath+strLeftMapID+".dem",m_dHeightScale))
  1069. {
  1070. GetDEMList[3]->LoadGridTexture(strPath+"\3\"+strLeftMapID+".bmp",&textureID[3]);
  1071. //textureID[3]=GetDEMList[3]->m_iDEMTextureObjectID;
  1072. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  1073. }
  1074. if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
  1075. {
  1076. GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
  1077. //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
  1078. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  1079. }
  1080. if(GetDEMList[7]->OpenDEMFile(strPath+strTopMapID+".dem",m_dHeightScale))
  1081. {
  1082. GetDEMList[7]->LoadGridTexture(strPath+"\3\"+strTopMapID+".bmp",&textureID[7]);
  1083. //textureID[7]=GetDEMList[7]->m_iDEMTextureObjectID;
  1084. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  1085. }
  1086. if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
  1087. {
  1088. GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
  1089. //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
  1090. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  1091. }
  1092. }
  1093. else if(m_strMapID==strOldRightTopMapID)
  1094. {
  1095. delete GetDEMList[0];delete GetDEMList[1];delete GetDEMList[2];
  1096. delete GetDEMList[3];delete GetDEMList[6];
  1097. glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[1]);
  1098. glDeleteTextures(1,&textureID[2]);glDeleteTextures(1,&textureID[3]);
  1099. glDeleteTextures(1,&textureID[6]);
  1100. GetDEMList[0]=GetDEMList[4];
  1101. GetDEMList[1]=GetDEMList[5];
  1102. GetDEMList[3]=GetDEMList[7];
  1103. GetDEMList[4]=GetDEMList[8];
  1104. textureID[0]=textureID[4];
  1105. textureID[1]=textureID[5];
  1106. textureID[3]=textureID[7];
  1107. textureID[4]=textureID[8];
  1108. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  1109. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  1110. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  1111. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  1112. GetDEMList[2]=new CGetDEMList;
  1113. GetDEMList[5]=new CGetDEMList;
  1114. GetDEMList[6]=new CGetDEMList;
  1115. GetDEMList[7]=new CGetDEMList;
  1116. GetDEMList[8]=new CGetDEMList;
  1117. if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
  1118. {
  1119. GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
  1120. //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
  1121. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  1122. }
  1123. if(GetDEMList[5]->OpenDEMFile(strPath+strRightMapID+".dem",m_dHeightScale))
  1124. {
  1125. GetDEMList[5]->LoadGridTexture(strPath+"\3\"+strRightMapID+".bmp",&textureID[5]);
  1126. //textureID[5]=GetDEMList[5]->m_iDEMTextureObjectID;
  1127. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  1128. }
  1129. if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
  1130. {
  1131. GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
  1132. //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
  1133. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  1134. }
  1135. if(GetDEMList[7]->OpenDEMFile(strPath+strTopMapID+".dem",m_dHeightScale))
  1136. {
  1137. GetDEMList[7]->LoadGridTexture(strPath+"\3\"+strTopMapID+".bmp",&textureID[7]);
  1138. //textureID[7]=GetDEMList[7]->m_iDEMTextureObjectID;
  1139. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  1140. }
  1141. if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
  1142. {
  1143. GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
  1144. //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
  1145. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  1146. }
  1147. }
  1148. else if(m_strMapID==strOldLeftBottomMapID)
  1149. {
  1150. delete GetDEMList[2];delete GetDEMList[5];delete GetDEMList[6];
  1151. delete GetDEMList[7];delete GetDEMList[8];
  1152. glDeleteTextures(1,&textureID[2]);glDeleteTextures(1,&textureID[5]);
  1153. glDeleteTextures(1,&textureID[6]);glDeleteTextures(1,&textureID[7]);
  1154. glDeleteTextures(1,&textureID[8]);
  1155. GetDEMList[4]=GetDEMList[0];
  1156. GetDEMList[5]=GetDEMList[1];
  1157. GetDEMList[7]=GetDEMList[3];
  1158. GetDEMList[8]=GetDEMList[4];
  1159. textureID[4]=textureID[0];
  1160. textureID[5]=textureID[1];
  1161. textureID[7]=textureID[3];
  1162. textureID[8]=textureID[4];
  1163. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  1164. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  1165. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  1166. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  1167. GetDEMList[0]=new CGetDEMList;
  1168. GetDEMList[1]=new CGetDEMList;
  1169. GetDEMList[2]=new CGetDEMList;
  1170. GetDEMList[3]=new CGetDEMList;
  1171. GetDEMList[6]=new CGetDEMList;
  1172. if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
  1173. {
  1174. GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
  1175. //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
  1176. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  1177. }
  1178. if(GetDEMList[1]->OpenDEMFile(strPath+strBottomMapID+".dem",m_dHeightScale))
  1179. {
  1180. GetDEMList[1]->LoadGridTexture(strPath+"\3\"+strBottomMapID+".bmp",&textureID[1]);
  1181. //textureID[1]=GetDEMList[1]->m_iDEMTextureObjectID;
  1182. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  1183. }
  1184. if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
  1185. {
  1186. GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
  1187. //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
  1188. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  1189. }
  1190. if(GetDEMList[3]->OpenDEMFile(strPath+strLeftMapID+".dem",m_dHeightScale))
  1191. {
  1192. GetDEMList[3]->LoadGridTexture(strPath+"\3\"+strLeftMapID+".bmp",&textureID[3]);
  1193. //textureID[3]=GetDEMList[3]->m_iDEMTextureObjectID;
  1194. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  1195. }
  1196. if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
  1197. {
  1198. GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
  1199. //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
  1200. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  1201. }
  1202. }
  1203. else if(m_strMapID==strOldRightBottomMapID)
  1204. {
  1205. delete GetDEMList[0];delete GetDEMList[3];delete GetDEMList[6];
  1206. delete GetDEMList[7];delete GetDEMList[8];
  1207. glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[3]);
  1208. glDeleteTextures(1,&textureID[6]);glDeleteTextures(1,&textureID[7]);
  1209. glDeleteTextures(1,&textureID[8]);
  1210. GetDEMList[3]=GetDEMList[1];
  1211. GetDEMList[4]=GetDEMList[2];
  1212. GetDEMList[6]=GetDEMList[4];
  1213. GetDEMList[7]=GetDEMList[5];
  1214. textureID[3]=textureID[1];
  1215. textureID[4]=textureID[2];
  1216. textureID[6]=textureID[4];
  1217. textureID[7]=textureID[5];
  1218. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  1219. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  1220. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  1221. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  1222. GetDEMList[0]=new CGetDEMList;
  1223. GetDEMList[1]=new CGetDEMList;
  1224. GetDEMList[2]=new CGetDEMList;
  1225. GetDEMList[5]=new CGetDEMList;
  1226. GetDEMList[8]=new CGetDEMList;
  1227. if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
  1228. {
  1229. GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
  1230. //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
  1231. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  1232. }
  1233. if(GetDEMList[1]->OpenDEMFile(strPath+strBottomMapID+".dem",m_dHeightScale))
  1234. {
  1235. GetDEMList[1]->LoadGridTexture(strPath+"\3\"+strBottomMapID+".bmp",&textureID[1]);
  1236. //textureID[1]=GetDEMList[1]->m_iDEMTextureObjectID;
  1237. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  1238. }
  1239. if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
  1240. {
  1241. GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
  1242. //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
  1243. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  1244. }
  1245. if(GetDEMList[5]->OpenDEMFile(strPath+strRightMapID+".dem",m_dHeightScale))
  1246. {
  1247. GetDEMList[5]->LoadGridTexture(strPath+"\3\"+strRightMapID+".bmp",&textureID[5]);
  1248. //textureID[5]=GetDEMList[5]->m_iDEMTextureObjectID;
  1249. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  1250. }
  1251. if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
  1252. {
  1253. GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
  1254. //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
  1255. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  1256. }
  1257. }
  1258. else
  1259. {
  1260. GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
  1261. GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
  1262. GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
  1263. GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
  1264. GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
  1265. GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
  1266. GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
  1267. GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
  1268. GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
  1269. }
  1270. }
  1271. m_bGetDataStatus=true;
  1272. }
  1273. bool baiscobj::InputTextureObjectData(CString strFilePath, CString strTextureFolderPath)
  1274. {
  1275. //判断文件类型
  1276. if(strFilePath.Right(4)!="zzp3")
  1277. {
  1278. ::MessageBox(NULL,"文件类型不符!","错误",MB_ICONERROR | MB_OK);
  1279. return false;
  1280. }
  1281. //打开文件并判断是否打开成功
  1282. char cFilePath[100];
  1283. sprintf(cFilePath,"%s",strFilePath);
  1284. FILE* fp;
  1285. fp=fopen(cFilePath,"r");
  1286. if(!fp)
  1287. {
  1288. ::MessageBox(NULL,"文件打开失败!","错误",MB_ICONERROR | MB_OK);
  1289. return false;
  1290. }
  1291. //读取纹理模型数据
  1292. fscanf(fp,"%d",&m_iTextureObjectNum);
  1293. m_pTextureObject=new CTextureObject[m_iTextureObjectNum];
  1294. CString strTexturePath;
  1295. for(int i=0;i<m_iTextureObjectNum;i++)
  1296. {
  1297. char cModelName[100];//读取该物体名
  1298. fscanf(fp,"%s",cModelName);
  1299. m_pTextureObject[i].m_strObjectName=cModelName;
  1300. fscanf(fp,"%s",m_pTextureObject[i].m_cTexturePath);//读取该纹理物体的纹理路径
  1301. strTexturePath=m_pTextureObject[i].m_cTexturePath;
  1302. strTexturePath=strTextureFolderPath+strTexturePath;
  1303. sprintf(m_pTextureObject[i].m_cTexturePath,"%s",strTexturePath);
  1304. fscanf(fp,"%f",&(m_pTextureObject[i].m_fXLong));//读取该纹理物体大小
  1305. fscanf(fp,"%f",&(m_pTextureObject[i].m_fYLong));
  1306. int num;
  1307. fscanf(fp,"%d",&num);//这类物体画几次
  1308. m_pTextureObject[i].m_iDrawNum=num;
  1309. m_pTextureObject[i].m_pTextureObjectCoordinate=new TextureObjectCoordinate[num];
  1310. GLfloat x,y,z;
  1311. for(int j=0;j<num;j++)//每次画的实际位置
  1312. {
  1313. fscanf(fp,"%f%f%f",&x,&y,&z);
  1314. (m_pTextureObject[i].m_pTextureObjectCoordinate)[j].x=x;
  1315. (m_pTextureObject[i].m_pTextureObjectCoordinate)[j].y=y-0.015;
  1316. (m_pTextureObject[i].m_pTextureObjectCoordinate)[j].z=z;
  1317. }
  1318. }
  1319. fclose(fp);
  1320. return true;
  1321. }
  1322. void baiscobj::SetFog()
  1323. {
  1324. float fog_r = 170.f/255.f;
  1325. float fog_g = 203.f/255.f;
  1326. float fog_b = 245.f/255.f;
  1327. GLfloat visual_distance =1;
  1328. // 设置雾化效果
  1329. GLuint fogMode[]= { GL_EXP, GL_EXP2, GL_LINEAR }; // 保存三种雾的模式
  1330. GLfloat fogColor[4] = {fog_r, fog_g, fog_b, 1}; // 雾的颜色
  1331. glFogi(GL_FOG_MODE, fogMode[2]);         // 设置雾的模式
  1332. glFogfv(GL_FOG_COLOR, fogColor); // 设置雾的颜色
  1333. glFogf(GL_FOG_DENSITY, 100.0f); //1.035 // 设置雾的浓度
  1334. glFogf(GL_FOG_START, 0.1); // 设置雾的开始深度
  1335. glFogf(GL_FOG_END, 0.25); // 设置雾的结束深度
  1336. glHint(GL_FOG_HINT,GL_DONT_CARE);
  1337. }
  1338. void baiscobj::GetCircumsphereInfo()
  1339. {
  1340. //充分利用空间向量几何知识,(x-x1)/(x2-x1)=(y-y1)/(y2-y1)=(z-z1)/(z2-z1)=距离之比
  1341. GLfloat r;//眼睛与目标点距离
  1342. r=(GLfloat)sqrt( (g_look[0]-g_eye[0])*(g_look[0]-g_eye[0])+
  1343. (g_look[1]-g_eye[1])*(g_look[1]-g_eye[1])+
  1344. (g_look[2]-g_eye[2])*(g_look[2]-g_eye[2]) );
  1345. GLfloat nearpointx,nearpointy,nearpointz;//近视点坐标
  1346. GLfloat farpointx,farpointy,farpointz;//远视点坐标
  1347. nearpointx=(m_fProjectionNear/r)*(g_look[0]-g_eye[0])+g_eye[0];
  1348. nearpointy=(m_fProjectionNear/r)*(g_look[1]-g_eye[1])+g_eye[1];
  1349. nearpointz=(m_fProjectionNear/r)*(g_look[2]-g_eye[2])+g_eye[2];
  1350. farpointx=(m_fProjectionFar/r)*(g_look[0]-g_eye[0])+g_eye[0];
  1351. farpointy=(m_fProjectionFar/r)*(g_look[1]-g_eye[1])+g_eye[1];
  1352. farpointz=(m_fProjectionFar/r)*(g_look[2]-g_eye[2])+g_eye[2];
  1353. m_fSphereX=(nearpointx+farpointx)/2;
  1354. m_fSphereY=(nearpointy+farpointy)/2;
  1355. m_fSphereZ=(nearpointz+farpointz)/2;
  1356. GLfloat h,w;// 圆锥近视面的半高、半宽
  1357.     h=(GLfloat)tan((m_fProjectionAngle/2)*PI/180.0)*m_fProjectionNear;
  1358. w=h*((GLfloat)1024/(GLfloat)768);
  1359. GLfloat r1;//近视点到近视面一个角点的距离
  1360. r1=(GLfloat)sqrt(h*h+w*w);
  1361. GLfloat r2;//近视点到中心的距离
  1362. r2=(m_fProjectionFar-m_fProjectionNear)/2;
  1363. m_fSphereRadius=(GLfloat)sqrt(r1*r1+r2*r2);
  1364. if(!eye_flag)
  1365. {
  1366. m_fSphereX=g_eye[0];
  1367. m_fSphereY=g_eye[1];
  1368. m_fSphereZ=g_eye[2];
  1369. }
  1370. else
  1371. {
  1372. m_fSphereX=g_eye[0];
  1373. m_fSphereY=g_eye[1];
  1374. m_fSphereZ=g_eye[2];
  1375. }
  1376. }
  1377. CString baiscobj::GetRightMapID(CString strScale, CString strMapID)
  1378. {
  1379. if(strScale=="50000")
  1380. {
  1381. CString strThisMap8;//该图第89位
  1382. strThisMap8=strMapID.Right(1);
  1383. int iThisMap8=atoi(strThisMap8);
  1384. if((iThisMap8%2)==0)//判断该一万图是否在所属十万图的最右边,是
  1385. {
  1386. CString strThisMap567;
  1387. strThisMap567=strMapID.Mid(4,3);
  1388. int iThisMap567=atoi(strThisMap567);
  1389. if((iThisMap567%12)==0)//判断该十万图是否在所属百万图的最左边,是
  1390. {
  1391. CString strThisMap34;
  1392. strThisMap34=strMapID.Mid(2,2);
  1393. int iThisMap34=atoi(strThisMap34);
  1394. int iRightMap34=iThisMap34+1;
  1395. CString strRightMap34;
  1396. strRightMap34.Format("%d",iRightMap34);
  1397. int iRightMap567=iThisMap567-11;
  1398. CString strRightMap567;
  1399. strRightMap567.Format("%d",iRightMap567);
  1400. if(iRightMap567<10)
  1401. strRightMap567="00"+strRightMap567;
  1402. if(iRightMap567>=10&&iRightMap567<100)
  1403. strRightMap567="0"+strRightMap567;
  1404. int iRightMap8=iThisMap8-1;
  1405. CString strRightMap8;
  1406. strRightMap8.Format("%d",iRightMap8);
  1407. CString strRightMapID;
  1408. strRightMapID=strMapID.Left(2)+strRightMap34+strRightMap567+strRightMap8;
  1409. return strRightMapID;
  1410. }
  1411. else//不是
  1412. {
  1413. CString strRightMap567;
  1414. int iRightMap567=iThisMap567+1;
  1415. strRightMap567.Format("%d",iRightMap567);
  1416. if(iRightMap567<10)
  1417. strRightMap567="00"+strRightMap567;
  1418. if(iRightMap567>=10&&iRightMap567<100)
  1419. strRightMap567="0"+strRightMap567;
  1420. int iRightMap8=iThisMap8-1;
  1421. CString strRightMap8;
  1422. strRightMap8.Format("%d",iRightMap8);
  1423.                 CString strRightMapID;
  1424. strRightMapID=strMapID.Left(4)+strRightMap567+strRightMap8;
  1425. return strRightMapID;
  1426. }
  1427. }
  1428. else//不是
  1429. {
  1430. int iRightMap8=iThisMap8+1;
  1431. CString strRightMap8;
  1432. strRightMap8.Format("%d",iRightMap8);
  1433. CString strRightMapID;
  1434. strRightMapID=strMapID.Left(7)+strRightMap8;
  1435. return strRightMapID;
  1436. }
  1437. }
  1438. return "CANNOT DEAL";
  1439. }
  1440. CString baiscobj::GetLeftMapID(CString strScale, CString strMapID)
  1441. {
  1442. if(strScale=="50000")
  1443. {
  1444. CString strThisMap8;//该图第89位
  1445. strThisMap8=strMapID.Right(1);
  1446. int iThisMap8=atoi(strThisMap8);
  1447. if((iThisMap8%2)==1)//判断该五万图是否在所属十万图的最左边,是
  1448. {
  1449. CString strThisMap567;
  1450. strThisMap567=strMapID.Mid(4,3);
  1451. int iThisMap567=atoi(strThisMap567);
  1452. if((iThisMap567%12)==1)//判断该十万图是否在所属百万图的最左边,是
  1453. {
  1454. CString strThisMap34;
  1455. strThisMap34=strMapID.Mid(2,2);
  1456. int iThisMap34=atoi(strThisMap34);
  1457. int iLeftMap34=iThisMap34-1;
  1458. CString strLeftMap34;
  1459. strLeftMap34.Format("%d",iLeftMap34);
  1460. int iLeftMap567=iThisMap567+7;
  1461. CString strLeftMap567;
  1462. strLeftMap567.Format("%d",iLeftMap567);
  1463. if(iLeftMap567<100)
  1464. strLeftMap567="0"+strLeftMap567;
  1465. int iLeftMap8=iThisMap8+1;
  1466. CString strLeftMap8;
  1467. strLeftMap8.Format("%d",iLeftMap8);
  1468. CString strLeftMapID;
  1469. strLeftMapID=strMapID.Left(2)+strLeftMap34+strLeftMap567+strLeftMap8;
  1470. return strLeftMapID;
  1471. }
  1472. else//不是
  1473. {
  1474. CString strLeftMap567;
  1475. int iLeftMap567=iThisMap567-1;
  1476. strLeftMap567.Format("%d",iLeftMap567);
  1477. if(iLeftMap567<10)
  1478. strLeftMap567="00"+strLeftMap567;
  1479. if(iLeftMap567>=10&&iLeftMap567<100)
  1480. strLeftMap567="0"+strLeftMap567;
  1481. int iLeftMap8=iThisMap8+1;
  1482. CString strLeftMap8;
  1483. strLeftMap8.Format("%d",iLeftMap8);
  1484.                 CString strLeftMapID;
  1485. strLeftMapID=strMapID.Left(4)+strLeftMap567+strLeftMap8;
  1486. return strLeftMapID;
  1487. }
  1488. }
  1489. else//不是
  1490. {
  1491. int iLeftMap8=iThisMap8-1;
  1492. CString strLeftMap8;
  1493. strLeftMap8.Format("%d",iLeftMap8);
  1494. CString strLeftMapID;
  1495. strLeftMapID=strMapID.Left(7)+strLeftMap8;
  1496. return strLeftMapID;
  1497. }
  1498. }
  1499. return "CANNOT DEAL";
  1500. }
  1501. CString baiscobj::GetTopMapID(CString strScale, CString strMapID)
  1502. {
  1503. if(strScale=="50000")
  1504. {
  1505. CString strThisMap8;//该图第89位
  1506. strThisMap8=strMapID.Right(1);
  1507. int iThisMap8=atoi(strThisMap8);
  1508. if(((iThisMap8-1)/2)==0)//判断该一万图是否在所属十万图的最上边,是
  1509. {
  1510. CString strThisMap567;
  1511. strThisMap567=strMapID.Mid(4,3);
  1512. int iThisMap567=atoi(strThisMap567);
  1513. if(((iThisMap567-1)/12)==0)//判断该十万图是否在所属百万图的最上边,是
  1514. {
  1515. CString strThisMap12;
  1516. strThisMap12=strMapID.Mid(0,2);
  1517. int iThisMap12=atoi(strThisMap12);
  1518. int iTopMap12=iThisMap12+1;
  1519. CString strTopMap12;
  1520. strTopMap12.Format("%d",iTopMap12);
  1521. if(iTopMap12<10)
  1522. strTopMap12="0"+strTopMap12;
  1523. int iTopMap567=iThisMap567+132;
  1524. CString strTopMap567;
  1525. strTopMap567.Format("%d",iTopMap567);
  1526. int iTopMap8=iThisMap8+2;
  1527. CString strTopMap8;
  1528. strTopMap8.Format("%d",iTopMap8);
  1529. CString strTopMapID;
  1530. strTopMapID=strTopMap12+strMapID.Mid(2,2)+strTopMap567+strTopMap8;
  1531. return strTopMapID;
  1532. }
  1533. else//不是
  1534. {
  1535. CString strTopMap567;
  1536. int iTopMap567=iThisMap567-12;
  1537. strTopMap567.Format("%d",iTopMap567);
  1538. if(iTopMap567<10)
  1539. strTopMap567="00"+strTopMap567;
  1540. if(iTopMap567>=10&&iTopMap567<100)
  1541. strTopMap567="0"+strTopMap567;
  1542. int iTopMap8=iThisMap8+2;
  1543. CString strTopMap8;
  1544. strTopMap8.Format("%d",iTopMap8);
  1545.                 CString strTopMapID;
  1546. strTopMapID=strMapID.Left(4)+strTopMap567+strTopMap8;
  1547. return strTopMapID;
  1548. }
  1549. }
  1550. else//不是
  1551. {
  1552. int iTopMap8=iThisMap8-2;
  1553. CString strTopMap8;
  1554. strTopMap8.Format("%d",iTopMap8);
  1555. CString strTopMapID;
  1556. strTopMapID=strMapID.Left(7)+strTopMap8;
  1557. return strTopMapID;
  1558. }
  1559. }
  1560. return "CANNOT DEAL";
  1561. }
  1562. CString baiscobj::CalculateFiftyThousandMapSheetNumber(double l, double b)
  1563. {
  1564. // 求1:100万图号
  1565. int before,after;
  1566. CString Map100Number,Map10Number,Map5Number,str;
  1567. before = int(b)/4+1;
  1568. after  = int(l)/6+31;
  1569. if(before<10) Map100Number.Format("0%d%d",before,after);
  1570. else Map100Number.Format("%d%d",before,after);
  1571. // 求1:10万图号
  1572. int Row,Col;
  1573. Col = (int)((l-(after-31.0)*6.0)*10.0/5.0);
  1574. Row = 11-(int)((b-(before-1.0)*4.0)*3.0);
  1575. int Code;
  1576. Code = Row*12+Col+1;
  1577. if(Code<10) Map10Number.Format("00%d",Code);
  1578. else if(Code<100) Map10Number.Format("0%2d",Code);
  1579. else Map10Number.Format("%3d",Code);
  1580. // 求1:5万图号
  1581. int Row5,Col5;
  1582. Col5 = (int)((l-(Col/2.0+(after-31.0)*6.0))*4.0);
  1583. Row5 = 1 - (int)((b-((11.0-Row)/3.0+(before-1.0)*4.0))*6.0);
  1584. int Code5;
  1585. Code5 = Row5*2+Col5+1;
  1586. str.Format("%d",Code5);
  1587. Map5Number = Map100Number + Map10Number + str;
  1588. return Map5Number;
  1589. }
  1590. CString baiscobj::GetBottomMapID(CString strScale, CString strMapID)
  1591. {
  1592. if(strScale=="50000")
  1593. {
  1594. CString strThisMap8;//该图第89位
  1595. strThisMap8=strMapID.Right(1);
  1596. int iThisMap8=atoi(strThisMap8);
  1597. if(((iThisMap8-1)/2)==1)//判断该五万图是否在所属十万图的最下边,是
  1598. {
  1599. CString strThisMap567;
  1600. strThisMap567=strMapID.Mid(4,3);
  1601. int iThisMap567=atoi(strThisMap567);
  1602. if(((iThisMap567-1)/12)==11)//判断该十万图是否在所属百万图的最下边,是
  1603. {
  1604. CString strThisMap12;
  1605. strThisMap12=strMapID.Mid(0,2);
  1606. int iThisMap12=atoi(strThisMap12);
  1607. int iBottomMap12=iThisMap12-1;
  1608. CString strBottomMap12;
  1609. strBottomMap12.Format("%d",iBottomMap12);
  1610. if(iBottomMap12<10)
  1611. strBottomMap12="0"+strBottomMap12;
  1612. int iBottomMap567=iThisMap567-132;
  1613. CString strBottomMap567;
  1614. strBottomMap567.Format("%d",iBottomMap567);
  1615. if(iBottomMap567<10)
  1616. strBottomMap567="00"+strBottomMap567;
  1617. if(iBottomMap567>=10)
  1618. strBottomMap567="0"+strBottomMap567;
  1619. int iBottomMap8=iThisMap8-2;
  1620. CString strBottomMap8;
  1621. strBottomMap8.Format("%d",iBottomMap8);
  1622. CString strBottomMapID;
  1623. strBottomMapID=strBottomMap12+strMapID.Mid(2,2)+strBottomMap567+strBottomMap8;
  1624. return strBottomMapID;
  1625. }
  1626. else//不是
  1627. {
  1628. CString strBottomMap567;
  1629. int iBottomMap567=iThisMap567+12;
  1630. strBottomMap567.Format("%d",iBottomMap567);
  1631. if(iBottomMap567<100)
  1632. strBottomMap567="0"+strBottomMap567;
  1633. int iBottomMap8=iThisMap8-2;
  1634. CString strBottomMap8;
  1635. strBottomMap8.Format("%d",iBottomMap8);
  1636.                 CString strBottomMapID;
  1637. strBottomMapID=strMapID.Left(4)+strBottomMap567+strBottomMap8;
  1638. return strBottomMapID;
  1639. }
  1640. }
  1641. else//不是
  1642. {
  1643. int iBottomMap8=iThisMap8+2;
  1644. CString strBottomMap8;
  1645. strBottomMap8.Format("%d",iBottomMap8);
  1646. CString strBottomMapID;
  1647. strBottomMapID=strMapID.Left(7)+strBottomMap8;
  1648. return strBottomMapID;
  1649. }
  1650. }
  1651. return "CANNOT DEAL";
  1652. }