I have a ball model that I want to move in screen using keyboard, I’ve tried different things including this code so please any help would be great, I’ve been stuck in this for a while.
void special(int key, int x, int y) {
switch (key) {
//when the up key is pressed
case GLUT_KEY_UP:
ball.pos.y+=1;
glutPostRedisplay();
break;
case GLUT_KEY_DOWN: //when the down arrow key is pressed
ball.pos.y-=1;
/* glutPostRedisplay();*/
break;
//when the left arrow key is pressed
case GLUT_KEY_LEFT:
ball.pos.x-=1;
ball.Draw();
/* glutPostRedisplay();*/
break;
case GLUT_KEY_RIGHT: //when the right arrow key is pressed
ball.pos.x+=1;
ball.Draw();
/*glutPostRedisplay();
break;
}
}