PDA

View Full Version : Basic animation

Debbie
11-07-2011, 02:21 AM
I'm confused on how to get started with animation, i know a timer function is essential for redisplaying my object every few milliseconds. But i need a bullet to travel from the center of a 'spaceship' shape i have and go forward at the same angle as the spaceship when the space bar is pressed.
I think i might have an idea of how to go about it, but i'm not sure so if anyone could point me in the right direction or suggest an animation tutorial (haven't been able to find one via google that helps) that would be amazing, thanks.

Here's the code i'm currently working on

glPushMatrix();
glRotatef(yRotationAngle, 0.0, 0.0, 1.0);

glBegin(GL_LINE_LOOP);

//specify the vertices of the spaceship
glVertex3f(0.0,1.0,0.0); //top of spaceship
glVertex3f(-1.0,-1.0,0.0); //left point of spaceship
glVertex3f(0.0,0.0,0.0); //centre of spaceship
glVertex3f(1.0,-1.0,0.0); //right point of spaceship
glEnd();

glPointSize(2);

glBegin(GL_POINTS);
glVertex2f(Bulletx,Bullety);
glEnd();
glPopMatrix();
glPopMatrix();

glutSwapBuffers();

}

void keyboard(unsigned char key, int x, int y)
{
switch ( key )
{
case 'r': yRotationAngle = yRotationAngle + 10.0;
glutPostRedisplay();
break;
case 'e': yRotationAngle = yRotationAngle - 10.0;
glutPostRedisplay();
break;
case 't': Bulletx= Bulletx + 1.0;
Bullety= Bullety + 1.0;
default: break;

}
}

void TimerFunction(int value)
{
glClear (GL_COLOR_BUFFER_BIT);
glutPostRedisplay();
glutTimerFunc(5,TimerFunction, 0);//calls TimerFunction on tick - callback
}