/* Objets graphiques                            */
/*                                              */
/* Auteur: Nicolas JANEY                        */
/* nicolas.janey@univ-fcomte.fr                 */
/* Fevrier 2014                                 */

#include <stdlib.h>
#include <stdio.h>

#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>

/* Objets graphiques                            */

/* Une roue                                     */

 void roue(void) {
  glPushMatrix();
  glPushMatrix();
  glScalef(1.0F,1.0F,2.0F);
  glutSolidTorus(0.1,0.9F,18,72);
  glPopMatrix();
  for ( int i = 0 ; i < 8 ; i++ ) {
    glPushMatrix();
    glRotatef(22.5F*i,0.0F,0.0F,1.0F);
    glScalef(1.8F,0.04F,0.04F);
    glutSolidCube(1.0);
    glPopMatrix(); }
  glPopMatrix();
}

/* Un essieu                                    */

void essieu(void) {
  glPushMatrix();
  glPushMatrix();
  glScalef(0.1F,0.1F,2.2F);
  glutSolidCube(1.0);
  glPopMatrix();
  glTranslatef(0.0F,0.0F,1.1F);
  glScalef(0.4F,0.4F,0.4F);
  roue();
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.0F,0.0F,-1.1F);
  glScalef(0.4F,0.4F,0.4F);
  roue();
  glPopMatrix();
}

/* Une automobile stylisee                      */

void mobile(void) {
  glPushMatrix();
  glPushMatrix();
  glTranslatef(0.0F,0.6F,0.0F);
  glPushMatrix();
  glScalef(5.0F,0.7F,1.7F);
  glutSolidSphere(0.65,72,72);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(2.5F,0.3F,0.0F);
  glScalef(0.3F,0.3F,0.3F);
  glutSolidSphere(0.25,72,72);
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.5F,0.35F,0.0F);
  glScalef(2.8F,0.7F,1.7F);
  glutSolidSphere(0.5,72,72);
  glPopMatrix();
  glPopMatrix();
  glPushMatrix();
  glTranslatef(1.7F,0.4F,0.0F);
  essieu();
  glPopMatrix();
  glPushMatrix();
  glTranslatef(-1.8F,0.4F,0.0F);
  essieu();
  glPopMatrix();
  glPopMatrix();
}
