




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、計(jì)算機(jī)圖!形學(xué)i學(xué)號:課實(shí)驗(yàn)一直線的DDA<法一、【實(shí)驗(yàn)?zāi)康摹? .掌握DDA!法的基本原理。2 .掌握DDAft線掃描轉(zhuǎn)換算法。3 . 深入了解直線掃描轉(zhuǎn)換的編程思想。二、【實(shí)驗(yàn)內(nèi)容】1 .利用DDA勺算法原理,編程實(shí)現(xiàn)對直線的掃描轉(zhuǎn)換。2 .加強(qiáng)對DDA#法的理解和掌握。三、【測試數(shù)據(jù)及其結(jié)果】四 、【實(shí)驗(yàn)源代碼】#include<stdlib.h>#include<math.h>#include<GL/glut.h>#include<stdio.h>GLsizei winWidth=500;GLsizei winHeight=500;
2、void Initial(void)glClearColor(1.0f,1.0f,1.0f,1.0f);glMatrixMode(GL_PROJECTION);gluOrtho2D(0.0,200.0,0.0,150.0);void DDALine(int x0,int y0,int x1,int y1)glColor3f(1.0,0.0,0.0);int dx,dy,epsl,k;float x,y,xIncre,yIncre;dx=x1-x0; dy=y1-y0;x=x0;y=y0;if(abs(dx)>abs(dy) epsl=abs(dx);else epsl=abs(dy);x
3、Incre=(float)dx/(float)epsl;yIncre=(float)dy/(float)epsl;for(k=0;k<=epsl;k+)glPointSize(3);glBegin(GL_POINTS);glVertex2i(int(x+0.5),(int)(y+0.5);glEnd();x+=xIncre;y+=yIncre;void Display(void)glClear(GL_COLOR_BUFFER_BIT);DDALine(100,100,200,180);glFlush();void winReshapeFcn(GLint newWidth, GLint n
4、ewHeight)glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0, GLdouble(newWidth), 0.0, GLdouble(newHeight);glClear(GL_COLOR_BUFFER_BIT);winWidth=newWidth;winHeight=newHeight;int main(int argc,char*argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(400,
5、300);glutInitWindowPosition(100,120);glutCreateWindow("line");Initial();glutDisplayFunc(Display);glutReshapeFunc(winReshapeFcn);glutMainLoop();return 0;Bresenham 繪制直線和圓一、【實(shí)驗(yàn)?zāi)康摹?.掌握Bresenham算法掃描轉(zhuǎn)換圓和直線的基本原理。二、【實(shí)驗(yàn)內(nèi)容】1.利用Bresenham算法掃描轉(zhuǎn)換圓和直線的基本原理編程實(shí)現(xiàn)對圓和直線的掃描轉(zhuǎn)換。三、【測試數(shù)據(jù)及其結(jié)果】四 、【實(shí)驗(yàn)源代碼】繪制直線:#includ
6、e<stdlib.h>#include<math.h>#include<GL/glut.h>#include<stdio.h>GLsizei winWidth=500;GLsizei winHeight=500;void lineBres(int x0, int y0, int xEnd, int yEnd)glColor3f(0.0, 0.0, 1.0);int dx=fabs(xEnd-x0), dy=fabs(yEnd-y0);int p=2*dy-dx;int twoDy=2*dy, twoDyMinusDx=2*(dy-dx);int
7、x, y;if (x0>xEnd)x=xEnd;y=yEnd;xEnd=x0;elsex=x0;y=y0;glPointSize(6);glBegin(GL_POINTS);glVertex2i(x, y);glEnd();while (x<xEnd) x+;if (p<0)p+=twoDy;elsey+;p+=twoDyMinusDx;glPointSize(2);glBegin(GL_POINTS);glVertex2i(x, y);glEnd();void init (void)glClearColor(1.0, 1.0, 1.0, 1.0);glShadeModel(
8、GL_FLAT);void display (void)glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);lineBres(10, 10, 400, 300);glFlush();void winReshapeFcn(GLint newWidth, GLint newHeight)glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0, GLdouble(newWidth), 0.0, GLdouble(newHeight);glClear(GL_COLOR_BUFFER_BIT);
9、winWidth=newWidth;winHeight=newHeight;void main(int argc, char* argv)glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutInitWindowPosition(10, 10);glutInitWindowSize(winWidth, winHeight);glutCreateWindow("lineBres");init();glutDisplayFunc(display);glutReshapeFunc(win
10、ReshapeFcn);glutMainLoop();繪制圓:#include<gl/glut.h>void init()glClearColor(0,0,0,0);void MidBresenhamCircle(int r)int x,y,d;x=0;y=r;d=1-r;glBegin(GL_LINE_STRIP);while(x<=y)glVertex2f(x,y);if(d<0) d+=2*x+3;elsed+=2*(x-y)+5;y-;x+;glEnd();void display()glClearColor(1,1,1,1);glClear(GL_COLOR_
11、BUFFER_BIT);glColor3f(1,0,0);MidBresenhamCircle(8);glRotated(45,0,0,1);MidBresenhamCircle(8);glRotated(45,0,0,1);MidBresenhamCircle(8);glRotated(45,0,0,1);MidBresenhamCircle(8);glRotated(45,0,0,1);MidBresenhamCircle(8);glRotated(45,0,0,1);MidBresenhamCircle(8);glRotated(45,0,0,1);MidBresenhamCircle(
12、8);glRotated(45,0,0,1);MidBresenhamCircle(8);glutSwapBuffers();void reshape(int w,int h)glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(-10,10,-10,10);int main(int argc,char*argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);glutInitWindowSize(400,400
13、);glutInitWindowPosition(100,100);glutCreateWindow(" 掃描轉(zhuǎn)換圓");glutDisplayFunc(display);glutReshapeFunc(reshape);glutMainLoop();return 0;實(shí)驗(yàn)三 反走樣及五環(huán)的繪制一、【實(shí)驗(yàn)?zāi)康摹?. 了解走樣和反走樣的內(nèi)容,熟練掌握用opengl 實(shí)現(xiàn)圖形的反走樣。2. 學(xué)會用反走樣消除走樣現(xiàn)象。3. 學(xué)會五環(huán)的繪制方法。二、【實(shí)驗(yàn)內(nèi)容】1. 通過學(xué)習(xí)反走樣相關(guān)課程,用opengl 實(shí)現(xiàn)光柵圖形的反走樣。2. 繪制五環(huán)。三、【測試數(shù)據(jù)及其結(jié)果】四 、【實(shí)驗(yàn)源
14、代碼】反走樣:#include<gl/glut.h>#pragma comment(linker,"/subsystem:"windows" /entry:"mainCRTStartup"")GLuint lineList; /指定顯示列表void Initial()glClearColor(1.0f,1.0f,1.0f,0.0f);glLineWidth(12.0f);glColor4f(0.0,0.6,1.0,1.0);lineList=glGenLists(1); / 獲得一個顯示列表標(biāo)識glNewList(line
15、List,GL_COMPILE); / 定義顯示列表glBegin(GL_LINE_LOOP);glVertex2f(1.0f,1.0f);glVertex2f(4.0f,2.0f);glVertex2f(2.0f,5.0f);glEnd();glEndList();void ChangeSize(GLsizei w,GLsizei h)if(h=0) h=1;glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION); / 指定設(shè)置投影參數(shù)glLoadIdentity();if(w<=h)gluOrtho2D(0.0,5.0,0.0,6.0*(GLf
16、loat)h/(GLfloat)w);elsegluOrtho2D(0.0,5.0*(GLfloat)w/(GLfloat)h,0.0,6.0);glMatrixMode(GL_MODELVIEW); / 指定設(shè)置模型視圖變換參數(shù)glLoadIdentity();void Displayt(void)glClear(GL_COLOR_BUFFER_BIT);glCallList(lineList); /調(diào)用顯示列表glFlush();void Displayw(void)glClear(GL_COLOR_BUFFER_BIT);glEnable(GL_LINE_SMOOTH); / 使用反走樣
17、glEnable(GL_BLEND); / 啟用混合函數(shù)glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 指定混合函數(shù) / glCallList(lineList); /調(diào)用顯示列表glFlush();void main(void)glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowSize(300,300);glutCreateWindow(" 原始圖形");glutDisplayFunc(Displayt);glutReshapeFunc(ChangeSize)
18、;Initial();glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowPosition(300,300);glutInitWindowSize(300,300);glutCreateWindow(" 反走樣圖形");glutDisplayFunc(Displayw);glutReshapeFunc(ChangeSize);Initial();glutMainLoop();五環(huán):#include<gl/glut.h>#include <MATH.H>#pragma comment(link
19、er,"/subsystem:"windows" /entry:"mainCRTStartup"") const float PI=3.1415;void DrawCircle(GLfloat radius)GLfloat x,y,z;glBegin(GL_LINE_LOOP);for (int alpha=0;alpha<360;alpha+)x=radius*cos(alpha*PI/180);y=radius*sin(alpha*PI/180);z=0;glVertex3f(x,y,z); glEnd();void Dis
20、play()glClearColor(1,1,1,1);glClear(GL_COLOR_BUFFER_BIT);glLoadIdentity();glTranslatef(0,0,-25);glColor3f(0,1,0);glLineWidth(3);DrawCircle(3.0);glPopMatrix();glPushMatrix();glTranslatef(7,0,0);glColor3f(1,0,0);DrawCircle(3.0);glPopMatrix();glPushMatrix();glTranslatef(-7,0,0);glColor3f(0,0,1);DrawCir
21、cle(3.0);glPopMatrix();glPushMatrix();glTranslatef(-3.5,-3.5,0);glColor3f(0.3,0.5,0.7);DrawCircle(3.0);glPopMatrix();glPushMatrix();glTranslatef(3.5,-3.5,0);glColor3f(0.7,0.0,0.3);DrawCircle(3.0);glPopMatrix();glutSwapBuffers();void reshape(int w,int h)glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION)
22、;glLoadIdentity();gluPerspective(45,GLdouble(w)/h,1,100);glMatrixMode(GL_MODELVIEW);void main(int argc,char *argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);glutInitWindowPosition(10,10);glutInitWindowSize(500,500);glutCreateWindow("Test");glutDisplayFunc(Display);
23、glutReshapeFunc(reshape);glutMainLoop();多視區(qū)一、【實(shí)驗(yàn)?zāi)康摹?. 熟練掌握各種裁剪算法和二維觀察變換。2. 學(xué)會在屏幕坐標(biāo)系下創(chuàng)建多個視區(qū)、指定視區(qū)的寬度和高度,了解二維觀察變換中包含 窗口到視區(qū)的映射。二、【實(shí)驗(yàn)內(nèi)容】1. 在一個顯示窗口內(nèi)指定多個視區(qū),分別顯示具有相同坐標(biāo)、不同顏色和不同顯示模式的各種圖形面。2. 在書本給定程序基礎(chǔ)上,對程序做一些改變并在視區(qū)中繪制各種圖形。三、【測試數(shù)據(jù)及其結(jié)果】、【實(shí)驗(yàn)源代碼】#include<gl/glut.h>#include<MATH.H>const float PI=3.1415
24、;void initial(void)glClearColor(1.0,1.0,1.0,1.0);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(-10.0,10.0,-10.0,10.0);void triangle(GLsizei mode)if(mode=1)glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); elseglPolygonMode(GL_FRONT_AND_BACK,GL_FILL);glBegin(GL_TRIANGLES);glVertex2f(0.0,5.0);glVert
25、ex2f(5.0,-5.0);glVertex2f(-5.0,-5.0);glEnd();void polygon(GLsizei mode)if(mode=1)glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); elseglPolygonMode(GL_FRONT_AND_BACK,GL_FILL);glBegin(GL_POLYGON);glVertex2f(2.0,7.0);glVertex2f(5.0,3.0);glVertex2f(4.0,0.0);glVertex2f(0.0,0.0);glVertex2f(1.0,4.0);glEnd();void
26、 DrawCircle(GLfloat r)GLfloat x,y,z;glBegin(GL_LINE_LOOP);for (int alpha=0;alpha<360;alpha+)x=r*cos(alpha*PI/180);y=r*sin(alpha*PI/180);z=0;glVertex3f(x,y,z);glEnd();void Display()glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);glViewport(0,0,100,100);triangle(1);glColor3f(0.0,0.0,1.0);glView
27、port(100,0,100,100);triangle(2);glColor3f(1.0,0.0,0.0);glViewport(0,100,100,100);polygon(2);glViewport(100,100,100,100);DrawCircle(5);glFlush();void main(void)glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowPosition(10,10);glutInitWindowSize(400,200);glutCreateWindow(" 多視區(qū) ");initi
28、al();glutDisplayFunc(Display);glutMainLoop();實(shí)驗(yàn)五 分子模型一、【實(shí)驗(yàn)?zāi)康摹?. 熟練掌握二維、三維幾何變換矩陣和透視投影的相關(guān)知識從而用opengl 實(shí)現(xiàn)分子模型的運(yùn)動。2. 熟練掌握opengl 中相關(guān)函數(shù)的調(diào)用和實(shí)現(xiàn)。二、【實(shí)驗(yàn)內(nèi)容】1. 顯示分子模型:紅色大球表示原子,三個黃色小球表示電子,分別繞原子旋轉(zhuǎn),采用透視投影變換顯示電子旋轉(zhuǎn)過程。2. 啟用深度測試和模型視圖矩陣完成分子動畫。三、【測試數(shù)據(jù)及其結(jié)果】四 、【實(shí)驗(yàn)源代碼】#include<gl/glut.h>GLint angleSelf=0;void Initial()
29、glEnable(GL_DEPTH_TEST);glClearColor(1.0f,1.0f,1.0f,1.0f);void ChangeSize(int w,int h)if(h=0) h=1;glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();GLfloat fAspect;fAspect=(float)w/(float)h;gluPerspective(45.0,fAspect,1,500.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();void Display(v
30、oid)static float fElect1=0.0f;glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0f,0.0f,-250.0f);glColor3f(1.0f,0.0f,0.0f);glutWireSphere(12.0f,15,15);glColor3f(0.0f,1.0f,0.0f);glPushMatrix();glRotatef(fElect1,0.0f,1.0f,0.0f);glTranslatef(90.
31、0f,0.0f,0.0f);glRotatef(angleSelf,0,1,0);glutWireSphere(6.0f,15,15);glPopMatrix();glPushMatrix();glRotatef(45.0f,0.0f,0.0f,1.0f);glRotatef(fElect1,0.0f,1.0f,0.0f);glTranslatef(-70.0f,0.0f,0.0f);glRotatef(angleSelf,0,1,0);glutWireSphere(6.0f,15,15);glPopMatrix();glPushMatrix();glRotatef(-45.0f,0.0f,0
32、.0f,1.0f);glRotatef(fElect1,0.0f,1.0f,0.0);glTranslatef(0.0f,0.0f,60.0f);glRotatef(angleSelf,0,1,0);glutWireSphere(6.0f,15,15);glPopMatrix();fElect1 +=5.0f;if(fElect1>360.0f) fElect1=10.0f;glutSwapBuffers();void RotateSelf(int value)if(value=1)angleSelf+=5;angleSelf%=360;glutPostRedisplay();glutT
33、imerFunc(100,RotateSelf,1);void TimerFunc(int value)glutPostRedisplay();glutTimerFunc(100,TimerFunc,1);int main(int argc,char*argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);glutCreateWindow(" 分子動畫示例");glutReshapeFunc(ChangeSize);glutDisplayFunc(Display);
34、glutTimerFunc(500,TimerFunc,1);glutTimerFunc(100,RotateSelf,1);Initial();glutMainLoop();return 0;Bezier 曲線一、【實(shí)驗(yàn)?zāi)康摹?. 掌握 Bezire 曲線定義。2. 掌握設(shè)計(jì)繪制一次、二次和三次Bezier 曲線算法。二、【實(shí)驗(yàn)內(nèi)容】1 .繪制NURB釉面。2 . 基于 Bezier 定義根據(jù)控制多邊形的階次繪制Bezier 曲線。三、【測試數(shù)據(jù)及其結(jié)果】四 、【實(shí)驗(yàn)源代碼】原實(shí)驗(yàn)代碼:#include<GL/glut.h>#include<math.h>#inclu
35、de<stdlib.h>class Pt3Dpublic:GLfloat x,y,z;void GetCnk(GLint n,GLint *c) GLint i,k;for(k=0;k<=n;k+)ck=1;for(i=n;i>=k+1;i-)ck=ck*i;for(i=n-k;i>=2;i-)ck=ck/i;void GetPointPr(GLint *c,GLfloat t,Pt3D*Pt,int ControlN,Pt3D*ControlP)GLint k,n=ControlN-1;GLfloat Bernstein;Pt->x=0.0;Pt->
36、y=0.0;Pt->z=0.0;for(k=0;k<ControlN;k+)Bernstein=ck*pow(t,k)*pow(1-t,n-k);Pt->x+=ControlPk.x*Bernstein;Pt->y+=ControlPk.y*Bernstein;Pt->z+=ControlPk.z*Bernstein;void BezierCurve(GLint m,GLint ControlN,Pt3D *ControlP)GLint *C,i;Pt3D CurvePt;C=new GLintControlN;GetCnk(ControlN-1,C);glBeg
37、in(GL_POINTS);for(i=0;i<=m;i+)GetPointPr(C,(GLfloat)i/(GLfloat)m,&CurvePt,ControlN,ControlP);glVertex2f(CurvePt.x,CurvePt.y);glEnd();delete C;void initial(void)glClearColor(1.0,1.0,1.0,1.0);void Display(void)glClear(GL_COLOR_BUFFER_BIT);GLint ControlN=4,m=500;Pt3DControlP4=-80.0,-40.0,0.0,-10
38、.0,90.0,0.0,10.0,-90.0,0.0,80.0,40.0,0.0;glPointSize(2);glColor3f(0.0,0.0,0.0);BezierCurve(m,ControlN,ControlP);glBegin(GL_LINE_STRIP);for(GLinti=0;i<4;i+)glVertex3f(ControlPi.x,ControlPi.y,ControlPi.z);glEnd();glFlush();void reshape(GLint newWidth,GLint newHeight)glViewport(0,0,newWidth,newHeigh
39、t);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(-100.0,100.0,-100.0,100.0);void main(void)glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowPosition(100,100);glutInitWindowSize(400,400);glutCreateWindow("Bezier 曲線 ");initial();glutDisplayFunc(Display);glutReshapeFunc(resha
40、pe);glutMainLoop();加改后的:#include<GL/glut.h>void initial(void)glClearColor(1.0,1.0,1.0,1.0);glLineWidth(4.0);GLfloat ControlP43=-80.0,40.0,0.0,-10.0,90.0,0.0, 10.0,-90.0,0.0,80.0,40.0,0.0;glMap1f(GL_MAP1_VERTEX_3,0.0,1.0,3,4,*ControlP);glEnable(GL_MAP1_VERTEX_3);void Display(void)glClear(GL_COL
41、OR_BUFFER_BIT);glColor3f(1.0,0.0,0.0);glMapGrid1f(100,0.0,1.0);glEvalMesh1(GL_LINE,0,100);glFlush();void Reshape(GLint newWidth,GLint newHeight)glViewport(0,0,newWidth,newHeight);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(-100.0,100.0,-100.0,100.0);void main(void)glutInitDisplayMode(GLU
42、T_SINGLE|GLUT_RGB);glutInitWindowPosition(100,100);glutInitWindowSize(400,400);glutCreateWindow("Bezier 曲線 ");initial();glutDisplayFunc(Display);glutReshapeFunc(Reshape);glutMainLoop();實(shí)驗(yàn)七NURBSffi面和Bezier曲面一、【實(shí)驗(yàn)?zāi)康摹? .掌握NURB釉線定義。2 .掌握設(shè)計(jì)繪制一次、二次和三次 NURB釉面算法。【實(shí)驗(yàn)內(nèi)容】1 .在屏幕上單擊鼠標(biāo)左鍵繪制控制多邊形,基于NURBS定
43、義根據(jù)控制多邊形的階次繪制NURB釉面。2 . 繪制的曲面中,紅色的點(diǎn)表示曲面的控制點(diǎn),并增加了光標(biāo)鍵控制旋轉(zhuǎn)的交互式方式,以獲得更好的顯示效果。三、【測試數(shù)據(jù)及其結(jié)果】四 、【實(shí)驗(yàn)源代碼】NURB舐面:#include<windows.h>#include<gl/glut.h>#include<math.h>GLUnurbsObj*pNurb=NULL;GLint nNumPoints=4;GLfloat ctrlPoints443= -6.0f,-6.0f,0.0f,-6.0f,-2.0f,0.0f,-6.0f,2.0f,0.0f,-6.0f,6.0f,
44、0.0f,-2.0f,-6.0f,0.0f,-2.0f,-2.0f,8.0f,-2.0f,2.0f,8.0f,-2.0f,6.0f,0.0f,2.0f,-6.0f,0.0f,2.0f,-2.0f,8.0f,2.0f,2.0f,8.0f,2.0f,6.0f,0.0f,6.0f,-6.0f,0.0f,6.0f,-2.0f,0.0f,6.0f,2.0f,0.0f,6.0f,6.0f,0.0f;GLfloat Knots8=0.0f,0.0f,0.0f,0.0f,1.0f,1.0f,1.0f,1.0f;static GLfloat xRot=0.0f;static GLfloat yRot=0.0f;
45、void DrawPoints(void)int i,j;glPointSize(5.0f);glColor3ub(255,0,0);glBegin(GL_POINTS);for(i=0;i<4;i+)for(j=0;j<4;j+)glVertex3fv(ctrlPointsij);glEnd();void Initial()glClearColor(1.0f,1.0f,1.0f,1.0f);pNurb=gluNewNurbsRenderer();gluNurbsProperty(pNurb,GLU_SAMPLING_TOLERANCE,25.0f);gluNurbsPropert
46、y(pNurb,GLU_DISPLAY_MODE,(GLfloat)GLU_OUTLINE_POLYGON); void ReDraw(void)glColor3ub(0,0,220);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glPushMatrix();glRotatef(330.0f,1.0f,0.0f,0.0f);glRotatef(xRot,1.0f,0.0f,0.0f);glRotatef(yRot,0.0f,1.0f,0.0f);gluBeginSurface(pNurb
47、);gluNurbsSurface(pNurb,8,Knots,8,Knots,4*3,3,&ctrlPoints000,4,4,GL_MAP2_VERTEX_3);gluEndSurface(pNurb);DrawPoints();glPopMatrix();glutSwapBuffers();void SpecialKeys(int key,int x,int y)if(key=GLUT_KEY_UP) xRot-=5.0f;if(key=GLUT_KEY_DOWN) xRot+=5.0f;if(key=GLUT_KEY_LEFT) yRot-=5.0f;if(key=GLUT_K
48、EY_RIGHT) yRot+=5.0f;if(xRot>356.0f) xRot=0.0f;if(xRot<-1.0f) xRot=355.0f;if(yRot>356.0) yRot=0.0f;if(yRot<-1.0f) yRot=355.0f;glutPostRedisplay();void ChangeSize(int w,int h)if(h=0) h=1;glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0f,(GLdouble)w/(GLd
49、ouble)h,1.0,40.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0f,0.0f,-20.0f);int main(int argc,char *argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);glutCreateWindow("NURBS 曲面 ");glutReshapeFunc(ChangeSize);glutDisplayFunc(ReDraw);glutSpe
50、cialFunc(SpecialKeys);Initial();glutMainLoop();return 0;在原來的基礎(chǔ)上加的:#include <windows.h>#include <gl/glut.h>#include <math.h>GLUnurbsObj*pNurb=NULL;GLint nNumPoints=4;GLfloat Knots8=0.0f,0.0f,0.0f,0.0f,1.0f,1.0f,1.0f,1.0f;GLfloat ControlP443=-1.5,-1.5,4.0,-0.5,-1.5,2.0,-0.5,-1.5,-1.0
51、,1.5,-1.5,2.0,-1.5,-0.5,1.0,-0.5,-0.5,3.0,-0.5,-0.5,0.0,1.5,-0.5,-1.0,-1.5,0.5,4.0,-0.5,0.5,0.0,0.5,0.5,3.0,1.5,0.5,4.0,-1.5,1.5,-2.0,-0.5,1.5,-2.0,0.5,1.5,0.0,1.5,1.5,-1.0;void DrawPoints(void)int i,j;glPointSize(5.0f);glColor3ub(255,0,0);glBegin(GL_POINTS);for(i=0;i<4;i+)for(j=0;j<4;j+)glVer
52、tex3fv(ControlPij);glEnd();void ReDraw(void)glColor3ub(0,0,220);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glMap2f(GL_MAP2_VERTEX_3,0.0,1.0,3,4,0.0,1.0,12,4,&ControlP000);glEnable(GL_MAP2_VERTEX_3);glColor3f(1.0,1.0,1.0);glMapGrid2f(40,0.0,1.0,40,0.0,1.0);glEvalM
53、esh2(GL_FILL,0,40,0,40);DrawPoints();glutSwapBuffers();void ChangeSize(int w,int h) if(h=0)h=1;glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0f,(GLdouble)w/(GLdouble)h,1.0,40.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0f,0.0f,-20.0f);int main(
54、int argc,char*argv) glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);glutCreateWindow("NURBS 曲面 ");glutReshapeFunc(ChangeSize);glutDisplayFunc(ReDraw);glutMainLoop();return 0;兩點(diǎn)光源在球體上的效果一、【實(shí)驗(yàn)?zāi)康摹?. 掌握漫反射光、鏡面反射光和聚光源的含義。2. 掌握 opengl 中不同點(diǎn)光源的設(shè)置。二、【實(shí)驗(yàn)內(nèi)容】1. 設(shè)置兩個光源,一個是漫反射的藍(lán)色點(diǎn)光源,另一個是紅色聚光光源,他們都照在一個球體上,產(chǎn)生亮斑。2. 調(diào)用 opengl 中的函數(shù)指定當(dāng)前設(shè)定的材質(zhì)應(yīng)用于物體表面的哪個面,從而使光照下產(chǎn)生特殊的效果。三、【測試數(shù)據(jù)及其結(jié)果】四 、【實(shí)驗(yàn)源代碼】#include
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 歐洲招商活動方案
- 武侯區(qū)法治教育活動方案
- 永年過年活動方案
- 畢業(yè)年級教研活動方案
- 汽修洗車策劃活動方案
- 樓盤銀行圈層活動方案
- 氏族祭祖活動方案
- 汽貿(mào)店圣誕活動方案
- 母親節(jié)活動糕點(diǎn)活動方案
- 水頭志愿活動方案
- 大學(xué)英語四六級詞匯表
- 黑龍江省2024年普通高校招生體育類本科批院校專業(yè)組投檔分?jǐn)?shù)線(歷史類)
- 水閘地基施工方案
- 企業(yè)數(shù)字化轉(zhuǎn)型服務(wù)協(xié)議
- 《建立合適邊界:親子教育課件》
- DB37-T 4516-2022 高速公路邊坡光伏發(fā)電工程技術(shù)規(guī)范
- 變電所設(shè)備更換申請報告
- 2023年遺傳學(xué)考試題庫(含答案)
- 課題申報參考:基于多模態(tài)大數(shù)據(jù)的大學(xué)生心理危機(jī)預(yù)警機(jī)制研究
- 《消費(fèi)者行為學(xué)》教學(xué)大綱
- 《礦井扇風(fēng)機(jī)》課件
評論
0/150
提交評論