I'm trying to rotate a ship in an asteroid game. What I'm doing is creating a float angle variable and at each time I press left or right buttons, I increase and decrease it, and in the drawing function, I rotate the ship by that amount.
The behaviour that I get is not really correct, because what I want is at each press, the ship should move smoothly and not by small increments. This is what I'm doing:
static float ang = 20.0f;
if(event.getCode() == KeyEvent::KEY_RIGHT)
{
ship.m_Angle+=ang*getElapsedSeconds();
}
else if(event.getCode() == KeyEvent::KEY_LEFT)
{
ship.m_Angle-=ang*getElapsedSeconds();
}
gl::pushMatrices();
gl::translate(Vec2f(m_Pos.x,m_Pos.y));
gl::rotate(Vec3f(0,0,m_Angle));
gl::scale(0.3,0.3,0.3);
gl::color(ci::Color(1,1,1));
gl::drawLine(Vec2f(-52,-23),Vec2f(69,0));
gl::drawLine(Vec2f(-43,-20),Vec2f(-43,20));
gl::drawLine(Vec2f(69,0),Vec2f(-52,23));
gl::popMatrices();
EDIT: I would also like to limit the angle, it goes forever and the variable will overflow.