L'exécutable

Robot01.gif (10091 octets) Robot01v.gif (2997 octets)

Le source : TD-Minilangage-Robot2.cpp

/* Auteur: Nicolas JANEY            */
/* nicolas.janey@univ-fcomte.fr     */
/* Janvier 2002                     */
/* Modelisation OpenGL d'une scene  */
/* composee d'un bras robot         */

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

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

#include "ModuleCouleurs.h"
#include "ModuleFont.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"

static int f1 ;
static int f2 ;
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_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,couleurNoir());
  glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
  glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBlanc());
  glLightfv(GL_LIGHT0,GL_SPECULAR,couleurNoir());
  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);
  glEnable(GL_ALPHA_TEST);
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
  setManipulateurClavierAngle(16.0F,20.0F,0.0F);
}

void axes() {
  glPushMatrix() ;
  glColor4fv(couleurJaune()) ;
  glBegin(GL_LINES) ;
  glVertex3f(0.0F,0.0F,0.0F) ;
  glVertex3f(1.0F,0.0F,0.0F) ;
  glEnd() ;
  placeFontCursor(1.05F,0.05F,0.05F);
  simpleBitmapOutput("x");
  glColor4fv(couleurCyan()) ;
  glBegin(GL_LINES) ;
  glVertex3f(0.0F,0.0F,0.0F) ;
  glVertex3f(0.0F,1.0F,0.0F) ;
  glEnd() ;
  placeFontCursor(0.05F,1.05F,0.05F);
  simpleBitmapOutput("y");
  glColor4fv(couleurMagenta()) ;
  glBegin(GL_LINES) ;
  glVertex3f(0.0F,0.0F,0.0F) ;
  glVertex3f(0.0F,0.0F,1.0F) ;
  glEnd() ;
  placeFontCursor(0.05F,0.05F,1.05F);
  simpleBitmapOutput("z");
  if ( maille ) {
    glColor4fv(couleurGrisMoyen()) ;
    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 display(void) {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_DEPTH_TEST);
  glPushMatrix() ;
  manipulateurSouris();
  manipulateurClavier();
  axes() ;
  glPushMatrix();
  glRotatef(r1,0.0F,1.0F,0.0F) ;
  glTranslatef(1.5F,0.0F,0.0F) ;
  glColor4fv(couleurRouge()) ;
  glPushMatrix();
  glScalef(3.0F,1.0F,1.0F) ;
  glutWireCube(1.0) ;
  glPopMatrix();
  glTranslatef(1.5F,0.0F,0.0F) ;
  glRotatef(r2,0.0F,1.0F,0.0F) ;
  glTranslatef(1.5F,0.0F,0.0F) ;
  glColor4fv(couleurVert()) ;
  glPushMatrix();
  glScalef(3.0F,0.8F,0.8F) ;
  glutWireCube(1.0) ;
  glPopMatrix();
  glTranslatef(1.8F,0.0F,0.0F) ;
  glRotatef(r3,1.0F,0.0F,0.0F) ;
  glColor4fv(couleurBleu()) ;
  glPushMatrix();
  glScalef(0.6F,1.2F,1.8F) ;
  glutWireCube(1.0) ;
  glPopMatrix();
  glTranslatef(0.8F,0.0F,0.0F) ;
  glPushMatrix();
  glTranslatef(0.0F,0.0F,ouv+0.2F) ;
  glColor4fv(couleurJaune()) ;
  glPushMatrix();
  glScalef(1.0F,1.2F,0.4F) ;
  glutWireCube(1.0) ;
  glPopMatrix();
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.0F,0.0F,-ouv-0.2F) ;
  glColor4fv(couleurJaune()) ;
  glPushMatrix();
  glScalef(1.0F,1.2F,0.4F) ;
  glutWireCube(1.0) ;
  glPopMatrix();
  glPopMatrix();
  glPopMatrix();
  glPushMatrix();
  glPopMatrix();
  glEnable(GL_CULL_FACE);
  glEnable(GL_LIGHTING);
  glPushMatrix();
  glRotatef(r1,0.0F,1.0F,0.0F) ;
  glTranslatef(1.5F,0.0F,0.0F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge(0.4F)) ;
  glPushMatrix();
  glScalef(3.0F,1.0F,1.0F) ;
  glutSolidCube(1.0) ;
  glPopMatrix();
  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,couleurVert(0.4F)) ;
  glPushMatrix();
  glScalef(3.0F,0.8F,0.8F) ;
  glutSolidCube(1.0) ;
  glPopMatrix();
  glTranslatef(1.8F,0.0F,0.0F) ;
  glRotatef(r3,1.0F,0.0F,0.0F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu(0.4F)) ;
  glPushMatrix();
  glScalef(0.6F,1.2F,1.8F) ;
  glutSolidCube(1.0) ;
  glPopMatrix();
  glTranslatef(0.8F,0.0F,0.0F) ;
  glPushMatrix();
  glTranslatef(0.0F,0.0F,ouv+0.2F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurJaune(0.4F)) ;
  glPushMatrix();
  glScalef(1.0F,1.2F,0.4F) ;
  glutSolidCube(1.0) ;
  glPopMatrix();
  glPopMatrix();
  glPushMatrix();
  glTranslatef(0.0F,0.0F,-ouv-0.2F) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurJaune(0.4F)) ;
  glPushMatrix();
  glScalef(1.0F,1.2F,0.4F) ;
  glutSolidCube(1.0) ;
  glPopMatrix();
  glPopMatrix();
  glPopMatrix();
  glDisable(GL_LIGHTING);
  glDisable(GL_CULL_FACE);
  glPopMatrix() ;
  glDisable(GL_DEPTH_TEST);
  glFlush();
  glutSwapBuffers();
}

