How to move a 3d model using keyboard?

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;
	}
}

The keyboard handler should just update ball.pos then call glutPostRedisplay; ball.Draw() should only be called from the display callback.

1 Like

still nothing happened, but what if I’m already using the keyboard function for the camera.

sorry I’m beginner in opengl