资源简介

基于vc平台的opengl地形绘制,使用了三角形带,增加了材质和光照

资源截图

代码片段和文件信息

#include 
#include 
#include 
#define dx 1.0
#define dy 1.0
typedef struct materialStruct
{
GLfloat ambient[4];
    GLfloat diffuse[4];
GLfloat specular[4];
GLfloat shininess;
} materialStruct;
  GLfloat xpoints[200];
  GLfloat ypoints[200];
  GLfloat zpoints[200];
  GLfloat trianglenormals[200][3];
  GLfloat vertexnormals[200][3];    
void Idle()    //空闲时调用函数
{
for(int i=0;i<200;i++)
{
if(i%2==0)
  ypoints[i]=-50;
else
  ypoints[i]=-49;
    }
    glRotatef(0.1 0 0 1);
    glutPostRedisplay();
}
void init()    //初始化顶点数据以及法向(未归一化)数据
{  
int i;
srand((unsigned int)time(NULL)); 
    for(i=0;i<200;i++)
{    
if((i%2)==0)
{    
xpoints[i]=-50+i/2*dx;
        ypoints[i]=-50;
}
else
{
       xpoints[i]=xpoints[i-1];
           ypoints[i]=-49;
        }
 zpoints[i]=(float)(rand()*1.0/RAND_MAX);   //控制z坐标在0-1范围内
 
}
for(i=0;i<200;i++)
{
   if(i%2==0)
   {
trianglenormals[i][0]=-(dy*(zpoints[i+2]-zpoints[i]));
    trianglenormals[i][1]=-(dx*(zpoints[i+1]-zpoints[i]));
    trianglenormals[i][2]=dx*dy; 
   }
   else
   {
trianglenormals[i][0]=(dy*(zpoints[i+2]-zpoints[i]));
    trianglenormals[i][1]=-(dx*(zpoints[i+1]-zpoints[i]));
    trianglenormals[i][2]=-(dx*dy); 
   }
}
vertexnormals[0][0]=trianglenormals[0][0];
vertexnormals[0][1]=trianglenormals[0][1];
vertexnormals[0][2]=trianglenormals[0][2];
        vertexnormals[1][0]=(trianglenormals[0][0]*2+trianglenormals[1][0])/3;
vertexnormals[1][1]=(trianglenormals[0][1]*2+trianglenormals[1][1])/3;
vertexnormals[1][2]=(trianglenormals[0][2]*2+trianglenormals[1][2])/3;
vertexnormals[199][0]=(trianglenormals[199][0]*2+trianglenormals[198][0])/3;
vertexnormals[199][1]=(trianglenormals[199][1]*2+trianglenormals[198][1])/3;
vertexnormals[199][2]=(trianglenormals[199][2]*2+trianglenormals[198][2])/3;
        vertexnormals[198][0]=(trianglenormals[199][0]+trianglenormals[198][0])/2;
vertexnormals[198][1]=(trianglenormals[199][1]+trianglenormals[198][1])/2;
vertexnormals[198][2]=(trianglenormals[199][2]+trianglenormals[198][2])/2;
for(i=2;i<198;i++)
{
if(i%2==0)
{
vertexnormals[i][0]=(trianglenormals[i-2][0]+trianglenormals[i-1][0]+trianglenormals[i][0])/3;
                vertexnormals[i][1]=(trianglenormals[i-2][1]+trianglenormals[i-1][1]+trianglenormals[i][1])/3;
vertexnormals[i][2]=(trianglenormals[i-2][2]+trianglenormals[i-1][2]+trianglenormals[i][2])/3;
}
else
{
vertexnormals[i][0]=(trianglenormals[i-3][0]+trianglenormals[i-2][0]*2+trianglenormals[i-1][0]*2+trianglenormals[i][0])/6;
vertexnormals[i][1]=(trianglenormals[i-3][1]+trianglenormals[i-2][1]*2+trianglenormals[i-1][1]*2+trianglenormals[i][1])/6;
vertexnormals[i][2]=(trianglenormals[i-3][2]+trianglenormals[i-2][2]*2+trianglenormals[i-1][2]*2+trianglenormals[i][2])/6;
}

}
glClearColor(0.75f 0.75f

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1166  2013-10-27 19:55  地形绘制(Enhancement)\Debug\cl.command.1.tlog

     文件      20790  2013-10-27 19:55  地形绘制(Enhancement)\Debug\CL.read.1.tlog

     文件        362  2013-10-27 19:55  地形绘制(Enhancement)\Debug\CL.write.1.tlog

     文件          2  2013-10-27 19:55  地形绘制(Enhancement)\Debug\link-cvtres.read.1.tlog

     文件          2  2013-10-27 19:55  地形绘制(Enhancement)\Debug\link-cvtres.write.1.tlog

     文件          2  2013-10-27 19:55  地形绘制(Enhancement)\Debug\link.4768-cvtres.read.1.tlog

     文件          2  2013-10-27 19:55  地形绘制(Enhancement)\Debug\link.4768-cvtres.write.1.tlog

     文件          2  2013-10-27 19:55  地形绘制(Enhancement)\Debug\link.4768.read.1.tlog

     文件          2  2013-10-27 19:55  地形绘制(Enhancement)\Debug\link.4768.write.1.tlog

     文件       2478  2013-10-27 19:55  地形绘制(Enhancement)\Debug\link.command.1.tlog

     文件       7006  2013-10-27 19:55  地形绘制(Enhancement)\Debug\link.read.1.tlog

     文件        930  2013-10-27 19:55  地形绘制(Enhancement)\Debug\link.write.1.tlog

     文件      64609  2013-10-27 19:55  地形绘制(Enhancement)\Debug\Map.obj

     文件        654  2013-10-27 19:55  地形绘制(Enhancement)\Debug\mt.command.1.tlog

     文件        410  2013-10-27 19:55  地形绘制(Enhancement)\Debug\mt.read.1.tlog

     文件        186  2013-10-27 19:55  地形绘制(Enhancement)\Debug\mt.write.1.tlog

     文件        826  2013-10-27 19:55  地形绘制(Enhancement)\Debug\rc.command.1.tlog

     文件        354  2013-10-27 19:55  地形绘制(Enhancement)\Debug\rc.read.1.tlog

     文件        370  2013-10-27 19:55  地形绘制(Enhancement)\Debug\rc.write.1.tlog

     文件     297984  2013-10-27 19:55  地形绘制(Enhancement)\Debug\vc100.idb

     文件     208896  2013-10-27 19:55  地形绘制(Enhancement)\Debug\vc100.pdb

     文件      74752  2013-10-27 18:48  地形绘制(Enhancement)\Debug\vc60.idb

     文件     102400  2013-10-27 18:48  地形绘制(Enhancement)\Debug\vc60.pdb

     文件     439808  2013-10-27 19:55  地形绘制(Enhancement)\Debug\地形绘制.exe

     文件        406  2013-10-27 18:58  地形绘制(Enhancement)\Debug\地形绘制.exe.embed.manifest

     文件        472  2013-10-27 19:55  地形绘制(Enhancement)\Debug\地形绘制.exe.embed.manifest.res

     文件        381  2013-10-27 19:55  地形绘制(Enhancement)\Debug\地形绘制.exe.intermediate.manifest

     文件    1086400  2013-10-27 19:55  地形绘制(Enhancement)\Debug\地形绘制.ilk

     文件         56  2013-10-27 19:57  地形绘制(Enhancement)\Debug\地形绘制.lastbuildstate

     文件        876  2013-10-27 19:57  地形绘制(Enhancement)\Debug\地形绘制.log

............此处省略23个文件信息

评论

共有 条评论