求助:OPENGL的动画实现
本人毕业设计需要使用opengl制作动画,不知如何实现动画,请高人指教!先给出一个一条线段示例,起始点是(0,0,0),终点是(5000+x,5000+y,5000+z)
现在需要做一个简单动画如下表表示:
时间(s) 0.1 0.2 0.3 .... 假设到2秒为止
x 100 200 300 ....
y 100 200 300 ....
z 100 200 300 ....
下面是这条线段的代码,希望有高人能在这段代码的基础上帮我添加实现动画的语句,谢谢!
#include <windows.h>
#include <windows.h>
#include <GL/glut.h>
#include <math.h>
float x=0;
float y=0;
float z=0;
void model(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(-100,-100,40,100,0,0,0,0,100);
glLineWidth(1);
glBegin(GL_LINES);//坐标轴
glColor3f(1,1,1);
glVertex3f(0,0,0);//X轴
glVertex3f(100000,0,0);
glVertex3f(0,0,0); //Y轴
glVertex3f(0,100000,0);
glVertex3f(0,0,0);//Z轴
glVertex3f(0,0,100000);
glEnd();
glLineWidth(5);
glBegin(GL_LINES);
glColor3f(0,1,1);
glVertex3f(0,0,0);
glVertex3f(5000+x,5000+y,5000+z);
glEnd();
glFlush();
}
void reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15000,15000,-10000,20000,-30000,30000);
}
void init()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0,0.0,0.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(200,100);
glutInitWindowSize(600,600);
glutCreateWindow("DESIGN");
glutReshapeFunc(reshape);
glutDisplayFunc(&model);
glutMainLoop();
init();
return 0;
}