計算機圖形學(xué)實驗報告_第1頁
計算機圖形學(xué)實驗報告_第2頁
計算機圖形學(xué)實驗報告_第3頁
計算機圖形學(xué)實驗報告_第4頁
計算機圖形學(xué)實驗報告_第5頁
已閱讀5頁,還剩30頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上計 算 機 圖 形 學(xué)課程實驗報告 姓名:學(xué)號:專心-專注-專業(yè)目 錄實驗一 直線的DDA算法一、【實驗?zāi)康摹?.掌握DDA算法的基本原理。2.掌握DDA直線掃描轉(zhuǎn)換算法。3.深入了解直線掃描轉(zhuǎn)換的編程思想。二、【實驗內(nèi)容】1.利用DDA的算法原理,編程實現(xiàn)對直線的掃描轉(zhuǎn)換。2.加強對DDA算法的理解和掌握。三、【測試數(shù)據(jù)及其結(jié)果】四、【實驗源代碼】#include<stdlib.h>#include<math.h>#include<GL/glut.h>#include<stdio.h>GLsizei winWidth=

2、500;GLsizei winHeight=500;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(

3、dy) epsl=abs(dx); else epsl=abs(dy); xIncre=(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); gl

4、Flush();void winReshapeFcn(GLint newWidth, GLint newHeight) 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); glutIni

5、tDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(400,300); glutInitWindowPosition(100,120); glutCreateWindow("line"); Initial(); glutDisplayFunc(Display); glutReshapeFunc(winReshapeFcn); glutMainLoop(); return 0;實驗二 Bresenham繪制直線和圓一、【實驗?zāi)康摹?.掌握Bresenham算法掃描轉(zhuǎn)換圓和直線的基本原理。二、【實驗內(nèi)容】1.利用Bres

6、enham算法掃描轉(zhuǎn)換圓和直線的基本原理編程實現(xiàn)對圓和直線的掃描轉(zhuǎn)換。三、【測試數(shù)據(jù)及其結(jié)果】四、【實驗源代碼】繪制直線:#include<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=f

7、abs(yEnd-y0); int p=2*dy-dx; int twoDy=2*dy, twoDyMinusDx=2*(dy-dx); int x, y; if (x0>xEnd) x=xEnd; y=yEnd; xEnd=x0; else x=x0; y=y0; glPointSize(6); glBegin(GL_POINTS); glVertex2i(x, y); glEnd(); while (x<xEnd) x+; if (p<0) p+=twoDy; else y+; p+=twoDyMinusDx; glPointSize(2); glBegin(GL_POI

8、NTS); glVertex2i(x, y); glEnd(); void init (void) glClearColor(1.0, 1.0, 1.0, 1.0); glShadeModel(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); glLoa

9、dIdentity(); gluOrtho2D(0.0, GLdouble(newWidth), 0.0, GLdouble(newHeight); glClear(GL_COLOR_BUFFER_BIT); winWidth=newWidth; winHeight=newHeight;void main(int argc, char* argv) glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(10, 10); glutInitWindowSize(w

10、inWidth, winHeight); glutCreateWindow("lineBres"); init(); glutDisplayFunc(display); glutReshapeFunc(winReshapeFcn); 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)glVe

11、rtex2f(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_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);glRot

12、ated(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); glutSwapBuffers();void reshape(int w,int h)glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(-10,10,-10,10);in

13、t main(int argc,char*argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);glutInitWindowSize(400,400);glutInitWindowPosition(100,100);glutCreateWindow("掃描轉(zhuǎn)換圓");glutDisplayFunc(display);glutReshapeFunc(reshape);glutMainLoop();return 0;實驗三 反走樣及五環(huán)的繪制一、【實驗?zāi)康摹?.了解走樣和反走樣的內(nèi)容,熟練

14、掌握用opengl實現(xiàn)圖形的反走樣。 2.學(xué)會用反走樣消除走樣現(xiàn)象。3.學(xué)會五環(huán)的繪制方法。二、【實驗內(nèi)容】1.通過學(xué)習(xí)反走樣相關(guān)課程,用opengl實現(xiàn)光柵圖形的反走樣。2.繪制五環(huán)。三、【測試數(shù)據(jù)及其結(jié)果】四、【實驗源代碼】反走樣:#include<gl/glut.h>#pragma comment(linker,"/subsystem:"windows" /entry:"mainCRTStartup"")GLuint lineList; /指定顯示列表void Initial()glClearColor(1

