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>
|
|
|
|
|
|
|
|
/* 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);
|
2020-12-20 12:28:30 +01:00
|
|
|
static void mouse(int button, int state, int x, int 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
|
|
|
|
|
|
|
/*!\brief une surface représentant une sphere */
|
2020-12-18 08:12:23 +01:00
|
|
|
static surface_t * _sun = NULL;
|
2020-12-20 13:28:41 +01:00
|
|
|
static surface_t * _planet[9] = {NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
NULL, NULL, NULL};
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-12-22 16:04:12 +01:00
|
|
|
static cam_t _cam = {0, 1.0f, 10, 0};
|
2020-12-18 08:12:23 +01:00
|
|
|
|
2020-12-19 16:56:01 +01:00
|
|
|
static float _v = 0.1f;
|
2020-12-12 22:25:54 +01:00
|
|
|
|
2020-12-19 16:56:01 +01:00
|
|
|
static int _wW = 1200, _wH = 1000;
|
|
|
|
static int _xm = 400, _ym = 300;
|
2020-12-18 08:12:23 +01:00
|
|
|
|
2020-12-20 12:28:30 +01:00
|
|
|
static int _pause = 0;
|
2020-12-22 14:35:23 +01:00
|
|
|
static float _s = 1.0f;
|
2020-12-20 12:28:30 +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-13 12:04:32 +01:00
|
|
|
/* tentative de création d'une fenêtre pour GL4Dummies */
|
|
|
|
if(!gl4duwCreateWindow(argc, argv, /* args du programme */
|
|
|
|
"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 */
|
2020-12-20 12:28:30 +01:00
|
|
|
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 */
|
|
|
|
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) {
|
2020-12-22 15:31:33 +01:00
|
|
|
uint id[9], sun_id, i;
|
2020-12-18 08:12:23 +01:00
|
|
|
/*vec4 g = {0, 1, 0, 1};*/
|
2020-12-13 12:04:32 +01:00
|
|
|
/* on créé nos trois type de surfaces */
|
2020-12-22 14:35:23 +01:00
|
|
|
_sun = mkSphere(12, 12); /*ça fait 12x12x2 trianles !*/
|
2020-12-13 12:04:32 +01:00
|
|
|
/* on change les couleurs de surfaces */
|
2020-12-18 08:12:23 +01:00
|
|
|
/*_sun->dcolor = g; */
|
2020-12-22 15:31:33 +01:00
|
|
|
for(i = 0; i < 9; ++i) {
|
|
|
|
_planet[i] = mkSphere(12, 12);
|
|
|
|
}
|
2020-12-20 13:14:49 +01:00
|
|
|
sun_id = getTexFromBMP("images/2k-sun.bmp");
|
2020-12-22 15:31:33 +01:00
|
|
|
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");
|
2020-12-20 13:14:49 +01:00
|
|
|
setTexId(_sun, sun_id);
|
2020-12-22 15:31:33 +01:00
|
|
|
for(i = 0; i < 9; ++i)
|
|
|
|
setTexId(_planet[i], id[i]);
|
2020-12-13 12:04:32 +01:00
|
|
|
/* si _use_tex != 0, on active l'utilisation de la texture pour les
|
|
|
|
* trois */
|
|
|
|
if(_use_tex) {
|
2020-12-18 08:12:23 +01:00
|
|
|
enableSurfaceOption(_sun, SO_USE_TEXTURE);
|
2020-12-22 15:31:33 +01:00
|
|
|
for(i = 0; i < 9; ++i)
|
|
|
|
enableSurfaceOption(_planet[i], SO_USE_TEXTURE);
|
2020-12-13 12:04:32 +01:00
|
|
|
}
|
|
|
|
/* si _use_lighting != 0, on active l'ombrage */
|
|
|
|
if(_use_lighting) {
|
2020-12-18 08:12:23 +01:00
|
|
|
enableSurfaceOption(_sun, SO_USE_LIGHTING);
|
2020-12-22 15:31:33 +01:00
|
|
|
for(i = 0; i < 9; ++i)
|
|
|
|
enableSurfaceOption(_planet[i], SO_USE_LIGHTING);
|
2020-12-13 12:04:32 +01:00
|
|
|
}
|
2020-12-18 08:12:23 +01:00
|
|
|
disableSurfaceOption(_sun, SO_USE_COLOR);
|
2020-12-22 15:31:33 +01:00
|
|
|
for(i = 0; i < 9; ++i)
|
|
|
|
disableSurfaceOption(_planet[i], SO_USE_COLOR);
|
2020-12-13 12:04:32 +01:00
|
|
|
atexit(sortie);
|
2020-12-12 22:25:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!\brief la fonction appelée à chaque display. */
|
|
|
|
void draw(void) {
|
2020-12-13 12:04:32 +01:00
|
|
|
static float a = 0.0f;
|
2020-12-19 16:56:01 +01:00
|
|
|
static double t0 = 0, t, dt;
|
|
|
|
t = gl4dGetElapsedTime();
|
|
|
|
dt = (t - t0) / 10000.0;
|
2020-12-18 09:08:19 +01:00
|
|
|
t0 = t;
|
2020-12-13 12:04:32 +01:00
|
|
|
float mvMat[16], projMat[16], nmv[16];
|
|
|
|
/* 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.05f, 0.05f, -0.05f, 0.05f, 0.1f, 1000.0f);
|
|
|
|
/* charger la matrice identité dans model-view */
|
|
|
|
MIDENTITY(mvMat);
|
|
|
|
/* on place la caméra en arrière-haut, elle regarde le centre de la scène */
|
2020-12-18 08:12:23 +01:00
|
|
|
/*lookAt(mvMat, _xcam, _ycam, _zcam, _x, _y, _z, 0, 1, 0);*/
|
2020-12-19 16:56:01 +01:00
|
|
|
/*lookAt(mvMat, _cam.x, 0.0, _cam.z, _cam.x - sin(_cam.theta), 1.0f - _ym / 200.0f, _cam.z - cos(_cam.theta), 0.0, 1.0, 0.0);*/
|
2020-12-20 12:28:30 +01:00
|
|
|
/*_cam.x = (_xm - (_wW >> 1)) / (float)_wW;*/
|
|
|
|
|
|
|
|
/*_cam.y = 1.0 - (_ym - (_wH >> 1)) / 300.0f;*/
|
|
|
|
lookAt(mvMat, _cam.x, _cam.y, _cam.z, _cam.x - sin(_cam.theta), 1.0 - (_ym - (_wH >> 1)) / 300.0f, _cam.z - cos(_cam.theta), 0.0, 1.0, 0.0);
|
2020-12-19 16:56:01 +01:00
|
|
|
|
2020-12-22 14:35:23 +01:00
|
|
|
// scales https://www.jpl.nasa.gov/infographics/infographic.view.php?id=10749
|
|
|
|
|
2020-12-13 12:04:32 +01:00
|
|
|
/* la sphère est laissée au centre et tourne autour de son axe y */
|
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 */
|
2020-12-22 14:35:23 +01:00
|
|
|
rotate(nmv, (a / 24.5f), 0.0f, 1.0f, 0.0f);
|
2020-12-19 16:56:01 +01:00
|
|
|
translate(nmv, 0.0f, 1.0f, 0.0f);
|
2020-12-22 14:35:23 +01:00
|
|
|
scale(nmv, 2,2,2);
|
2020-12-18 08:12:23 +01:00
|
|
|
transform_n_raster(_sun, nmv, projMat);
|
|
|
|
|
2020-12-22 15:31:33 +01:00
|
|
|
// MERCURY
|
2020-12-18 08:12:23 +01:00
|
|
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
2020-12-22 15:31:33 +01:00
|
|
|
rotate(nmv, (a / 87.97f), 0.0f, 1.0f, 0.0f); // orbit mouvement
|
2020-12-22 16:55:56 +01:00
|
|
|
translate(nmv, 3.9f, 1.0f, 0.0f);
|
2020-12-22 14:35:23 +01:00
|
|
|
scale(nmv, (1/227.0f) * 12.0f, (1/227.0f) * 12.0f, (1/227.0f) * 12.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
rotate(nmv, (a / 59.0f), 0.0f, 1.0f, 0.0f); // rotation
|
2020-12-20 13:28:41 +01:00
|
|
|
transform_n_raster(_planet[0], nmv, projMat);
|
2020-12-20 13:14:49 +01:00
|
|
|
|
2020-12-22 15:31:33 +01:00
|
|
|
// VENUS
|
2020-12-20 13:14:49 +01:00
|
|
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
2020-12-22 14:35:23 +01:00
|
|
|
rotate(nmv, (a / 224.7f), 0.0f, 1.0f, 0.0f); // orbit mouvement
|
2020-12-22 16:55:56 +01:00
|
|
|
translate(nmv, 7.9f, 1.0f, 0.0f);
|
2020-12-22 14:35:23 +01:00
|
|
|
scale(nmv, (1/113.0f) * 12.0f, (1/113.0f) * 12.0f, (1/113.0f) * 12.0f);
|
2020-12-22 15:45:10 +01:00
|
|
|
rotate(nmv, (a / 243.75f), 0.1773f, -1.0f, 0.0f); // rotation anti-clockwise
|
2020-12-20 13:28:41 +01:00
|
|
|
transform_n_raster(_planet[1], nmv, projMat);
|
2020-12-20 13:14:49 +01:00
|
|
|
|
2020-12-22 15:31:33 +01:00
|
|
|
// EARTH
|
2020-12-20 13:14:49 +01:00
|
|
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
2020-12-22 16:04:12 +01:00
|
|
|
rotate(nmv, (a / 365.2425f), 0.0f, 1.0f, 0.0f);
|
2020-12-22 16:55:56 +01:00
|
|
|
translate(nmv, 10.0f, 1.0f, 0.0f);
|
2020-12-22 14:35:23 +01:00
|
|
|
scale(nmv, (1/108.0f) * 12.0f, (1/108.0f) * 12.0f, (1/108.0f) * 12.0f);
|
2020-12-22 16:04:12 +01:00
|
|
|
rotate(nmv, a, 0.234f, 1.0f, 0.0f);
|
2020-12-20 13:28:41 +01:00
|
|
|
transform_n_raster(_planet[2], nmv, projMat);
|
2020-12-20 13:14:49 +01:00
|
|
|
|
2020-12-22 15:31:33 +01:00
|
|
|
// MARS
|
|
|
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
|
|
|
rotate(nmv, (a / 686.98f), 0.0f, 1.0f, 0.0f);
|
2020-12-22 16:55:56 +01:00
|
|
|
translate(nmv, 15.2f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
scale(nmv, (1/208.0f) * 12.0f, (1/208.0f) * 12.0f, (1/208.0f) * 12.0f);
|
2020-12-22 16:55:56 +01:00
|
|
|
rotate(nmv, a / 1.0416f, 0.252f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
transform_n_raster(_planet[3], nmv, projMat);
|
|
|
|
|
|
|
|
// JUPITER
|
|
|
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
|
|
|
rotate(nmv, a / (12 * 365.2425f), 0.0f, 1.0f, 0.0f);
|
2020-12-22 16:55:56 +01:00
|
|
|
translate(nmv, 52.0f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
scale(nmv, (1/9.7f) * 12.0f, (1/9.7f) * 12.0f, (1/9.7f) * 12.0f);
|
2020-12-22 15:45:10 +01:00
|
|
|
rotate(nmv, a / 0.416f, 0.031f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
transform_n_raster(_planet[4], nmv, projMat);
|
|
|
|
|
|
|
|
// SATURN
|
|
|
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
|
|
|
rotate(nmv, a / (30 * 365.2425f), 0.0f, 1.0f, 0.0f);
|
2020-12-22 16:55:56 +01:00
|
|
|
translate(nmv, 95.4f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
scale(nmv, (1/11.4f) * 12.0f, (1/11.4f) * 12.0f, (1/11.4f) * 12.0f);
|
2020-12-22 15:45:10 +01:00
|
|
|
rotate(nmv, a / 0.4583f, 0.267f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
transform_n_raster(_planet[5], nmv, projMat);
|
|
|
|
|
|
|
|
// URANUS
|
|
|
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
|
|
|
rotate(nmv, a / (84 * 365.2425f), 0.0f, 1.0f, 0.0f);
|
2020-12-22 16:55:56 +01:00
|
|
|
translate(nmv, 192.0f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
scale(nmv, (1/26.8f) * 12.0f, (1/26.8f) * 12.0f, (1/26.8f) * 12.0f);
|
2020-12-22 15:45:10 +01:00
|
|
|
rotate(nmv, a / 0.7083f, 0.978f, 0.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
transform_n_raster(_planet[6], nmv, projMat);
|
|
|
|
|
|
|
|
// NEPTUNE
|
|
|
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
|
|
|
rotate(nmv, a / (165 * 365.2425f), 0.0f, 1.0f, 0.0f);
|
2020-12-22 16:55:56 +01:00
|
|
|
translate(nmv, 301.0f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
scale(nmv, (1/27.7f) * 12.0f, (1/27.7f) * 12.0f, (1/27.7f) * 12.0f);
|
2020-12-22 15:45:10 +01:00
|
|
|
rotate(nmv, a / 0.6f, 0.283f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
transform_n_raster(_planet[7], nmv, projMat);
|
|
|
|
|
|
|
|
// PLUTO
|
|
|
|
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
|
|
|
|
rotate(nmv, a / (248 * 365.2425f), 0.0f, 1.0f, 0.0f);
|
2020-12-22 16:55:56 +01:00
|
|
|
translate(nmv, 394.0f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
scale(nmv, (1/500.0f) * 12.0f, (1/500.0f) * 12.0f, (1/500.0f) * 12.0f);
|
2020-12-22 15:45:10 +01:00
|
|
|
rotate(nmv, a / 6.4, 0.119f, 1.0f, 0.0f);
|
2020-12-22 15:31:33 +01:00
|
|
|
transform_n_raster(_planet[8], nmv, projMat);
|
|
|
|
|
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-20 12:28:30 +01:00
|
|
|
if (_pause != 1)
|
2020-12-22 14:35:23 +01:00
|
|
|
a += (dt * 60) * _s; // 1 minute == 1 day
|
2020-12-12 22:25:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!\brief intercepte l'événement clavier pour modifier les options. */
|
|
|
|
void key(int keycode) {
|
2020-12-19 16:56:01 +01:00
|
|
|
double dtheta = M_PI, step = 5.0;
|
2020-12-13 12:04:32 +01:00
|
|
|
switch(keycode) {
|
|
|
|
case GL4DK_UP:
|
2020-12-22 16:04:12 +01:00
|
|
|
_cam.y += 5 * dtheta;
|
2020-12-13 12:04:32 +01:00
|
|
|
break;
|
|
|
|
case GL4DK_DOWN:
|
2020-12-22 16:04:12 +01:00
|
|
|
_cam.y -= 5 * dtheta;
|
2020-12-13 12:04:32 +01:00
|
|
|
break;
|
|
|
|
case GL4DK_RIGHT:
|
2020-12-22 14:35:23 +01:00
|
|
|
_s += 30.0f;
|
2020-12-13 12:04:32 +01:00
|
|
|
break;
|
|
|
|
case GL4DK_LEFT:
|
2020-12-22 14:35:23 +01:00
|
|
|
_s -= 30.0f;
|
2020-12-13 12:04:32 +01:00
|
|
|
break;
|
|
|
|
case GL4DK_w:
|
2020-12-20 12:28:30 +01:00
|
|
|
_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-20 12:28:30 +01:00
|
|
|
_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-20 12:28:30 +01:00
|
|
|
_cam.theta -= -_v * dtheta;
|
2020-12-13 12:04:32 +01:00
|
|
|
break;
|
|
|
|
case GL4DK_d:
|
2020-12-20 12:28:30 +01:00
|
|
|
_cam.theta += -_v * dtheta;
|
|
|
|
break;
|
|
|
|
case GL4DK_p:
|
|
|
|
if (_pause == 0)
|
|
|
|
_pause = 1;
|
|
|
|
else
|
|
|
|
_pause = 0;
|
2020-12-18 08:12:23 +01:00
|
|
|
break;
|
|
|
|
case GL4DK_MINUS:
|
2020-12-19 16:56:01 +01:00
|
|
|
_v -= 0.001f;
|
|
|
|
if (_v < 0.001f){
|
|
|
|
_v = 0.001f;
|
2020-12-18 08:12:23 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GL4DK_EQUALS:
|
2020-12-19 16:56:01 +01:00
|
|
|
_v += 0.001f;
|
|
|
|
if (_v > 0.5f){
|
|
|
|
_v = 0.5f;
|
|
|
|
}
|
2020-12-13 12:04:32 +01:00
|
|
|
break;
|
2020-12-22 14:35:23 +01:00
|
|
|
case GL4DK_f:
|
|
|
|
break;
|
|
|
|
case GL4DK_z:
|
|
|
|
break;
|
2020-12-13 12:04:32 +01:00
|
|
|
case GL4DK_t: /* 't' la texture */
|
|
|
|
_use_tex = !_use_tex;
|
|
|
|
if(_use_tex) {
|
2020-12-18 08:12:23 +01:00
|
|
|
enableSurfaceOption(_sun, SO_USE_TEXTURE);
|
2020-12-20 13:28:41 +01:00
|
|
|
enableSurfaceOption(_planet[0], SO_USE_TEXTURE);
|
|
|
|
enableSurfaceOption(_planet[1], SO_USE_TEXTURE);
|
|
|
|
enableSurfaceOption(_planet[2], SO_USE_TEXTURE);
|
2020-12-13 12:04:32 +01:00
|
|
|
} else {
|
2020-12-18 08:12:23 +01:00
|
|
|
disableSurfaceOption(_sun, SO_USE_TEXTURE);
|
2020-12-20 13:28:41 +01:00
|
|
|
disableSurfaceOption(_planet[0], SO_USE_TEXTURE);
|
|
|
|
disableSurfaceOption(_planet[1], SO_USE_TEXTURE);
|
|
|
|
disableSurfaceOption(_planet[2], 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) {
|
2020-12-18 08:12:23 +01:00
|
|
|
enableSurfaceOption(_sun, SO_USE_COLOR);
|
2020-12-20 13:28:41 +01:00
|
|
|
enableSurfaceOption(_planet[0], SO_USE_COLOR);
|
|
|
|
enableSurfaceOption(_planet[1], SO_USE_COLOR);
|
|
|
|
enableSurfaceOption(_planet[2], SO_USE_COLOR);
|
2020-12-19 16:56:01 +01:00
|
|
|
} else {
|
2020-12-18 08:12:23 +01:00
|
|
|
disableSurfaceOption(_sun, SO_USE_COLOR);
|
2020-12-20 13:28:41 +01:00
|
|
|
disableSurfaceOption(_planet[0], SO_USE_COLOR);
|
|
|
|
disableSurfaceOption(_planet[1], SO_USE_COLOR);
|
|
|
|
disableSurfaceOption(_planet[2], 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) {
|
2020-12-18 08:12:23 +01:00
|
|
|
enableSurfaceOption(_sun, SO_USE_LIGHTING);
|
2020-12-20 13:28:41 +01:00
|
|
|
enableSurfaceOption(_planet[0], SO_USE_LIGHTING);
|
|
|
|
enableSurfaceOption(_planet[1], SO_USE_LIGHTING);
|
|
|
|
enableSurfaceOption(_planet[2], SO_USE_LIGHTING);
|
2020-12-19 16:56:01 +01:00
|
|
|
} else {
|
2020-12-18 08:12:23 +01:00
|
|
|
disableSurfaceOption(_sun, SO_USE_LIGHTING);
|
2020-12-20 13:28:41 +01:00
|
|
|
disableSurfaceOption(_planet[0], SO_USE_LIGHTING);
|
|
|
|
disableSurfaceOption(_planet[1], SO_USE_LIGHTING);
|
|
|
|
disableSurfaceOption(_planet[2], SO_USE_LIGHTING);
|
2020-12-13 12:04:32 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
2020-12-12 22:25:54 +01:00
|
|
|
}
|
|
|
|
|
2020-12-19 16:56:01 +01:00
|
|
|
static void pmotion(int x, int y) {
|
|
|
|
_xm = x;
|
|
|
|
_ym = y;
|
|
|
|
}
|
|
|
|
|
2020-12-20 12:28:30 +01:00
|
|
|
static void mouse(int button, int state, int x, int y) {
|
|
|
|
double dtheta = M_PI;
|
|
|
|
if (button == GL4D_BUTTON_LEFT)
|
|
|
|
_cam.y += (_v/2) * dtheta;
|
|
|
|
if (button == GL4D_BUTTON_RIGHT)
|
|
|
|
_cam.y -= (_v/2) * 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) {
|
2020-12-20 13:28:41 +01:00
|
|
|
int i;
|
2020-12-18 08:12:23 +01:00
|
|
|
if(_sun) {
|
|
|
|
freeSurface(_sun);
|
|
|
|
_sun = NULL;
|
2020-12-13 12:04:32 +01:00
|
|
|
}
|
2020-12-20 13:28:41 +01:00
|
|
|
for(i = 0; i < 9; ++i) {
|
|
|
|
if(_planet[i]){
|
|
|
|
freeSurface(_planet[i]);
|
|
|
|
_planet[i] = NULL;
|
|
|
|
}
|
2020-12-20 13:14:49 +01:00
|
|
|
}
|
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
|
|
|
}
|