glutKeyboardFunc with glutTimerFunc problem

Hi everybody,

I have a small issue to come over.

I have made a ball game which I kick a ball against a wall.

Basically what is meant to happen is when I press ‘z’ once the ball is meant to be kicked against the wall.

In order to do this I need a glutTimerFunction which needs to animate the ball and kick it against the wall, and if it hits the wall then the ball should retur back to where it started.

With this code I have done I have so far I need to hold onto ‘z’ the key in order for it to kick the ball against the wall.

I have supplied the relevant code below:

GLfloat ballXpos = 40.0f;
GLfloat ballYpos = -30.0f;
GLfloat ballZpos = 160.0f;

void frontWall()
{
glBegin(GL_QUADS);
glVertex3f(-100.0, -50.0, -350.0);
glVertex3f(-100.0, 50.0, -350.0);
glVertex3f(100.0, 50.0, -350.0);
glVertex3f(100.0, -50.0, -350.0);
glEnd();
}

void normalKeys(unsigned char key, int x, int y) {
{

if (key == ‘z’) {
ballZpos = ballZpos - ballZspeed;
ballYpos = ballYpos + 0.5f;
glutPostRedisplay();
}

void TimerFunc(int value)
{

}

Assuming the ‘normalKeys’ function really does work, all you should have
to do is -


void TimerFunc (int value)
{
    ballZpos = ballZpos - ballZspeed;
    ballYpos = ballYpos + 0.5f;
    glutPostRedisplay();
}

Google something like ‘TimerFunc example’ to see how to set it up.
Also read the manual on TimerFunc. Have fun.

The normalKeys function works fine at the moment I have to hold down on ‘z’ key in order to move the ball, I want to set up a timerFunc so when I click it once the ball kicks against the wall. I believe to do this I have set up a glutTimerFunc with a Boolean function so when z = true then the timerFunc runs.

I’m just a bit confused on how to do this.