資源簡介
內容和要求:
1. 利用GLUT庫,編寫一個OpenGL程序,實現以下功能:
? 仿照課本的例子,繪制若干OpenGL基本體素(三角形、三角形帶、四邊形、四邊
形帶)構成的球體,
? 可以控制改變球的數量和球的體積,來改變基本體素的數量以及頂點的數量。
? 可以通過改變glPolygonMode,切換是否填充所繪制的基本體素。
? 可以通過glRotate,使繪制的球體旋轉。
? 利用函數glutGet(GLUT_ELAPSED_TIME)(returns the time in milliseconds since
glutInit or the first invocation of the function)統計繪制時間

代碼片段和文件信息
#include?“stdafx.h“
#include?
#include?
#include?
#include?
#define?pi?3.1415926
#define?GLfloat?float
#define?GLdouble?double
#define?GLint?int
double?c=pi/180.0;
double?radius=90.0;
int?w=1000h=700;
double?a=10.0;
int?aa=0;
int?bb=1;
int?cc=0;
int?dd=0;
int?num=1;
int?strip=GL_TRIANGLE_STRIP;
int?mode=GL_LINE;
void?drawSphere(void)
{
????float?thetaphirphithetarphir20;
????float?xyz;
????for(phi=-90.0;phi<=90.0;phi+=a)
????????{
????????????phir=c*phi;
????????????phir20=c*(phi+a);
????????????glPolygonMode(GL_FRONTmode);
????????????glPolygonMode(GL_BACK?mode);
????????????glFrontFace(GL_CCW);?//逆時針為正面
????????????glBegin(strip);
????????????for(theta=-180.0;theta<=180.0;theta+=a)
????????????????{
????????????????????thetar=c*theta;
????????????????????x=radius*sin(thetar)*cos(phir);
????????????????????y=radius*cos(thetar)*cos(phir);
????????????????????z=radius*sin(phir);
????????????????????glVertex3f(xyz);
????????????????????x=radius*sin(thetar)*cos(phir20);
????????????????????y=radius*cos(thetar)*cos(phir20);
????????????????????z=radius*sin(phir20);
????????????????????glVertex3f(xyz);
????????????????}
????????????glEnd();
????????}
????glPolygonMode(GL_FRONTmode);
????glPolygonMode(GL_BACK?mode);
????glFrontFace(GL_CCW);
????glBegin(strip);
????glVertex3d(0.00.0radius);
????double?c80=c*90.0;
????z=radius*sin(c80);
????for(theta=-180.0;theta<=180.0;theta+=a)
????{
????????????thetar=c*theta;
????????????x=radius*sin(thetar)*cos(c80);
????????????y=radius*cos(thetar)*cos(c80);
????????????glVertex3f(xyz);
?????}
????glEnd();
????glPolygonMode(GL_FRONTmode);
????glPolygonMode(GL_BACK?mode);
????glFrontFace(GL_CCW);
????glBegin(strip);
????glVertex3f(0.00.0-radius);
????z=-radius*sin(c80);
????for(theta=-180.0;theta<=180.0;theta+=a)
????{
????????????thetar=c*theta;
????????????x=radius*sin(thetar)*cos(c80);
????????????y=radius*cos(thetar)*cos(c80);
????????????glVertex3f(xyz);
????}
????glEnd();
}
void?init(void)
{
????glViewport(00wh);
????glMatrixMode(GL_PROJECTION);
????glLoadIdentity();
????glClearColor(1.01.01.00.0);
????glColor3f(0.01.00.0);
????glMatrixMode(GL_MODELVIEW);
????glLoadIdentity();
}
//void?mouse(int?btnint?stateint?xint?y)
//{
//
//}
void?reshape(GLsizei?ww?GLsizei?hh)
{??
glViewport?(0?0?(GLsizei)?w?(GLsizei)?h);
????glMatrixMode(GL_PROJECTION);
????glLoadIdentity();
????glOrtho(0.0?(GLdouble)w??0.0(GLdouble)h?-w?h);
????glMatrixMode(GL_MODELVIEW);
????glLoadIdentity();??
????glClear(GL_COLOR_BUFFER_BIT);
glutPostRedisplay();
????w=ww;
????h=hh;
}
void?display(void)
{
????glMatrixMode(GL_MODELVIEW);
????glLoadIdentity();
????glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
????int?n=1;
????for(n=1;n<=num;n++)
????{?
glTranslated(90+40*nh/20);
????????glRotated(aabb+n*100cc+n*100dd);????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????37888??2012-12-23?08:53??polycom\Debug\polycom.exe
?????文件?????416512??2012-12-23?08:53??polycom\Debug\polycom.ilk
?????文件?????568320??2012-12-23?08:53??polycom\Debug\polycom.pdb
?????文件???????6304??2012-12-23?08:53??polycom\polycom\Debug\BuildLog.htm
?????文件?????????60??2012-12-23?08:53??polycom\polycom\Debug\mt.dep
?????文件????????663??2012-11-19?16:33??polycom\polycom\Debug\polycom.exe.em
?????文件????????728??2012-11-19?16:33??polycom\polycom\Debug\polycom.exe.em
?????文件????????621??2012-12-23?08:53??polycom\polycom\Debug\polycom.exe.intermediate.manifest
?????文件??????46684??2012-12-23?08:53??polycom\polycom\Debug\polycom.obj
?????文件????3211264??2012-11-19?16:33??polycom\polycom\Debug\polycom.pch
?????文件??????12009??2012-11-19?16:33??polycom\polycom\Debug\stdafx.obj
?????文件?????363520??2012-12-23?08:53??polycom\polycom\Debug\vc90.idb
?????文件?????167936??2012-12-23?08:53??polycom\polycom\Debug\vc90.pdb
?????文件???????5578??2012-11-19?16:47??polycom\polycom\polycom.cpp
?????文件???????4498??2012-11-16?20:14??polycom\polycom\polycom.vcproj
?????文件???????1413??2012-12-23?08:55??polycom\polycom\polycom.vcproj.Smile-PC.Smile.user
?????文件???????1183??2012-11-16?20:14??polycom\polycom\ReadMe.txt
?????文件????????212??2012-11-16?20:14??polycom\polycom\stdafx.cpp
?????文件????????233??2012-11-16?20:14??polycom\polycom\stdafx.h
?????文件????????498??2012-11-16?20:14??polycom\polycom\targetver.h
?????文件???11996160??2012-12-23?08:55??polycom\polycom.ncb
?????文件????????887??2012-11-16?20:14??polycom\polycom.sln
????..A..H.?????10752??2012-12-23?08:55??polycom\polycom.suo
?????目錄??????????0??2012-12-23?08:53??polycom\polycom\Debug
?????目錄??????????0??2012-11-19?16:33??polycom\Debug
?????目錄??????????0??2012-11-19?16:47??polycom\polycom
?????目錄??????????0??2012-11-16?20:15??polycom
-----------?---------??----------?-----??----
?????????????16853923????????????????????27
............此處省略0個文件信息
評論
共有 條評論