L'exécutable

Image3001.gif (5266 octets)

Image3001.gif (5266 octets)

Image3001.gif (5266 octets)

Le source : TD-Minilangage-Robot.cpp

#include "windows.h"

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

#include <stdio.h>
#include <math.h>

#include "ModuleFont.h"

static GLfloat view_rotx=16.0F ;
static GLfloat view_roty=20.0F ;
static GLfloat view_rotz=0.0F ;
static int type = 0 ;
static int maille = 0 ;
static float r1 = -100.0 ;
static float r2 = 40.0 ;
static float r3 = 75.0 ;
static float ouv = 0.0 ;

void myinit(void) {
  GLfloat light_ambient[] = { 0.0F,0.0F,0.0F,1.0F };
  GLfloat light_diffuse[] = { 1.0F,1.0F,1.0F,1.0F };
  GLfloat light_specular[] = { 0.0F,0.0F,0.0F,1.0F };
  GLfloat light_position0[] = { 0.0F,0.0F,1.0F,0.0F };
  GLfloat light_position1[] = { 0.0F,0.0F,1.0F,0.0F };
  glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);
  glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
  glLightfv(GL_LIGHT1,GL_DIFFUSE,light_diffuse);
  glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);
  glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
  glLightfv(GL_LIGHT1,GL_POSITION,light_position1);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glEnable(GL_AUTO_NORMAL);
  glDepthFunc(GL_LESS);
  glClearAccum(0.0,0.0,0.0,0.0);
  makeRasterFont();
}

void axes() {
  glPushMatrix() ;
  float rouge[] = { 1.0F,1.0F,0.0F,1.0F };
  glColor4fv(rouge) ;
  glBegin(GL_LINES) ;
  glVertex3f(0.0F,0.0F,0.0F) ;
  glVertex3f(1.0F,0.0F,0.0F) ;
  glEnd() ;
  glRasterPos3f(1.05F,0.05F,0.05F);
  printString("x");
  float vert[] = { 0.0F,1.0F,1.0F,1.0F };
  glColor4fv(vert) ;
  glBegin(GL_LINES) ;
  glVertex3f(0.0F,0.0F,0.0F) ;
  glVertex3f(0.0F,1.0F,0.0F) ;
  glEnd() ;
  glRasterPos3f(0.05F,1.05F,0.05F);
  printString("y");
  float bleu[] = { 1.0F,0.0F,1.0F,1.0F };
  glColor4fv(bleu) ;
  glBegin(GL_LINES) ;
  glVertex3f(0.0F,0.0F,0.0F) ;
  glVertex3f(0.0F,0.0F,1.0F) ;
  glEnd() ;
  glRasterPos3f(0.05F,0.05F,1.05F);
  printString("z");
  if ( maille ) {
    float gris[] = { 0.5F,0.5F,0.5F,1.0F };
    glColor4fv(gris) ;
    for ( int i = -100 ; i < 100 ; i++ ) {
      glBegin(GL_LINES) ;
      glVertex3f((float) i,0.0F,200.0F) ;
      glVertex3f((float) i,0.0F,-200.0F) ;
      glEnd() ;
      glBegin(GL_LINES) ;
      glVertex3f(200.0F,0.0F,(float) i) ;
      glVertex3f(-200.0F,0.0F,(float) i) ;
      glEnd() ; } }
  glPopMatrix() ;
}

void displayCotes(void) {
  float jaune[] = { 1.0F,1.0F,0.0F,0.5F };
  float blanc[] = { 1.0F,1.0F,1.0F,0.5F };
  float rouge[] = { 1.0F,0.0F,0.0F,0.5F };
  float vert[] = { 0.0F,1.0F,0.0F,0.5F };
  float bleu[] = { 0.0F,0.0F,1.0F,0.5F };
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glPushMatrix();
  glRotatef(view_rotx,1.0,0.0,0.0);
  glRotatef(view_roty,0.0,1.0,0.0);
  glRotatef(view_rotz,0.0,0.0,1.0);
  glPushMatrix();
  glPushMatrix();
  glRotatef(r1,0.0F,1.0F,0.0F) ;
  glTranslatef(1.5F,0.0F,0.0F) ;
  glColor3fv(rouge) ;
  auxWireBox(3.0,1.0,1.0) ;
  glTranslatef(1.5F,0.0F,0.0F) ;
  glRotatef(r2,0.0F,1.0F,0.0F) ;
  glTranslatef(1.5F,0.0F,0.0F) ;
  glColor3fv(vert) ;
  auxWireBox(3.0,0.8,0.8) ;
  glTranslatef(1.8F,0.0F,0.0F) ;
  glRotatef(r3,1.0F,0.0F,0.0F) ;
  glColor3fv(bleu) ;
  auxWireBox(0.6,1.2,1.8) ;
  glTranslatef(0.8F,0.0F,0.0F) ;
  glPushMatrix();
  glTranslatef(0.0F,0.0F,ouv+0.2F) ;
  glColor3fv(jaune) ;
  auxWireBox(1.0,1.2,0.4) ;
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.0F,0.0F,-ouv-0.2F) ;
  glColor3fv(jaune) ;
  auxWireBox(1.0,1.2,0.4) ;
  glPopMatrix();
  glPopMatrix();
  axes() ;
  glPopMatrix();
  glDisable(GL_DEPTH_TEST);
  glPopMatrix();
  glAccum(GL_ACCUM,0.6F);
}