15、.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(lineList,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;

16、glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION); /指定設(shè)置投影參數(shù)glLoadIdentity();if(w<=h)gluOrtho2D(0.0,5.0,0.0,6.0*(GLfloat)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);glCa

17、llList(lineList); /調(diào)用顯示列表glFlush();void Displayw(void)glClear(GL_COLOR_BUFFER_BIT);glEnable(GL_LINE_SMOOTH); /使用反走樣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);glutI

18、nitWindowSize(300,300);glutCreateWindow("原始圖形");glutDisplayFunc(Displayt); glutReshapeFunc(ChangeSize);Initial();glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowPosition(300,300);glutInitWindowSize(300,300);glutCreateWindow("反走樣圖形"); glutDisplayFunc(Displayw);glutReshapeF

19、unc(ChangeSize);Initial();glutMainLoop();五環(huán):#include<gl/glut.h>#include <MATH.H>#pragma comment(linker,"/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;al

20、pha<360;alpha+)x=radius*cos(alpha*PI/180);y=radius*sin(alpha*PI/180);z=0;glVertex3f(x,y,z);glEnd();void Display()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,

21、0);glColor3f(1,0,0);DrawCircle(3.0);glPopMatrix();glPushMatrix();glTranslatef(-7,0,0);glColor3f(0,0,1); DrawCircle(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); DrawCir

22、cle(3.0);glPopMatrix();glutSwapBuffers();void reshape(int w,int h)glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);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);glutI

23、nitWindowPosition(10,10);glutInitWindowSize(500,500);glutCreateWindow("Test");glutDisplayFunc(Display);glutReshapeFunc(reshape);glutMainLoop();實驗四 多視區(qū)一、【實驗?zāi)康摹?.熟練掌握各種裁剪算法和二維觀察變換。 2.學(xué)會在屏幕坐標(biāo)系下創(chuàng)建多個視區(qū)、指定視區(qū)的寬度和高度,了解二維觀察變換中包含窗口到視區(qū)的映射。二、【實驗內(nèi)容】1.在一個顯示窗口內(nèi)指定多個視區(qū),分別顯示具有相同坐標(biāo)、不同顏色和不同顯示模式的各種圖形面。

24、60;2.在書本給定程序基礎(chǔ)上,對程序做一些改變并在視區(qū)中繪制各種圖形。三、【測試數(shù)據(jù)及其結(jié)果】四、【實驗源代碼】#include<gl/glut.h>#include<MATH.H>const float PI=3.1415;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)glPolygonM

25、ode(GL_FRONT_AND_BACK,GL_LINE);else glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);glBegin(GL_TRIANGLES);glVertex2f(0.0,5.0);glVertex2f(5.0,-5.0);glVertex2f(-5.0,-5.0);glEnd();void polygon(GLsizei mode)if(mode=1)glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);else glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);glBegin

26、(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 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 D

27、isplay()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); glViewport(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)glutInitDis

28、playMode(GLUT_SINGLE|GLUT_RGB);glutInitWindowPosition(10,10);glutInitWindowSize(400,200);glutCreateWindow("多視區(qū)");initial();glutDisplayFunc(Display);glutMainLoop();實驗五 分子模型一、【實驗?zāi)康摹?.熟練掌握二維、三維幾何變換矩陣和透視投影的相關(guān)知識從而用opengl實現(xiàn)分子模型的運動。 2.熟練掌握opengl中相關(guān)函數(shù)的調(diào)用和實現(xiàn)。二、【實驗內(nèi)容】1.顯示分子模型:紅色大球表示原子,三個黃色小球表示電

29、子,分別繞原子旋轉(zhuǎn),采用透視投影變換顯示電子旋轉(zhuǎn)過程。2.啟用深度測試和模型視圖矩陣完成分子動畫。三、【測試數(shù)據(jù)及其結(jié)果】四、【實驗源代碼】#include<gl/glut.h>GLint angleSelf=0;void Initial()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 fA

30、spect;fAspect=(float)w/(float)h;gluPerspective(45.0,fAspect,1,500.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();void Display(void)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.0

31、f,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.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);glTranslat

