|
|
发表于 2006-1-3 20:10:00
|
显示全部楼层
Re: Re:为什么不能连续转动?
Jackie_cai: Re:为什么不能连续转动?
谢谢这位大哥。这种方法我试过了,但是不行。为了找出具体问题,我把完整的代码列出来。
#include "G...
我根据你第3楼的代码进行了修改,可以连续转动了。下面红色的代码是我添加的。
//-------------------------------------------------------------------------------
#include "GL/glut.h"
#pragma comment( lib, "glut32.lib")
static GLfloat rotateAngle = 0.0;
void TimerFunction(int value)
{
rotateAngle += 3.0; //这3行代码是从你原来的 display() 中移动过来的
if(rotateAngle > 360) //这3行代码是从你原来的 display() 中移动过来的
rotateAngle -= 360; //这3行代码是从你原来的 display() 中移动过来的
glutPostRedisplay();
glutTimerFunc(33,TimerFunction,1);
}
//------------------------------------------
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}
//------------------------------------------
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glColor3f(1.0, 1.0, 1.0);
glTranslatef(0.0, 0.0, -5.0);
glRotatef(rotateAngle, 0.0, 1.0, 0.0);
glScalef(1.0, 2.0, 1.0);
glutWireCube(1.0);
glFlush();
}
//------------------------------------------
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, 1.0, 1.5, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
//------------------------------------------
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutTimerFunc(33,TimerFunction,1);
glutMainLoop();
return 0;
}
|
|