simplifying

1. bind `m` to reset speed multiplier
2. using an object_t struct
3. get object parameters from a file
4. draw all planets and moons in one loop
This commit is contained in:
Volodymyr Patuta 2021-01-02 23:22:22 +01:00
parent 93afaab0c3
commit 34e979895e
2 changed files with 145 additions and 234 deletions

28
vars.txt Normal file
View File

@ -0,0 +1,28 @@
0 24.5 0 1 0 1 0 2 0 0 0
1 87.97 0 1 4.2 1 0 0.0881 59.0 0 1
1 224.7 0 1 7.9 1 0 0.177 243.75 -0.1773 -1
1 364.2425 0 1 10 1 0 0.185 1 -0.234 1
2 1 0 0 4.0 0 0 0.2 1 0 0
1 686.98 0 1 15.2 1 0 0.096 1.0416 -0.252 1
2 0.2325 0 0.1 10 0 0 0.2 0 0 0
2 1.5 0 0.1 25 0 0 0.1666 0 0 0
1 4382.91 0 1 30 1 0 2.062 0.416 -0.031 1
2 0.33 0 0.1 1 0 1 0.0893 0 0 0
2 2 0 0.1 -2.0 0 -1 0.076 0 0 0
2 3 0 0.1 -3 0 -1.5 0.111 0 0 0
2 5 0 0.1 4 0 0 0.2 0 0 0
1 10957.275 0 1 50.4 1 0 1.7544 0.4583 -0.267 1
2 0.2 0 0.1 1 0 -1 0.05 0 0 0
2 0.244 0 0.1 -2 0 -0.5 0.0556 0 0 0
2 0.3125 0 0.1 3 0 -2.5 0.0667 0 0 0
2 4.3 0 0.1 -4.0 0 -2.2 0.1 0 0 0
2 6.3 0 0.1 5 0 0 0.0714 0 0 0
1 30680.37 0 1 65 1 0 0.7463 0.7083 -0.978 0
2 1 0.01 0 0 3 -2.2 0.05 0 0 0
2 2 0.01 0 0 -4 -1.2 0.05 0 0 0
2 5 0.01 0 0 5.0 0 0.0588 0 0 0
2 7 0.01 0 0 6 -4.4 0.0588 0 0 0
1 60265.0125 0 1 75 1 0 0.722 0.6 -0.283 1
2 5 0 0.01 3 0 0 0.1 0 0 0
1 90580.14 0 1 85 1 0 0.03994 6.4 -0.119 1
2 5 0 0.01 3 0 0 0.0769 0 0 0

343
window.c
View File

