left only a sphere
This commit is contained in:
		
							parent
							
								
									7992c2761a
								
							
						
					
					
						commit
						a49f484272
					
				
							
								
								
									
										68
									
								
								window.c
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								window.c
									
									
									
									
									
								
							@ -28,10 +28,6 @@ static void sortie(void);
 | 
				
			|||||||
/*!\brief un identifiant pour l'écran (de dessin) */
 | 
					/*!\brief un identifiant pour l'écran (de dessin) */
 | 
				
			||||||
static GLuint _screenId = 0;
 | 
					static GLuint _screenId = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*!\brief une surface représentant un quadrilatère */
 | 
					 | 
				
			||||||
static surface_t * _quad = NULL;
 | 
					 | 
				
			||||||
/*!\brief une surface représentant un cube */
 | 
					 | 
				
			||||||
static surface_t * _cube = NULL;
 | 
					 | 
				
			||||||
/*!\brief une surface représentant une sphere */
 | 
					/*!\brief une surface représentant une sphere */
 | 
				
			||||||
static surface_t * _sphere = NULL;
 | 
					static surface_t * _sphere = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -39,7 +35,8 @@ static surface_t * _sphere = NULL;
 | 
				
			|||||||
static int _use_tex = 1, _use_color = 1, _use_lighting = 1;
 | 
					static int _use_tex = 1, _use_color = 1, _use_lighting = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*!\brief on peut bouger la caméra vers le haut et vers le bas avec cette variable */
 | 
					/*!\brief on peut bouger la caméra vers le haut et vers le bas avec cette variable */
 | 
				
			||||||
static float _ycam = 3.0f;
 | 
					static float _ycam = 1.0f;
 | 
				
			||||||
 | 
					static float _xcam = 1.0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*!\brief paramètre l'application et lance la boucle infinie. */
 | 
					/*!\brief paramètre l'application et lance la boucle infinie. */
 | 
				
			||||||
