计算机图形学实验利用OpenGL实现图形的平移旋转缩放.doc
文本预览下载声明
XXXXXXXX大学(计算机图形学)实验报告
实验名称 利用OpenGL实现图形的平移、旋转、缩放
实验时间 年 月 日
专 业 姓 名 学 号
预 习 操 作 座 位 号
教师签名 总 评
一、实验目的:二、实验原理:glRotatef(theta, vx, vy, vz);
glTranslatef(dx, dy, dz);
glScalef(sx,sy,sz);
三、实验内容:// 1.cpp : Defines the entry point for the console application.
//
#include stdafx.h
#include glut.h
#include math.h
void display()
{
glClear( GL_COLOR_BUFFER_BIT); // Clear the frame buffer
glColor3f( 0.0, 1.0, 1.0); // Set current color to green
glBegin( GL_POLYGON); // Draw the triangle
glVertex2f( 0.0, -0.2);
glVertex2f( 0.2, 0.0);
glVertex2f( 0.0, 0.0);
glEnd();
glFlush();
}
void dsp()
{
glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Clear the frame buffer
glColor3f( 0.0, 1.0, 1.0); // Set current color to green
display();
//-------------------------- //平移
glPushMatrix();
glTranslatef(0.5,0.5,0.0);
display();
glPopMatrix();
//-------------------------- //缩放
glPushMatrix();
glScalef(0.5,0.5,0.0);
display();
glPopMatrix();
//-------------------------- //旋转
glPushMatrix();
glRotatef(60,0.0,0.0,1.0);
display();
glPopMatrix();
}
void init()
{
glClearColor( 0.0, 0.0, 0.0, 0.0); // Set the clear color to black
// Specify the boundaries of the viewing window
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, -1.0, 1.0); // The para are: (left, right, bottom, top)
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char* argv[])
{
glutInit(argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glEnable(GL_DEPTH_TEST);
glutCreateWindow(simple);
glutDisplayFunc(dsp);
init();
glutMainLoop();
return 0;
}
原图:
平移:
缩放:
旋转:
显示全部