void key2(unsigned char key,int x,int y) {
  switch ( key ) {
    case '1'  : r1 += 2 ; 
                glutPostWindowRedisplay(f1);
                glutPostWindowRedisplay(f2);
                break;
    case '7'  : r1 -= 2 ; 
                glutPostWindowRedisplay(f1);
                glutPostWindowRedisplay(f2);
                break;
    case '2'  : r2 += 2 ; 
                glutPostWindowRedisplay(f1);
                glutPostWindowRedisplay(f2);
                break;
    case '8'  : r2 -= 2 ; 
                glutPostWindowRedisplay(f1);
                glutPostWindowRedisplay(f2);
                break;
    case '3'  : r3 += 2 ; 
                glutPostWindowRedisplay(f1);
                glutPostWindowRedisplay(f2);
                break;
    case '9'  : r3 -= 2 ; 
                glutPostWindowRedisplay(f1);
                glutPostWindowRedisplay(f2);
                break;
    case 43   : ouv += 0.02F ;
                if ( ouv > 0.5 )
                  ouv = 0.5 ;
                glutPostWindowRedisplay(f1);
                glutPostWindowRedisplay(f2);
                break;
    case 45   : ouv -= 0.02F ;
                if ( ouv < 0.0 )
                  ouv = 0.0 ;
                glutPostWindowRedisplay(f1);
                glutPostWindowRedisplay(f2);
                break;
    case 32   : maille = 1 - maille ;
                glutPostWindowRedisplay(f1);
                break;
    case 0x1B : exit(0);
                break; }
}

void key(unsigned char key,int x,int y) {
  if ( keyManipulateur(key,x,y) )
    glutPostWindowRedisplay(f1);
    else
    key2(key,x,y);
}

void special2(int key,int x,int y) {
  if ( specialManipulateur(key,x,y) ) {
    glutPostWindowRedisplay(f1); }
}

void reshape2(int w,int h) {
  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0,w,-h,0,-1.0,1.0); 
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void display2() {
  glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
  glClearColor(0.0F,0.0F,0.0F,1.0F) ;
  glColor4fv(couleurBlanc());
  glPushMatrix();
  float pos = 1.0F;
  placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
  simpleBitmapOutput(REGULAR8x13,"ANGLE R1 : %8.3f",r1) ;
  pos += 1.0F;
  placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
  simpleBitmapOutput(REGULAR8x13,"ANGLE R2 : %8.3f",r2) ;
  pos += 1.0F;
  placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
  simpleBitmapOutput(REGULAR8x13,"ANGLE R3 : %8.3f",r3) ;
  pos += 1.0F;
  placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
  simpleBitmapOutput(REGULAR8x13,"VALEUR D : %8.3f",ouv) ;
  glPopMatrix();
  glutSwapBuffers();
}

int main(int argc,char **argv) {
  glutInit(&argc,argv);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  glutInitWindowSize(380,270); 
  glutInitWindowPosition(50,50); 
  f1 = glutCreateWindow("Mini-langage"); 
  myinit(); 
  creationMenuBasique();
  setParametresOrthoBasique(-5.0,5.0,-5.0,5.0,-50.0,50.0);
  setManipulateurDistance(1.0F);
  glutReshapeFunc(reshapeOrthoBasique);
  glutKeyboardFunc(key);
  glutSpecialFunc(specialBasique);
  glutMotionFunc(motionBasique);
  glutMouseFunc(sourisBasique);
  glutDisplayFunc(display);
  glutInitWindowSize(210,90);
  glutInitWindowPosition(60,370);
  glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
  f2 = glutCreateWindow("Valeurs");
  creationMenuBasique();
  glutDisplayFunc(display2);
  glutReshapeFunc(reshape2);
  glutKeyboardFunc(key2);
  glutSpecialFunc(special2);
  glutMainLoop();
  return(0);
}

Les modules utilitaires : Modules.zip

WB01624_.gif (281 octets) RETOUR