资源描述:
《在opengl中创建一个球体动画,是球体在窗口内做自由落体运动,并在撞击地面后能够弹回原来的高度。.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#includevoidInitial(){glEnable(GL_DEPTH_TEST);glClearColor(1.0f,1.0f,1.0f,0.0f);}voidChangeSize(intw,inth){if(h==0)h=1;glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();GLfloataspect;aspect=(float)w/(float)h;gluPerspective(90,aspect,2.0,.0);glMatrixMode(GL_MODELVIEW
2、);glLoadIdentity();}voidmyDisplay(){staticGLfloatfElect1=250.0f,fligt=0.0f;staticGLinti=0;i++;glClear(GL_COLOR_BUFFER_BIT
3、GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(0.0f,fElect1,-250.0f);glColor3f(1.0f,0.0f,0.0f);//glutSolidSphere(10.0f,90.0,90.0);//小球的属性if
4、(fligt==0.0f&&fElect1>-250.0f)fElect1-=i*1.0f;//自由落体if(fElect1<=-245.0f)fligt=1.0f;//标记值if(fligt==1.0f&&fElect1<250.0f)fElect1+=10.0f;//反弹设置if(fElect1>=250.0f){fligt=0.0f;i=0;}//第二次下落设置glutSwapBuffers();}voidTimerFunc(intvalue){glutPostRedisplay();glutTimerFunc(100,TimerFunc,1);}intmain(inta
5、rgc,char*argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_RGB
6、GLUT_DOUBLE
7、GLUT_DEPTH);glutInitWindowPosition(100,100);glutInitWindowSize(400,400);glutCreateWindow("");glutReshapeFunc(ChangeSize);glutDisplayFunc(myDisplay);glutTimerFunc(500,TimerFunc,1);Initial();glutMainLoop();return0;}
8、希望对大家有帮助······2012-6-4.