How DO I animate so the ball keeps on moving and how do i scale per keyboard input?


1) Below is a code which moves the ball towards the target once the z key is pressed incrementing it once per click so I have to keep on pressing z. How can I just animate the ball so it continues until it hits the target?

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

if (key == 'z') {

Ballz = Ballz - Speed;
Bally = Bally + 2.8;

}

I tried

Ballx++
Bally++
Bally++

But even that doesn't animate



2) Basically we have to add two levers/bars or rectangles so for example when i press the left key the lever is supposed to increase on the x axis showing the user is aiming left

I have 2 problems in this section, I've done both levers or bars but its only displayed on the scene when it's on line loop and not polygon...

b) I'm trying to scale the bars every time a left or right arrow key is pressed, so for example if I press left the x axis on the leftrightbar has to scale towards the left, how can this be done?

What would I put in the special keys section, I tried putting

if(key == GLUT_KEY_LEFT){
Ballx = Ballx - Speed;
leftrightbar == glScalef (2.0, 4.0, 4.0);


leftrightbar is the name of my function for the horizontal bar...


here's the code for the bars (important parts highlighted)

void updownbar(){
glBegin(GL_LINE_LOOP);
glColor3f(1.0, 0.0, 1.0);
//specify the vertices (points in 3D space) of the shape - note that these are 2D points

glVertex2f( 0.0, 0.0);
glVertex2f( 0.0, 20.0);
glVertex2f( 4.0, 20.0);
glVertex2f( 4.0, 0.0);
glEnd();

glFlush();

}

////////////////////////////
void leftrightbar(){
glBegin(GL_LINE_LOOP);
glColor3f(1.0, 0.0, 0.0);
//specify the vertices (points in 3D space) of the shape - note that these are 2D points

glVertex2f( 0.0, 0.0);
glVertex2f( 0.0, 4.0);
glVertex2f( 20.0, 4.0);
glVertex2f( 20.0, 0.0);
glEnd();

glFlush();

}

if(key == GLUT_KEY_LEFT){
Ballx = Ballx - Speed;

}

if(key == GLUT_KEY_RIGHT){
Ballx = Ballx + Speed;

}

glutPostRedisplay();

}

glMatrixMode(GL_MODELVIEW);


glPushMatrix();
glScalef (4.0, 4.0, 4.0);
glTranslatef (Ballx, Bally-20.0, Ballz +50.0);
ball();

glPopMatrix();


glPushMatrix();
glScalef (4.0, 4.0, 4.0);
glTranslatef (0.0, 12.0, 25.0);
target1();

glPopMatrix();

//////////////////////////////

glPushMatrix();
glScalef (4.0, 3.0, 4.0);
glTranslatef (-30.0, -45.0, 25.0);
updownbar();

glPopMatrix();

////////////////////////

glPushMatrix();
glScalef (3.0, 4.0, 4.0);
glTranslatef (25.0, -30.0, 25.0);
leftrightbar();

glPopMatrix();