int main(int argc, char ** argv) {
 | 
					int main(int argc, char ** argv) {
 | 
				
			||||||
@ -75,33 +72,21 @@ void init(void) {
 | 
				
			|||||||
  GLuint id;
 | 
					  GLuint id;
 | 
				
			||||||
  vec4 r = {1, 0, 0, 1}, g = {0, 1, 0, 1}, b = {0, 0, 1, 1};
 | 
					  vec4 r = {1, 0, 0, 1}, g = {0, 1, 0, 1}, b = {0, 0, 1, 1};
 | 
				
			||||||
  /* on créé nos trois type de surfaces */
 | 
					  /* on créé nos trois type de surfaces */
 | 
				
			||||||
  _quad   =   mkQuad();       /* ça fait 2 triangles        */
 | 
					 | 
				
			||||||
  _cube   =   mkCube();       /* ça fait 2x6 triangles      */
 | 
					 | 
				
			||||||
  _sphere = mkSphere(12, 12); /* ça fait 12x12x2 trianles ! */
 | 
					  _sphere = mkSphere(12, 12); /* ça fait 12x12x2 trianles ! */
 | 
				
			||||||
  /* on change les couleurs de surfaces */
 | 
					  /* on change les couleurs de surfaces */
 | 
				
			||||||
  _quad->dcolor = r; _cube->dcolor = b; _sphere->dcolor = g; 
 | 
					  _sphere->dcolor = g; 
 | 
				
			||||||
  /* on leur rajoute la même texture */
 | 
					  /* on leur rajoute la même texture */
 | 
				
			||||||
  id = getTexFromBMP("images/tex.bmp");
 | 
					  id = getTexFromBMP("images/2k-jupiter.bmp");
 | 
				
			||||||
  setTexId(  _quad, id);
 | 
					 | 
				
			||||||
  setTexId(  _cube, id);
 | 
					 | 
				
			||||||
  setTexId(_sphere, id);
 | 
					  setTexId(_sphere, id);
 | 
				
			||||||
  /* si _use_tex != 0, on active l'utilisation de la texture pour les
 | 
					  /* si _use_tex != 0, on active l'utilisation de la texture pour les
 | 
				
			||||||
   * trois */
 | 
					   * trois */
 | 
				
			||||||
  if(_use_tex) {
 | 
					  if(_use_tex) {
 | 
				
			||||||
    enableSurfaceOption(  _quad, SO_USE_TEXTURE);
 | 
					 | 
				
			||||||
    enableSurfaceOption(  _cube, SO_USE_TEXTURE);
 | 
					 | 
				
			||||||
    enableSurfaceOption(_sphere, SO_USE_TEXTURE);
 | 
					    enableSurfaceOption(_sphere, SO_USE_TEXTURE);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  /* si _use_lighting != 0, on active l'ombrage */
 | 
					  /* si _use_lighting != 0, on active l'ombrage */
 | 
				
			||||||
  if(_use_lighting) {
 | 
					  if(_use_lighting) {
 | 
				
			||||||
    enableSurfaceOption(  _quad, SO_USE_LIGHTING);
 | 
					 | 
				
			||||||
    enableSurfaceOption(  _cube, SO_USE_LIGHTING);
 | 
					 | 
				
			||||||
    enableSurfaceOption(_sphere, SO_USE_LIGHTING);
 | 
					    enableSurfaceOption(_sphere, SO_USE_LIGHTING);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  /* on désactive le back cull face pour le quadrilatère, ainsi on
 | 
					 | 
				
			||||||
   * peut voir son arrière quand le lighting est inactif */
 | 
					 | 
				
			||||||
  disableSurfaceOption(_quad, SO_CULL_BACKFACES);
 | 
					 | 
				
			||||||
  /* mettre en place la fonction à appeler en cas de sortie */
 | 
					 | 
				
			||||||
  atexit(sortie);
 | 
					  atexit(sortie);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -120,20 +105,10 @@ void draw(void) {
 | 
				
			|||||||
  /* charger la matrice identité dans model-view */
 | 
					  /* charger la matrice identité dans model-view */
 | 
				
			||||||
  MIDENTITY(mvMat);
 | 
					  MIDENTITY(mvMat);
 | 
				
			||||||
  /* on place la caméra en arrière-haut, elle regarde le centre de la scène */
 | 
					  /* on place la caméra en arrière-haut, elle regarde le centre de la scène */
 | 
				
			||||||
  lookAt(mvMat, 0, _ycam, 10, 0, 0, 0, 0, 1, 0);
 | 
					  lookAt(mvMat, _xcam, _ycam, 10, 0, 0, 0, 0, 1, 0);
 | 
				
			||||||
  /* le quadrilatère est mis à gauche et tourne autour de son axe x */
 | 
					 | 
				
			||||||
  memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
 | 
					 | 
				
			||||||
  translate(nmv, -3.0f, 0.0f, 0.0f);
 | 
					 | 
				
			||||||
  rotate(nmv, a, 1.0f, 0.0f, 0.0f);
 | 
					 | 
				
			||||||
  transform_n_raster(_quad, nmv, projMat);
 | 
					 | 
				
			||||||
  /* le cube est mis à droite et tourne autour de son axe z */
 | 
					 | 
				
			||||||
  memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
 | 
					 | 
				
			||||||
  translate(nmv, 3.0f, 0.0f, 0.0f);
 | 
					 | 
				
			||||||
  rotate(nmv, a, 0.0f, 0.0f, 1.0f);
 | 
					 | 
				
			||||||
  transform_n_raster(_cube, nmv, projMat);
 | 
					 | 
				
			||||||
  /* la sphère est laissée au centre et tourne autour de son axe y */
 | 
					  /* la sphère est laissée au centre et tourne autour de son axe y */
 | 
				
			||||||
  memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
 | 
					  memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
 | 
				
			||||||
  rotate(nmv, a, 0.0f, 1.0f, 0.0f);
 | 
					  /*rotate(nmv, a, 0.0f, 1.0f, 0.0f);*/
 | 
				
			||||||
  transform_n_raster(_sphere, nmv, projMat);
 | 
					  transform_n_raster(_sphere, nmv, projMat);
 | 
				
			||||||
  /* déclarer qu'on a changé (en bas niveau) des pixels du screen  */
 | 
					  /* déclarer qu'on a changé (en bas niveau) des pixels du screen  */
 | 
				
			||||||
  gl4dpScreenHasChanged();
 | 
					  gl4dpScreenHasChanged();
 | 
				
			||||||
@ -146,44 +121,38 @@ void draw(void) {
 | 
				
			|||||||
void key(int keycode) {
 | 
					void key(int keycode) {
 | 
				
			||||||
  switch(keycode) {
 | 
					  switch(keycode) {
 | 
				
			||||||
  case GL4DK_UP:
 | 
					  case GL4DK_UP:
 | 
				
			||||||
    _ycam += 0.05f;
 | 
					    _ycam += 0.55f;
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  case GL4DK_DOWN:
 | 
					  case GL4DK_DOWN:
 | 
				
			||||||
    _ycam -= 0.05f;
 | 
					    _ycam -= 0.55f;
 | 
				
			||||||
 | 
					    break;
 | 
				
			||||||
 | 
						case GL4DK_RIGHT:
 | 
				
			||||||
 | 
						_xcam += 0.55f;
 | 
				
			||||||
 | 
						break;
 | 
				
			||||||
 | 
						case GL4DK_LEFT:
 | 
				
			||||||
 | 
						_xcam -= 0.55f;
 | 
				
			||||||
	break;
 | 
						break;
 | 
				
			||||||
  case GL4DK_t: /* 't' la texture */
 | 
					  case GL4DK_t: /* 't' la texture */
 | 
				
			||||||
    _use_tex = !_use_tex;
 | 
					    _use_tex = !_use_tex;
 | 
				
			||||||
    if(_use_tex) {
 | 
					    if(_use_tex) {
 | 
				
			||||||
      enableSurfaceOption(  _quad, SO_USE_TEXTURE);
 | 
					 | 
				
			||||||
      enableSurfaceOption(  _cube, SO_USE_TEXTURE);
 | 
					 | 
				
			||||||
      enableSurfaceOption(_sphere, SO_USE_TEXTURE);
 | 
					      enableSurfaceOption(_sphere, SO_USE_TEXTURE);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      disableSurfaceOption(  _quad, SO_USE_TEXTURE);
 | 
					 | 
				
			||||||
      disableSurfaceOption(  _cube, SO_USE_TEXTURE);
 | 
					 | 
				
			||||||
      disableSurfaceOption(_sphere, SO_USE_TEXTURE);
 | 
					      disableSurfaceOption(_sphere, SO_USE_TEXTURE);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  case GL4DK_c: /* 'c' utiliser la couleur */
 | 
					  case GL4DK_c: /* 'c' utiliser la couleur */
 | 
				
			||||||
    _use_color = !_use_color;
 | 
					    _use_color = !_use_color;
 | 
				
			||||||
    if(_use_color) {
 | 
					    if(_use_color) {
 | 
				
			||||||
      enableSurfaceOption(  _quad, SO_USE_COLOR);
 | 
					 | 
				
			||||||
      enableSurfaceOption(  _cube, SO_USE_COLOR);
 | 
					 | 
				
			||||||
      enableSurfaceOption(_sphere, SO_USE_COLOR);
 | 
					      enableSurfaceOption(_sphere, SO_USE_COLOR);
 | 
				
			||||||
    } else { 
 | 
					    } else { 
 | 
				
			||||||
      disableSurfaceOption(  _quad, SO_USE_COLOR);
 | 
					 | 
				
			||||||
      disableSurfaceOption(  _cube, SO_USE_COLOR);
 | 
					 | 
				
			||||||
      disableSurfaceOption(_sphere, SO_USE_COLOR);
 | 
					      disableSurfaceOption(_sphere, SO_USE_COLOR);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  case GL4DK_l: /* 'l' utiliser l'ombrage par la méthode Gouraud */
 | 
					  case GL4DK_l: /* 'l' utiliser l'ombrage par la méthode Gouraud */
 | 
				
			||||||
    _use_lighting = !_use_lighting;
 | 
					    _use_lighting = !_use_lighting;
 | 
				
			||||||
    if(_use_lighting) {
 | 
					    if(_use_lighting) {
 | 
				
			||||||
      enableSurfaceOption(  _quad, SO_USE_LIGHTING);
 | 
					 | 
				
			||||||
      enableSurfaceOption(  _cube, SO_USE_LIGHTING);
 | 
					 | 
				
			||||||
      enableSurfaceOption(_sphere, SO_USE_LIGHTING);
 | 
					      enableSurfaceOption(_sphere, SO_USE_LIGHTING);
 | 
				
			||||||
    } else { 
 | 
					    } else { 
 | 
				
			||||||
      disableSurfaceOption(  _quad, SO_USE_LIGHTING);
 | 
					 | 
				
			||||||
      disableSurfaceOption(  _cube, SO_USE_LIGHTING);
 | 
					 | 
				
			||||||
      disableSurfaceOption(_sphere, SO_USE_LIGHTING);
 | 
					      disableSurfaceOption(_sphere, SO_USE_LIGHTING);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
@ -193,15 +162,6 @@ void key(int keycode) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/*!\brief à appeler à la sortie du programme. */
 | 
					/*!\brief à appeler à la sortie du programme. */
 | 
				
			||||||
void sortie(void) {
 | 
					void sortie(void) {
 | 
				
			||||||
  /* on libère nos trois surfaces */
 | 
					 | 
				
			||||||
  if(_quad) {
 | 
					 | 
				
			||||||
    freeSurface(_quad);
 | 
					 | 
				
			||||||
    _quad = NULL;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if(_cube) {
 | 
					 | 
				
			||||||
    freeSurface(_cube);
 | 
					 | 
				
			||||||
    _cube = NULL;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  if(_sphere) {
 | 
					  if(_sphere) {
 | 
				
			||||||
    freeSurface(_sphere);
 | 
					    freeSurface(_sphere);
 | 
				
			||||||
    _sphere = NULL;
 | 
					    _sphere = NULL;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user