Code:
void draw_canon()
{
/* Only redraw the part that is changing */
glPushMatrix();
glEnable(GL_SCISSOR_TEST);
glScissor(0, TEXTHEIGHT, WIDTH, HEIGHT);
glDisable(GL_SCISSOR_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, WIDTH, HEIGHT);
gluPerspective(45.0, 1.0, 1.0, 300.0);
gluLookAt(
0.0, 0.0, 30.0,
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);
glRotatef(canon_pitch, 1.0, 0.0, 0.0);
glRotatef(canon_yaw, 0.0, 1.0, 0.0);
glBegin(GL_QUADS);
glColor3f(0.0, 0.0, 1.0);
/* canon front */
glVertex3f(-0.5, -0.5, -1.5);
glVertex3f( 0.5, -0.5, -1.5);
glVertex3f( 0.5, 0.5, -1.5);
glVertex3f(-0.5, 0.5, -1.5);
// canon back */
glVertex3f(-0.5, -0.5, -0.5);
glVertex3f(-0.5, 0.5, -0.5);
glVertex3f( 0.5, 0.5, -0.5);
glVertex3f( 0.5, -0.5, -0.5);
/* canon left */
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, -2.0);
glVertex3f(-0.5, -0.5, -2.0);
/* canon right */
glVertex3f( 0.5, -0.5, -2.0);
glVertex3f( 0.5, 0.5, -2.0);
glVertex3f( 0.5, 0.5, 0.5);
glVertex3f( 0.5, -0.5, 0.5);
glColor3f(0.2, 0.0, 1.0);
/* canon top */
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f( 0.5, 0.5, 0.5);
glVertex3f( 0.5, 0.5, -2.0);
glVertex3f(-0.5, 0.5, -2.0);
/* canon bottom */
glVertex3f(-0.5, -0.5, 0.5);
glVertex3f(-0.5, -0.5, -2.0);
glVertex3f( 0.5, -0.5, -2.0);
glVertex3f( 0.5, -0.5, 0.5);
glEnd();
glPopMatrix();
glFlush();
}
draws the canon