Help with switch statements in GLUT

Hello ladies and gents!
Just a quickie - I'm making a game in OpenGL GLUT. A ball is going to move forwards along the Z axis and hit a wall. I want to be able to move the ball left and right, up and down before firing it off on the Z axis. I'm using glutSpecialKeys for this, and I've got everything set up, but I'm not sure how I use it with a switch statement? Here is a snippet of code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Special_Keys (int key, int x, int y)
{
	switch(key)
	{
	case GLUT_KEY_UP: //do something
	break;
	case GLUT_KEY_DOWN: //do something
	break;
	case GLUT_KEY_LEFT: //do something
	break;
	case GLUT_KEY_RIGHT: //do something
	break;
	}

	glutPostRedisplay();
}


Where the comment is saying "do something", I'm not sure what I actually need to do? Is it a method or what?
Thanks in advance for any replies and solutions.
If I understood your question you should place instead of //do something the code that will move the ball up,down,left or right
the code could be series of operations like
1
2
3
4
5
6
7
switch(x)
{
case 0:cout<<"x="<<0;y=0;break;
case 1:cout<<"x="<<1;y=1;break;
case 2:cout<<"x="<<2;y=4;break;
default:cout<<"x="<<x;y=x*x;
}

or function like
1
2
3
4
5
6
7
switch(x)
{
case 0:f_0();break;
case 1:f_1();break;
case 2:f_2();break;
default:f_n(x);
}
Topic archived. No new replies allowed.