goto each planet on keypress

This commit is contained in:
Volodymyr Patuta 2020-12-28 15:39:22 +01:00
parent e8a7a266d2
commit 33c7215e02

314
window.c
View File

@ -26,15 +26,19 @@ static void key(int keycode);
static void sortie(void); static void sortie(void);
static void pmotion(int x, int y); static void pmotion(int x, int y);
static void mouse(int button, int state, int x, int y); static void mouse(int button, int state, int x, int y);
static void goto_obj(float * mvMat);
static void move_to(float posx, float posy , float posz);
static int get_sign(float x, float y);
/*!\brief un identifiant pour l'écran (de dessin) */ /*!\brief un identifiant pour l'écran (de dessin) */
static uint _screenId = 0; 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 * _planet[9] = {NULL, NULL, NULL, static surface_t * _planet[9] = { NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL}; NULL, NULL, NULL };
static surface_t * _moon[18] = {NULL, NULL, NULL, NULL, static surface_t * _moon[18] = {NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
@ -60,6 +64,9 @@ static int _xm = 400, _ym = 300;
static int _pause = 0; static int _pause = 0;
static float _s = 1.0f; static float _s = 1.0f;
static int _movement = 1;
static int _p = -1;
static float _a = 0.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) {
@ -162,9 +169,83 @@ void init(void) {
atexit(sortie); atexit(sortie);
} }
static int get_sign(float x, float y) {
if (x > y)
return 1;
return -1;
}
static void move_to(float posx, float posy , float posz){
float epsilon = 0.1f;
if (fabsf(_cam.x - posx) > epsilon){
_cam.x = _cam.x - (get_sign(_cam.x, posx) * 0.2f);
}
if (fabsf(_cam.y - posy) > epsilon){
_cam.y = _cam.y - (get_sign(_cam.y, posy) * 0.2f);
}
if (fabsf(_cam.z - posz) > epsilon){
_cam.z = _cam.z - (get_sign(_cam.z, posz) * 0.2f);
}
}
static void goto_obj(float * mvMat) {
switch (_p) {
case 1:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0,1,0,0,1,0);
move_to(4.5f, 1.0f, 0.0f);
break;
case 2:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0,1,0,0,1,0);
move_to(8.5f, 1.0f, 0.0f);
break;
case 3:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0,1,0,0,1,0);
move_to(10.5f, 1.0f, 0.0f);
break;
case 4:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0,1,0,0,1,0);
move_to(15.5f, 1.0f, 0.0f);
break;
case 5:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0,1,0,0,1,0);
move_to(35.0f, 1.0f, 0.0f);
break;
case 6:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0,1,0,0,1,0);
move_to(55.0f, 1.0f, 0.0f);
break;
case 7:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0,1,0,0,1,0);
move_to(67.0f, 1.0f, 0.0f);
break;
case 8:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0,1,0,0,1,0);
move_to(77.0f, 1.0f, 0.0f);
break;
case 9:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 0,1,0,0,1,0);
move_to(85.5f, 1.0f, 0.0f);
break;
case 0:
_a = 0;
lookAt(mvMat, _cam.x, _cam.y, _cam.z, 10,1,0,0,1,0);
move_to(5.0f, 1.0f, 0.0f);
break;
}
}
/*!\brief la fonction appelée à chaque display. */ /*!\brief la fonction appelée à chaque display. */
void draw(void) { void draw(void) {
static float a = 0.0f; static float r = 0.0f;
static double t0 = 0, t, dt; static double t0 = 0, t, dt;
t = gl4dGetElapsedTime(); t = gl4dGetElapsedTime();
dt = (t - t0) / 1000.0; dt = (t - t0) / 1000.0;
@ -182,121 +263,121 @@ void draw(void) {
MIDENTITY(mvMat); MIDENTITY(mvMat);
// Y ----> 1.0 - (_ym - (_wH >> 1)) / (float)_wH * 5 // Y ----> 1.0 - (_ym - (_wH >> 1)) / (float)_wH * 5
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); 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
// scales https://www.jpl.nasa.gov/infographics/infographic.view.php?id=10749 goto_obj(mvMat);
// https://www.exploratorium.edu/ronh/solar_system/scale.pdf
// SUN // SUN
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 24.5f), 0.0f, 1.0f, 0.0f); rotate(nmv, (r / 24.5f), 0.0f, 1.0f, 0.0f);
translate(nmv, 0.0f, 1.0f, 0.0f); translate(nmv, 0.0f, 1.0f, 0.0f);
scale(nmv, 2,2,2); scale(nmv, 2,2,2);
transform_n_raster(_sun, nmv, projMat); transform_n_raster(_sun, nmv, projMat);
// MERCURY // MERCURY
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 87.97f), 0.0f, 1.0f, 0.0f); // orbit mouvement rotate(nmv, (_a / 87.97f), 0.0f, 1.0f, 0.0f); // orbit mouvement
translate(nmv, 3.9f, 1.0f, 0.0f); translate(nmv, 4.2f, 1.0f, 0.0f);
scale(nmv, (1/227.0f) * 12.0f, (1/227.0f) * 12.0f, (1/227.0f) * 12.0f); scale(nmv, (1/227.0f) * 12.0f, (1/227.0f) * 12.0f, (1/227.0f) * 12.0f);
rotate(nmv, (a / 59.0f), 0.0f, 1.0f, 0.0f); // rotation rotate(nmv, (r / 59.0f), 0.0f, 1.0f, 0.0f); // rotation
transform_n_raster(_planet[0], nmv, projMat); transform_n_raster(_planet[0], nmv, projMat);
// VENUS // VENUS
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 224.7f), 0.0f, 1.0f, 0.0f); // orbit mouvement rotate(nmv, (_a / 224.7f), 0.0f, 1.0f, 0.0f); // orbit mouvement
translate(nmv, 7.9f, 1.0f, 0.0f); translate(nmv, 7.9f, 1.0f, 0.0f);
scale(nmv, (1/113.0f) * 12.0f, (1/113.0f) * 12.0f, (1/113.0f) * 12.0f); scale(nmv, (1/113.0f) * 12.0f, (1/113.0f) * 12.0f, (1/113.0f) * 12.0f);
rotate(nmv, (a / 243.75f), -0.1773f, -1.0f, 0.0f); // rotation anti-clockwise rotate(nmv, (r / 243.75f), -0.1773f, -1.0f, 0.0f); // rotation anti-clockwise
transform_n_raster(_planet[1], nmv, projMat); transform_n_raster(_planet[1], nmv, projMat);
// EARTH // EARTH
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 365.2425f), 0.0f, 1.0f, 0.0f); rotate(nmv, (_a / 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 10.0f, 1.0f, 0.0f); translate(nmv, 10.0f, 1.0f, 0.0f);
scale(nmv, (1/108.0f) * 12.0f, (1/108.0f) * 12.0f, (1/108.0f) * 12.0f); scale(nmv, (1/108.0f) * 12.0f, (1/108.0f) * 12.0f, (1/108.0f) * 12.0f);
rotate(nmv, a, -0.234f, 1.0f, 0.0f); rotate(nmv, r, -0.234f, 1.0f, 0.0f);
transform_n_raster(_planet[2], nmv, projMat); transform_n_raster(_planet[2], nmv, projMat);
// Moon // Moon
translate(nmv, 11.0f, 2.0f, 0.0f); translate(nmv, 4.0f, 0.0f, 0.0f);
scale(nmv, (1/50.0f) , (1/50.0f), (1/50.0f)); scale(nmv, (1/5.0f) , (1/5.0f), (1/5.0f));
transform_n_raster(_moon[0], nmv, projMat); transform_n_raster(_moon[0], nmv, projMat);
// MARS // MARS
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, (a / 686.98f), 0.0f, 1.0f, 0.0f); rotate(nmv, (_a / 686.98f), 0.0f, 1.0f, 0.0f);
translate(nmv, 15.2f, 1.0f, 0.0f); translate(nmv, 15.2f, 1.0f, 0.0f);
scale(nmv, (1/208.0f) * 12.0f, (1/208.0f) * 12.0f, (1/208.0f) * 12.0f); scale(nmv, (1/208.0f) * 12.0f, (1/208.0f) * 12.0f, (1/208.0f) * 12.0f);
rotate(nmv, a / 1.0416f, -0.252f, 1.0f, 0.0f); rotate(nmv, r / 1.0416f, -0.252f, 1.0f, 0.0f);
transform_n_raster(_planet[3], nmv, projMat); transform_n_raster(_planet[3], nmv, projMat);
memcpy(cpy, nmv, sizeof cpy); memcpy(cpy, nmv, sizeof cpy);
// Phobos // Phobos
rotate(nmv, a * 4.3f, 0.0f, 0.1f, 0.0f); rotate(nmv, r * 4.3f, 0.0f, 0.1f, 0.0f);
translate(nmv, 10.0f, 1.0f, 0.0f); translate(nmv, 10.0f, 1.0f, 0.0f);
scale(nmv, (1/5.0f), (1/5.0f), (1/5.0f)); scale(nmv, (1/5.0f), (1/5.0f), (1/5.0f));
transform_n_raster(_moon[1], nmv, projMat); transform_n_raster(_moon[1], nmv, projMat);
// Deimos // Deimos
rotate(cpy, a / 1.5f, 0.0f, 0.1f, 0.0f); rotate(cpy, r / 1.5f, 0.0f, 0.1f, 0.0f);
translate(cpy, 25.0f, 1.0f, 0.0f); translate(cpy, 25.0f, 1.0f, 0.0f);
scale(cpy, (1/6.0f), (1/6.0f), (1/6.0f)); scale(cpy, (1/6.0f), (1/6.0f), (1/6.0f));
transform_n_raster(_moon[2], cpy, projMat); transform_n_raster(_moon[2], cpy, projMat);
// JUPITER // JUPITER
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (12 * 365.2425f), 0.0f, 1.0f, 0.0f); rotate(nmv, _a / (12 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 52.0f, 1.0f, 0.0f); translate(nmv, 30.0f, 1.0f, 0.0f);
scale(nmv, (1/9.7f) * 12.0f, (1/9.7f) * 12.0f, (1/9.7f) * 12.0f); scale(nmv, (1/9.7f) * 12.0f, (1/9.7f) * 12.0f, (1/9.7f) * 12.0f);
rotate(nmv, a / 0.416f, -0.031f, 1.0f, 0.0f); rotate(nmv, r / 0.416f, -0.031f, 1.0f, 0.0f);
transform_n_raster(_planet[4], nmv, projMat); transform_n_raster(_planet[4], nmv, projMat);
memcpy(cpy, nmv, sizeof cpy); memcpy(cpy, nmv, sizeof cpy);
// Io // Io
rotate(nmv, a * 3.0f, 0.0f, 0.1f, 0.0f); rotate(nmv, r * 3.0f, 0.0f, 0.1f, 0.0f);
translate(nmv, 5.0f, 0.0f, 0.0f); translate(nmv, 3.0f, 0.0f, 0.0f);
scale(nmv, (1/11.2f), (1/11.2f), (1/11.2f)); // 1/11.2f -> Jupiter is bigger then earth 11.2x / 50 io ~= moon size. scale(nmv, (1/11.2f), (1/11.2f), (1/11.2f)); // 1/11.2f -> Jupiter is bigger then earth 11.2x / 50 io ~= moon size.
transform_n_raster(_moon[3], nmv, projMat); transform_n_raster(_moon[3], nmv, projMat);
memcpy(nmv, cpy, sizeof nmv); memcpy(nmv, cpy, sizeof nmv);
// Europa // Europa
rotate(nmv, a / 2.0f, 0.0f, 0.1f, 0.0f); rotate(nmv, r / 2.0f, 0.0f, 0.1f, 0.0f);
translate(nmv, 8.0f, 0.0f, 0.0f); translate(nmv, 4.0f, 0.0f, 0.0f);
scale(nmv, (1/13.2f), (1/13.2f), (1/13.2f)); scale(nmv, (1/13.2f), (1/13.2f), (1/13.2f));
transform_n_raster(_moon[4], nmv, projMat); transform_n_raster(_moon[4], nmv, projMat);
memcpy(nmv, cpy, sizeof nmv); memcpy(nmv, cpy, sizeof nmv);
// Ganymede // Ganymede
rotate(nmv, a / 3.0f, 0.0f, 0.1f, 0.0f); rotate(nmv, r / 3.0f, 0.0f, 0.1f, 0.0f);
translate(nmv, 10.0f, 0.0f, 0.0f); translate(nmv, 5.0f, 0.0f, 0.0f);
scale(nmv, (1/9.0f), (1/9.0f), (1/9.0f)); scale(nmv, (1/9.0f), (1/9.0f), (1/9.0f));
transform_n_raster(_moon[5], nmv, projMat); transform_n_raster(_moon[5], nmv, projMat);
memcpy(nmv, cpy, sizeof nmv); memcpy(nmv, cpy, sizeof nmv);
// Callisto // Callisto
rotate(nmv, a / 5.0f, 0.0f, 0.1f, 0.0f); rotate(nmv, r / 5.0f, 0.0f, 0.1f, 0.0f);
translate(nmv, 11.0f, 0.0f, 0.0f); translate(nmv, 6.0f, 0.0f, 0.0f);
scale(nmv, (1/10.0f), (1/10.0f), (1/10.0f)); scale(nmv, (1/10.0f), (1/10.0f), (1/10.0f));
transform_n_raster(_moon[6], nmv, projMat); transform_n_raster(_moon[6], nmv, projMat);
// SATURN // SATURN
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (30 * 365.2425f), 0.0f, 1.0f, 0.0f); rotate(nmv, _a / (30 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 95.4f, 1.0f, 0.0f); translate(nmv, 50.4f, 1.0f, 0.0f);
scale(nmv, (1/11.4f) * 12.0f, (1/11.4f) * 12.0f, (1/11.4f) * 12.0f); scale(nmv, (1/11.4f) * 12.0f, (1/11.4f) * 12.0f, (1/11.4f) * 12.0f);
rotate(nmv, a / 0.4583f, -0.267f, 1.0f, 0.0f); rotate(nmv, r / 0.4583f, -0.267f, 1.0f, 0.0f);
transform_n_raster(_planet[5], nmv, projMat); transform_n_raster(_planet[5], nmv, projMat);
memcpy(cpy, nmv, sizeof cpy); memcpy(cpy, nmv, sizeof cpy);
// Enceladus // Enceladus
rotate(nmv, a * 5.0f, 0.0f, 0.1f, 0.0f); rotate(nmv, r * 5.0f, 0.0f, 0.1f, 0.0f);
translate(nmv, 2.0f, 0.0f, 0.0f); translate(nmv, 2.0f, 0.0f, 0.0f);
scale(nmv, (1/20.0f), (1/20.0f), (1/20.0f)); scale(nmv, (1/20.0f), (1/20.0f), (1/20.0f));
transform_n_raster(_moon[7], nmv, projMat); transform_n_raster(_moon[7], nmv, projMat);
@ -304,7 +385,7 @@ void draw(void) {
memcpy(nmv, cpy, sizeof nmv); memcpy(nmv, cpy, sizeof nmv);
// Dione // Dione
rotate(nmv, a * 4.0f, 0.0f, 0.01f, 0.0f); rotate(nmv, r * 4.0f, 0.0f, 0.01f, 0.0f);
translate(nmv, 3.0f, 0.0f, 0.0f); translate(nmv, 3.0f, 0.0f, 0.0f);
scale(nmv, (1/18.0f), (1/18.0f), (1/18.0f)); scale(nmv, (1/18.0f), (1/18.0f), (1/18.0f));
transform_n_raster(_moon[8], nmv, projMat); transform_n_raster(_moon[8], nmv, projMat);
@ -312,7 +393,7 @@ void draw(void) {
memcpy(nmv, cpy, sizeof nmv); memcpy(nmv, cpy, sizeof nmv);
// Rhea // Rhea
rotate(nmv, a * 3.0f, 0.0f, 0.01f, 0.0f); rotate(nmv, r * 3.0f, 0.0f, 0.01f, 0.0f);
translate(nmv, 4.0f, 0.0f, 0.0f); translate(nmv, 4.0f, 0.0f, 0.0f);
scale(nmv, (1/15.0f), (1/15.0f), (1/15.0f)); scale(nmv, (1/15.0f), (1/15.0f), (1/15.0f));
transform_n_raster(_moon[9], nmv, projMat); transform_n_raster(_moon[9], nmv, projMat);
@ -320,7 +401,7 @@ void draw(void) {
memcpy(nmv, cpy, sizeof nmv); memcpy(nmv, cpy, sizeof nmv);
// Titan // Titan
rotate(nmv, a / 4.0f, 0.0f, 0.01f, 0.0f); rotate(nmv, r / 4.0f, 0.0f, 0.01f, 0.0f);
translate(nmv, 6.0f, 0.0f, 0.0f); translate(nmv, 6.0f, 0.0f, 0.0f);
scale(nmv, (1/10.0f), (1/10.0f), (1/10.0f)); scale(nmv, (1/10.0f), (1/10.0f), (1/10.0f));
transform_n_raster(_moon[10], nmv, projMat); transform_n_raster(_moon[10], nmv, projMat);
@ -328,23 +409,23 @@ void draw(void) {
memcpy(nmv, cpy, sizeof nmv); memcpy(nmv, cpy, sizeof nmv);
// Iapetus // Iapetus
rotate(nmv, a / 6.0f, 0.0f, 0.01f, 0.0f); rotate(nmv, r / 6.0f, 0.0f, 0.01f, 0.0f);
translate(nmv, 7.0f, 0.0f, 0.0f); translate(nmv, 7.0f, 0.0f, 0.0f);
scale(nmv, (1/14.0f), (1/14.0f), (1/14.0f)); scale(nmv, (1/14.0f), (1/14.0f), (1/14.0f));
transform_n_raster(_moon[11], nmv, projMat); transform_n_raster(_moon[11], nmv, projMat);
// URANUS // URANUS
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (84 * 365.2425f), 0.0f, 1.0f, 0.0f); rotate(nmv, _a / (84 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 192.0f, 1.0f, 0.0f); translate(nmv, 65.0f, 1.0f, 0.0f);
scale(nmv, (1/26.8f) * 12.0f, (1/26.8f) * 12.0f, (1/26.8f) * 12.0f); scale(nmv, (1/26.8f) * 12.0f, (1/26.8f) * 12.0f, (1/26.8f) * 12.0f);
rotate(nmv, a / 0.7083f, -0.978f, 0.0f, 0.0f); rotate(nmv, r / 0.7083f, -0.978f, 0.0f, 0.0f);
transform_n_raster(_planet[6], nmv, projMat); transform_n_raster(_planet[6], nmv, projMat);
memcpy(cpy, nmv, sizeof cpy); memcpy(cpy, nmv, sizeof cpy);
// Ariel // Ariel
rotate(nmv, a , 0.01f, 0.0f, 0.0f); rotate(nmv, r , 0.01f, 0.0f, 0.0f);
translate(nmv, 0.0f, 3.0f, 0.0f); translate(nmv, 0.0f, 3.0f, 0.0f);
scale(nmv, (1/20.0f), (1/20.0f), (1/20.0f)); scale(nmv, (1/20.0f), (1/20.0f), (1/20.0f));
transform_n_raster(_moon[12], nmv, projMat); transform_n_raster(_moon[12], nmv, projMat);
@ -352,7 +433,7 @@ void draw(void) {
memcpy (nmv, cpy, sizeof nmv); memcpy (nmv, cpy, sizeof nmv);
// Umbriel // Umbriel
rotate(nmv, a / 2.0f, 0.01f, 0.0f, 0.0f); rotate(nmv, r / 2.0f, 0.01f, 0.0f, 0.0f);
translate(nmv, 0.0f, 4.0f, 0.0f); translate(nmv, 0.0f, 4.0f, 0.0f);
scale(nmv, (1/20.0f), (1/20.0f), (1/20.0f)); scale(nmv, (1/20.0f), (1/20.0f), (1/20.0f));
transform_n_raster(_moon[13], nmv, projMat); transform_n_raster(_moon[13], nmv, projMat);
@ -360,7 +441,7 @@ void draw(void) {
memcpy (nmv, cpy, sizeof nmv); memcpy (nmv, cpy, sizeof nmv);
// Titania // Titania
rotate(nmv, a / 3.0f, 0.01f, 0.0f, 0.0f); rotate(nmv, r / 3.0f, 0.01f, 0.0f, 0.0f);
translate(nmv, 0.0f, 5.0f, 0.0f); translate(nmv, 0.0f, 5.0f, 0.0f);
scale(nmv, (1/17.0f), (1/17.0f), (1/17.0f)); scale(nmv, (1/17.0f), (1/17.0f), (1/17.0f));
transform_n_raster(_moon[14], nmv, projMat); transform_n_raster(_moon[14], nmv, projMat);
@ -368,35 +449,35 @@ void draw(void) {
memcpy (nmv, cpy, sizeof nmv); memcpy (nmv, cpy, sizeof nmv);
// Oberon // Oberon
rotate(nmv, a / 5.0f, 0.01f, 0.0f, 0.0f); rotate(nmv, r / 5.0f, 0.01f, 0.0f, 0.0f);
translate(nmv, 0.0f, 6.0f, 0.0f); translate(nmv, 0.0f, 6.0f, 0.0f);
scale(nmv, (1/17.0f), (1/17.0f), (1/17.0f)); scale(nmv, (1/17.0f), (1/17.0f), (1/17.0f));
transform_n_raster(_moon[15], nmv, projMat); transform_n_raster(_moon[15], nmv, projMat);
// NEPTUNE // NEPTUNE
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (165 * 365.2425f), 0.0f, 1.0f, 0.0f); rotate(nmv, _a / (165 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 301.0f, 1.0f, 0.0f); translate(nmv, 75.0f, 1.0f, 0.0f);
scale(nmv, (1/27.7f) * 12.0f, (1/27.7f) * 12.0f, (1/27.7f) * 12.0f); scale(nmv, (1/27.7f) * 12.0f, (1/27.7f) * 12.0f, (1/27.7f) * 12.0f);
rotate(nmv, a / 0.6f, -0.283f, 1.0f, 0.0f); rotate(nmv, r / 0.6f, -0.283f, 1.0f, 0.0f);
transform_n_raster(_planet[7], nmv, projMat); transform_n_raster(_planet[7], nmv, projMat);
// Triton // Triton
rotate(nmv, a / 5.0f, 0.0f, 0.01f, 0.0f); rotate(nmv, r / 5.0f, 0.0f, 0.01f, 0.0f);
translate(nmv, 3.0f, 0.0f, 0.0f); translate(nmv, 3.0f, 0.0f, 0.0f);
scale(nmv, (1/10.0f), (1/10.0f), (1/10.0f)); scale(nmv, (1/10.0f), (1/10.0f), (1/10.0f));
transform_n_raster(_moon[16], nmv, projMat); transform_n_raster(_moon[16], nmv, projMat);
// PLUTO // PLUTO
memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */
rotate(nmv, a / (248 * 365.2425f), 0.0f, 1.0f, 0.0f); rotate(nmv, _a / (248 * 365.2425f), 0.0f, 1.0f, 0.0f);
translate(nmv, 394.0f, 1.0f, 0.0f); translate(nmv, 85.4f, 1.0f, 0.0f);
scale(nmv, (1/500.0f) * 12.0f, (1/500.0f) * 12.0f, (1/500.0f) * 12.0f); scale(nmv, (1/500.0f) * 12.0f, (1/500.0f) * 12.0f, (1/500.0f) * 12.0f);
rotate(nmv, a / 6.4, -0.119f, 1.0f, 0.0f); rotate(nmv, r / 6.4, -0.119f, 1.0f, 0.0f);
transform_n_raster(_planet[8], nmv, projMat); transform_n_raster(_planet[8], nmv, projMat);
// Charon // Charon
rotate(nmv, a / 5.0f, 0.0f, 0.01f, 0.0f); rotate(nmv, r / 5.0f, 0.0f, 0.01f, 0.0f);
translate(nmv, 3.0f, 0.0f, 0.0f); translate(nmv, 3.0f, 0.0f, 0.0f);
scale(nmv, (1/13.0f), (1/13.0f), (1/13.0f)); scale(nmv, (1/13.0f), (1/13.0f), (1/13.0f));
transform_n_raster(_moon[16], nmv, projMat); transform_n_raster(_moon[16], nmv, projMat);
@ -405,39 +486,51 @@ void draw(void) {
gl4dpScreenHasChanged(); gl4dpScreenHasChanged();
/* fonction permettant de raffraîchir l'ensemble de la fenêtre*/ /* fonction permettant de raffraîchir l'ensemble de la fenêtre*/
gl4dpUpdateScreen(NULL); gl4dpUpdateScreen(NULL);
if (_pause != 1) if (_pause != 1){
a += ((360.0 * dt) / 60) * _s; // 360 in 1 minute so 1 day = 1 min _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
}
} }
/*!\brief intercepte l'événement clavier pour modifier les options. */ /*!\brief intercepte l'événement clavier pour modifier les options. */
void key(int keycode) { void key(int keycode) {
double dtheta = M_PI, step = 5.0; double step = 5.0;
int i; int i;
switch(keycode) { switch(keycode) {
case GL4DK_UP: case GL4DK_UP:
_cam.y += 5 * dtheta; if (_movement)
_cam.y += 5;
break; break;
case GL4DK_DOWN: case GL4DK_DOWN:
_cam.y -= 5 * dtheta; if (_movement)
_cam.y -= 5;
break; break;
case GL4DK_RIGHT: case GL4DK_RIGHT:
_s += 60.0f; if (!_pause)
_s += 30.0f;
break; break;
case GL4DK_LEFT: case GL4DK_LEFT:
_s -= 60.0f; if (!_pause)
_s -= 30.0f;
break; break;
case GL4DK_w: case GL4DK_w:
if (_movement) {
_cam.x += -_v * step * sin(_cam.theta); _cam.x += -_v * step * sin(_cam.theta);
_cam.z += -_v * step * cos(_cam.theta); _cam.z += -_v * step * cos(_cam.theta);
}
break; break;
case GL4DK_s: case GL4DK_s:
if (_movement) {
_cam.x += _v * step * sin(_cam.theta); _cam.x += _v * step * sin(_cam.theta);
_cam.z += _v * step * cos(_cam.theta); _cam.z += _v * step * cos(_cam.theta);
}
break; break;
case GL4DK_a: case GL4DK_a:
if (_movement)
_cam.theta += _v * step; _cam.theta += _v * step;
break; break;
case GL4DK_d: case GL4DK_d:
if (_movement)
_cam.theta -= _v * step; _cam.theta -= _v * step;
break; break;
case GL4DK_p: case GL4DK_p:
@ -458,19 +551,100 @@ void key(int keycode) {
_v = 0.5f; _v = 0.5f;
} }
break; break;
case GL4DK_f: case GL4DK_o:
if (_movement) {
_cam.x = 0;
_cam.y = 200.0f;
_cam.z = 0;
_cam.theta = 0;
}
break;
case GL4DK_r:
_p = -1;
_pause = 0;
_movement = 1;
break; break;
case GL4DK_z: case GL4DK_z:
break; break;
case GL4DK_0: case GL4DK_0:
_cam.x = 0; _p = 0;
_cam.y = 1.0f; _pause = 1;
_cam.z = 10; _movement = 0;
_cam.theta = 0; _cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break; break;
case GL4DK_1: case GL4DK_1:
_p = 1;
_pause = 1;
_movement = 0;
_cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break; break;
case GL4DK_2: case GL4DK_2:
_p = 2;
_pause = 1;
_movement = 0;
_cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break;
case GL4DK_3:
_p = 3;
_pause = 1;
_movement = 0;
_cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break;
case GL4DK_4:
_p = 4;
_pause = 1;
_movement = 0;
_cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break;
case GL4DK_5:
_p = 5;
_pause = 1;
_movement = 0;
_cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break;
case GL4DK_6:
_p = 6;
_pause = 1;
_movement = 0;
_cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break;
case GL4DK_7:
_p = 7;
_pause = 1;
_movement = 0;
_cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break;
case GL4DK_8:
_p = 8;
_pause = 1;
_movement = 0;
_cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break;
case GL4DK_9:
_p = 9;
_pause = 1;
_movement = 0;
_cam.x = (int)_cam.x;
_cam.y = (int)_cam.y;
_cam.z = (int)_cam.z;
break; break;
case GL4DK_t: /* 't' la texture */ case GL4DK_t: /* 't' la texture */
_use_tex = !_use_tex; _use_tex = !_use_tex;
@ -525,19 +699,23 @@ void key(int keycode) {
} }
static void pmotion(int x, int y) { static void pmotion(int x, int y) {
if (_movement){
_xm = x; _xm = x;
_ym = y; _ym = y;
_cam.theta = -(_xm - (_wW >> 1)) / (float)_wW*10; _cam.theta = -(_xm - (_wW >> 1)) / (float)_wW*10;
}
} }
static void mouse(int button, int state, int x, int y) { static void mouse(int button, int state, int x, int y) {
if (_movement){
double dtheta = M_PI; double dtheta = M_PI;
if (button == GL4D_BUTTON_LEFT) if (button == GL4D_BUTTON_LEFT)
_cam.y += 10 * dtheta; _cam.y += dtheta;
if (button == GL4D_BUTTON_RIGHT) if (button == GL4D_BUTTON_RIGHT)
_cam.y -= 10 * dtheta; _cam.y -= dtheta;
if (button == GL4D_BUTTON_MIDDLE) if (button == GL4D_BUTTON_MIDDLE)
_cam.y = 1.0f; _cam.y = 1.0f;
}
} }
/*!\brief à appeler à la sortie du programme. */ /*!\brief à appeler à la sortie du programme. */