How to make smooth movements in OpenGL?
Posted
by thyrgle
on Stack Overflow
See other posts from Stack Overflow
or by thyrgle
Published on 2010-05-10T23:11:02Z
Indexed on
2010/05/10
23:14 UTC
Read the original article
Hit count: 132
opengl
|Transformations
So this kind of on topic to my other OpenGL question (not my OpenGL ES question but OpenGL the desktop version). If you have someone press a key to move a square how do you make the square movement naturally and less jumpy but also at the same speed I have it now? This is my code for the glutKeyboardFunc() function:
void handleKeypress(unsigned char key, int x, int y)
{
if (key == 'w')
{
for (int i = 0; i < 12; i++)
{
if (i == 1 || i == 7 || i == 10 || i == 4)
{
square[i] = square[i] + 1;
}
}
glutPostRedisplay();
}
if (key == 'd')
{
for (int i = 0; i < 12; i++)
{
if (i == 0 || i % 3 == 0)
{
square[i] = square[i] + 1;
}
}
glutPostRedisplay();
}
if (key == 's')
{
for (int i = 0; i < 12; i++)
{
if (i == 1 || i == 7 || i == 10 || i == 4)
{
square[i] = square[i] - 1;
}
}
glutPostRedisplay();
}
if (key == 'a')
{
for (int i = 0; i < 12; i++)
{
if (i == 0 || i % 3 == 0)
{
square[i] = square[i] - 1;
}
}
glutPostRedisplay();
}
}
I'm sorry if this doesn't quite make sense I'll try to rephrase it in a better way if it doesn't make sense.
© Stack Overflow or respective owner