void displayCubes(void) {
  float jaune[] = { 1.0F,1.0F,0.0F,0.5F };
  float blanc[] = { 1.0F,1.0F,1.0F,0.5F };
  float rouge[] = { 1.0F,0.0F,0.0F,0.5F };
  float vert[] = { 0.0F,1.0F,0.0F,0.5F };
  float bleu[] = { 0.0F,0.0F,1.0F,0.5F };
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glPushMatrix();
  glRotatef(view_rotx,1.0,0.0,0.0);
  glRotatef(view_roty,0.0,1.0,0.0);
  glRotatef(view_rotz,0.0,0.0,1.0);
  glEnable(GL_LIGHTING);
  glEnable(GL_DEPTH_TEST);
  glPushMatrix();
  glRotatef(r1,0.0F,1.0F,0.0F) ;
  glTranslatef(1.5F,0.0F,0.0F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,rouge) ;
  auxSolidBox(3.0,1.0,1.0) ;
  glTranslatef(1.5F,0.0F,0.0F) ;
  glRotatef(r2,0.0F,1.0F,0.0F) ;
  glTranslatef(1.5F,0.0F,0.0F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,vert) ;
  auxSolidBox(3.0,0.8,0.8) ;
  glTranslatef(1.8F,0.0F,0.0F) ;
  glRotatef(r3,1.0F,0.0F,0.0F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,bleu) ;
  auxSolidBox(0.6,1.2,1.8) ;
  glTranslatef(0.8F,0.0F,0.0F) ;
  glPushMatrix();
  glTranslatef(0.0F,0.0F,ouv+0.2F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,jaune) ;
  auxSolidBox(1.0,1.2,0.4) ;
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.0F,0.0F,-ouv-0.2F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,jaune) ;
  auxSolidBox(1.0,1.2,0.4) ;
  glPopMatrix();
  glPopMatrix();
  glDisable(GL_LIGHTING);
  glPopMatrix();
  glAccum(GL_ACCUM,0.4F);
}

void CALLBACK display(void) {
  glClear(GL_ACCUM_BUFFER_BIT);
  glPushMatrix() ;
  displayCubes() ;
  displayCotes() ;
  glAccum(GL_RETURN,1.0);
  glPopMatrix() ;
  glFlush();
  auxSwapBuffers() ;
}
void CALLBACK myReshape(int w,int h) {
  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-5.0,5.0,-h*5.0/w,h*5.0/w,-100.0,100.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void CALLBACK key1(void) {
  r1 += 4 ;
}

void CALLBACK key4(void) {
  r1 -= 4 ;
}

void CALLBACK key2(void) {
  r2 += 4 ;
}

void CALLBACK key5(void) {
  r2 -= 4 ;
}

void CALLBACK key3(void) {
  r3 += 4 ;
}

void CALLBACK key6(void) {
  r3 -= 4 ;
}

void CALLBACK key7(void) {
  ouv += 0.02 ;
  if ( ouv > 0.5 )
    ouv = 0.5 ;
}

void CALLBACK key8(void) {
  ouv -= 0.02 ;
  if ( ouv < 0.0 )
    ouv = 0.0 ;
}

void CALLBACK keyx(void) {
  view_rotx += 4 ;
}

void CALLBACK keyX(void) {
  view_rotx -= 4 ;
}

void CALLBACK keyy(void) {
  view_roty += 4 ;
}

void CALLBACK keyY(void) {
  view_roty -= 4 ;
}

void CALLBACK keyz(void) {
  view_rotz += 4 ;
}

void CALLBACK keyZ(void) {
  view_rotz -= 4 ;
}

void CALLBACK keyReturn(void) {
  type = (type+1)%5 ;
}

void CALLBACK keySpace(void) {
  maille = 1 - maille ;
}

void main(void) {
  auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH|AUX_ACCUM);
  auxInitPosition(0,0,380,270);
  auxInitWindow("Mini-langage");
  myinit();
  auxKeyFunc(AUX_x,keyx) ;
  auxKeyFunc(AUX_X,keyX) ;
  auxKeyFunc(AUX_y,keyy) ;
  auxKeyFunc(AUX_Y,keyY) ;
  auxKeyFunc(AUX_z,keyz) ;
  auxKeyFunc(AUX_Z,keyZ) ;
  auxKeyFunc(AUX_1,key1) ;
  auxKeyFunc(AUX_2,key2) ;
  auxKeyFunc(AUX_3,key3) ;
  auxKeyFunc(AUX_4,key4) ;
  auxKeyFunc(AUX_5,key5) ;
  auxKeyFunc(AUX_6,key6) ;
  auxKeyFunc(AUX_7,key7) ;
  auxKeyFunc(AUX_8,key8) ;
  auxKeyFunc(AUX_RETURN,keyReturn) ;
  auxKeyFunc(AUX_SPACE,keySpace) ;
  auxReshapeFunc(myReshape);
  auxMainLoop(display);
}

Le source : ModuleFont.cpp

Le source : ModuleFont.h

WB01624_.gif (281 octets) RETOUR