planets in a vector, easier to manipulate
This commit is contained in:
parent
0ae64708ab
commit
81462a084c
81
window.c
81
window.c
@ -32,9 +32,9 @@ static uint _screenId = 0;
|
|||||||
|
|
||||||
/*!\brief une surface représentant une sphere */
|
/*!\brief une surface représentant une sphere */
|
||||||
static surface_t * _sun = NULL;
|
static surface_t * _sun = NULL;
|
||||||
static surface_t * _mercury = NULL;
|
static surface_t * _planet[9] = {NULL, NULL, NULL,
|
||||||
static surface_t * _venus = NULL;
|
NULL, NULL, NULL,
|
||||||
static surface_t * _earth = NULL;
|
NULL, NULL, NULL};
|
||||||
|
|
||||||
/* des variable d'états pour activer/désactiver des options de rendu */
|
/* des variable d'états pour activer/désactiver des options de rendu */
|
||||||
static int _use_tex = 1, _use_color = 0, _use_lighting = 1;
|
static int _use_tex = 1, _use_color = 0, _use_lighting = 1;
|
||||||
@ -94,37 +94,37 @@ void init(void) {
|
|||||||
_sun = mkSphere(12, 12, 1); /*ça fait 12x12x2 trianles !*/
|
_sun = mkSphere(12, 12, 1); /*ça fait 12x12x2 trianles !*/
|
||||||
/* on change les couleurs de surfaces */
|
/* on change les couleurs de surfaces */
|
||||||
/*_sun->dcolor = g; */
|
/*_sun->dcolor = g; */
|
||||||
_mercury = mkSphere(12, 12, (1/227.0f) * 12.0f);
|
_planet[0] = mkSphere(12, 12, (1/227.0f) * 12.0f);
|
||||||
_venus = mkSphere(12, 12, (1/113.0f) * 12.0f);
|
_planet[1] = mkSphere(12, 12, (1/113.0f) * 12.0f);
|
||||||
_earth = mkSphere(12, 12, (1/108.0f) * 12.0f);
|
_planet[2] = mkSphere(12, 12, (1/108.0f) * 12.0f);
|
||||||
|
|
||||||
sun_id = getTexFromBMP("images/2k-sun.bmp");
|
sun_id = getTexFromBMP("images/2k-sun.bmp");
|
||||||
mercury_id = getTexFromBMP("images/2k-mercury.bmp");
|
mercury_id = getTexFromBMP("images/2k-mercury.bmp");
|
||||||
venus_id = getTexFromBMP("images/2k-venus-surface.bmp");
|
venus_id = getTexFromBMP("images/2k-venus-surface.bmp");
|
||||||
earth_id = getTexFromBMP("images/2k-earth-daymap.bmp");
|
earth_id = getTexFromBMP("images/2k-earth-daymap.bmp");
|
||||||
setTexId(_sun, sun_id);
|
setTexId(_sun, sun_id);
|
||||||
setTexId(_mercury, mercury_id);
|
setTexId(_planet[0], mercury_id);
|
||||||
setTexId(_venus, venus_id);
|
setTexId(_planet[1], venus_id);
|
||||||
setTexId(_earth, earth_id);
|
setTexId(_planet[2], earth_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(_mercury, SO_USE_TEXTURE);
|
|
||||||
enableSurfaceOption(_sun, SO_USE_TEXTURE);
|
enableSurfaceOption(_sun, SO_USE_TEXTURE);
|
||||||
enableSurfaceOption(_venus, SO_USE_TEXTURE);
|
enableSurfaceOption(_planet[0], SO_USE_TEXTURE);
|
||||||
enableSurfaceOption(_earth, SO_USE_TEXTURE);
|
enableSurfaceOption(_planet[1], SO_USE_TEXTURE);
|
||||||
|
enableSurfaceOption(_planet[2], 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(_sun, SO_USE_LIGHTING);
|
enableSurfaceOption(_sun, SO_USE_LIGHTING);
|
||||||
enableSurfaceOption(_mercury, SO_USE_LIGHTING);
|
enableSurfaceOption(_planet[0], SO_USE_LIGHTING);
|
||||||
enableSurfaceOption(_venus, SO_USE_LIGHTING);
|
enableSurfaceOption(_planet[1], SO_USE_LIGHTING);
|
||||||
enableSurfaceOption(_earth, SO_USE_LIGHTING);
|
enableSurfaceOption(_planet[2], SO_USE_LIGHTING);
|
||||||
}
|
}
|
||||||
disableSurfaceOption(_sun, SO_USE_COLOR);
|
disableSurfaceOption(_sun, SO_USE_COLOR);
|
||||||
disableSurfaceOption(_mercury, SO_USE_COLOR);
|
disableSurfaceOption(_planet[0], SO_USE_COLOR);
|
||||||
disableSurfaceOption(_venus, SO_USE_COLOR);
|
disableSurfaceOption(_planet[1], SO_USE_COLOR);
|
||||||
disableSurfaceOption(_earth, SO_USE_COLOR);
|
disableSurfaceOption(_planet[2], SO_USE_COLOR);
|
||||||
atexit(sortie);
|
atexit(sortie);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,19 +164,19 @@ void draw(void) {
|
|||||||
rotate(nmv, a, 0.0f, 1.0f, 0.0f); // orbit mouvement
|
rotate(nmv, a, 0.0f, 1.0f, 0.0f); // orbit mouvement
|
||||||
translate(nmv, 10.0f, 1.0f, 0.0f);
|
translate(nmv, 10.0f, 1.0f, 0.0f);
|
||||||
rotate(nmv, a, 0.0f, 1.0f, 0.0f); // rotation
|
rotate(nmv, a, 0.0f, 1.0f, 0.0f); // rotation
|
||||||
transform_n_raster(_mercury, nmv, projMat);
|
transform_n_raster(_planet[0], nmv, projMat);
|
||||||
|
|
||||||
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
||||||
rotate(nmv, a - 10, 0.0f, 1.0f, 0.0f); // orbit mouvement
|
rotate(nmv, a - 10, 0.0f, 1.0f, 0.0f); // orbit mouvement
|
||||||
translate(nmv, 20.0f, 1.0f, 0.0f);
|
translate(nmv, 20.0f, 1.0f, 0.0f);
|
||||||
rotate(nmv, a, 0.0f, -1.0f, 0.0f); // rotation anti-clockwise
|
rotate(nmv, a, 0.0f, -1.0f, 0.0f); // rotation anti-clockwise
|
||||||
transform_n_raster(_venus, nmv, projMat);
|
transform_n_raster(_planet[1], nmv, projMat);
|
||||||
|
|
||||||
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
||||||
rotate(nmv, a - 20, 0.0f, 1.0f, 0.0f); // orbit mouvement
|
rotate(nmv, a - 20, 0.0f, 1.0f, 0.0f); // orbit mouvement
|
||||||
translate(nmv, 30.0f, 1.0f, 0.0f);
|
translate(nmv, 30.0f, 1.0f, 0.0f);
|
||||||
rotate(nmv, a, 0.0f, 1.0f, 0.0f); // rotation
|
rotate(nmv, a, 0.0f, 1.0f, 0.0f); // rotation
|
||||||
transform_n_raster(_earth, nmv, projMat);
|
transform_n_raster(_planet[2], 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();
|
||||||
@ -234,30 +234,42 @@ void key(int keycode) {
|
|||||||
_use_tex = !_use_tex;
|
_use_tex = !_use_tex;
|
||||||
if(_use_tex) {
|
if(_use_tex) {
|
||||||
enableSurfaceOption(_sun, SO_USE_TEXTURE);
|
enableSurfaceOption(_sun, SO_USE_TEXTURE);
|
||||||
enableSurfaceOption(_mercury, SO_USE_TEXTURE);
|
enableSurfaceOption(_planet[0], SO_USE_TEXTURE);
|
||||||
|
enableSurfaceOption(_planet[1], SO_USE_TEXTURE);
|
||||||
|
enableSurfaceOption(_planet[2], SO_USE_TEXTURE);
|
||||||
} else {
|
} else {
|
||||||
disableSurfaceOption(_sun, SO_USE_TEXTURE);
|
disableSurfaceOption(_sun, SO_USE_TEXTURE);
|
||||||
disableSurfaceOption(_mercury, SO_USE_TEXTURE);
|
disableSurfaceOption(_planet[0], SO_USE_TEXTURE);
|
||||||
|
disableSurfaceOption(_planet[1], SO_USE_TEXTURE);
|
||||||
|
disableSurfaceOption(_planet[2], 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(_sun, SO_USE_COLOR);
|
enableSurfaceOption(_sun, SO_USE_COLOR);
|
||||||
enableSurfaceOption(_mercury, SO_USE_COLOR);
|
enableSurfaceOption(_planet[0], SO_USE_COLOR);
|
||||||
|
enableSurfaceOption(_planet[1], SO_USE_COLOR);
|
||||||
|
enableSurfaceOption(_planet[2], SO_USE_COLOR);
|
||||||
} else {
|
} else {
|
||||||
disableSurfaceOption(_sun, SO_USE_COLOR);
|
disableSurfaceOption(_sun, SO_USE_COLOR);
|
||||||
disableSurfaceOption(_mercury, SO_USE_COLOR);
|
disableSurfaceOption(_planet[0], SO_USE_COLOR);
|
||||||
|
disableSurfaceOption(_planet[1], SO_USE_COLOR);
|
||||||
|
disableSurfaceOption(_planet[2], 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(_sun, SO_USE_LIGHTING);
|
enableSurfaceOption(_sun, SO_USE_LIGHTING);
|
||||||
enableSurfaceOption(_mercury, SO_USE_LIGHTING);
|
enableSurfaceOption(_planet[0], SO_USE_LIGHTING);
|
||||||
|
enableSurfaceOption(_planet[1], SO_USE_LIGHTING);
|
||||||
|
enableSurfaceOption(_planet[2], SO_USE_LIGHTING);
|
||||||
} else {
|
} else {
|
||||||
disableSurfaceOption(_sun, SO_USE_LIGHTING);
|
disableSurfaceOption(_sun, SO_USE_LIGHTING);
|
||||||
disableSurfaceOption(_mercury, SO_USE_LIGHTING);
|
disableSurfaceOption(_planet[0], SO_USE_LIGHTING);
|
||||||
|
disableSurfaceOption(_planet[1], SO_USE_LIGHTING);
|
||||||
|
disableSurfaceOption(_planet[2], SO_USE_LIGHTING);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
@ -281,21 +293,16 @@ static void mouse(int button, int state, int x, int y) {
|
|||||||
|
|
||||||
/*!\brief à appeler à la sortie du programme. */
|
/*!\brief à appeler à la sortie du programme. */
|
||||||
void sortie(void) {
|
void sortie(void) {
|
||||||
if(_mercury) {
|
int i;
|
||||||
freeSurface(_mercury);
|
|
||||||
_mercury = NULL;
|
|
||||||
}
|
|
||||||
if(_sun) {
|
if(_sun) {
|
||||||
freeSurface(_sun);
|
freeSurface(_sun);
|
||||||
_sun = NULL;
|
_sun = NULL;
|
||||||
}
|
}
|
||||||
if(_venus) {
|
for(i = 0; i < 9; ++i) {
|
||||||
freeSurface(_venus);
|
if(_planet[i]){
|
||||||
_venus = NULL;
|
freeSurface(_planet[i]);
|
||||||
|
_planet[i] = NULL;
|
||||||
}
|
}
|
||||||
if(_earth) {
|
|
||||||
freeSurface(_earth);
|
|
||||||
_earth = NULL;
|
|
||||||
}
|
}
|
||||||
/* libère tous les objets produits par GL4Dummies, ici
|
/* libère tous les objets produits par GL4Dummies, ici
|
||||||
* principalement les screen */
|
* principalement les screen */
|
||||||
|
Loading…
Reference in New Issue
Block a user