計算機圖形學-自行車-旋轉(zhuǎn)平移-等代碼_第1頁
計算機圖形學-自行車-旋轉(zhuǎn)平移-等代碼_第2頁
計算機圖形學-自行車-旋轉(zhuǎn)平移-等代碼_第3頁
計算機圖形學-自行車-旋轉(zhuǎn)平移-等代碼_第4頁
計算機圖形學-自行車-旋轉(zhuǎn)平移-等代碼_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、自行車代碼#include Conio.h#include graphics.h#define closegr closegraphvoid initgr(void) /* BGI初始化 */ int gd = DETECT, gm = 0; /* 和gd = VGA,gm = VGAHI是同樣效果 */ registerbgidriver(EGAVGA_driver);/* 注冊BGI驅(qū)動后可以不需要.BGI文件的支持運行 */ initgraph(&gd, &gm, );int main(void) void *w1,*w2; int i,k; int x=500,y=300; initg

2、r(); /* BGI初始化 */ setbkcolor(6);/*畫前輪*/circle(x/2,y/2,30);for(k=0;k=360;k+=30)line( x/2,y/2,x/2+30*cos(x/2+k)*0.01745),y/2+30*sin(x/2+k)*0.01745); /*畫后輪*/circle(x/2+100,y/2,30);for(k=0;k=360;k+=30)line( x/2+100,y/2,x/2+100+30*cos(x/2+100+k)*0.01745),y/2+30*sin(x/2+100+k)*0.01745);circle(x/2+50,y/2,8

3、);line(x/2+50,y/2,x/2+100,y/2);line(x/2,y/2,x/2+20,y/2-70);line(x/2+50,y/2,x/2+80,y/2-60);line(x/2+100,y/2,x/2+80,y/2-60);line(x/2+50,y/2,x/2+20,y/2-70);line(x/2+20,y/2-70,x/2+20,y/2-90);circle(x/2+20,y/2-90,4);line(x/2+70,y/2-60,x/2+90,y/2-60);w1=malloc(imagesize(x/2-130,y/2-90,x/2+130,y/2+30);geti

4、mage(x/2-130,y/2-90,x/2+130,y/2+30,w1);/*畫前輪*/circle(x/2,y/2,30);for(k=0;k=360;k+=30)line( x/2,y/2,x/2+30*cos(x/2+k)*0.01745),y/2+30*sin(x/2+k)*0.01745); /*畫后輪*/circle(x/2+100,y/2,30);for(k=0;k0;i-)if (i%2=0)putimage(i,175,w1,COPY_PUT);elseputimage(i,175,w2,COPY_PUT);putimage(i,175,w1,COPY_PUT);line

