L'exécutable

Temple1.gif (5936 octets) Temple1.gif (5936 octets)

Le source : TD-EllipsoïdeAnime.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=25.0F ;
static GLfloat view_roty=20.0F ;
static GLfloat view_rotz=0.0F ;
static float rx = 1.04f ;
static float rz = 1.0f ;
static int type = 0 ;
static int maille = 0 ;
static float noir[] = { 0.0F,0.0F,0.0F,0.5F };
static float rouge[] = { 1.0F,0.0F,0.0F,0.5F };
static float vert[] = { 0.0F,1.0F,0.0F,0.5F };
static float bleu[] = { 0.0F,0.0F,1.0F,0.5F };
static float jaune[] = { 1.0F,1.0F,0.0F,1.0F };
static float magenta[] = { 1.0F,0.0F,1.0F,1.0F };
static float cyan[] = { 0.0F,1.0F,1.0F,1.0F };
static float blanc[] = { 1.0F,1.0F,1.0F,0.5F };

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);
  glEnable(GL_DEPTH_TEST);
  glClearAccum(0.0,0.0,0.0,0.0);
  makeRasterFont();
}

void axes() {
  glPushMatrix() ;
  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");
  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");
  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 displayCotesEllipsoide(void) {
  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();
  glScalef(rx,1.0F,rz) ;
  glColor3fv(blanc) ;
  auxWireSphere(1.0) ;
  glPopMatrix();
  axes() ;
  glPopMatrix();
  glAccum(GL_ACCUM,0.7F);
}

void displayEllipsoide(void) {
  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);
  glScalef(rx,1.0F,rz) ;
  glMaterialfv(GL_FRONT,GL_DIFFUSE,blanc);
  auxSolidSphere(1.0) ;
  glDisable(GL_LIGHTING);
  glPopMatrix();
  glAccum(GL_ACCUM,0.3F);
}

void CALLBACK display(void) {
  glClear(GL_ACCUM_BUFFER_BIT);
  glPushMatrix() ;
  displayEllipsoide() ;
  displayCotesEllipsoide() ;
  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(-3.0,3.0,-h*3.0/w,h*3.0/w,-100.0,100.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

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 keySpace(void) {
  maille = 1 - maille ;
}

void CALLBACK idle(void) {
  static float dx = 0.04f;
  static float dz = 0.00f;
  rx += dx;
  rz += dz;
  if ( fabs(rx-3.0) < 0.001 ) {
    dx = -0.04f; }
    else
    if ( ( fabs(rx-1.0) < 0.001 ) && ( dx < 0.0f ) ) {
      dz = 0.04f;
      dx = 0.00f; }
      else
      if ( fabs(rz-3.0) < 0.001 ) {
        dz = -0.04f; }
        else
        if ( ( fabs(rz-1.0) < 0.001 ) && ( dz < 0.0f ) ) {
          dx = 0.04f;
          dz = 0.00f; }
  display();
}

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

void main(void) {
  auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH|AUX_ACCUM);
  auxInitPosition(0,0,250,140);
  auxInitWindow("Ellipsoide anime");
  myinit();
  auxIdleFunc(idle) ;
  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_SPACE,keySpace) ;
  auxKeyFunc(AUX_RETURN,keyReturn) ;
  auxReshapeFunc(myReshape);
  auxMainLoop(display);
}

Le source : ModuleFont.cpp

Le source : ModuleFont.h

WB01624_.gif (281 octets) RETOUR