1 / 59
文档名称:

山大教材资料`交互式计算机图形学`附录源码.doc

格式:doc   页数:59
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

山大教材资料`交互式计算机图形学`附录源码.doc

上传人:智客网 2011/12/30 文件大小:0 KB

下载得到文件列表

山大教材资料`交互式计算机图形学`附录源码.doc

文档介绍

文档介绍:交互式计算机图形学——基于openGL的自顶向下方法
山东大学数字媒体技术专业课本教材附录程序第四版
Sierpinski镂垫程序
/* two-dimensional Sierpinski gasket */
/* generated using randomly selected vertices */
/* and bisection */
#include <GL/>
/*you may have to change the include to<> or
elsewhere depending on where it is stored on your system */
/* usually has included for and */
void myinit(void)
{
/* attributes */
glClearColor(, , , ); /* white background */
glColor3f(, , ); /* draw in red */
/* set up viewing */
/* × camera coordinate window with origin lower left */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(, , , );
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
/* A triangle */
GLfloat vertices[3][2]={{,},{,},{,}};
int i, j, k;
int rand(); /* standard random number generator */
GLfloat p[2] ={,}; /* an arbitrary initial point inside traingle */
glClear(GL_COLOR_BUFFER_BIT); /* clear the window */
glBegin(GL_POINTS);
/* compute and plots 5000 new points */
for( k=0; k<5000; k++)
{
j=rand()%3; /* pick a vertex at random */
/* Compute point halfway between selected vertex and old point */
p[0] = (p[0]+vertices[j][0])/;
p[1] = (p[1]+vertices[j][1])/;

/* plot new point */
glVertex2fv(p);

}
glEnd();
glFlush(); /* clear buffers */
}
void main(int argc, char** argv)
{
/* Standard GLUT initialization */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); /* default, not needed */
glutInitWindowSize(500,500); /* 500 × 500 pixel window */
glutInitWindowPosition(0,0); /* place window top left on display */
glutCreateWindow("Sierpinski Gasket"); /* window title */
glutDisplayFunc(display);
/* display callback invoked when window opened */
myinit(); /* set attributes */
glutMainLoop(); /* enter event loop */
}
生成Sierpinski镂垫的递归程序
/* Recursive subdivision of triangle to form Sierpi