5、(0,330,730,330);getch(); /* closegr(); /* 恢復TEXT屏幕模式 * return 0;菱形旋轉(zhuǎn)代碼#include static GLsizei iMode = 1;static GLfloat xRot = 0.0f; /x方向旋轉(zhuǎn)參數(shù)static GLfloat yRot = 0.0f; /y方向旋轉(zhuǎn)參數(shù)GLUquadricObj *obj; /二次曲面對象void Initial(void)glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glColor3f(0.0f, 0.0f, 0.0f);obj = gluNewQ

6、uadric( );gluQuadricDrawStyle(obj, GLU_LINE); /以線框方式繪制二次曲面對象void ChangeSize(int w, int h)glViewport(0, 0, w, h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D (-1.5f, 1.5f, -1.5f, 1.5f);void Display(void)glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW);glLoadIdentity();glRotatef(xRo

7、t, 1.0f, 0.0f, 0.0f); /旋轉(zhuǎn)圖形glRotatef(yRot, 0.0f, 1.0f, 0.0f); /旋轉(zhuǎn)圖形/指定需要繪制的圖元switch(iMode)case 1:glutWireTetrahedron();break;case 2:glutSolidTetrahedron();break;case 3:glutWireOctahedron();break;case 4:glutSolidOctahedron();break;case 5:glutWireSphere(1.0f,15,15); break;case 6:glutSolidSphere(1.0f,1

8、5,15); break;case 7:glutWireTeapot(1.0f); break;case 8:glutSolidTeapot(1.0f); break;case 9:gluSphere(obj, 1.0f, 15, 15); break;case 10:gluCylinder(obj,1.0f,0.0f,1.0f,15,15);break;case 11:gluPartialDisk(obj,0.3f,0.8f,15,15,30.0f,260.0f);break;default: break;glFlush(); void ProcessMenu(int value)iMode

9、 = value; glutPostRedisplay();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_KEY_RIGHT)yRot += 5.0f;if(xRot 356.0f)xRot = 0.0f;if(xRot 356.0f)yRot = 0.0f;if(yRot -1.0f)yRot = 355.0f;glutPos

10、tRedisplay();int main(int argc, char* argv)glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(400,400); glutInitWindowPosition(100,100); glutCreateWindow(OpenGL模型繪制函數(shù)示例); /創(chuàng)建菜單并定義菜單回調(diào)函數(shù)int nGlutPolyMenu = glutCreateMenu(ProcessMenu); glutAddMenuEntry(線框正四面體,1); /創(chuàng)建

11、GLUT多面體繪制菜單glutAddMenuEntry(實體正四面體,2);glutAddMenuEntry(線框正八面體,3);glutAddMenuEntry(實體正八面體,4);int nGlutCurveMenu = glutCreateMenu(ProcessMenu); /創(chuàng)建GLUT曲面繪制菜單glutAddMenuEntry(線框球面,5);glutAddMenuEntry(實體球面,6);glutAddMenuEntry(線框茶壺,7);glutAddMenuEntry(實體茶壺,8);int nGluCurveMenu = glutCreateMenu(ProcessMen

12、u); /創(chuàng)建GLU曲面繪制菜單glutAddMenuEntry(線框球面,9);glutAddMenuEntry(線框圓錐面,10);glutAddMenuEntry(線框圓環(huán)面,11);int nMainMenu = glutCreateMenu(ProcessMenu); /創(chuàng)建主菜單glutAddSubMenu(GLUT多面體, nGlutPolyMenu);glutAddSubMenu(GLUT曲面, nGlutCurveMenu);glutAddSubMenu(GLU曲面, nGluCurveMenu);glutAttachMenu(GLUT_RIGHT_BUTTON);glutD

13、isplayFunc(Display);glutReshapeFunc(ChangeSize);glutSpecialFunc(SpecialKeys);Initial(); glutMainLoop(); return 0;旋轉(zhuǎn)平移代碼#include #include #include #define PI 3.1415926535 GLsizei w=500, h=500; GLuint regHex; static GLfloat rotTheta = 0.0; static GLfloat move = 0.0; static GLfloat go= 0.0; static GLfl

14、oat fraction = 1.0; static void init() glClearColor(1.0, 1.0, 1.0, 0.0); void display() glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 0.0, 1.0); glPushMatrix(); glTranslatef(move, go, 0.0); glScalef( fraction, fraction, fraction ); glRotatef(rotTheta, 0.0, 0.0, 1.0); glutWireSphere(5.0, 8, 6); glPopM

15、atrix(); glFlush(); / glutSwapBuffers(); void moveRightSphere() move+=20.0; if (move100.0) move=0.0; glutPostRedisplay(); void moveLeftSphere() move-=20.0; if (move100.0) go=0.0; glutPostRedisplay(); void moveDownSphere() go-=20.0; if (go=360.0) rotTheta=0.0; glutPostRedisplay(); void reshape(GLsize

16、i w, GLsizei h) glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-100.0, 100.0, -100.0, 100.0, 0.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); void specialKeyFcn(GLint specialKey, GLint x, GLint y) switch(specialKey) case GLUT_KEY_LEFT: moveLeftSphere(); break; case GLUT_KEY_RIGHT: moveRightSphere(); break; case GLUT_KEY_UP: moveUpSphere(); break; case GLUT_KEY_DOWN: moveDownSphere(); break; default: break

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論