資源簡介
該代碼實(shí)現(xiàn)了dem數(shù)據(jù)的讀入,三角網(wǎng)的構(gòu)建,紋理的映射,法線的設(shè)置,并能在構(gòu)建的地形上畫任意的建筑,并能對(duì)建筑的每一個(gè)面進(jìn)行拾取,其中含有數(shù)據(jù)和紋理

代碼片段和文件信息
//?Dem.cpp:?implementation?of?the?CDem?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“test.h“
#include?“Dem.h“
#include?
#include?
#include?
#include?
#include?“Vector32.h“
#ifdef?_DEBUG
#undef?THIS_FILE
static?char?THIS_FILE[]=__FILE__;
#define?new?DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDem::CDem()
{
??m_fInterval=0;
??m_fNumberX=0;
??m_fNumberY=0;
??m_list=0;
??m_fHeight=NULL;
??bshow?=?true;
??
??
}
CDem::~CDem()
{
??if?(m_fHeight!=NULL)
??delete?[]?m_fHeight;
}
void?CDem::ReadDem(char?*demfile)
{
???
FILE?*fp=NULL;
fp?=?fopen(demfile?“r“);
if?(fp!=NULL)
{
char?a[10];
fscanf(fp?“%s?%d?%d?%d“&a&m_fNumberX&m_fNumberY&m_fInterval);
????fgets(a?8?fp);
????m_fHeight?=?new?float?[m_fNumberX?*?m_fNumberY];
for(int?i=0;?i {
fscanf(fp?“%f“?&m_fHeight[i]);
}
}
fclose(fp);
}
void?CDem::CreateCompileList()
{
??m_texture=CreateTexture(“test/image1024.bmp“);
??glBindTexture(GL_TEXTURE_2Dm_texture);
???CVpoint?p[4];
???float?r[4];
???float?s[4];
???
???float?dx=m_fInterval*m_fNumberX;
???float?dy=m_fInterval*m_fNumberY;
???m_list=glGenLists(1);
???glNewList(m_listGL_COMPILE);
???for?(int?j=0;j ???{
???for?(int?i=0;i ???{
???p[0].x=i*m_fInterval;
???p[0].z=m_fHeight[j*m_fNumberX?+?i];
???p[0].y=j*m_fInterval;
???????????p[1].x=(i+1)*m_fInterval;
???p[1].z=m_fHeight[j*m_fNumberX?+?i+1];
???p[1].y=j*m_fInterval;
???p[2].x=(i+1)*m_fInterval;
???p[2].z=m_fHeight[(j+1)*m_fNumberX?+?i+1];
???p[2].y=(j+1)*m_fInterval;
???p[3].x=i*m_fInterval;
???p[3].z=m_fHeight[(j+1)*m_fNumberX?+?i];
???p[3].y=(j+1)*m_fInterval;
????
? r[0]=p[0].x/dx;
r[1]=p[1].x/dx;
r[2]=p[2].x/dx;
r[3]=p[3].x/dx;
s[0]=p[0].y/dy;
s[1]=p[1].y/dy;
s[2]=p[2].y/dy;
s[3]=p[3].y/dy;
???????????
???glColor3f(1.00.00.0);
???
???????glBegin(GL_TRIANGLES);
??????SetNormal(ij);
???????glTexCoord2f(r[0]s[0]);
???glVertex3f(p[0].xp[0].yp[0].z);
???SetNormal(i+1j);
???????????glTexCoord2f(r[3]s[3]);
???????????glVertex3f(p[3].xp[3].yp[3].z);
???????????SetNormal(ij+1);
???glTexCoord2f(r[1]s[1]);
???????????glVertex3f(p[1].xp[1].yp[1].z);
???
???????????SetNormal(i+1j);
???glTexCoord2f(r[3]s[3]);
???????????glVertex3f(p[3].xp[3].yp[3].z);
???SetNormal(i+1j+1);
???glTexCoord2f(r[2]s[2]);
???glVertex3f(p[2].xp[2].yp[2].z);
???SetNormal(ij+1);
???glTexCoord2f(r[1]s[1]);
???????????glVertex3f(p[1].xp[1].yp[1].z);
???????glEnd();
???}
???}
???
???glEndList();
}
void?CDem::RenderDem()
{???
if(!bshow)return;
????glEnable(GL_TE
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件?????196664??2001-03-02?21:13??test\dam1.BMP
?????文件???????5456??2009-09-21?09:47??test\Dem.cpp
?????文件????????906??2009-09-21?09:47??test\Dem.h
?????文件???????1244??2009-09-17?16:50??test\HeightIn.cpp
?????文件???????1251??2009-09-09?10:47??test\HeightIn.h
?????文件???????3726??2009-09-01?20:18??test\MainFrm.cpp
?????文件???????1807??2004-03-30?21:45??test\MainFrm.h
?????文件??????23195??2009-09-21?10:09??test\OpenGL.cpp
?????文件???????2429??2009-09-03?22:04??test\OpenGL.h
?????文件???????2428??2009-09-02?15:41??test\Pt3d.cpp
?????文件???????1369??2009-09-02?15:42??test\Pt3d.h
?????文件???????4710??2004-06-28?10:28??test\RES\icon2.ico
?????文件???????3190??2004-04-01?21:28??test\RES\mainfram.bmp
?????文件???????1137??2002-06-10?16:45??test\RES\Netli
?????文件???????2904??2002-06-10?16:45??test\RES\Netli
?????文件???????1078??2004-03-30?22:26??test\RES\test.ico
?????文件????????396??2002-01-06?17:06??test\RES\TEST.RC2
?????文件???????1078??2002-01-06?17:06??test\RES\testDoc.ico
????..A.SH.??????8192??2009-09-18?15:06??test\RES\Thumbs.db
?????文件???????1878??2009-09-08?09:59??test\RES\Toolbar.bmp
?????目錄??????????0??2009-09-08?09:59??test\RES
?????文件???????9268??2009-09-08?09:26??test\resource.h
?????文件????????937??2009-09-08?21:41??test\rrr.cpp
?????文件???????1183??2009-09-08?21:41??test\rrr.h
?????文件????????198??2004-02-28?18:59??test\StdAfx.cpp
?????文件???????2032??2004-10-26?15:28??test\StdAfx.h
?????文件?????173500??2008-05-30?10:26??test\test\beijing.dem
?????文件????3145782??2009-08-31?10:54??test\test\image1024.bmp
?????目錄??????????0??2009-09-03?17:32??test\test
?????文件??????57324??2009-09-08?09:59??test\test.aps
............此處省略27個(gè)文件信息
評(píng)論
共有 條評(píng)論