Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
BAISCOBJ.CPP
Package: VCtracking.rar [view]
Upload User: xuczgm
Upload Date: 2022-04-25
Package Size: 8601k
Code Size: 62k
Category:
Special Effects
Development Platform:
Visual C++
- // 学程序编游戏系列丛书
- // 唐明理 E_mail: cqtmL@163.com
- //====================================================================
- #include "stdafx.h"
- #include "baiscobj.h"
- #include "../include/BITMAP.H"
- #define PLANE_FLY_SPEED 1.0f //liuying
- #define PLANE_MAX_SPEED 6.0f //liuying
- #define CHANGE 3.13149/180.0f //liuying
- extern GLfloat r; //飞机盘旋角度
- float gao=0.8f;
- extern CString test; //场景信息
- //////////////////////////////////////////////////////////////////////
- baiscobj::baiscobj()
- {
- g_eye[0]=250; //2*MAP-2*MAP_SCALE;//
- g_eye[2]=-260;//
- g_Angle=60;//
- g_elev=-0;//
- char charTemp[200];
- ::GetCurrentDirectory(200,charTemp);
- m_strFolderName = (CString)charTemp;
- for(int i=0;i<9;i++)
- {
- GetDEMList[i]= new CGetDEMList;
- }
- m_bGetDataStatus=false;
- ////////////////////////////////////////////////////////////////////////
- LoadT8("data/images/sand3.bmp", g_cactus[0]); //地面帖图
- LoadT8("data/images/3RBack.bmp",g_cactus[2]); //天空贴图后
- LoadT8("data/images/3Front.bmp",g_cactus[3]); //天空贴图前
- LoadT8("data/images/3Top.bmp", g_cactus[4]); //天空贴图顶
- LoadT8("data/images/3Left.bmp", g_cactus[5]); //天空贴图左
- LoadT8("data/images/3Right.bmp",g_cactus[6]); //天空贴图右
- InitTerrain(5);//初始化地面
- m_3ds=new CLoad3DS();
- load3dobj("data/3ds/","飞机歼击1.3ds",1);
- //战斗机状态初始化
- plane_x=250,plane_y=2,plane_z=-250; //初始化战斗机位置
- plane_x_angle=0,plane_y_angle=0,plane_z_angle=0; //初始化战斗机旋转的角度
- plane_speed=0; //初始化战斗机速度
- plane_can_fly=false;
- plane_left_right_sign=0;
- cameratype=0; //摄象机角度类型初始化
- glEnable(GL_TEXTURE_2D);
- ///////////////////////////////////////爆炸碎片初始化
- InitData();
- }
- baiscobj::~baiscobj()
- {
- for(int i=0;i<9;i++)
- {
- delete GetDEMList[i];
- glDeleteTextures(1,&textureID[i]);
- }
- //注记
- for(i=0;i<m_iTextureObjectNum;i++)//纹理物体
- {
- glDeleteLists(m_pTextureObject[i].m_ilid,1);
- glDeleteTextures(1,&(m_pTextureObject[i].m_iTextureObjectID));
- if(m_pTextureObject[i].m_iDrawNum!=0)
- delete []m_pTextureObject[i].m_pTextureObjectCoordinate;
- }
- if(m_iTextureObjectNum!=0)
- delete []m_pTextureObject;
- //天空
- glDeleteLists(listsky,1);
- glDeleteTextures(1,&textureIDsky);
- for(i=0;i<16;i++) glDeleteTextures(1, &g_cactus[i]);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- }
- //场景===========================================================
- void baiscobj::light0()
- {
- GLfloat light_position[] = {1.0,5.0,1.0,1.0};
- glLightfv(GL_LIGHT0, GL_POSITION, light_position);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_COLOR_MATERIAL);
- }
- BOOL baiscobj::DisplayScene()//摄像漫游
- {
- float speed=0.5f; //步长
- float x=g_eye[0],y=g_eye[1],z=g_eye[2]; //保存上一步
- if (KEY_DOWN(VK_SHIFT)) speed =speed*2;//按SHIFT时的加速true
- 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(VK_F1)) gao+=0.5f; //升高
- if (KEY_DOWN(VK_F2)) gao-=0.5f; //降低
- g_eye[1]=gao;
- if (KEY_DOWN(33)) g_elev +=speed; //Page UP 键
- if (KEY_DOWN(34)) g_elev -=speed; //Page Down键
- 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; //视点的x分量
- g_eye[0]+=(float)cos(rad_xz)*speed; //视点的Z分量
- }
- if (KEY_DOWN(VK_DOWN)) //后退
- { g_eye[2]-=(float)sin(rad_xz)*speed; //视点的x分量
- g_eye[0]-=(float)cos(rad_xz)*speed; //视点的Z分量
- }
- if (KEY_DOWN(49)) cameratype=0; //Page UP 键
- if (KEY_DOWN(50)) cameratype=1; //Page Down键
- if (KEY_DOWN(51)) cameratype=2; //Page Down键
- //摄像机的方向
- g_look[0] = (float)(g_eye[0] +100*cos(rad_xz)); //目标点X分量
- g_look[2] = (float)(g_eye[2] +100*sin(rad_xz)); //目标点Z分量
- g_look[1] = g_eye[1] +g_elev; //目标点Y分量
- //建立modelview矩阵方向
- switch(cameratype)
- {
- case 0:
- gluLookAt(g_eye[0],g_eye[1],g_eye[2],
- plane_x,plane_y,plane_z, //目标点
- 0.0,1.0,0.0 //视点方向
- ); //观察员的视角
- break;
- case 1:
- gluLookAt(plane_x-cos(plane_y_angle*CHANGE)*25,
- plane_y,
- plane_z+sin(plane_y_angle*CHANGE)*25,
- plane_x,plane_y,plane_z, //目标点
- 0.0,1.0,0.0 //视点方向
- ); //驾驶员的视角
- break;
- case 2:
- 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 //视点方向
- ); //自由人的视点
- break;
- }
- ////////////////////////////////////////////////////////////////
- // int r0=abs((int)g_Angle);
- test.Format("[速度=%3.1f 高度=%3.0f x=%3.0f,z=%3.0f]",plane_speed,plane_y,plane_x,plane_z);
- return TRUE;
- }
- //==========================================================================
- void baiscobj::InitTerrain(float h)//建立地域数组
- { int index = 0;
- int Vertex;
- for (int z = 0; z < MAP_W; z++)
- for (int x = 0; x < MAP_W; x++)
- { Vertex = z * MAP_W + x;
- g_terrain [Vertex][0] = float(x)*MAP_SCALE; //地域数据X分量
- // g_terrain [Vertex][1] = (float)(g_imageData[(z*MAP_W+x)*3]/3);//Y分量,山的高度
- g_terrain [Vertex][1] = 0; //Y分量,随机产生山的高度
- g_terrain [Vertex][2] = -float(z)*MAP_SCALE; //地域数据Z分量
- g_texcoord[Vertex][0] = (float) x; //索引数组x
- g_texcoord[Vertex][1] = (float) z; //索引数组z
- g_index [index++] = Vertex; //顶点数组1维
- g_index [index++] = Vertex+ MAP_W;
- }
- glEnableClientState(GL_VERTEX_ARRAY); //允许使用地域数组
- glVertexPointer (3,GL_FLOAT,0,g_terrain); //装入地域数据
- glEnableClientState(GL_TEXTURE_COORD_ARRAY); //允许使用索引数组
- glTexCoordPointer (2,GL_FLOAT,0,g_texcoord); //装入索引数组
- }
- void baiscobj::DrawSand()//显示随机山势
- {
- glBindTexture(GL_TEXTURE_2D, g_cactus[0]);//地贴图
- glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//放大采用线性滤波
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
- for (int z = 0; z < MAP_W-1; z++)
- glDrawElements(GL_TRIANGLE_STRIP,MAP_W*2,GL_UNSIGNED_INT,&g_index[z*MAP_W*2]);
- //显示由顶点数组指定的面。
- }
- float baiscobj::GetHeight(float x, float z)// 取地面高度
- { float CameraX = x/MAP_SCALE; //计算在那一块
- 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; //相邻列大于地块数,取首列
- 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); //求块内X偏移位置
- float ty =CameraZ - int(CameraZ); //求块内Z偏移位置
- float txty = tx * ty; //以下为双线性插值(内插)计算
- return h00*(1.0f-ty-tx+txty)
- + h01*(tx-txty)
- + h11*txty
- + h10*(ty-txty); //返回插值计算值,为所求点的高度。
- }
- void baiscobj::CreateSkyBox(int a,int wi,int he,int le)//显示天空
- { float width =MAP*wi; // 天空盒宽
- float height=MAP*he; // 天空盒高
- float length=MAP*le; // 天空盒长
- float x = MAP -width /2; // 天空的位置x
- float y = MAP/a-height/2; // 天空的位置y
- float z = -MAP -length/2; // 天空的位置z
- ///////////////////////////////////////////////////////////////////////////////
- texture(g_cactus[2]); // 设置BACK贴图左
- glBegin(GL_QUADS); // 多组独立填充四边形
- glTexCoord2f(1.0f,0.0f); glVertex3f(x+width,y, z);
- glTexCoord2f(1.0f,1.0f); glVertex3f(x+width,y+height,z);
- glTexCoord2f(0.0f,1.0f); glVertex3f(x, y+height,z);
- glTexCoord2f(0.0f,0.0f); glVertex3f(x, y, z);
- glEnd();
- texture(g_cactus[3]); // 设置FRONT贴图右
- glBegin(GL_QUADS); // 多组独立填充四边形
- glTexCoord2f(1.0f,0.0f); glVertex3f(x, y, z+length);
- glTexCoord2f(1.0f,1.0f); glVertex3f(x, y+height,z+length);
- glTexCoord2f(0.0f,1.0f); glVertex3f(x+width,y+height,z+length);
- glTexCoord2f(0.0f,0.0f); glVertex3f(x+width,y, z+length);
- glEnd();
- texture(g_cactus[4]); // 设置TOP贴图顶
- glBegin(GL_QUADS); // 多组独立填充四边形
- glTexCoord2f(0.0f,1.0f); glVertex3f(x+width,y+height,z);
- glTexCoord2f(0.0f,0.0f); glVertex3f(x+width,y+height,z+length);
- glTexCoord2f(1.0f,0.0f); glVertex3f(x, y+height,z+length);
- glTexCoord2f(1.0f,1.0f); glVertex3f(x, y+height,z);
- glEnd();
- texture(g_cactus[5]); // 设置LEFT贴图前
- glBegin(GL_QUADS); // 多组独立填充四边形
- glTexCoord2f(1.0f,1.0f); glVertex3f(x, y+height,z);
- glTexCoord2f(0.0f,1.0f); glVertex3f(x, y+height,z+length);
- glTexCoord2f(0.0f,0.0f); glVertex3f(x, y, z+length);
- glTexCoord2f(1.0f,0.0f); glVertex3f(x, y, z);
- glEnd();
- texture(g_cactus[6]); // 设置RIGHT贴图后
- glBegin(GL_QUADS); // 多组独立填充四边形
- glTexCoord2f(0.0f,0.0f); glVertex3f(x+width,y, z);
- glTexCoord2f(1.0f,0.0f); glVertex3f(x+width,y, z+length);
- glTexCoord2f(1.0f,1.0f); glVertex3f(x+width,y+height,z+length);
- glTexCoord2f(0.0f,1.0f); glVertex3f(x+width,y+height,z);
- glEnd();
- }
- void baiscobj::texture(UINT textur)//设置贴图滤波
- { glBindTexture (GL_TEXTURE_2D, textur);// 设置贴图
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); //缩小采用线性滤波
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//放大采用线性滤波
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
- }
- //组合图形=================================================================
- bool baiscobj::LoadT8(char *filename, GLuint &texture)//调8位贴图
- { AUX_RGBImageRec *pImage = NULL;
- pImage = auxDIBImageLoad(filename); // 装入位图
- if(pImage == NULL) return false; // 位图没装入返回错误
- glGenTextures(1, &texture); // 生成贴图(纹理)
- glBindTexture (GL_TEXTURE_2D,texture);// 捆绑贴图(纹理)
- gluBuild2DMipmaps(GL_TEXTURE_2D,4, //
- pImage->sizeX, // 图形宽
- pImage->sizeY, // 图形高
- GL_RGB, GL_UNSIGNED_BYTE,
- pImage->data // 图形数据
- );
- free(pImage->data); // 释放位图数据占据的内存资源
- free(pImage);
- return true; // 返回成功
- }
- void baiscobj::LoadT16(char *filename, GLuint &texture)//调帖图
- { glGenTextures(1, &texture); //获取1个未使用的贴图名称
- glBindTexture(GL_TEXTURE_2D, texture); //选择要绑定的贴图(纹理)
- BITMAPINFOHEADER bitHeader; //定义位图结构
- unsigned char *buffer; //定义位图指针
- buffer=LoadBitmapFileWithAlpha(filename,&bitHeader); //调入位图
- gluBuild2DMipmaps ( GL_TEXTURE_2D, // 创建一个 2D贴图(纹理)
- 4, // 使用3种颜色(RGB)+ 颜色深度
- bitHeader.biWidth, // 图像宽
- bitHeader.biHeight,// 图像高
- GL_RGBA, // 红绿蓝顺序
- GL_UNSIGNED_BYTE, // 图像的数据类型是字节
- buffer // 指定贴图(纹理)数据
- ); // 创建贴图(纹理)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); //缩小采用三线性滤波
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//放大采用线性滤波
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
- free(buffer); // 释放位图数据
- }
- unsigned char * baiscobj::LoadBit(char *filename, BITMAPINFOHEADER *bitmap)
- { FILE *filePtr; // 定义文件句柄
- BITMAPFILEHEADER Header; // 定义位图指针
- unsigned char *Image; // 位图数据区
- unsigned int imageIdx = 0; // 图形索引
- unsigned char tempRGB; // 交换变量
- filePtr = fopen(filename, "rb");// 读文件
- if (filePtr == NULL) return NULL;// 读文件出错返回
- fread(&Header, sizeof(BITMAPFILEHEADER), 1, filePtr);
- if (Header.bfType != BITMAP_ID)
- { fclose(filePtr);
- return NULL;
- }
- fread(bitmap, sizeof(BITMAPINFOHEADER), 1, filePtr);
- fseek(filePtr, Header.bfOffBits, SEEK_SET);
- Image = (unsigned char*)malloc(bitmap->biSizeImage);
- if (!Image)
- { free(Image);
- fclose(filePtr);
- return NULL;
- }
- fread(Image, 1, bitmap->biSizeImage, filePtr);//将图形数据读入
- if (Image == NULL)
- { fclose(filePtr);
- return NULL;
- }
- for (imageIdx = 0; imageIdx < bitmap->biSizeImage; imageIdx+=3)
- { tempRGB = Image[imageIdx];
- Image[imageIdx] = Image[imageIdx + 2];
- Image[imageIdx + 2] = tempRGB;
- }
- fclose(filePtr);
- return Image;
- }
- /////////////////////////////////////////////////////////////////////////////
- void baiscobj::load3dobj(char* dir,char* cn,int a)
- { char appdir[256];
- GetCurrentDirectory(256,appdir);
- SetCurrentDirectory(dir);
- m_3ds->Init(cn,a);
- SetCurrentDirectory(appdir);
- }
- void baiscobj::Scene(int obj,float x,float y,float z,float rx,float ry,float rz,float size)//显示对象
- { //序号obj,位置 x,高度 h,位置 z,角度re,大小 size
- glPushMatrix();
- // int y=GetHeight(x,z)+h;
- glTranslatef(x,y,z); //飞机定位
- glRotatef(ry, 0.0, 1.0, 0.0); //飞机的旋转
- glRotatef(rz, 0.0, 0.0, 1.0); //飞机的旋转
- glRotatef(rx, 1.0, 0.0, 0.0); //飞机的旋转
- // if(obj>0) glRotatef(-20, 1.0, 0.0, 0.0); //飞机的斜角
- m_3ds->show3ds(obj,0,0,0,size);//显示3ds模型飞机运行半径的定位
- glPopMatrix();
- }
- //---------------------------------------------------------------------------------------
- //DEL void baiscobj::zangan(float x,float z)//碰撞绕行
- //DEL { float pp,qq;
- //DEL for(int i=0;i<TREESL;i++) //障碍检测
- //DEL for(int j=0;j<TREESL;j++) //障碍检测
- //DEL { if(iftf(i,j)) //有障碍
- //DEL {pp=g_eye[0];g_eye[0]=x; //X方向回原点
- //DEL if(!iftf(i,j)) continue; //没障碍,绕行。
- //DEL else g_eye[0]=pp; //有障碍,X方向不变
- //DEL ///////////////////////////////////////////
- //DEL qq=g_eye[2];g_eye[2]=z; //Y方向回原点
- //DEL if(!iftf(i,j)) continue; //没障碍了,绕行。
- //DEL else g_eye[2]=qq; //有障碍,Y方向不变
- //DEL ///////////////////////////////////////////
- //DEL }
- //DEL }
- //DEL return;
- //DEL }
- //----------------------------------------------------------------------------------------
- BOOL baiscobj::iftf(int i,int j)//判断障碍
- {
- if(objposi[i][j].exist==false)return false; //没遇到
- else
- {
- if(fabs(g_eye[0]-objposi[i][j].x)<20&&
- fabs(g_eye[2]-objposi[i][j].z)<20)
- return TRUE; //遇到障碍
- else return FALSE; //没遇到
- }
- }
- //----------------------------------------------------------------------------------------
- void baiscobj::caculate()
- {
- ////////////////////战斗机的键盘控制/////////////////////////////////////////////
- if (KEY_DOWN(70)||KEY_DOWN(102)) plane_speed+=0.02f; //战斗机加速,F键
- if (KEY_DOWN(67)||KEY_DOWN(99)) plane_speed-=0.02f; //战斗机减速,C键
- if (KEY_DOWN(65)||KEY_DOWN(97))
- {
- plane_y_angle++;
- plane_left_right_sign=-1;
- } //左转向,A键
- if (KEY_DOWN(68)||KEY_DOWN(100))
- {
- plane_y_angle--;
- plane_left_right_sign=1;
- } //右转向,D键
- if (KEY_DOWN(87)||KEY_DOWN(119)) plane_z_angle++; //爬升,W键
- if (KEY_DOWN(83)||KEY_DOWN(115)) plane_z_angle--; //俯冲,S键
- //////////////////////////飞行速度优化////////////////////////////////////
- if(plane_speed<0.6f&&plane_y>2)
- plane_speed=0.6f;
- if(plane_speed<0)
- plane_speed=0;
- else if(plane_speed>PLANE_MAX_SPEED)
- plane_speed=PLANE_MAX_SPEED;
- //限制飞机飞行的速度
- if(plane_speed>PLANE_FLY_SPEED)
- plane_can_fly=true;
- else
- plane_can_fly=false;
- //判断飞机是否达到起飞的速度
- //////////////////////////飞机俯冲、爬升角度优化///////////////////////////
- if(plane_z_angle>0)
- plane_z_angle-=0.5f;
- else if(plane_z_angle<0)
- plane_z_angle+=0.5f;
- //飞机的俯仰角度回复代码
- if(plane_y==2)
- {
- if(plane_speed<PLANE_FLY_SPEED)
- plane_z_angle=0;
- if((plane_z_angle>180&&plane_z_angle<360)||(plane_z_angle>-180&&plane_z_angle<0))
- plane_z_angle=0;
- }
- //////////////////////////飞机左右转弯优化/////////////////////////////////
- if(plane_y>5)
- {
- if(plane_left_right_sign==0)
- {
- if(plane_x_angle>0)
- plane_x_angle-=1.5f;
- else if(plane_x_angle<0)
- plane_x_angle+=1.5f;
- }
- else if(plane_left_right_sign==-1)
- {
- plane_x_angle-=0.5f;
- plane_left_right_sign=0;
- }
- else if(plane_left_right_sign==1)
- {
- plane_x_angle+=0.5f;
- plane_left_right_sign=0;
- }
- //控制飞机左右旋转时的细节动作
- if(plane_x_angle>90)
- plane_x_angle=90;
- else if(plane_x_angle<-90)
- plane_x_angle=-90;
- //控制飞机细节动作的范围
- }
- else
- plane_x_angle=0;
- ////////////////////////////////飞行路线优化////////////////////////////////
- if(plane_z_angle>360)
- plane_z_angle-=360;
- else if(plane_z_angle<-360)
- plane_z_angle+=360;
- //控制飞机俯仰角度的范围
- if(plane_can_fly==true)
- {
- if((plane_z_angle>0&&plane_z_angle<180)||(plane_z_angle>-360&&plane_z_angle<-180))
- plane_y=plane_y+sin(plane_z_angle*CHANGE)*(plane_speed-PLANE_FLY_SPEED);
- else if((plane_z_angle>180&&plane_z_angle<360)||(plane_z_angle>-180&&plane_z_angle<0))
- plane_y=plane_y+sin(plane_z_angle*CHANGE)*(plane_speed+PLANE_FLY_SPEED);
- }
- else if(plane_can_fly==false)
- plane_y=plane_y-(PLANE_FLY_SPEED-plane_speed);
- //y轴的升高与降低控制,(!!没有考虑)升高时的减速与降低时的加速
- plane_x=plane_x+cos(plane_z_angle*CHANGE)*cos(plane_y_angle*CHANGE)*plane_speed;
- plane_z=plane_z-cos(plane_z_angle*CHANGE)*sin(plane_y_angle*CHANGE)*plane_speed;
- //飞行路线的产生
- if(plane_y<2)
- {
- plane_y=2;
- if(plane_speed>2.5||plane_z_angle<-15) //触发爆炸的条件
- explode=true;
- }
- //控制飞行的范围
- }
- void baiscobj::InitData()
- {
- int t;
- for(t=0;t<MAXFRAGMENT;t++)
- {
- // fragment[t].x=(float)(rand()%100-rand()%100)/1000;
- fragment[t].x=0;
- fragment[t].y=0;
- fragment[t].z=0;
- fragment[t].active=true;
- fragment[t].anx=(float)(rand()%360);
- fragment[t].any=0;
- fragment[t].anz=(float)(rand()%360);
- fragment[t].dim=(float)(rand()%100)/200;
- fragment[t].ddim=(float)(rand()%3);
- fragment[t].r=1;
- fragment[t].g=1;
- fragment[t].b=1;
- // fragment[t].dx=(float)(rand()%100-rand()%100)/50;
- // fragment[t].dy=(float)(rand()%100-rand()%100)/50;
- // fragment[t].dz=0.1+(float)(rand()%100)/200;
- fragment[t].dx=(float)(rand()%100-rand()%100)/50;
- fragment[t].dy=(float)(rand()%100-rand()%100)/50;
- fragment[t].dz=(float)(rand()%100-rand()%100)/50;
- }
- fine=false;
- explode=false;
- }
- void baiscobj::CalFragment()
- {
- int t,k=false;
- for(t=0;t<MAXFRAGMENT;t++)
- {
- if(fragment[t].active==true)
- {
- k=true;
- fragment[t].anx+=4;
- fragment[t].anz+=3;
- fragment[t].x+=fragment[t].dx;
- fragment[t].y+=fragment[t].dy;
- fragment[t].z+=fragment[t].dz;
- if(fragment[t].y<-4)
- {
- fragment[t].dy/=2;
- fragment[t].dy=-fragment[t].dy;
- fragment[t].y+=fragment[t].dy;
- fragment[t].ddim--;
- if(fragment[t].ddim<=0)
- fragment[t].active=false;
- }
- fragment[t].dy-=0.01f;
- }
- }
- if(k==false)
- fine=true;
- }
- void baiscobj::DrawFragment(float x, float y, float z)
- {
- int t;
- glColor3f(1,1,1);
- for(t=0;t<MAXFRAGMENT;t++)
- {
- if(fragment[t].active==true)
- {
- glPushMatrix();
- glTranslatef(fragment[t].x+x,fragment[t].y+y,fragment[t].z+z);
- glRotatef(fragment[t].anx,1,0,0);
- glRotatef(fragment[t].anz,0,0,1);
- glBegin(GL_TRIANGLES);
- glVertex3f(0,0,1.0f);
- glVertex3f(1.0f,0,-1.0f);
- glVertex3f(-1.0f,0,-1.0f);
- glEnd();
- glPopMatrix();
- }
- }
- }
- void baiscobj::CreateTexture(UINT textureArray[], LPSTR strFileName, int textureID)
- {
- AUX_RGBImageRec *pBitmap = NULL;
- if(!strFileName) // 如果无此文件,则直接返回
- return;
- CString a,b="HnFlyData\modle\";
- a=b+strFileName;
- pBitmap = auxDIBImageLoad(a); //strFileName // 装入位图,并保存数据
- if(pBitmap == NULL) // 如果装入位图失败,则退出
- {
- AfxMessageBox("目录下没有 "+a+" 位图!");
- return;//exit(0);
- }
- // 生成纹理
- glGenTextures(1, &textureArray[textureID]);
- // 设置像素对齐格式
- glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
- glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);
- gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- // glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);/////去除其他立体效果 () GL_DECAL
- if (pBitmap) // 释放位图占用的资源
- {
- if (pBitmap->data)
- {
- free(pBitmap->data);
- }
- free(pBitmap);
- }
- }
- void baiscobj::DrawObject(t3DModel g_3DModel, UINT tex[], double ratio)
- {
- // 遍历模型中所有的对象
- for(int i = 0; i < g_3DModel.numOfObjects; i++)
- {
- // 如果对象的大小小于0,则退出
- if(g_3DModel.pObject.size() <= 0) break;
- // 获得当前显示的对象
- t3DObject *pObject = &g_3DModel.pObject[i];
- // 判断该对象是否有纹理映射
- if(pObject->bHasTexture)
- {
- // 打开纹理映射
- glEnable(GL_TEXTURE_2D);
- glColor3ub(255, 255, 255);
- glBindTexture(GL_TEXTURE_2D, tex[pObject->materialID]);
- }
- else
- {
- // 关闭纹理映射
- glDisable(GL_TEXTURE_2D);
- glColor3ub(255, 255, 255);
- }
- //////////////////////////////////////////////////////////////////////////
- // 初始化名称堆栈
- glInitNames();
- glPushName(0);
- glPushMatrix();
- glLoadName(i+1);
- glTranslatef(0.0f,-0.025f,0.0f);
- glBegin(GL_TRIANGLES);
- // 遍历所有的面
- for(int j = 0; j < pObject->numOfFaces; j++)
- {
- // 遍历三角形的所有点
- for(int whichVertex = 0; whichVertex < 3; whichVertex++)
- {
- // 获得面对每个点的索引
- int index = pObject->pFaces[j].vertIndex[whichVertex];
- // 给出法向量
- glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z);
- // 如果对象具有纹理
- if(pObject->bHasTexture)
- {
- // 确定是否有UVW纹理坐标
- if(pObject->pTexVerts)
- {
- glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
- }
- }
- else
- {
- if(g_3DModel.pMaterials.size() && pObject->materialID >= 0)
- {
- BYTE *pColor = g_3DModel.pMaterials[pObject->materialID].color;
- glColor3ub(pColor[0], pColor[1], pColor[2]);
- }
- }
- glVertex3f(pObject->pVerts[ index ].x*ratio, pObject->pVerts[ index ].y*ratio, pObject->pVerts[ index ].z*ratio);
- }
- }
- glEnd();// 绘制结束
- glPopMatrix();
- glPopName();
- // DrawObjectBox(g_3DModel,ratio);
- }
- }
- void baiscobj::ShowMap()
- {
- ClearScreen();
- SetModelView();
- // SetLight();
- glMatrixMode(GL_PROJECTION);//设置矩阵模式
- glLoadIdentity();//给投影变换赋单位矩阵
- gluPerspective (cameratype, // Field-of-view angle
- 1024/768, // Aspect ratio of viewing volume
- 10, // Distance to near clipping plane
- 10000);
- glMatrixMode(GL_MODELVIEW);//矩阵模式还原成视模变换模式
- CGetDEMList GetDEMList;
- //天空
- listsky=GetDEMList.GetSkyList(m_strFolderName+"\HnFlyData\SKY\Sky.bmp",112.5,0,-33.0,3000,-6000);
- textureIDsky=GetDEMList.m_iSkyTextureObjectID;
- //天空
- // if(!fog_flag)
- glCallList(listsky);
- SetProjection();
- ShowLand();
- //注记
- glDepthMask(GL_FALSE);
- for(int i=0;i<m_iTextureObjectNum;i++)//有几类注记
- {
- GLfloat fTextureObjectX,fTextureObjectY,fTextureObjectZ;//实际位置
- GLdouble angle;//所需旋转角度
- GLdouble dx,dz;//计算角度所需
- for(int j=0;j<m_pTextureObject[i].m_iDrawNum;j++)//每类注记画几次
- {
- fTextureObjectX=(m_pTextureObject[i].m_pTextureObjectCoordinate)[j].x;
- fTextureObjectY=(m_pTextureObject[i].m_pTextureObjectCoordinate)[j].y;
- fTextureObjectZ=(m_pTextureObject[i].m_pTextureObjectCoordinate)[j].z;
- dx=(GLdouble)(g_eye [0]-g_eye [0]);
- dz=(GLdouble)(g_eye [2]-g_eye [2]);
- if(dx>0&&dz>0)
- angle=atan(dx/dz)*180.0/PI;
- if(dx<0&&dz>0)
- angle=-atan(-dx/dz)*180.0/PI;
- if(dx<0&&dz<0)
- angle=-(90.0+atan(dz/dx)*180.0/PI);
- if(dx>0&&dz<0)
- angle=90.0+atan(-dz/dx)*180.0/PI;
- if(dx==0&&dz!=0)
- if(dz>0)
- angle=0.0;
- else
- angle=180.0;
- if(dx!=0&&dz==0)
- if(dx>0)
- angle=90.0;
- else
- angle=-90.0;
- if(dx==0&&dz==0)
- break;
- glPushMatrix();
- glTranslatef(fTextureObjectX,fTextureObjectY,fTextureObjectZ);
- glRotatef((GLfloat)angle,0.0,1.0,0.0);
- glCallList(m_pTextureObject[i].m_ilid);
- glPopMatrix();
- }
- }
- glDepthMask(GL_TRUE);
- SwapBuffers(wglGetCurrentDC());
- }
- void baiscobj::SetModelView()
- {
- glLoadIdentity();//给视模变换赋单位矩阵
- 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);
- }
- void baiscobj::ClearScreen()
- {
- float fog_r = 170.f/255.f;
- float fog_g = 203.f/255.f;
- float fog_b = 245.f/255.f;
- glClearColor(fog_r,fog_g,fog_b,1.0f);//清屏颜色
- glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//颜色,深缓清屏
- //在其它颜色启动前所有未指定颜色物体为白色
- glColor3f(1.0f, 1.0f, 1.0f);
- glEnable (GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);//使能够剔除
- glCullFace(GL_BACK);//剔除背面
- }
- void baiscobj::SetProjection()
- {
- glMatrixMode(GL_PROJECTION);//设置矩阵模式
- glLoadIdentity();//给投影变换赋单位矩阵
- gluPerspective (cameratype, // Field-of-view angle
- 1024/768, // Aspect ratio of viewing volume
- 0.005, // Distance to near clipping plane
- 10000);
- glMatrixMode(GL_MODELVIEW);//矩阵模式还原成视模变换模式
- }
- void baiscobj::ShowLand()
- {
- SetFog();
- CString strPath=m_strFolderName+"\HnFlyData\DEM\";
- if(!m_bGetDataStatus)//第一次进来
- {
- GetCircumsphereInfo();
- m_strMapID=CalculateFiftyThousandMapSheetNumber(m_fSphereX,-m_fSphereZ);
- // BeginWaitCursor();
- //DEM
- CString strLeftMapID=GetLeftMapID("50000",m_strMapID);
- CString strRightMapID=GetRightMapID("50000",m_strMapID);
- CString strTopMapID=GetTopMapID("50000",m_strMapID);
- CString strBottomMapID=GetBottomMapID("50000",m_strMapID);
- CString strLeftBottomMapID=GetLeftMapID("50000",strBottomMapID);
- CString strRightBottomMapID=GetRightMapID("50000",strBottomMapID);
- CString strLeftTopMapID=GetLeftMapID("50000",strTopMapID);
- CString strRightTopMapID=GetRightMapID("50000",strTopMapID);
- m_old_strLeftTopMapID = strLeftTopMapID;
- m_old_strTopMapID = strTopMapID;
- m_old_strRightTopMapID = strRightTopMapID;
- m_old_strLeftMapID = strLeftMapID;
- m_old_strMapID = m_strMapID;
- m_old_strRightMapID = strRightMapID;
- m_old_strLeftBottomMapID = strLeftBottomMapID;
- m_old_strBottomMapID = strBottomMapID;
- m_old_strRightBottomMapID = strRightBottomMapID;
- double L,B,LS,BS;
- //下
- if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
- //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- }
- if(GetDEMList[1]->OpenDEMFile(strPath+strBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[1]->LoadGridTexture(strPath+"\3\"+strBottomMapID+".bmp",&textureID[1]);
- //textureID[1]=GetDEMList[1]->m_iDEMTextureObjectID;
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- }
- if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
- //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- }
- //中
- if(GetDEMList[3]->OpenDEMFile(strPath+strLeftMapID+".dem",m_dHeightScale))
- {
- GetDEMList[3]->LoadGridTexture(strPath+"\3\"+strLeftMapID+".bmp",&textureID[3]);
- //textureID[3]=GetDEMList[3]->m_iDEMTextureObjectID;
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- }
- if(GetDEMList[4]->OpenDEMFile(strPath+m_strMapID+".dem",m_dHeightScale))
- {
- GetDEMList[4]->LoadGridTexture(strPath+m_strMapID+".bmp",&textureID[4]);
- //textureID[4]=GetDEMList[4]->m_iDEMTextureObjectID;
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- }
- if(GetDEMList[5]->OpenDEMFile(strPath+strRightMapID+".dem",m_dHeightScale))
- {
- GetDEMList[5]->LoadGridTexture(strPath+"\3\"+strRightMapID+".bmp",&textureID[5]);
- //textureID[5]=GetDEMList[5]->m_iDEMTextureObjectID;
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- }
- //上
- if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
- //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- }
- if(GetDEMList[7]->OpenDEMFile(strPath+strTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[7]->LoadGridTexture(strPath+"\3\"+strTopMapID+".bmp",&textureID[7]);
- //textureID[7]=GetDEMList[7]->m_iDEMTextureObjectID;
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- }
- if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
- //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- }
- //注记
- CGetDEMList GetNoteList;
- InputTextureObjectData(m_strFolderName+"\HnFlyData\NOTE\Note.zzp3",m_strFolderName+"\HnFlyData\NOTE\");
- for(int i=0;i<m_iTextureObjectNum;i++)//有几个纹理物体就建立几个显示列表
- {
- m_pTextureObject[i].m_ilid=GetNoteList.GetTextureObjectList(
- m_pTextureObject[i].m_cTexturePath,m_pTextureObject[i].m_fXLong*0.4,
- m_pTextureObject[i].m_fYLong*0.4);
- m_pTextureObject[i].m_iTextureObjectID=GetNoteList.m_iTextureObjectTextureObjectID;
- }
- //模型
- // EndWaitCursor();
- }
- else
- {
- CString strMapID;
- strMapID=m_strMapID;
- GetCircumsphereInfo();
- m_strMapID=CalculateFiftyThousandMapSheetNumber(m_fSphereX,-m_fSphereZ);
- CString strOldLeftMapID=GetLeftMapID("50000",strMapID);
- CString strOldRightMapID=GetRightMapID("50000",strMapID);
- CString strOldTopMapID=GetTopMapID("50000",strMapID);
- CString strOldBottomMapID=GetBottomMapID("50000",strMapID);
- CString strOldLeftBottomMapID=GetLeftMapID("50000",strOldBottomMapID);
- CString strOldRightBottomMapID=GetRightMapID("50000",strOldBottomMapID);
- CString strOldLeftTopMapID=GetLeftMapID("50000",strOldTopMapID);
- CString strOldRightTopMapID=GetRightMapID("50000",strOldTopMapID);
- //DEM
- CString strLeftMapID=GetLeftMapID("50000",m_strMapID);
- CString strRightMapID=GetRightMapID("50000",m_strMapID);
- CString strTopMapID=GetTopMapID("50000",m_strMapID);
- CString strBottomMapID=GetBottomMapID("50000",m_strMapID);
- CString strLeftBottomMapID=GetLeftMapID("50000",strBottomMapID);
- CString strRightBottomMapID=GetRightMapID("50000",strBottomMapID);
- CString strLeftTopMapID=GetLeftMapID("50000",strTopMapID);
- CString strRightTopMapID=GetRightMapID("50000",strTopMapID);
- double L,B,LS,BS;
- if(m_strMapID==strOldTopMapID)
- {
- delete GetDEMList[0];delete GetDEMList[1];delete GetDEMList[2];
- glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[1]);glDeleteTextures(1,&textureID[2]);
- GetDEMList[0]=GetDEMList[3];
- GetDEMList[1]=GetDEMList[4];
- GetDEMList[2]=GetDEMList[5];
- textureID[0]=textureID[3];
- textureID[1]=textureID[4];
- textureID[2]=textureID[5];
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- GetDEMList[3]=GetDEMList[6];
- GetDEMList[4]=GetDEMList[7];
- GetDEMList[5]=GetDEMList[8];
- textureID[3]=textureID[6];
- textureID[4]=textureID[7];
- textureID[5]=textureID[8];
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- GetDEMList[6]=new CGetDEMList;
- GetDEMList[7]=new CGetDEMList;
- GetDEMList[8]=new CGetDEMList;
- if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
- //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- }
- if(GetDEMList[7]->OpenDEMFile(strPath+strTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[7]->LoadGridTexture(strPath+"\3\"+strTopMapID+".bmp",&textureID[7]);
- //textureID[7]=GetDEMList[7]->m_iDEMTextureObjectID;
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- }
- if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
- //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- }
- }
- else if(m_strMapID==strOldBottomMapID)
- {
- delete GetDEMList[6];delete GetDEMList[7];delete GetDEMList[8];
- glDeleteTextures(1,&textureID[6]);glDeleteTextures(1,&textureID[7]);glDeleteTextures(1,&textureID[8]);
- GetDEMList[6]=GetDEMList[3];
- GetDEMList[7]=GetDEMList[4];
- GetDEMList[8]=GetDEMList[5];
- textureID[6]=textureID[3];
- textureID[7]=textureID[4];
- textureID[8]=textureID[5];
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- GetDEMList[3]=GetDEMList[0];
- GetDEMList[4]=GetDEMList[1];
- GetDEMList[5]=GetDEMList[2];
- textureID[3]=textureID[0];
- textureID[4]=textureID[1];
- textureID[5]=textureID[2];
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- GetDEMList[0]=new CGetDEMList;
- GetDEMList[1]=new CGetDEMList;
- GetDEMList[2]=new CGetDEMList;
- if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
- //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- }
- if(GetDEMList[1]->OpenDEMFile(strPath+strBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[1]->LoadGridTexture(strPath+"\3\"+strBottomMapID+".bmp",&textureID[1]);
- //textureID[1]=GetDEMList[1]->m_iDEMTextureObjectID;
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- }
- if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
- //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- }
- }
- else if(m_strMapID==strOldLeftMapID)
- {
- delete GetDEMList[2];delete GetDEMList[5];delete GetDEMList[8];
- glDeleteTextures(1,&textureID[2]);glDeleteTextures(1,&textureID[5]);glDeleteTextures(1,&textureID[8]);
- GetDEMList[2]=GetDEMList[1];
- GetDEMList[5]=GetDEMList[4];
- GetDEMList[8]=GetDEMList[7];
- textureID[2]=textureID[1];
- textureID[5]=textureID[4];
- textureID[8]=textureID[7];
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- GetDEMList[1]=GetDEMList[0];
- GetDEMList[4]=GetDEMList[3];
- GetDEMList[7]=GetDEMList[6];
- textureID[1]=textureID[0];
- textureID[4]=textureID[3];
- textureID[7]=textureID[6];
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- GetDEMList[0]=new CGetDEMList;
- GetDEMList[3]=new CGetDEMList;
- GetDEMList[6]=new CGetDEMList;
- if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
- //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- }
- if(GetDEMList[3]->OpenDEMFile(strPath+strLeftMapID+".dem",m_dHeightScale))
- {
- GetDEMList[3]->LoadGridTexture(strPath+"\3\"+strLeftMapID+".bmp",&textureID[3]);
- //textureID[3]=GetDEMList[3]->m_iDEMTextureObjectID;
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- }
- if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
- //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- }
- }
- else if(m_strMapID==strOldRightMapID)
- {
- delete GetDEMList[0];delete GetDEMList[3];delete GetDEMList[6];
- glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[3]);glDeleteTextures(1,&textureID[6]);
- GetDEMList[0]=GetDEMList[1];
- GetDEMList[3]=GetDEMList[4];
- GetDEMList[6]=GetDEMList[7];
- textureID[0]=textureID[1];
- textureID[3]=textureID[4];
- textureID[6]=textureID[7];
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- GetDEMList[1]=GetDEMList[2];
- GetDEMList[4]=GetDEMList[5];
- GetDEMList[7]=GetDEMList[8];
- textureID[1]=textureID[2];
- textureID[4]=textureID[5];
- textureID[7]=textureID[8];
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- GetDEMList[2]=new CGetDEMList;
- GetDEMList[5]=new CGetDEMList;
- GetDEMList[8]=new CGetDEMList;
- if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
- //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- }
- if(GetDEMList[5]->OpenDEMFile(strPath+strRightMapID+".dem",m_dHeightScale))
- {
- GetDEMList[5]->LoadGridTexture(strPath+"\3\"+strRightMapID+".bmp",&textureID[5]);
- //textureID[5]=GetDEMList[5]->m_iDEMTextureObjectID;
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- }
- if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
- //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- }
- }
- else if(m_strMapID==strOldLeftTopMapID)
- {
- delete GetDEMList[0];delete GetDEMList[1];delete GetDEMList[2];
- delete GetDEMList[5];delete GetDEMList[8];
- glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[1]);
- glDeleteTextures(1,&textureID[2]);glDeleteTextures(1,&textureID[5]);
- glDeleteTextures(1,&textureID[8]);
- GetDEMList[1]=GetDEMList[3];
- GetDEMList[2]=GetDEMList[4];
- GetDEMList[4]=GetDEMList[6];
- GetDEMList[5]=GetDEMList[7];
- textureID[1]=textureID[3];
- textureID[2]=textureID[4];
- textureID[4]=textureID[6];
- textureID[5]=textureID[7];
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- GetDEMList[0]=new CGetDEMList;
- GetDEMList[3]=new CGetDEMList;
- GetDEMList[6]=new CGetDEMList;
- GetDEMList[7]=new CGetDEMList;
- GetDEMList[8]=new CGetDEMList;
- if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
- //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- }
- if(GetDEMList[3]->OpenDEMFile(strPath+strLeftMapID+".dem",m_dHeightScale))
- {
- GetDEMList[3]->LoadGridTexture(strPath+"\3\"+strLeftMapID+".bmp",&textureID[3]);
- //textureID[3]=GetDEMList[3]->m_iDEMTextureObjectID;
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- }
- if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
- //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- }
- if(GetDEMList[7]->OpenDEMFile(strPath+strTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[7]->LoadGridTexture(strPath+"\3\"+strTopMapID+".bmp",&textureID[7]);
- //textureID[7]=GetDEMList[7]->m_iDEMTextureObjectID;
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- }
- if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
- //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- }
- }
- else if(m_strMapID==strOldRightTopMapID)
- {
- delete GetDEMList[0];delete GetDEMList[1];delete GetDEMList[2];
- delete GetDEMList[3];delete GetDEMList[6];
- glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[1]);
- glDeleteTextures(1,&textureID[2]);glDeleteTextures(1,&textureID[3]);
- glDeleteTextures(1,&textureID[6]);
- GetDEMList[0]=GetDEMList[4];
- GetDEMList[1]=GetDEMList[5];
- GetDEMList[3]=GetDEMList[7];
- GetDEMList[4]=GetDEMList[8];
- textureID[0]=textureID[4];
- textureID[1]=textureID[5];
- textureID[3]=textureID[7];
- textureID[4]=textureID[8];
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- GetDEMList[2]=new CGetDEMList;
- GetDEMList[5]=new CGetDEMList;
- GetDEMList[6]=new CGetDEMList;
- GetDEMList[7]=new CGetDEMList;
- GetDEMList[8]=new CGetDEMList;
- if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
- //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- }
- if(GetDEMList[5]->OpenDEMFile(strPath+strRightMapID+".dem",m_dHeightScale))
- {
- GetDEMList[5]->LoadGridTexture(strPath+"\3\"+strRightMapID+".bmp",&textureID[5]);
- //textureID[5]=GetDEMList[5]->m_iDEMTextureObjectID;
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- }
- if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
- //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- }
- if(GetDEMList[7]->OpenDEMFile(strPath+strTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[7]->LoadGridTexture(strPath+"\3\"+strTopMapID+".bmp",&textureID[7]);
- //textureID[7]=GetDEMList[7]->m_iDEMTextureObjectID;
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- }
- if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
- //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- }
- }
- else if(m_strMapID==strOldLeftBottomMapID)
- {
- delete GetDEMList[2];delete GetDEMList[5];delete GetDEMList[6];
- delete GetDEMList[7];delete GetDEMList[8];
- glDeleteTextures(1,&textureID[2]);glDeleteTextures(1,&textureID[5]);
- glDeleteTextures(1,&textureID[6]);glDeleteTextures(1,&textureID[7]);
- glDeleteTextures(1,&textureID[8]);
- GetDEMList[4]=GetDEMList[0];
- GetDEMList[5]=GetDEMList[1];
- GetDEMList[7]=GetDEMList[3];
- GetDEMList[8]=GetDEMList[4];
- textureID[4]=textureID[0];
- textureID[5]=textureID[1];
- textureID[7]=textureID[3];
- textureID[8]=textureID[4];
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- GetDEMList[0]=new CGetDEMList;
- GetDEMList[1]=new CGetDEMList;
- GetDEMList[2]=new CGetDEMList;
- GetDEMList[3]=new CGetDEMList;
- GetDEMList[6]=new CGetDEMList;
- if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
- //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- }
- if(GetDEMList[1]->OpenDEMFile(strPath+strBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[1]->LoadGridTexture(strPath+"\3\"+strBottomMapID+".bmp",&textureID[1]);
- //textureID[1]=GetDEMList[1]->m_iDEMTextureObjectID;
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- }
- if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
- //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- }
- if(GetDEMList[3]->OpenDEMFile(strPath+strLeftMapID+".dem",m_dHeightScale))
- {
- GetDEMList[3]->LoadGridTexture(strPath+"\3\"+strLeftMapID+".bmp",&textureID[3]);
- //textureID[3]=GetDEMList[3]->m_iDEMTextureObjectID;
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- }
- if(GetDEMList[6]->OpenDEMFile(strPath+strLeftTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[6]->LoadGridTexture(strPath+"\3\"+strLeftTopMapID+".bmp",&textureID[6]);
- //textureID[6]=GetDEMList[6]->m_iDEMTextureObjectID;
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- }
- }
- else if(m_strMapID==strOldRightBottomMapID)
- {
- delete GetDEMList[0];delete GetDEMList[3];delete GetDEMList[6];
- delete GetDEMList[7];delete GetDEMList[8];
- glDeleteTextures(1,&textureID[0]);glDeleteTextures(1,&textureID[3]);
- glDeleteTextures(1,&textureID[6]);glDeleteTextures(1,&textureID[7]);
- glDeleteTextures(1,&textureID[8]);
- GetDEMList[3]=GetDEMList[1];
- GetDEMList[4]=GetDEMList[2];
- GetDEMList[6]=GetDEMList[4];
- GetDEMList[7]=GetDEMList[5];
- textureID[3]=textureID[1];
- textureID[4]=textureID[2];
- textureID[6]=textureID[4];
- textureID[7]=textureID[5];
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- GetDEMList[0]=new CGetDEMList;
- GetDEMList[1]=new CGetDEMList;
- GetDEMList[2]=new CGetDEMList;
- GetDEMList[5]=new CGetDEMList;
- GetDEMList[8]=new CGetDEMList;
- if(GetDEMList[0]->OpenDEMFile(strPath+strLeftBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[0]->LoadGridTexture(strPath+"\3\"+strLeftBottomMapID+".bmp",&textureID[0]);
- //textureID[0]=GetDEMList[0]->m_iDEMTextureObjectID;
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- }
- if(GetDEMList[1]->OpenDEMFile(strPath+strBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[1]->LoadGridTexture(strPath+"\3\"+strBottomMapID+".bmp",&textureID[1]);
- //textureID[1]=GetDEMList[1]->m_iDEMTextureObjectID;
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- }
- if(GetDEMList[2]->OpenDEMFile(strPath+strRightBottomMapID+".dem",m_dHeightScale))
- {
- GetDEMList[2]->LoadGridTexture(strPath+"\3\"+strRightBottomMapID+".bmp",&textureID[2]);
- //textureID[2]=GetDEMList[2]->m_iDEMTextureObjectID;
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- }
- if(GetDEMList[5]->OpenDEMFile(strPath+strRightMapID+".dem",m_dHeightScale))
- {
- GetDEMList[5]->LoadGridTexture(strPath+"\3\"+strRightMapID+".bmp",&textureID[5]);
- //textureID[5]=GetDEMList[5]->m_iDEMTextureObjectID;
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- }
- if(GetDEMList[8]->OpenDEMFile(strPath+strRightTopMapID+".dem",m_dHeightScale))
- {
- GetDEMList[8]->LoadGridTexture(strPath+"\3\"+strRightTopMapID+".bmp",&textureID[8]);
- //textureID[8]=GetDEMList[8]->m_iDEMTextureObjectID;
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- }
- }
- else
- {
- GetDEMList[0]->GetList(1,1,1,textureID[0],&L,&B,&LS,&BS);
- GetDEMList[1]->GetList(1,1,1,textureID[1],&L,&B,&LS,&BS);
- GetDEMList[2]->GetList(1,1,1,textureID[2],&L,&B,&LS,&BS);
- GetDEMList[3]->GetList(1,1,1,textureID[3],&L,&B,&LS,&BS);
- GetDEMList[4]->GetList(1,1,1,textureID[4],&L,&B,&LS,&BS);
- GetDEMList[5]->GetList(1,1,1,textureID[5],&L,&B,&LS,&BS);
- GetDEMList[6]->GetList(1,1,1,textureID[6],&L,&B,&LS,&BS);
- GetDEMList[7]->GetList(1,1,1,textureID[7],&L,&B,&LS,&BS);
- GetDEMList[8]->GetList(1,1,1,textureID[8],&L,&B,&LS,&BS);
- }
- }
- m_bGetDataStatus=true;
- }
- bool baiscobj::InputTextureObjectData(CString strFilePath, CString strTextureFolderPath)
- {
- //判断文件类型
- if(strFilePath.Right(4)!="zzp3")
- {
- ::MessageBox(NULL,"文件类型不符!","错误",MB_ICONERROR | MB_OK);
- return false;
- }
- //打开文件并判断是否打开成功
- char cFilePath[100];
- sprintf(cFilePath,"%s",strFilePath);
- FILE* fp;
- fp=fopen(cFilePath,"r");
- if(!fp)
- {
- ::MessageBox(NULL,"文件打开失败!","错误",MB_ICONERROR | MB_OK);
- return false;
- }
- //读取纹理模型数据
- fscanf(fp,"%d",&m_iTextureObjectNum);
- m_pTextureObject=new CTextureObject[m_iTextureObjectNum];
- CString strTexturePath;
- for(int i=0;i<m_iTextureObjectNum;i++)
- {
- char cModelName[100];//读取该物体名
- fscanf(fp,"%s",cModelName);
- m_pTextureObject[i].m_strObjectName=cModelName;
- fscanf(fp,"%s",m_pTextureObject[i].m_cTexturePath);//读取该纹理物体的纹理路径
- strTexturePath=m_pTextureObject[i].m_cTexturePath;
- strTexturePath=strTextureFolderPath+strTexturePath;
- sprintf(m_pTextureObject[i].m_cTexturePath,"%s",strTexturePath);
- fscanf(fp,"%f",&(m_pTextureObject[i].m_fXLong));//读取该纹理物体大小
- fscanf(fp,"%f",&(m_pTextureObject[i].m_fYLong));
- int num;
- fscanf(fp,"%d",&num);//这类物体画几次
- m_pTextureObject[i].m_iDrawNum=num;
- m_pTextureObject[i].m_pTextureObjectCoordinate=new TextureObjectCoordinate[num];
- GLfloat x,y,z;
- for(int j=0;j<num;j++)//每次画的实际位置
- {
- fscanf(fp,"%f%f%f",&x,&y,&z);
- (m_pTextureObject[i].m_pTextureObjectCoordinate)[j].x=x;
- (m_pTextureObject[i].m_pTextureObjectCoordinate)[j].y=y-0.015;
- (m_pTextureObject[i].m_pTextureObjectCoordinate)[j].z=z;
- }
- }
- fclose(fp);
- return true;
- }
- void baiscobj::SetFog()
- {
- float fog_r = 170.f/255.f;
- float fog_g = 203.f/255.f;
- float fog_b = 245.f/255.f;
- GLfloat visual_distance =1;
- // 设置雾化效果
- GLuint fogMode[]= { GL_EXP, GL_EXP2, GL_LINEAR }; // 保存三种雾的模式
- GLfloat fogColor[4] = {fog_r, fog_g, fog_b, 1}; // 雾的颜色
- glFogi(GL_FOG_MODE, fogMode[2]); // 设置雾的模式
- glFogfv(GL_FOG_COLOR, fogColor); // 设置雾的颜色
- glFogf(GL_FOG_DENSITY, 100.0f); //1.035 // 设置雾的浓度
- glFogf(GL_FOG_START, 0.1); // 设置雾的开始深度
- glFogf(GL_FOG_END, 0.25); // 设置雾的结束深度
- glHint(GL_FOG_HINT,GL_DONT_CARE);
- }
- void baiscobj::GetCircumsphereInfo()
- {
- //充分利用空间向量几何知识,(x-x1)/(x2-x1)=(y-y1)/(y2-y1)=(z-z1)/(z2-z1)=距离之比
- GLfloat r;//眼睛与目标点距离
- r=(GLfloat)sqrt( (g_look[0]-g_eye[0])*(g_look[0]-g_eye[0])+
- (g_look[1]-g_eye[1])*(g_look[1]-g_eye[1])+
- (g_look[2]-g_eye[2])*(g_look[2]-g_eye[2]) );
- GLfloat nearpointx,nearpointy,nearpointz;//近视点坐标
- GLfloat farpointx,farpointy,farpointz;//远视点坐标
- nearpointx=(m_fProjectionNear/r)*(g_look[0]-g_eye[0])+g_eye[0];
- nearpointy=(m_fProjectionNear/r)*(g_look[1]-g_eye[1])+g_eye[1];
- nearpointz=(m_fProjectionNear/r)*(g_look[2]-g_eye[2])+g_eye[2];
- farpointx=(m_fProjectionFar/r)*(g_look[0]-g_eye[0])+g_eye[0];
- farpointy=(m_fProjectionFar/r)*(g_look[1]-g_eye[1])+g_eye[1];
- farpointz=(m_fProjectionFar/r)*(g_look[2]-g_eye[2])+g_eye[2];
- m_fSphereX=(nearpointx+farpointx)/2;
- m_fSphereY=(nearpointy+farpointy)/2;
- m_fSphereZ=(nearpointz+farpointz)/2;
- GLfloat h,w;// 圆锥近视面的半高、半宽
- h=(GLfloat)tan((m_fProjectionAngle/2)*PI/180.0)*m_fProjectionNear;
- w=h*((GLfloat)1024/(GLfloat)768);
- GLfloat r1;//近视点到近视面一个角点的距离
- r1=(GLfloat)sqrt(h*h+w*w);
- GLfloat r2;//近视点到中心的距离
- r2=(m_fProjectionFar-m_fProjectionNear)/2;
- m_fSphereRadius=(GLfloat)sqrt(r1*r1+r2*r2);
- if(!eye_flag)
- {
- m_fSphereX=g_eye[0];
- m_fSphereY=g_eye[1];
- m_fSphereZ=g_eye[2];
- }
- else
- {
- m_fSphereX=g_eye[0];
- m_fSphereY=g_eye[1];
- m_fSphereZ=g_eye[2];
- }
- }
- CString baiscobj::GetRightMapID(CString strScale, CString strMapID)
- {
- if(strScale=="50000")
- {
- CString strThisMap8;//该图第89位
- strThisMap8=strMapID.Right(1);
- int iThisMap8=atoi(strThisMap8);
- if((iThisMap8%2)==0)//判断该一万图是否在所属十万图的最右边,是
- {
- CString strThisMap567;
- strThisMap567=strMapID.Mid(4,3);
- int iThisMap567=atoi(strThisMap567);
- if((iThisMap567%12)==0)//判断该十万图是否在所属百万图的最左边,是
- {
- CString strThisMap34;
- strThisMap34=strMapID.Mid(2,2);
- int iThisMap34=atoi(strThisMap34);
- int iRightMap34=iThisMap34+1;
- CString strRightMap34;
- strRightMap34.Format("%d",iRightMap34);
- int iRightMap567=iThisMap567-11;
- CString strRightMap567;
- strRightMap567.Format("%d",iRightMap567);
- if(iRightMap567<10)
- strRightMap567="00"+strRightMap567;
- if(iRightMap567>=10&&iRightMap567<100)
- strRightMap567="0"+strRightMap567;
- int iRightMap8=iThisMap8-1;
- CString strRightMap8;
- strRightMap8.Format("%d",iRightMap8);
- CString strRightMapID;
- strRightMapID=strMapID.Left(2)+strRightMap34+strRightMap567+strRightMap8;
- return strRightMapID;
- }
- else//不是
- {
- CString strRightMap567;
- int iRightMap567=iThisMap567+1;
- strRightMap567.Format("%d",iRightMap567);
- if(iRightMap567<10)
- strRightMap567="00"+strRightMap567;
- if(iRightMap567>=10&&iRightMap567<100)
- strRightMap567="0"+strRightMap567;
- int iRightMap8=iThisMap8-1;
- CString strRightMap8;
- strRightMap8.Format("%d",iRightMap8);
- CString strRightMapID;
- strRightMapID=strMapID.Left(4)+strRightMap567+strRightMap8;
- return strRightMapID;
- }
- }
- else//不是
- {
- int iRightMap8=iThisMap8+1;
- CString strRightMap8;
- strRightMap8.Format("%d",iRightMap8);
- CString strRightMapID;
- strRightMapID=strMapID.Left(7)+strRightMap8;
- return strRightMapID;
- }
- }
- return "CANNOT DEAL";
- }
- CString baiscobj::GetLeftMapID(CString strScale, CString strMapID)
- {
- if(strScale=="50000")
- {
- CString strThisMap8;//该图第89位
- strThisMap8=strMapID.Right(1);
- int iThisMap8=atoi(strThisMap8);
- if((iThisMap8%2)==1)//判断该五万图是否在所属十万图的最左边,是
- {
- CString strThisMap567;
- strThisMap567=strMapID.Mid(4,3);
- int iThisMap567=atoi(strThisMap567);
- if((iThisMap567%12)==1)//判断该十万图是否在所属百万图的最左边,是
- {
- CString strThisMap34;
- strThisMap34=strMapID.Mid(2,2);
- int iThisMap34=atoi(strThisMap34);
- int iLeftMap34=iThisMap34-1;
- CString strLeftMap34;
- strLeftMap34.Format("%d",iLeftMap34);
- int iLeftMap567=iThisMap567+7;
- CString strLeftMap567;
- strLeftMap567.Format("%d",iLeftMap567);
- if(iLeftMap567<100)
- strLeftMap567="0"+strLeftMap567;
- int iLeftMap8=iThisMap8+1;
- CString strLeftMap8;
- strLeftMap8.Format("%d",iLeftMap8);
- CString strLeftMapID;
- strLeftMapID=strMapID.Left(2)+strLeftMap34+strLeftMap567+strLeftMap8;
- return strLeftMapID;
- }
- else//不是
- {
- CString strLeftMap567;
- int iLeftMap567=iThisMap567-1;
- strLeftMap567.Format("%d",iLeftMap567);
- if(iLeftMap567<10)
- strLeftMap567="00"+strLeftMap567;
- if(iLeftMap567>=10&&iLeftMap567<100)
- strLeftMap567="0"+strLeftMap567;
- int iLeftMap8=iThisMap8+1;
- CString strLeftMap8;
- strLeftMap8.Format("%d",iLeftMap8);
- CString strLeftMapID;
- strLeftMapID=strMapID.Left(4)+strLeftMap567+strLeftMap8;
- return strLeftMapID;
- }
- }
- else//不是
- {
- int iLeftMap8=iThisMap8-1;
- CString strLeftMap8;
- strLeftMap8.Format("%d",iLeftMap8);
- CString strLeftMapID;
- strLeftMapID=strMapID.Left(7)+strLeftMap8;
- return strLeftMapID;
- }
- }
- return "CANNOT DEAL";
- }
- CString baiscobj::GetTopMapID(CString strScale, CString strMapID)
- {
- if(strScale=="50000")
- {
- CString strThisMap8;//该图第89位
- strThisMap8=strMapID.Right(1);
- int iThisMap8=atoi(strThisMap8);
- if(((iThisMap8-1)/2)==0)//判断该一万图是否在所属十万图的最上边,是
- {
- CString strThisMap567;
- strThisMap567=strMapID.Mid(4,3);
- int iThisMap567=atoi(strThisMap567);
- if(((iThisMap567-1)/12)==0)//判断该十万图是否在所属百万图的最上边,是
- {
- CString strThisMap12;
- strThisMap12=strMapID.Mid(0,2);
- int iThisMap12=atoi(strThisMap12);
- int iTopMap12=iThisMap12+1;
- CString strTopMap12;
- strTopMap12.Format("%d",iTopMap12);
- if(iTopMap12<10)
- strTopMap12="0"+strTopMap12;
- int iTopMap567=iThisMap567+132;
- CString strTopMap567;
- strTopMap567.Format("%d",iTopMap567);
- int iTopMap8=iThisMap8+2;
- CString strTopMap8;
- strTopMap8.Format("%d",iTopMap8);
- CString strTopMapID;
- strTopMapID=strTopMap12+strMapID.Mid(2,2)+strTopMap567+strTopMap8;
- return strTopMapID;
- }
- else//不是
- {
- CString strTopMap567;
- int iTopMap567=iThisMap567-12;
- strTopMap567.Format("%d",iTopMap567);
- if(iTopMap567<10)
- strTopMap567="00"+strTopMap567;
- if(iTopMap567>=10&&iTopMap567<100)
- strTopMap567="0"+strTopMap567;
- int iTopMap8=iThisMap8+2;
- CString strTopMap8;
- strTopMap8.Format("%d",iTopMap8);
- CString strTopMapID;
- strTopMapID=strMapID.Left(4)+strTopMap567+strTopMap8;
- return strTopMapID;
- }
- }
- else//不是
- {
- int iTopMap8=iThisMap8-2;
- CString strTopMap8;
- strTopMap8.Format("%d",iTopMap8);
- CString strTopMapID;
- strTopMapID=strMapID.Left(7)+strTopMap8;
- return strTopMapID;
- }
- }
- return "CANNOT DEAL";
- }
- CString baiscobj::CalculateFiftyThousandMapSheetNumber(double l, double b)
- {
- // 求1:100万图号
- int before,after;
- CString Map100Number,Map10Number,Map5Number,str;
- before = int(b)/4+1;
- after = int(l)/6+31;
- if(before<10) Map100Number.Format("0%d%d",before,after);
- else Map100Number.Format("%d%d",before,after);
- // 求1:10万图号
- int Row,Col;
- Col = (int)((l-(after-31.0)*6.0)*10.0/5.0);
- Row = 11-(int)((b-(before-1.0)*4.0)*3.0);
- int Code;
- Code = Row*12+Col+1;
- if(Code<10) Map10Number.Format("00%d",Code);
- else if(Code<100) Map10Number.Format("0%2d",Code);
- else Map10Number.Format("%3d",Code);
- // 求1:5万图号
- int Row5,Col5;
- Col5 = (int)((l-(Col/2.0+(after-31.0)*6.0))*4.0);
- Row5 = 1 - (int)((b-((11.0-Row)/3.0+(before-1.0)*4.0))*6.0);
- int Code5;
- Code5 = Row5*2+Col5+1;
- str.Format("%d",Code5);
- Map5Number = Map100Number + Map10Number + str;
- return Map5Number;
- }
- CString baiscobj::GetBottomMapID(CString strScale, CString strMapID)
- {
- if(strScale=="50000")
- {
- CString strThisMap8;//该图第89位
- strThisMap8=strMapID.Right(1);
- int iThisMap8=atoi(strThisMap8);
- if(((iThisMap8-1)/2)==1)//判断该五万图是否在所属十万图的最下边,是
- {
- CString strThisMap567;
- strThisMap567=strMapID.Mid(4,3);
- int iThisMap567=atoi(strThisMap567);
- if(((iThisMap567-1)/12)==11)//判断该十万图是否在所属百万图的最下边,是
- {
- CString strThisMap12;
- strThisMap12=strMapID.Mid(0,2);
- int iThisMap12=atoi(strThisMap12);
- int iBottomMap12=iThisMap12-1;
- CString strBottomMap12;
- strBottomMap12.Format("%d",iBottomMap12);
- if(iBottomMap12<10)
- strBottomMap12="0"+strBottomMap12;
- int iBottomMap567=iThisMap567-132;
- CString strBottomMap567;
- strBottomMap567.Format("%d",iBottomMap567);
- if(iBottomMap567<10)
- strBottomMap567="00"+strBottomMap567;
- if(iBottomMap567>=10)
- strBottomMap567="0"+strBottomMap567;
- int iBottomMap8=iThisMap8-2;
- CString strBottomMap8;
- strBottomMap8.Format("%d",iBottomMap8);
- CString strBottomMapID;
- strBottomMapID=strBottomMap12+strMapID.Mid(2,2)+strBottomMap567+strBottomMap8;
- return strBottomMapID;
- }
- else//不是
- {
- CString strBottomMap567;
- int iBottomMap567=iThisMap567+12;
- strBottomMap567.Format("%d",iBottomMap567);
- if(iBottomMap567<100)
- strBottomMap567="0"+strBottomMap567;
- int iBottomMap8=iThisMap8-2;
- CString strBottomMap8;
- strBottomMap8.Format("%d",iBottomMap8);
- CString strBottomMapID;
- strBottomMapID=strMapID.Left(4)+strBottomMap567+strBottomMap8;
- return strBottomMapID;
- }
- }
- else//不是
- {
- int iBottomMap8=iThisMap8+2;
- CString strBottomMap8;
- strBottomMap8.Format("%d",iBottomMap8);
- CString strBottomMapID;
- strBottomMapID=strMapID.Left(7)+strBottomMap8;
- return strBottomMapID;
- }
- }
- return "CANNOT DEAL";
- }