I declared two variables on class level. One is the angle the object is rotated by. The second is a stopwatch.
float yRot = 0.0f;
static CStopWatch rotTimer;
I rotate the cube using the SpecialKeys function.
void SpecialKeys(int key,int x,int y)
{
if(key == GLUT_KEY_RIGHT)
{
yRot = rotTimer.GetElapsedSeconds() * 10.0f;
}
if(key == GLUT_KEY_LEFT)
{
yRot = rotTimer.GetElapsedSeconds() * -10.0f;
}
glutPostRedisplay();
}
Finally the rotation matrix is calculated using the rotation variable, in the RenderScene
function.
// Create a rotation matrix based on the current value of yRot
m3dRotationMatrix44(mRotate, m3dDegToRad(yRot), 0.0f, 1.0f, 0.0f);
It actually works. My problem is that when I hold the key the animation looks fine. But if I press it the animation looks a little jumpy, like the angle is bigger then when I hold it. I suppose this hangs together with the stopwatch. How to solve this issue?