L'exécutable

 

Image67.gif (7062 octets)

Le source : Composantes.cpp

Le source : ModuleFont.cpp

Le source : ModuleFont.h

#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=0.0F ;
static GLfloat view_rotz=0.0F ;
static GLfloat px=-9.0F ;
static GLfloat py=9.0F ;
static GLfloat pz=0.0F ;
static GLfloat nfact=1.0F ;
static float ymax ;

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();
}

float norme(float x,float y,float z) {
  return((float) sqrt(x*x+y*y+z*z)) ;
}

void normalise(float *x,float *y,float *z) {
  float n = norme(*x,*y,*z);
  *x /= n ;
  *y /= n ;
  *z /= n ;
}

void reflexion(float px,float py,float pz) {
  float rouge[] = { 1.0F,0.0F,0.0F,1.0F };
  glColor4fv(rouge) ;
  glBegin(GL_LINES);
  float rx = -px ;
  float ry = py ;
  float rz = -pz ;
  normalise(&rx,&ry,&rz) ;
  glVertex3f(10*rx,10*ry,10*rz);
  glVertex3f(0.0F,0.0F,0.0F);
  glEnd();
}

void diffusion(float px,float py,float pz) {
  float vert[] = { 0.0F,0.4F,0.0F,1.0F };
  px *= -1 ;
  py *= -1 ;
  pz *= -1 ;
  normalise(&px,&py,&pz) ;
  float d = -py ;
  glColor4fv(vert) ;
  glBegin(GL_LINES);
  for ( int j = 15 ; j < 90 ; j+= 30 ) {
    float anglex = j * 3.14159F / 180.0F ;
    float daz = (((j-15)/30)%2 == 0) ? 20.0F : 0.0F ;
    for ( int i = 0 ; i < 360 ; i+= 40 ) {
      float anglez = (i+daz) * 3.14159F / 180.0F ;
      float x =(float) (cos(anglez)*cos(anglex)*5*d) ;
      float z =(float) (sin(anglez)*cos(anglex)*5*d) ;
      float y =(float) (sin(anglex)*5*d) ;
      glVertex3f(0.0F,0.0F,0.0F) ;
      glVertex3f(x,y,z) ; } }
  glEnd();
}

float produitScalaire(float ix,float iy, float iz,float nx,float ny, float nz) {
  return(ix*nx+iy*ny+iz*nz) ;
}

void transmission(float px,float py,float pz) {
  float bleu[] = { 0.0F,0.0F,1.0F,1.0F };
  float ix = px ;
  float iy = py ;
  float iz = pz ;
  normalise(&ix,&iy,&iz) ;
  float nx = 0.0F ;
  float ny = 1.0F ;
  float nz = 0.0F ;
  float ni = produitScalaire(ix,iy,iz,nx,ny,nz) ;
  float t = nfact*ni-(float) sqrt(1-nfact*nfact*(1-ni*ni)) ;
  float tx = t*nx - nfact*ix ;
  float ty = t*ny - nfact*iy ;
  float tz = t*nz - nfact*iz ;
  glColor4fv(bleu) ;
  glBegin(GL_LINES);
  glVertex3f(10*tx,10*ty,10*tz);
  glVertex3f(0.0F,0.0F,0.0F);
  glEnd();
}