@ -33,18 +33,14 @@ static void draw_object(float * nmv, float * projMat, surface_t * obj,
float ma, float mx, float my,
float tx, float ty, float tz, float s,
float ra, float rx, float ry);
static void get_params(void);
static int get_sign(float x, float y);
/*!\brief un identifiant pour l'écran (de dessin) */
static uint _screenId = 0;
// surface representing the Sun.
static surface_t * _sun;
// surface array representing 8 planets + pluto (dwarf planet).
static surface_t * _planet[9];
// surface array representing 18 moons of the planets.
static surface_t * _moon[18];
// obj contains all planets, the Sun, Pluto, all the moons and their parameters.
static object_t _obj[28];
/* des variable d'états pour activer/désactiver des options de rendu */
static int _use_tex = 1, _use_color = 0, _use_lighting = 1;
@ -115,7 +111,7 @@ int main(int argc, char ** argv) {
/*!\brief init de nos données, spécialement les trois surfaces
* utilisées dans ce code */
void init(void) {
uint id[9], sun_id, i, moon_id[18];
uint id[28], i;
int flags, initted;
flags = MIX_INIT_MP3;
@ -136,71 +132,71 @@ void init(void) {
fprintf(stderr, "Mix_PlayChannel: %s\n", Mix_GetError());
// create all spheres.
_sun = mkSphere(12, 12); /*ça fait 12x12x2 triangles !*/
for (i = 0; i < 18; ++i) {
_moon[i] = mkSphere(12, 12);
if (i < 9)
_planet[i] = mkSphere(12, 12);
for (i = 0; i < 28; ++i) {
_obj[i].s = mkSphere(12, 12);
}
// get all textures.
sun_id = getTexFromBMP("images/2k-sun.bmp");
id[0] = getTexFromBMP("images/2k-mercury.bmp");
id[1] = getTexFromBMP("images/2k-venus-surface.bmp");
id[2] = getTexFromBMP("images/2k-earth-daymap.bmp");
id[3] = getTexFromBMP("images/2k-mars.bmp");
id[4] = getTexFromBMP("images/2k-jupiter.bmp");
id[5] = getTexFromBMP("images/2k-saturn.bmp");
id[6] = getTexFromBMP("images/2k-uranus.bmp");
id[7] = getTexFromBMP("images/2k-neptune.bmp");
id[8] = getTexFromBMP("images/pluto.bmp");
id[0] = getTexFromBMP("images/2k-sun.bmp");
id[1] = getTexFromBMP("images/2k-mercury.bmp");
id[2] = getTexFromBMP("images/2k-venus-surface.bmp");
id[3] = getTexFromBMP("images/2k-earth-daymap.bmp");
id[4] = getTexFromBMP("images/2k-moon.bmp");
id[5] = getTexFromBMP("images/2k-mars.bmp");
id[6] = getTexFromBMP("images/moons/phobos.bmp");
id[7] = getTexFromBMP("images/moons/deimos.bmp");
id[8] = getTexFromBMP("images/2k-jupiter.bmp");
id[9] = getTexFromBMP("images/moons/io.bmp");
id[10] = getTexFromBMP("images/moons/europa.bmp");
id[11] = getTexFromBMP("images/moons/ganymede.bmp");
id[12] = getTexFromBMP("images/moons/callisto.bmp");
id[13] = getTexFromBMP("images/2k-saturn.bmp");
id[14] = getTexFromBMP("images/moons/enceladus.bmp");
id[15] = getTexFromBMP("images/moons/dione.bmp");
id[16] = getTexFromBMP("images/moons/rhea.bmp");
id[17] = getTexFromBMP("images/moons/titan.bmp");
id[18] = getTexFromBMP("images/moons/iapetus.bmp");
id[19] = getTexFromBMP("images/2k-uranus.bmp");
id[20] = getTexFromBMP("images/moons/ariel.bmp");
id[21] = getTexFromBMP("images/moons/umbriel.bmp");
id[22] = getTexFromBMP("images/moons/titania.bmp");
id[23] = getTexFromBMP("images/moons/oberon.bmp");
id[24] = getTexFromBMP("images/2k-neptune.bmp");
id[25] = getTexFromBMP("images/moons/triton.bmp");
id[26] = getTexFromBMP("images/pluto.bmp");
id[27] = getTexFromBMP("images/moons/charon.bmp");
// https://upload.wikimedia.org/wikipedia/commons/4/4f/Moons_of_solar_system_v7.jpg
// most of the biggest moons are here.
moon_id[0] = getTexFromBMP("images/2k-moon.bmp");
moon_id[1] = getTexFromBMP("images/moons/phobos.bmp");
moon_id[2] = getTexFromBMP("images/moons/deimos.bmp");
moon_id[3] = getTexFromBMP("images/moons/io.bmp");
moon_id[4] = getTexFromBMP("images/moons/europa.bmp");
moon_id[5] = getTexFromBMP("images/moons/ganymede.bmp");
moon_id[6] = getTexFromBMP("images/moons/callisto.bmp");
moon_id[7] = getTexFromBMP("images/moons/enceladus.bmp");
moon_id[8] = getTexFromBMP("images/moons/dione.bmp");
moon_id[9] = getTexFromBMP("images/moons/rhea.bmp");
moon_id[10] = getTexFromBMP("images/moons/titan.bmp");
moon_id[11] = getTexFromBMP("images/moons/iapetus.bmp");
moon_id[12] = getTexFromBMP("images/moons/ariel.bmp");
moon_id[13] = getTexFromBMP("images/moons/umbriel.bmp");
moon_id[14] = getTexFromBMP("images/moons/titania.bmp");
moon_id[15] = getTexFromBMP("images/moons/oberon.bmp");
moon_id[16] = getTexFromBMP("images/moons/triton.bmp");
moon_id[17] = getTexFromBMP("images/moons/charon.bmp");
// set texture to an object id and set all options.
setTexId(_sun, sun_id);
for (i = 0; i < 28; ++i) {
setTexId(_obj[i].s, id[i]);
disableSurfaceOption(_obj[i].s, SO_USE_COLOR);
if (_use_tex)
enableSurfaceOption(_sun, SO_USE_TEXTURE);
enableSurfaceOption(_obj[i].s, SO_USE_TEXTURE);
if (_use_lighting)
enableSurfaceOption(_sun, SO_USE_LIGHTING);
disableSurfaceOption(_sun, SO_USE_COLOR);
for (i = 0; i < 18; ++i) {
setTexId(_moon[i], moon_id[i]);
disableSurfaceOption(_moon[i], SO_USE_COLOR);
if (_use_tex)
enableSurfaceOption(_moon[i], SO_USE_TEXTURE);
if (_use_lighting)
enableSurfaceOption(_moon[i], SO_USE_LIGHTING);
if (i < 9) {
setTexId(_planet[i], id[i]);
disableSurfaceOption(_planet[i], SO_USE_COLOR);
if (_use_tex)
enableSurfaceOption(_planet[i], SO_USE_TEXTURE);
if (_use_lighting)
enableSurfaceOption(_planet[i], SO_USE_LIGHTING);
}
enableSurfaceOption(_obj[i].s, SO_USE_LIGHTING);
}
get_params();
atexit(sortie);
}
static void get_params(void) {
int i;
FILE * f;
f = fopen("vars.txt", "r");
for (i = 0; i < 28; ++i) {
fscanf(f, "%d %f %f %f %f %f %f %f %f %f %f", &_obj[i].id,
&_obj[i].vars[0], &_obj[i].vars[1], &_obj[i].vars[2], &_obj[i].vars[3], &_obj[i].vars[4],
&_obj[i].vars[5], &_obj[i].vars[6], &_obj[i].vars[7], &_obj[i].vars[8], &_obj[i].vars[9]);
// debug
/*fprintf(stderr, "%d %f %f %f %f %f %f %f %f %f %f\n", _obj[i].id,
_obj[i].vars[0], _obj[i].vars[1], _obj[i].vars[2], _obj[i].vars[3], _obj[i].vars[4],
_obj[i].vars[5], _obj[i].vars[6], _obj[i].vars[7], _obj[i].vars[8], _obj[i].vars[9]);*/
}
fclose(f);
}
// get sign for further move calculation.
static int get_sign(float x, float y) {
if (x > y)
@ -227,53 +223,53 @@ static void goto_obj(float * mvMat) {
switch (_p) {
case 1: // MERCURY
_a = 0; // reset angle to 0.
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 4.2f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(4.2f, 1.0f, 0.5f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[1].vars[3], _obj[1].vars[4], _obj[1].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[1].vars[3], _obj[1].vars[4], 0.5f);
break;
case 2: // VENUS
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 7.9f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(7.9f, 1.0f, 1.0f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[2].vars[3], _obj[2].vars[4], _obj[2].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[2].vars[3], _obj[2].vars[4], 1.0f);
break;
case 3: // EARTH
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 10.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(10.0f, 1.0f, 1.0f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[3].vars[3], _obj[3].vars[4], _obj[3].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[3].vars[3], _obj[3].vars[4], 1.0f);
break;
case 4: // MARS
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 15.2f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(15.2f, 1.0f, 0.5f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[5].vars[3], _obj[5].vars[4], _obj[5].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[5].vars[3], _obj[5].vars[4], 0.5f);
break;
case 5: // JUPITER
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 30.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(30.0f, 1.0f, 5.0f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[8].vars[3], _obj[8].vars[4], _obj[8].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[8].vars[3], _obj[8].vars[4], 8.0f);
break;
case 6: // SATURN
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 50.4f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(50.4f, 1.0f, 5.0f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[13].vars[3], _obj[13].vars[4], _obj[13].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[13].vars[3], _obj[13].vars[4], 8.0f);
break;
case 7: // URANUS
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 65.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(65.0f, 1.0f, 5.0f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[19].vars[3], _obj[19].vars[4], _obj[19].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[19].vars[3], _obj[19].vars[4], 5.0f);
break;
case 8: // NEPTUNE
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 75.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(75.0f, 1.0f, 4.0f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[24].vars[3], _obj[24].vars[4], _obj[24].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[24].vars[3], _obj[24].vars[4], 4.0f);
break;
case 9: // PLUTO
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 85.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(85.0f, 1.0f, 0.1f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[26].vars[3], _obj[26].vars[4], _obj[26].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[26].vars[3], _obj[26].vars[4], 0.4f);
break;
case 0: // SUN
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
move_to(0.0f, 1.0f, 10.0f);
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _obj[0].vars[3], _obj[0].vars[4], _obj[0].vars[5], 0.0f, 1.0f, 0.0f);
move_to(_obj[0].vars[3], _obj[0].vars[4], 10.0f);
break;
}
}
@ -292,10 +288,12 @@ static void draw_object(float * nmv, float * projMat, surface_t * obj,
/*!\brief la fonction appelée à chaque display. */
void draw(void) {
static double t0 = 0, t, dt;
int i;
float mvMat[16], projMat[16], nmv[16], cpy[16];
t = gl4dGetElapsedTime();
dt = (t - t0) / 1000.0;
t0 = t;
float mvMat[16], projMat[16], nmv[16], cpy[16];
/* effacer l'écran et le buffer de profondeur */
gl4dpClearScreen();
clearDepth();
@ -315,114 +313,24 @@ void draw(void) {
// SUN
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _sun, _r/24.5f, 0, 1, 0, 1, 0, 2, 0, 0, 0);
// MERCURY
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _planet[0], _a/87.97f, 0, 1, 4.2f, 1, 0, (2/227.0f)*10, _r/59.0f, 0, 1);
// VENUS
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _planet[1], _a/224.7f, 0, 1, 7.9f, 1, 0, (2/113.0f)*10, _r/243.75f, -0.1773f, -1);
// EARTH
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _planet[2], _a/365.2425f, 0, 1, 10.0f, 1, 0, (2/108.0f)*10, _r, -0.234f, 1);
// Moon
draw_object(nmv, projMat, _moon[0], 1, 0, 0, 4.0f, 0, 0, (1/5.0f), 1, 0, 0);
// MARS
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _planet[3], _a/686.98f, 0, 1, 15.2f, 1, 0, (2/208.0f)*10, _r/1.0416f, -0.252f, 1);
draw_object(nmv, projMat, _obj[0].s, _r/_obj[0].vars[0], _obj[0].vars[1], _obj[0].vars[2], _obj[0].vars[3],
_obj[0].vars[4], _obj[0].vars[5], _obj[0].vars[6], _obj[0].vars[7], _obj[0].vars[8], _obj[0].vars[9]);
for (i = 1; i < 28; ++i) {
if(_obj[i].id == 1) { // if object is a planet
memcpy(nmv, mvMat, sizeof nmv);
draw_object(nmv, projMat, _obj[i].s, _a/_obj[i].vars[0], _obj[i].vars[1], _obj[i].vars[2], _obj[i].vars[3],
_obj[i].vars[4], _obj[i].vars[5], _obj[i].vars[6], _r/_obj[i].vars[7], _obj[i].vars[8], _obj[i].vars[9]);
if (i <= 27) {
if (_obj[i+1].id == 2)
memcpy(cpy, nmv, sizeof cpy);
// Phobos
draw_object(nmv, projMat, _moon[1], _r*4.3f, 0, 0.1f, 10.0f, 0, 0, (1/5.0f), 0, 0, 0);
// Deimos
draw_object(cpy, projMat, _moon[2], _r/1.5f, 0, 0.1f, 25.0f, 0, 0, (1/6.0f), 0, 0, 0);
// JUPITER
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _planet[4], _a/(12 * 365.2425f), 0, 1, 30.0f, 1, 0, (2/9.7f)*10, _r/0.416f, -0.031f, 1);
memcpy(cpy, nmv, sizeof cpy);
// Io
draw_object(nmv, projMat, _moon[3], _r*3.0f, 0, 0.1f, 1.0f, 0, 1, (1/11.2f), 0, 0, 0);
// Europa
}
} else if (_obj[i].id == 2) { // if object is a moon
memcpy(nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[4], _r/2.0f, 0, 0.1f, -2.0f, 0, -1, (1/13.2f), 0, 0, 0);
// Ganymede
memcpy(nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[5], _r/3.0f, 0, 0.1f, -3.0f, 0, -1.5f, (1/9.0f), 0, 0, 0);
// Callisto
memcpy(nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[6], _r/5.0f, 0, 0.1f, 4.0f, 0, 0, (1/10.0f), 0, 0, 0);
// SATURN
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _planet[5], _a/(30 * 365.2425f), 0, 1, 50.4f, 1, 0, (2/11.4f)*10, _r/0.4583f, -0.267f, 1);
memcpy(cpy, nmv, sizeof cpy);
// Enceladus
draw_object(nmv, projMat, _moon[7], _r*5.0f, 0, 0.1f, 1.0f, 0, -1.0f, (1/20.0f), 0, 0, 0);
// Dione
memcpy(nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[8], _r*4.1f, 0, 0.1f, -2.0f, 0, -0.5f, (1/18.0f), 0, 0, 0);
// Rhea
memcpy(nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[9], _r*3.2f, 0, 0.1f, 3.0f, 0, -2.5f, (1/15.0f), 0, 0, 0);
// Titan
memcpy(nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[10], _r/4.3f, 0, 0.1f, -4.0f, 0, -2.2f, (1/10.0f), 0, 0, 0);
// Iapetus
memcpy(nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[11], _r/6.3f, 0, 0.1f, 5.0f, 0, 0, (1/14.0f), 0, 0, 0);
// URANUS
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _planet[6], _a/(84 * 365.2425f), 0, 1, 65.0f, 1, 0, (2/26.8f)*10, _r/0.7083f, -0.978f, 0);
memcpy(cpy, nmv, sizeof cpy);
// Ariel
draw_object(nmv, projMat, _moon[12], _r, 0.01f, 0, 0, 3.0f, -2.2f, (1/20.0f), 0, 0, 0);
// Umbriel
memcpy (nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[13], _r/2.0f, 0.01f, 0, 0, -4.0f, -1.2f, (1/20.0f), 0, 0, 0);
// Titania
memcpy (nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[14], _r/5.0f, 0.01f, 0, 0, 5.0f, 0, (1/17.0f), 0, 0, 0);
// Oberon
memcpy (nmv, cpy, sizeof nmv);
draw_object(nmv, projMat, _moon[15], _r/7.0f, 0.01f, 0, 0, 6.0f, -4.4f, (1/17.0f), 0, 0, 0);
// NEPTUNE
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _planet[7], _a/(165 * 365.2425f), 0, 1, 75.0f, 1, 0, (2/27.7f)*10, _r/0.6f, -0.283f, 1.0f);
// Triton
draw_object(nmv, projMat, _moon[16], _r/5.0f, 0, 0.01f, 3.0f, 0.0f, 0.0f, (1/10.0f), 0, 0, 0);
// PLUTO
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
draw_object(nmv, projMat, _planet[8], _a/(248 * 365.2425f), 0, 1, 85.0f, 1, 0, (2/500.7f)*10, _r/6.4f, -0.119f, 1.0f);
// Charon
draw_object(nmv, projMat, _moon[17], _r/5.0f, 0, 0.01f, 3.0f, 0.0f, 0.0f, (1/13.0f), 0, 0, 0);
draw_object(nmv, projMat, _obj[i].s, _r/_obj[i].vars[0], _obj[i].vars[1], _obj[i].vars[2], _obj[i].vars[3],
_obj[i].vars[4], _obj[i].vars[5], _obj[i].vars[6], _obj[i].vars[7], _obj[i].vars[8], _obj[i].vars[9]);
}
}
/* déclarer qu'on a changé (en bas niveau) des pixels du screen */
gl4dpScreenHasChanged();
@ -518,6 +426,9 @@ void key(int keycode) {
_movement = 1;
_overview = 0;
break;
case GL4DK_m:
_s = 1;
break;
case GL4DK_q:
exit(0);
break;
@ -614,54 +525,36 @@ void key(int keycode) {
case GL4DK_t: /* 't' la texture */
_use_tex = !_use_tex;
if(_use_tex) {
enableSurfaceOption(_sun, SO_USE_TEXTURE);
for (i = 0; i < 18; ++i) {
enableSurfaceOption(_moon[i], SO_USE_TEXTURE);
if (i < 9)
enableSurfaceOption(_planet[i], SO_USE_TEXTURE);
for (i = 0; i < 28; ++i) {
enableSurfaceOption(_obj[i].s, SO_USE_TEXTURE);
}
} else {
disableSurfaceOption(_sun, SO_USE_TEXTURE);
for (i = 0; i < 18; ++i) {
disableSurfaceOption(_moon[i], SO_USE_TEXTURE);
if (i < 9)
disableSurfaceOption(_planet[i], SO_USE_TEXTURE);
for (i = 0; i < 28; ++i) {
disableSurfaceOption(_obj[i].s, SO_USE_TEXTURE);
}
}
break;
case GL4DK_c: /* 'c' utiliser la couleur */
_use_color = !_use_color;
if(_use_color) {
enableSurfaceOption(_sun, SO_USE_COLOR);
for (i = 0; i < 18; ++i) {
enableSurfaceOption(_moon[i], SO_USE_COLOR);
if (i < 9)
enableSurfaceOption(_planet[i], SO_USE_COLOR);
for (i = 0; i < 28; ++i) {
enableSurfaceOption(_obj[i].s, SO_USE_COLOR);
}
} else {
disableSurfaceOption(_sun, SO_USE_COLOR);
for (i = 0; i < 18; ++i) {
disableSurfaceOption(_moon[i], SO_USE_COLOR);
if (i < 9)
disableSurfaceOption(_planet[i], SO_USE_COLOR);
for (i = 0; i < 28; ++i) {
disableSurfaceOption(_obj[i].s, SO_USE_COLOR);
}
}
break;
case GL4DK_l: /* 'l' utiliser l'ombrage par la méthode Gouraud */
_use_lighting = !_use_lighting;
if(_use_lighting) {
enableSurfaceOption(_sun, SO_USE_LIGHTING);
for (i = 0; i < 18; ++i) {
enableSurfaceOption(_moon[i], SO_USE_LIGHTING);
if (i < 9)
enableSurfaceOption(_planet[i], SO_USE_LIGHTING);
for (i = 0; i < 28; ++i) {
enableSurfaceOption(_obj[i].s, SO_USE_LIGHTING);
}
} else {
disableSurfaceOption(_sun, SO_USE_LIGHTING);
for (i = 0; i < 18; ++i) {
disableSurfaceOption(_moon[i], SO_USE_LIGHTING);
if (i < 9)
disableSurfaceOption(_planet[i], SO_USE_LIGHTING);
for (i = 0; i < 28; ++i) {
disableSurfaceOption(_obj[i].s, SO_USE_LIGHTING);
}
}
break;
@ -696,20 +589,10 @@ void sortie(void) {
int i;
Mix_CloseAudio();
Mix_Quit();
if (_sun) {
freeSurface(_sun);
_sun = NULL;
}
for (i = 0; i < 18; ++i) {
if(_moon[i]){
freeSurface(_moon[i]);
_moon[i] = NULL;
}
if (i < 9) {
if (_planet[i]){
freeSurface(_planet[i]);
_planet[i] = NULL;
}
for (i = 0; i < 28; ++i) {
if(_obj[i].s){
freeSurface(_obj[i].s);
_obj[i].s = NULL;
}
}
if (bsound)