Hello,
I am working on a very simple game in C++ OpenGL GLUT and i came across this odd problem with rotating.
When my game begins, it looks like this :
http://img258.imageshack.us/img258/3212/95325995mc5.png
When i press the up key, it moves the cannon. I wrote a bit of code to copy the movement off my cannon onto my cannon ball, so it would move along with the cannon - staying inside the cannon mouth.
But what actually happens is that the ball moves in a faster motion than the actual speed my cannon is moving and as a result, the cannon ball gets out of line like this :
http://img380.imageshack.us/img380/9159/98738468ww1.png
This is the code i use to manipulate cannon and cannon ball movement using keyboard input :
/* Process Keyboard Input */
void Key(unsigned char key, int x, int y)
{
switch (key)
{
// Escape game
case 27:
exit(0);
break;
// Move Cannon Up :: Keyboard Key W
case 119:
if (ceil(cannon.GetAngleDegrees()) < 140) {
cannon.SetAngleDegrees(cannon.GetAngleDegrees() + 1);
cannonBall.SetPos(cannonBall.GetXPos() + cos(cannon.GetAngleRadians()), cannonBall.GetYPos() + sin(cannon.GetAngleRadians()));
}
break;
// Move Cannon Down :: Keyboard Key S
case 115:
if (ceil(cannon.GetAngleDegrees()) > 27) {
cannon.SetAngleDegrees(cannon.GetAngleDegrees() - 1);
cannonBall.SetPos(cannonBall.GetXPos() - cos(cannon.GetAngleRadians()), cannonBall.GetYPos() - sin(cannon.GetAngleRadians()));
}
break;
// Pause Game
case ' ':
glutIdleFunc(Idle);
break;
default:
break;
}
}
Where am i going wrong? Can someone please advice?