32、ef(-70.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.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

33、.0f) fElect1=10.0f;glutSwapBuffers();void RotateSelf(int value)if(value=1)angleSelf+=5;angleSelf%=360;glutPostRedisplay();glutTimerFunc(100,RotateSelf,1);void TimerFunc(int value)glutPostRedisplay();glutTimerFunc(100,TimerFunc,1);int main(int argc,char*argv)glutInit(&argc,argv);glutInitDisplayMo

34、de(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);glutCreateWindow("分子動畫示例");glutReshapeFunc(ChangeSize);glutDisplayFunc(Display);glutTimerFunc(500,TimerFunc,1);glutTimerFunc(100,RotateSelf,1);Initial();glutMainLoop();return 0;實驗六 Bezier曲線一、【實驗?zāi)康摹?.掌握Bezire曲線定義。 2.掌握設(shè)計繪制一次、二次和三次Bezier曲線算法。二、【實驗內(nèi)容】1

35、.繪制NURBS曲面。2.基于Bezier定義根據(jù)控制多邊形的階次繪制 Bezier曲線。三、【測試數(shù)據(jù)及其結(jié)果】四、【實驗源代碼】原實驗代碼:#include<GL/glut.h>#include<math.h>#include<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;

36、void GetPointPr(GLint *c,GLfloat t,Pt3D*Pt,int ControlN,Pt3D*ControlP)GLint k,n=ControlN-1;GLfloat Bernstein;Pt->x=0.0;Pt->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*Ber

37、nstein;void BezierCurve(GLint m,GLint ControlN,Pt3D *ControlP)GLint *C,i;Pt3D CurvePt;C=new GLintControlN;GetCnk(ControlN-1,C);glBegin(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)g

38、lClearColor(1.0,1.0,1.0,1.0);void Display(void)glClear(GL_COLOR_BUFFER_BIT);GLint ControlN=4,m=500;Pt3D ControlP4=-80.0,-40.0,0.0,-10.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(GLint i=0;i<4;i+)glVertex

39、3f(ControlPi.x,ControlPi.y,ControlPi.z);glEnd();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(GLUT_SINGLE|GLUT_RGB);glutInitWindowPosition(

40、100,100);glutInitWindowSize(400,400);glutCreateWindow("Bezier曲線");initial();glutDisplayFunc(Display);glutReshapeFunc(reshape);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,

41、-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_COLOR_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,n

42、ewHeight);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(

43、Reshape);glutMainLoop();實驗七 NURBS曲面和Bezier曲面一、【實驗?zāi)康摹?.掌握NURBS曲線定義。 2.掌握設(shè)計繪制一次、二次和三次NURBS曲面算法。二、【實驗內(nèi)容】1.在屏幕上單擊鼠標(biāo)左鍵繪制控制多邊形,基于NURBS定義根據(jù)控制多邊形的階次繪制NURBS曲面。2.繪制的曲面中,紅色的點表示曲面的控制點,并增加了光標(biāo)鍵控制旋轉(zhuǎn)的交互式方式,以獲得更好的顯示效果。三、【測試數(shù)據(jù)及其結(jié)果】四、【實驗源代碼】NURBS曲面:#include<windows.h>#include<gl/glut.h>#include<mat

44、h.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,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.

45、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;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 Initia

46、l()glClearColor(1.0f,1.0f,1.0f,1.0f);pNurb=gluNewNurbsRenderer();gluNurbsProperty(pNurb,GLU_SAMPLING_TOLERANCE,25.0f); gluNurbsProperty(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

47、);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);gluNurbsSurface(pNurb,8,Knots,8,Knots,4*3,3,&ctrlPoints000,4,4,GL_MAP2_VERTEX_3);gluEndSurface(pNurb);DrawPoints();glPopMatrix();glutSwapBuffers();void SpecialKe

48、ys(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_KEY_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 Chan

49、geSize(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(int argc,char *argv)glutInit(&argc,argv);glutInitDisplayMode

50、(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);glutCreateWindow("NURBS曲面");glutReshapeFunc(ChangeSize);glutDisplayFunc(ReDraw);glutSpecialFunc(SpecialKeys);Initial();glutMainLoop();return 0;在原來的基礎(chǔ)上加的:#include <windows.h>#include <gl/glut.h>#include <math.h>GLUnurbsObj*pNurb=NULL;GLint

51、 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,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,-

52、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+)glVertex3fv(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_

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論