PDA

View Full Version : Need a little help understanding rotation

Latheesan
05-03-2008, 11:26 PM
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);
}
break;

// Move Cannon Down :: Keyboard Key S
case 115:
if (ceil(cannon.GetAngleDegrees()) > 27) {
cannon.SetAngleDegrees(cannon.GetAngleDegrees() - 1);
}
break;

// Pause Game
case ' ':
glutIdleFunc(Idle);
break;

default:
break;
}
}

-NiCo-
05-03-2008, 11:32 PM
I think it should be:

Latheesan
05-03-2008, 11:33 PM
here's the demo of what i have so far, so you can see the problem your self : http://www.mediafire.com/?iz0ml0g3jvk

-- Edit --

Okay, thanks NiCo, i will try that out and see what happens

Latheesan
05-03-2008, 11:34 PM
after change it to like this :

It jumped to some random place and it stopped moving

http://pastebin.ca/1006744 (cannon.cpp)
http://pastebin.ca/1006745 (cannon.h)

http://pastebin.ca/1006747 (ball.cpp)
http://pastebin.ca/1006748 (ball.h)

Latheesan
05-04-2008, 01:12 AM
anyone?

-NiCo-
05-04-2008, 02:15 AM
I'm using linux, so I can't test your code...

cannon.GetXPos() and cannon.GetYPos() return the point of rotation of the cannon, right?

Latheesan
05-04-2008, 02:06 PM
hmm, does this give you the info u need?

http://pastebin.ca/1007414 (main.cpp)