void displayRayons(void) {
  float jaune[] = { 1.0F,1.0F,0.0F,1.0F };
  float blanc[] = { 1.0F,1.0F,1.0F,1.0F };
  float magenta[] = { 1.0F,0.0F,1.0F,1.0F };
  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();
  glColor4fv(jaune) ;
  glBegin(GL_LINES);
  glVertex3f(px,py,pz);
  glVertex3f(0.0F,0.0F,0.0F);
  glEnd();
  glColor4fv(magenta) ;
  glBegin(GL_LINES);
  glVertex3f(0.0F,10.0F,0.0F);
  glVertex3f(0.0F,0.0F,0.0F);
  glEnd();
  glPopMatrix();
  glEnable(GL_LIGHTING);
  glPushMatrix();
  glMaterialfv(GL_FRONT,GL_DIFFUSE,jaune) ;
  glTranslatef(px,py,pz) ;
  auxSolidSphere(0.5);
  glPopMatrix();
  glDisable(GL_LIGHTING);
  reflexion(px,py,pz);
  diffusion(px,py,pz);
  transmission(px,py,pz);
  glPopMatrix();
  glDisable(GL_DEPTH_TEST);
  GLfloat white[4] = { 1.0,1.0,1.0,1.0 };
  glColor4fv(white);
  glRasterPos3f(-10,ymax-1,0);
  char st[50] ;
  sprintf(st,"n = %f",nfact);
  printString(st);
  glAccum(GL_ACCUM,0.8F);
}

void displayInterface(void) {
  float blanc[] = { 1.0F,1.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);
  glPushMatrix();
  glMaterialfv(GL_FRONT,GL_DIFFUSE,blanc) ;
  glTranslatef(0.0F,0.0F,0.0F) ;
  auxSolidBox(16.0,0.2,14.0) ;
  glPopMatrix();
  glDisable(GL_LIGHTING);
  glPopMatrix();
  glAccum(GL_ACCUM,0.2F);
}

void CALLBACK display(void) {
  glPushMatrix() ;
  glEnable(GL_DEPTH_TEST);
  glClear(GL_ACCUM_BUFFER_BIT);
  displayInterface() ;
  displayRayons() ;
  glAccum(GL_RETURN,1.0);
  glPopMatrix() ;
  glFlush();
  auxSwapBuffers() ;
}
void CALLBACK myReshape(int w,int h) {
  glViewport(0,0,w,h);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  ymax = h*11.0F/w ;
  glOrtho(-11,11,-h*11.0/w,h*11.0/w,-15.0,15.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}

void CALLBACK keyLeft(void) {
  px -= 0.2F ;
  if ( px < -9.0F )
    px = -9.0F ;
}

void CALLBACK keyRight(void) {
  px += 0.2F ;
  if ( px > 9.0F )
    px = 9.0F ;
}

void CALLBACK keyPageUp(void) {
  py += 0.2F ;
  if ( py > 9.0F )
    py = 9.0F ;
}

void CALLBACK keyPageDown(void) {
  py -= 0.2F ;
  if ( py < -9.0F )
    py = -9.0F ;
}

void CALLBACK keyUp(void) {
  pz -= 0.2F ;
  if ( pz < -9.0F )
    pz = -9.0F ;
}

void CALLBACK keyDown(void) {
  pz += 0.2F ;
  if ( pz > 9.0F )
    pz = 9.0F ;
}

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

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

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

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

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

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

void CALLBACK keyn(void) {
  nfact *= 1.01F ;
}

void CALLBACK keyN(void) {
  nfact /= 1.01F ;
}

void main(void) {
  auxInitDisplayMode(AUX_DOUBLE|AUX_RGB|AUX_DEPTH|AUX_ACCUM);
  auxInitPosition(0,0,300,300);
  auxInitWindow("Décomposition au niveau d'une interface");
  myinit();
  auxKeyFunc(AUX_U,keyPageUp) ;
  auxKeyFunc(AUX_u,keyPageUp) ;
  auxKeyFunc(AUX_D,keyPageDown) ;
  auxKeyFunc(AUX_d,keyPageDown) ;
  auxKeyFunc(AUX_LEFT,keyLeft) ;
  auxKeyFunc(AUX_RIGHT,keyRight) ;
  auxKeyFunc(AUX_UP,keyUp) ;
  auxKeyFunc(AUX_DOWN,keyDown) ;
  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_n,keyn) ;
  auxKeyFunc(AUX_N,keyN) ;
  auxReshapeFunc(myReshape);
  auxMainLoop(display);
}
WB01624_.gif (281 octets) RETOUR