ferum
2006.08.04, 09:18 AM
ok, having followed One Sad Cookie's tutorial (http://onesadcookie.com/Tutorials) I have implemented time based animation in my program, or so I thought. Here is my code:
void ProcessKeyboardInput(unsigned char key, int x, int y)
{
if (key == 32)
{
inMotion = 1;
}
}
void KeyUp(unsigned char key, int x, int y)
{
if (key == 32)
{
inMotion = 0;
prevTime = 0;
}
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (inMotion)
{
if (prevTime == 0)
prevTime = glutGet(GLUT_ELAPSED_TIME);
curenTime = glutGet(GLUT_ELAPSED_TIME);
timeDif = curenTime - prevTime;
timeDifer = timeDif / 1000.0f;
curenTime = prevTime;
coordy += timeDifer * 2;
if (coordy > 480)
coordy = -50.0;
}
glLoadIdentity();
glPushMatrix();
glTranslatef(320.0 + coordx, 50.0 + coordy, 0.0);
glColor3f(0.0, 0.5, 0.0);
drawOBJ(&ship);
if (inMotion)
{
glColor3f(1.0, 0.0, 0.0);
drawOBJ(&flame);
}
glPopMatrix();
glutSwapBuffers();
}
when I hold down key #32 (the spacebar) my crude, programmer art "ship" flies upwards... at an ever accelerating rate:\ what gives?
void ProcessKeyboardInput(unsigned char key, int x, int y)
{
if (key == 32)
{
inMotion = 1;
}
}
void KeyUp(unsigned char key, int x, int y)
{
if (key == 32)
{
inMotion = 0;
prevTime = 0;
}
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (inMotion)
{
if (prevTime == 0)
prevTime = glutGet(GLUT_ELAPSED_TIME);
curenTime = glutGet(GLUT_ELAPSED_TIME);
timeDif = curenTime - prevTime;
timeDifer = timeDif / 1000.0f;
curenTime = prevTime;
coordy += timeDifer * 2;
if (coordy > 480)
coordy = -50.0;
}
glLoadIdentity();
glPushMatrix();
glTranslatef(320.0 + coordx, 50.0 + coordy, 0.0);
glColor3f(0.0, 0.5, 0.0);
drawOBJ(&ship);
if (inMotion)
{
glColor3f(1.0, 0.0, 0.0);
drawOBJ(&flame);
}
glPopMatrix();
glutSwapBuffers();
}
when I hold down key #32 (the spacebar) my crude, programmer art "ship" flies upwards... at an ever accelerating rate:\ what gives?