I am trying to move a ship across the screen using the arrow keys. But everytime I move the ship it moves in the wrong direction. I need it to move in the direction it is pointing. I beleive the problem is in the calculation of xd and yd, the coordinates that I am translating too…it seems to move up and down correcting but anyother direction it moves, it seems, the opposite direction…
/***********************************************************/
void rotate(){
if(rot > 360.0) rot -= 360.0;
if(rot < 0.0) rot += 360.0;
if(Left_isPressed)
rot += 5.0;
if(Right_isPressed)
rot -= 5.0;
if(Up_isPressed){
yd += (cos((rot/1803.14)) * speed);
xd += (sin((rot/1803.14)) * speed);
}
/function to draw ship*/
glPushMatrix();
glTranslatef(xd,yd,0.0);
glRotatef(rot,0.0,0.0,1.0);
glBegin(GL_LINES);
for(i=0;i<=size;i++)
glVertex2f(x[i],y[i]);
glEnd();
glPopMatrix();
glutSwapBuffers();