欢迎来到天天文库
浏览记录
ID:57382183
大小:192.88 KB
页数:3页
时间:2020-08-14
《计算机图形学上机实验.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、《计算机图形学》上机实验报告姓名学号实验题目在屏幕上绘制如下参数曲线:1.建议将曲线分成200份小直线段绘制。2.做适当几何变换,将图形显示在屏幕中央。一、实验设计在曲线上按参数t进行for循环200次,每次将ti=i/200代入参数方程计算出一个点。将这些点连成折线段即可。glBegin(GL_LINE_STRIP);for(…)glVertex(xi,yi);glEnd();二、关键代码//test4.cpp:此文件包含"main"函数。程序执行将在此处开始并结束。//#include"pch.h"#include#include#include2、/glut.h>constGLfloatPi=3.f;//定义点集structdata{GLfloatx;GLfloaty;}Point[201];voidinit()//初始化函数{glClearColor(1.0,1.0,1.0,0.0);//设置背景颜色glMatrixMode(GL_PROJECTION);//设置投影参数gluOrtho2D(0.0,600.0,0.0,400.0);//设置场景的大小}voidmydisplay()//显示函数{glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);//设置线条颜色glPoin3、tSize(2);//设置点的大小glTranslatef(100.0f,0.0f,0.0f);//平移图形glScalef(0.5f,0.5f,0.0f);//缩小图像0.5倍glRotatef(60.0f,1.0f,0.0f,0.0f);//沿x轴旋转60度glBegin(GL_LINE_STRIP);for(inti=1;i<=200;i++){GLfloatt=i/200.0;Point[i].x=200.0+50.0*(2.0*cos(2.0*Pi*t)-cos(4.0*Pi*t));//参数曲线Point[i].y=150.0+50.0*(2.0*sin(2.0*Pi*t)4、-sin(4.0*Pi*t));//参数曲线glVertex2i(Point[i].x,Point[i].y);//绘制曲线}glEnd();glFlush();}intmain(intargc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB5、GLUT_SINGLE);glutInitWindowPosition(100,100);glutInitWindowSize(400,400);glutCreateWindow("绘制曲线及图形变换");init();glutDisplayFunc(&mydispla6、y);glutMainLoop();return0;}三、实验结果截图
2、/glut.h>constGLfloatPi=3.f;//定义点集structdata{GLfloatx;GLfloaty;}Point[201];voidinit()//初始化函数{glClearColor(1.0,1.0,1.0,0.0);//设置背景颜色glMatrixMode(GL_PROJECTION);//设置投影参数gluOrtho2D(0.0,600.0,0.0,400.0);//设置场景的大小}voidmydisplay()//显示函数{glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);//设置线条颜色glPoin
3、tSize(2);//设置点的大小glTranslatef(100.0f,0.0f,0.0f);//平移图形glScalef(0.5f,0.5f,0.0f);//缩小图像0.5倍glRotatef(60.0f,1.0f,0.0f,0.0f);//沿x轴旋转60度glBegin(GL_LINE_STRIP);for(inti=1;i<=200;i++){GLfloatt=i/200.0;Point[i].x=200.0+50.0*(2.0*cos(2.0*Pi*t)-cos(4.0*Pi*t));//参数曲线Point[i].y=150.0+50.0*(2.0*sin(2.0*Pi*t)
4、-sin(4.0*Pi*t));//参数曲线glVertex2i(Point[i].x,Point[i].y);//绘制曲线}glEnd();glFlush();}intmain(intargc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB
5、GLUT_SINGLE);glutInitWindowPosition(100,100);glutInitWindowSize(400,400);glutCreateWindow("绘制曲线及图形变换");init();glutDisplayFunc(&mydispla
6、y);glutMainLoop();return0;}三、实验结果截图
此文档下载收益归作者所有