Example #1
0
/*
 * draws a robot with a given size, using the various parameters
 *(orientation,
 * position, ..) from the robot struct
 */
void draw_robot(cairo_t* cr, struct robot* myRobot, double size)
{
    double x1 = -70, y1 = -30,
        y2 = 10,
        x4 = 70,
        x5 = 0, y5 = -100;
    double px2 = -70, py2 = 100,
        px3 = 70, py3 = 100,
        px4 = 70, py4 = 10;

    cairo_save(cr);
    cairo_translate(cr, myRobot->x, myRobot->y);
    cairo_scale(cr, size, size);
    cairo_save(cr);
    cairo_rotate(cr, degtorad(90 + myRobot->degree));

    cairo_set_source_rgba(cr, myRobot->color[0], myRobot->color[1],
        myRobot->color[2], 0.6);
    cairo_set_line_width(cr, 2);
    cairo_move_to(cr, x1, y1);
    cairo_line_to(cr, x1, y2);
    cairo_curve_to(cr, px2, py2, px3, py3, px4, py4);
    cairo_line_to(cr, x4, y1);
    cairo_line_to(cr, x5, y5);
    cairo_close_path(cr);
    cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
    cairo_move_to(cr, 30, 0);
    cairo_arc_negative(cr, 0, 0, 30, 0, -2 * M_PI);

    cairo_fill_preserve(cr);
    cairo_set_source_rgba(cr, 0.1, 0.7, 0.5, 0.5);

    cairo_stroke(cr);
    cairo_restore(cr); /* pop rotate */
    draw_cannon(cr, degtorad(270 + myRobot->cannon_degree));
    draw_radar(cr, degtorad(270 + myRobot->radar_degree));
    cairo_restore(cr); /* pop translate/scale */
    shot_animation(cr, size, degtorad(myRobot->cannon_degree),
        &myRobot->cannon[0]);
    shot_animation(cr, size, degtorad(myRobot->cannon_degree),
        &myRobot->cannon[1]);
}
Example #2
0
void display(void)
{
        static float angle = 0.0 ;

        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
   
        glLoadIdentity();

        gluLookAt (camera[0], camera[1], camera[2], 
                         (GLdouble) ball_position.x,  0.0, 
                         (GLdouble) ball_position.y, 
                         0.0,       0.0,       1.0);

        glLightfv(GL_LIGHT0, GL_POSITION, light_position);
        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);

        glColorMask(1,1,1,1);
        glEnable(GL_LIGHTING); 
        glEnable(GL_BLEND);

        draw_dirt();
        
        glPushMatrix();
        glTranslatef ( 2.0 , 0.0 , 0 );
        draw_cannon();
        glPopMatrix();

        glPushMatrix();
        glTranslatef ( ball_position.x , 0.0 , ball_position.y );
        if ( ball_position.y > 1.0 ) {
                 angle++;
                 glRotatef (angle, 0.0f, 0.0f, 1.0f);
        }
        draw_ball() ;
        glPopMatrix();

        glutSwapBuffers();
}