计算机图形学-自行车-旋转平移-等代码_第1页
计算机图形学-自行车-旋转平移-等代码_第2页
计算机图形学-自行车-旋转平移-等代码_第3页
计算机图形学-自行车-旋转平移-等代码_第4页
计算机图形学-自行车-旋转平移-等代码_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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驱动后可以不需要.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;菱形旋转代码#include static GLsizei iMode = 1;static GLfloat xRot = 0.0f; /x方向旋转参数static GLfloat yRot = 0.0f; /y方向旋转参数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); /旋转图形glRotatef(yRot, 0.0f, 1.0f, 0.0f); /旋转图形/指定需要绘制的图元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模型绘制函数示例); /创建菜单并定义菜单回调函数int nGlutPolyMenu = glutCreateMenu(ProcessMenu); glutAddMenuEntry(线框正四面体,1); /创建

11、GLUT多面体绘制菜单glutAddMenuEntry(实体正四面体,2);glutAddMenuEntry(线框正八面体,3);glutAddMenuEntry(实体正八面体,4);int nGlutCurveMenu = glutCreateMenu(ProcessMenu); /创建GLUT曲面绘制菜单glutAddMenuEntry(线框球面,5);glutAddMenuEntry(实体球面,6);glutAddMenuEntry(线框茶壶,7);glutAddMenuEntry(实体茶壶,8);int nGluCurveMenu = glutCreateMenu(ProcessMen

12、u); /创建GLU曲面绘制菜单glutAddMenuEntry(线框球面,9);glutAddMenuEntry(线框圆锥面,10);glutAddMenuEntry(线框圆环面,11);int nMainMenu = glutCreateMenu(ProcessMenu); /创建主菜单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;旋转平移代码#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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论