solar_system/window.c

575 lines
16 KiB
C
Raw Normal View History

2020-12-12 22:25:54 +01:00
/*!\file window.c
* \brief Utilisation du raster "maison" pour finaliser le pipeline de
* rendu 3D. Ici on peut voir les géométries disponibles.
* \author Farès BELHADJ, amsi@up8.edu
* \date December 4, 2020.
* \todo pour les étudiant(e)s : changer la variation de l'angle de
* rotation pour qu'il soit dépendant du temps et non du framerate
*/
#include <assert.h>
/* inclusion des entêtes de fonctions de gestion de primitives simples
* de dessin. La lettre p signifie aussi bien primitive que
* pédagogique. */
#include <GL4D/gl4dp.h>
/* inclure notre bibliothèque "maison" de rendu */
#include "moteur.h"
/* inclusion des entêtes de fonctions de création et de gestion de
* fenêtres système ouvrant un contexte favorable à GL4dummies. Cette
* partie est dépendante de la bibliothèque SDL2 */
#include <GL4D/gl4duw_SDL2.h>
2020-12-31 14:10:18 +01:00
#include <SDL_mixer.h>
2020-12-12 22:25:54 +01:00
/* protos de fonctions locales (static) */
static void init(void);
static void draw(void);
static void key(int keycode);
static void sortie(void);
2020-12-19 16:56:01 +01:00
static void pmotion(int x, int y);
static void mouse(int button, int state, int x, int y);
2020-12-28 15:39:22 +01:00
static void goto_obj(float * mvMat);
static void move_to(float posx, float posy , float posz);
2021-01-01 16:13:34 +01:00
static void draw_object(float * nmv, float * projMat, surface_t * obj,
float ma, float mx, float my,
2021-01-01 16:13:34 +01:00
float tx, float ty, float tz, float s,
float ra, float rx, float ry);
static void get_params(void);
2020-12-28 15:39:22 +01:00
static int get_sign(float x, float y);
2020-12-12 22:25:54 +01:00
/*!\brief un identifiant pour l'écran (de dessin) */
2020-12-19 18:14:39 +01:00
static uint _screenId = 0;
2020-12-12 22:25:54 +01:00
// obj contains all planets, the Sun, Pluto, all the moons and their parameters.
static object_t _obj[28];
2020-12-12 22:25:54 +01:00
/* des variable d'états pour activer/désactiver des options de rendu */
2020-12-12 22:49:18 +01:00
static int _use_tex = 1, _use_color = 0, _use_lighting = 1;
2020-12-12 22:25:54 +01:00
2020-12-18 08:12:23 +01:00
typedef struct cam_t cam_t;
2020-12-29 01:32:15 +01:00
// camera structure, borrowed from sample3d_01-1.6 of GL4Dummies samples.
2020-12-18 08:12:23 +01:00
struct cam_t {
2020-12-19 16:56:01 +01:00
float x, y, z;
float theta;
2020-12-18 08:12:23 +01:00
};
static cam_t _cam = {0, 1.0f, 10, 0};
2020-12-18 08:12:23 +01:00
2020-12-29 01:32:15 +01:00
// movement speed.
2020-12-19 16:56:01 +01:00
static float _v = 0.1f;
2020-12-12 22:25:54 +01:00
2020-12-29 01:32:15 +01:00
// window size.
static int _wW = 1200, _wH = 900;
2020-12-18 08:12:23 +01:00
2020-12-29 01:32:15 +01:00
// middle of the window.
static int _xm = 600, _ym = 450;
static int _pause = 0; // boolean value for the pause.
static int _movement = 1; // boolean to allow movement.
2020-12-31 15:18:38 +01:00
static int _overview = 0; // boolean to toggle overview (view from the top).
2020-12-29 01:32:15 +01:00
static int _p = -1; // the object (sun, planets, pluto) number to move.
2020-12-31 15:18:38 +01:00
static float _s = 1.0f; // multiplier for angle (for speeding planets movement and rotation).
2020-12-29 01:32:15 +01:00
static float _a = 0.0f; // rotation angle.
2021-01-01 16:13:34 +01:00
static float _r = 0.0f; // -//-
static Mix_Chunk * bsound; // background sound.
2020-12-31 14:10:18 +01:00
2020-12-12 22:25:54 +01:00
/*!\brief paramètre l'application et lance la boucle infinie. */
int main(int argc, char ** argv) {
2020-12-31 14:10:18 +01:00
if (SDL_Init(SDL_INIT_AUDIO) == -1) {
fprintf(stderr, "SDL_Init: %s\n,", Mix_GetError());
exit(3);
}
2020-12-13 12:04:32 +01:00
/* tentative de création d'une fenêtre pour GL4Dummies */
if (!gl4duwCreateWindow(argc, argv, /* args du programme */
2020-12-13 12:04:32 +01:00
"Solar System", /* titre */
2020-12-19 16:56:01 +01:00
10, 10, _wW, _wH, /* x, y, largeur, heuteur */
2020-12-13 12:04:32 +01:00
GL4DW_SHOWN) /* état visible */) {
/* ici si échec de la création souvent lié à un problème d'absence
* de contexte graphique ou d'impossibilité d'ouverture d'un
* contexte OpenGL (au moins 3.2) */
return 1;
}
/* Pour forcer la désactivation de la synchronisation verticale */
SDL_GL_SetSwapInterval(0);
init();
/* création d'un screen GL4Dummies (texture dans laquelle nous
* pouvons dessiner) aux dimensions de la fenêtre */
_screenId = gl4dpInitScreen();
/* mettre en place la fonction d'interception clavier */
gl4duwMouseFunc(mouse);
2020-12-13 12:04:32 +01:00
gl4duwKeyDownFunc(key);
2020-12-19 16:56:01 +01:00
gl4duwPassiveMotionFunc(pmotion);
2020-12-13 12:04:32 +01:00
/* mettre en place la fonction de display */
gl4duwDisplayFunc(draw);
/* boucle infinie pour éviter que le programme ne s'arrête et ferme
* la fenêtre immédiatement */
2020-12-31 14:10:18 +01:00
2020-12-13 12:04:32 +01:00
gl4duwMainLoop();
return 0;
2020-12-12 22:25:54 +01:00
}
/*!\brief init de nos données, spécialement les trois surfaces
* utilisées dans ce code */
void init(void) {
uint id[28], i;
2020-12-31 15:18:38 +01:00
int flags, initted;
flags = MIX_INIT_MP3;
initted = Mix_Init(flags);
2020-12-31 14:10:18 +01:00
if ((initted & flags) != flags) {
fprintf(stderr, "Mix_Init: Failed to init required mp3 support!\n");
fprintf(stderr, "Mix_Init: %s\n,", Mix_GetError());
exit(2);
}
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) == -1) {
fprintf(stderr, "Mix_OpenAudio: %s\n,", Mix_GetError());
exit(4);
}
if (bsound == NULL)
bsound = Mix_LoadWAV("./space.wav");
if (Mix_PlayChannel(-1, bsound, 0) < 0)
fprintf(stderr, "Mix_PlayChannel: %s\n", Mix_GetError());
2020-12-31 19:51:14 +01:00
2020-12-29 01:32:15 +01:00
// create all spheres.
for (i = 0; i < 28; ++i) {
_obj[i].s = mkSphere(12, 12);
2020-12-22 15:31:33 +01:00
}
2020-12-26 20:12:49 +01:00
2020-12-29 01:32:15 +01:00
// get all textures.
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");
2020-12-26 20:12:49 +01:00
// https://upload.wikimedia.org/wikipedia/commons/4/4f/Moons_of_solar_system_v7.jpg
2020-12-29 01:32:15 +01:00
// most of the biggest moons are here.
2020-12-26 20:12:49 +01:00
2020-12-29 01:32:15 +01:00
// set texture to an object id and set all options.
for (i = 0; i < 28; ++i) {
setTexId(_obj[i].s, id[i]);
disableSurfaceOption(_obj[i].s, SO_USE_COLOR);
if (_use_tex)
enableSurfaceOption(_obj[i].s, SO_USE_TEXTURE);
if (_use_lighting)
enableSurfaceOption(_obj[i].s, SO_USE_LIGHTING);
2020-12-31 18:18:08 +01:00
}
get_params();
2020-12-13 12:04:32 +01:00
atexit(sortie);
2020-12-12 22:25:54 +01:00
}
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);
}
2020-12-29 01:32:15 +01:00
// get sign for further move calculation.
2020-12-28 15:39:22 +01:00
static int get_sign(float x, float y) {
if (x > y)
return 1;
return -1;
}
2020-12-29 01:32:15 +01:00
// move to the coordinate.
2020-12-28 15:39:22 +01:00
static void move_to(float posx, float posy , float posz){
2020-12-29 01:32:15 +01:00
float epsilon = 0.1f; // precision for comparing
if (fabsf(_cam.x - posx) > epsilon) {
_cam.x = _cam.x - (get_sign(_cam.x, posx) * 0.09f);
2020-12-28 15:39:22 +01:00
}
2020-12-29 01:32:15 +01:00
if (fabsf(_cam.y - posy) > epsilon) {
_cam.y = _cam.y - (get_sign(_cam.y, posy) * 0.09f);
2020-12-28 15:39:22 +01:00
}
2020-12-29 01:32:15 +01:00
if (fabsf(_cam.z - posz) > epsilon) {
_cam.z = _cam.z - (get_sign(_cam.z, posz) * 0.09f);
2020-12-28 15:39:22 +01:00
}
}
2020-12-29 01:32:15 +01:00
// go to a choosen object (planet, star, pluto(dwarf))
2020-12-28 15:39:22 +01:00
static void goto_obj(float * mvMat) {
switch (_p) {
2020-12-29 01:32:15 +01:00
case 1: // MERCURY
_a = 0; // reset angle to 0.
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);
2020-12-28 15:39:22 +01:00
break;
2020-12-29 01:32:15 +01:00
case 2: // VENUS
2020-12-28 15:39:22 +01:00
_a = 0;
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);
2020-12-28 15:39:22 +01:00
break;
2020-12-29 01:32:15 +01:00
case 3: // EARTH
2020-12-28 15:39:22 +01:00
_a = 0;
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);
2020-12-28 15:39:22 +01:00
break;
2020-12-29 01:32:15 +01:00
case 4: // MARS
2020-12-28 15:39:22 +01:00
_a = 0;
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);
2020-12-28 15:39:22 +01:00
break;
2020-12-29 01:32:15 +01:00
case 5: // JUPITER
2020-12-28 15:39:22 +01:00
_a = 0;
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);
2020-12-28 15:39:22 +01:00
break;
2020-12-29 01:32:15 +01:00
case 6: // SATURN
2020-12-28 15:39:22 +01:00
_a = 0;
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);
2020-12-28 15:39:22 +01:00
break;
case 7: // URANUS
2020-12-28 15:39:22 +01:00
_a = 0;
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);
2020-12-28 15:39:22 +01:00
break;
case 8: // NEPTUNE
2020-12-28 15:39:22 +01:00
_a = 0;
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);
2020-12-28 15:39:22 +01:00
break;
2020-12-29 01:32:15 +01:00
case 9: // PLUTO
2020-12-28 15:39:22 +01:00
_a = 0;
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);
2020-12-28 15:39:22 +01:00
break;
2020-12-29 01:32:15 +01:00
case 0: // SUN
2020-12-28 15:39:22 +01:00
_a = 0;
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);
2020-12-28 15:39:22 +01:00
break;
}
}
2021-01-01 16:13:34 +01:00
static void draw_object(float * nmv, float * projMat, surface_t * obj,
float ma, float mx, float my,
2020-12-31 19:51:14 +01:00
float tx, float ty, float tz, float s,
float ra, float rx, float ry) {
rotate(nmv, ma, mx, my, 0); // orbit movement
2020-12-31 19:51:14 +01:00
translate(nmv, tx, ty, tz);
scale(nmv, s, s, s);
rotate(nmv, ra, rx, ry, 0); // rotation
2020-12-31 19:51:14 +01:00
transform_n_raster(obj, nmv, projMat);
}
2020-12-12 22:25:54 +01:00
/*!\brief la fonction appelée à chaque display. */
void draw(void) {
2020-12-19 16:56:01 +01:00
static double t0 = 0, t, dt;
int i;
2020-12-26 20:12:49 +01:00
float mvMat[16], projMat[16], nmv[16], cpy[16];
t = gl4dGetElapsedTime();
dt = (t - t0) / 1000.0;
t0 = t;
2020-12-13 12:04:32 +01:00
/* effacer l'écran et le buffer de profondeur */
gl4dpClearScreen();
clearDepth();
/* des macros facilitant le travail avec des matrices et des
* vecteurs se trouvent dans la bibliothèque GL4Dummies, dans le
* fichier gl4dm.h */
/* charger un frustum dans projMat */
MFRUSTUM(projMat, -0.005f, 0.005f, -0.005f, 0.005f, 0.01f, 1000.0f);
2020-12-13 12:04:32 +01:00
/* charger la matrice identité dans model-view */
MIDENTITY(mvMat);
// Y ----> 1.0 - (_ym - (_wH >> 1)) / (float)_wH * 5
2020-12-28 15:39:22 +01:00
if (_movement)
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _cam.x - sin(_cam.theta), 1.0, _cam.z - cos(_cam.theta), 0.0, 1.0, 0.0);
else
goto_obj(mvMat);
2020-12-22 15:31:33 +01:00
// SUN
2020-12-13 12:04:32 +01:00
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
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);
}
} else if (_obj[i].id == 2) { // if object is a moon
memcpy(nmv, cpy, sizeof nmv);
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]);
}
}
2020-12-26 20:12:49 +01:00
2020-12-13 12:04:32 +01:00
/* déclarer qu'on a changé (en bas niveau) des pixels du screen */
gl4dpScreenHasChanged();
/* fonction permettant de raffraîchir l'ensemble de la fenêtre*/
gl4dpUpdateScreen(NULL);
2020-12-31 15:18:38 +01:00
2020-12-29 01:32:15 +01:00
if (!_pause){
2020-12-28 15:39:22 +01:00
_a += ((360.0 * dt) / 60) * _s; // 360 in 1 minute so 1 day = 1 min
_r += ((360.0 * dt) / 60) * _s; // 360 in 1 minute so 1 day = 1 min
2020-12-28 15:39:22 +01:00
}
2020-12-12 22:25:54 +01:00
}
/*!\brief intercepte l'événement clavier pour modifier les options. */
void key(int keycode) {
2020-12-28 15:39:22 +01:00
double step = 5.0;
int i;
2020-12-13 12:04:32 +01:00
switch(keycode) {
case GL4DK_UP:
2020-12-28 15:39:22 +01:00
if (_movement)
_cam.y += step;
2020-12-13 12:04:32 +01:00
break;
case GL4DK_DOWN:
2020-12-28 15:39:22 +01:00
if (_movement)
_cam.y -= step;
2020-12-13 12:04:32 +01:00
break;
case GL4DK_RIGHT:
2020-12-28 15:39:22 +01:00
if (!_pause)
_s += 30.0f;
2020-12-13 12:04:32 +01:00
break;
case GL4DK_LEFT:
2020-12-28 15:39:22 +01:00
if (!_pause)
_s -= 30.0f;
2020-12-13 12:04:32 +01:00
break;
case GL4DK_w:
2020-12-28 15:39:22 +01:00
if (_movement) {
_cam.x += -_v * step * sin(_cam.theta);
_cam.z += -_v * step * cos(_cam.theta);
}
2020-12-13 12:04:32 +01:00
break;
case GL4DK_s:
2020-12-28 15:39:22 +01:00
if (_movement) {
_cam.x += _v * step * sin(_cam.theta);
_cam.z += _v * step * cos(_cam.theta);
}
2020-12-19 16:56:01 +01:00
break;
case GL4DK_a:
2020-12-28 15:39:22 +01:00
if (_movement)
2020-12-31 17:23:54 +01:00
_cam.theta += step * 0.01;
2020-12-13 12:04:32 +01:00
break;
case GL4DK_d:
2020-12-28 15:39:22 +01:00
if (_movement)
2020-12-31 17:23:54 +01:00
_cam.theta -= step * 0.01;
break;
case GL4DK_p:
if (_pause == 0)
_pause = 1;
else
_pause = 0;
2020-12-18 08:12:23 +01:00
break;
case GL4DK_MINUS:
_v -= 0.01f;
if (_v < 0.01f){
_v = 0.01f;
2020-12-18 08:12:23 +01:00
}
break;
case GL4DK_EQUALS:
_v += 0.01f;
2020-12-19 16:56:01 +01:00
if (_v > 0.5f){
_v = 0.5f;
}
2020-12-13 12:04:32 +01:00
break;
2020-12-28 15:39:22 +01:00
case GL4DK_o:
if (_movement) {
if (!_overview) {
_overview = !_overview;
_cam.x = 0.0f;
_cam.y = 200.0f;
_cam.z = 0.0f;
_cam.theta = 0.0f;
} else {
_overview = !_overview;
_cam.x = 0.0f;
_cam.y = 1.0f;
_cam.z = 10.0f;
_cam.theta = 0.0f;
}
2020-12-28 15:39:22 +01:00
}
break;
case GL4DK_r:
_a = _r;
2020-12-28 15:39:22 +01:00
_p = -1;
_pause = 0;
_movement = 1;
_overview = 0;
break;
case GL4DK_m:
_s = 1;
break;
2020-12-29 01:32:15 +01:00
case GL4DK_q:
exit(0);
break;
case GL4DK_0:
2020-12-28 15:39:22 +01:00
_p = 0;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
break;
case GL4DK_1:
2020-12-28 15:39:22 +01:00
_p = 1;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
break;
case GL4DK_2:
2020-12-28 15:39:22 +01:00
_p = 2;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
2020-12-28 15:39:22 +01:00
break;
case GL4DK_3:
_p = 3;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
2020-12-28 15:39:22 +01:00
break;
case GL4DK_4:
_p = 4;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
2020-12-28 15:39:22 +01:00
break;
case GL4DK_5:
_p = 5;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
2020-12-28 15:39:22 +01:00
break;
case GL4DK_6:
_p = 6;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
2020-12-28 15:39:22 +01:00
break;
case GL4DK_7:
_p = 7;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
2020-12-28 15:39:22 +01:00
break;
case GL4DK_8:
_p = 8;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
2020-12-28 15:39:22 +01:00
break;
case GL4DK_9:
_p = 9;
2020-12-31 16:12:36 +01:00
/*_pause = 1;*/
2020-12-28 15:39:22 +01:00
_movement = 0;
_overview = 0;
break;
2020-12-13 12:04:32 +01:00
case GL4DK_t: /* 't' la texture */
_use_tex = !_use_tex;
if(_use_tex) {
for (i = 0; i < 28; ++i) {
enableSurfaceOption(_obj[i].s, SO_USE_TEXTURE);
}
2020-12-13 12:04:32 +01:00
} else {
for (i = 0; i < 28; ++i) {
disableSurfaceOption(_obj[i].s, SO_USE_TEXTURE);
}
2020-12-13 12:04:32 +01:00
}
break;
case GL4DK_c: /* 'c' utiliser la couleur */
_use_color = !_use_color;
if(_use_color) {
for (i = 0; i < 28; ++i) {
enableSurfaceOption(_obj[i].s, SO_USE_COLOR);
}
2020-12-19 16:56:01 +01:00
} else {
for (i = 0; i < 28; ++i) {
disableSurfaceOption(_obj[i].s, SO_USE_COLOR);
}
2020-12-13 12:04:32 +01:00
}
break;
case GL4DK_l: /* 'l' utiliser l'ombrage par la méthode Gouraud */
_use_lighting = !_use_lighting;
if(_use_lighting) {
for (i = 0; i < 28; ++i) {
enableSurfaceOption(_obj[i].s, SO_USE_LIGHTING);
}
2020-12-19 16:56:01 +01:00
} else {
for (i = 0; i < 28; ++i) {
disableSurfaceOption(_obj[i].s, SO_USE_LIGHTING);
}
2020-12-13 12:04:32 +01:00
}
break;
default: break;
}
2020-12-12 22:25:54 +01:00
}
2020-12-29 01:32:15 +01:00
// handler of mouse motion.
2020-12-19 16:56:01 +01:00
static void pmotion(int x, int y) {
2020-12-28 15:39:22 +01:00
if (_movement){
_xm = x;
_ym = y;
_cam.theta = -(_xm - (_wW >> 1)) / (float)_wW*10;
}
2020-12-19 16:56:01 +01:00
}
2020-12-29 01:32:15 +01:00
// handler of mouse buttons.
static void mouse(int button, int state, int x, int y) {
2020-12-28 15:39:22 +01:00
if (_movement){
double dtheta = M_PI;
if (button == GL4D_BUTTON_LEFT)
_cam.y += dtheta;
if (button == GL4D_BUTTON_RIGHT)
_cam.y -= dtheta;
if (button == GL4D_BUTTON_MIDDLE)
_cam.y = 1.0f;
}
}
2020-12-12 22:25:54 +01:00
/*!\brief à appeler à la sortie du programme. */
void sortie(void) {
int i;
2020-12-31 14:10:18 +01:00
Mix_CloseAudio();
Mix_Quit();
for (i = 0; i < 28; ++i) {
if(_obj[i].s){
freeSurface(_obj[i].s);
_obj[i].s = NULL;
}
2020-12-20 13:14:49 +01:00
}
2020-12-31 14:10:18 +01:00
if (bsound)
Mix_FreeChunk(bsound);
bsound = NULL;
2020-12-13 12:04:32 +01:00
/* libère tous les objets produits par GL4Dummies, ici
* principalement les screen */
gl4duClean(GL4DU_ALL);
2020-12-12 22:25:54 +01:00
}