资源简介
OPENGL分形方法模拟山的形成,有条纹光照
代码片段和文件信息
#include
#include
#include
#include
#include
//#include
//#include
GLfloat pos[]={-2650};
GLfloat amb[]={0.20.20.21.0};
GLfloat front_amb_diff[]={0.70.750.751.0};
float theta=0 dt=0.4 p=3.141593/180;
bool flag=true;
int landscape[400][400];
void vxv(float *nfloat *v1float *v2){
n[0]=v1[1]*v2[2]-v1[2]*v2[1];
n[1]=v1[2]*v2[0]-v1[0]*v2[2];
n[2]=v1[0]*v2[1]-v1[1]*v2[0];
}
void elevation(int seedint n){
int ijkcenterx=200centery=200stepxstepyxminxmaxyminymax
xsqysqradius=25radius_sq=radius*radiusmaxh=0;
srand(seed);
for(k=0;k stepx=(rand()>RAND_MAX/2)? 3:-3;
stepy=(rand()>RAND_MAX/2)? 3:-3;
centerx += stepx;
centery += stepy;
if(centerx<0||400<=centerx) centerx=200;
if(centery<0||400<=centery) centery=200;
xmin=(0<=centerx-radius)? centerx-radius:0;
xmax=(400<=centerx+radius)? 399:centerx+radius;
ymin=(0 ymax=(400<=centery+radius)? 399:centery+radius;
for(i=xmin;i for(j=ymin;j xsq = i-centerx;
xsq *= xsq;
ysq = j-centery;
ysq *= ysq;
if((xsq+ysq)<=radius_sq)
landscape[i][j]++;
}
}
for(i=0;i<400;i++)
for(j=0;j<400;j++)
if(landscape[i][j]>maxh)
maxh = landscape[i][j];
float scale = 255.0/(float) maxh;
for(i=0;i<400;i++)
for(j=0;j<400;j++)
landscape[i][j] *= scale;
}
void display(void){
float v1[3]v2[3]v3[3]n[3];
int step = 3;
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(400*sin(theta*p)400
- 上一篇:CH422原厂C语言驱动
- 下一篇:m行k列矩阵乘以k行n列矩阵
评论
共有 条评论