diff --git a/window.c b/window.c index 6eaba68..f44f399 100644 --- a/window.c +++ b/window.c @@ -26,15 +26,19 @@ static void key(int keycode); static void sortie(void); static void pmotion(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) */ static uint _screenId = 0; /*!\brief une surface représentant une sphere */ static surface_t * _sun = NULL; -static surface_t * _planet[9] = {NULL, NULL, NULL, - NULL, NULL, NULL, - NULL, NULL, NULL}; +static surface_t * _planet[9] = { NULL, NULL, NULL, + NULL, NULL, NULL, + NULL, NULL, NULL }; + static surface_t * _moon[18] = {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 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. */ int main(int argc, char ** argv) { @@ -162,9 +169,83 @@ void init(void) { 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. */ void draw(void) { - static float a = 0.0f; + static float r = 0.0f; static double t0 = 0, t, dt; t = gl4dGetElapsedTime(); dt = (t - t0) / 1000.0; @@ -182,169 +263,169 @@ void draw(void) { MIDENTITY(mvMat); // Y ----> 1.0 - (_ym - (_wH >> 1)) / (float)_wH * 5 - 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); - - // scales https://www.jpl.nasa.gov/infographics/infographic.view.php?id=10749 - // https://www.exploratorium.edu/ronh/solar_system/scale.pdf + 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); // SUN 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); scale(nmv, 2,2,2); transform_n_raster(_sun, nmv, projMat); // MERCURY memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ - rotate(nmv, (a / 87.97f), 0.0f, 1.0f, 0.0f); // orbit mouvement - translate(nmv, 3.9f, 1.0f, 0.0f); + rotate(nmv, (_a / 87.97f), 0.0f, 1.0f, 0.0f); // orbit mouvement + 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); - 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); // VENUS 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); 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); // EARTH 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); 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); // Moon - translate(nmv, 11.0f, 2.0f, 0.0f); - scale(nmv, (1/50.0f) , (1/50.0f), (1/50.0f)); + translate(nmv, 4.0f, 0.0f, 0.0f); + scale(nmv, (1/5.0f) , (1/5.0f), (1/5.0f)); transform_n_raster(_moon[0], nmv, projMat); // MARS 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); 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); memcpy(cpy, nmv, sizeof cpy); // 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); scale(nmv, (1/5.0f), (1/5.0f), (1/5.0f)); transform_n_raster(_moon[1], nmv, projMat); // 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); scale(cpy, (1/6.0f), (1/6.0f), (1/6.0f)); transform_n_raster(_moon[2], cpy, projMat); // JUPITER memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ - rotate(nmv, a / (12 * 365.2425f), 0.0f, 1.0f, 0.0f); - translate(nmv, 52.0f, 1.0f, 0.0f); + rotate(nmv, _a / (12 * 365.2425f), 0.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); - 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); memcpy(cpy, nmv, sizeof cpy); // Io - rotate(nmv, a * 3.0f, 0.0f, 0.1f, 0.0f); - translate(nmv, 5.0f, 0.0f, 0.0f); + rotate(nmv, r * 3.0f, 0.0f, 0.1f, 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. transform_n_raster(_moon[3], nmv, projMat); memcpy(nmv, cpy, sizeof nmv); // Europa - rotate(nmv, a / 2.0f, 0.0f, 0.1f, 0.0f); - translate(nmv, 8.0f, 0.0f, 0.0f); + rotate(nmv, r / 2.0f, 0.0f, 0.1f, 0.0f); + translate(nmv, 4.0f, 0.0f, 0.0f); scale(nmv, (1/13.2f), (1/13.2f), (1/13.2f)); transform_n_raster(_moon[4], nmv, projMat); memcpy(nmv, cpy, sizeof nmv); // Ganymede - rotate(nmv, a / 3.0f, 0.0f, 0.1f, 0.0f); - translate(nmv, 10.0f, 0.0f, 0.0f); + rotate(nmv, r / 3.0f, 0.0f, 0.1f, 0.0f); + translate(nmv, 5.0f, 0.0f, 0.0f); scale(nmv, (1/9.0f), (1/9.0f), (1/9.0f)); transform_n_raster(_moon[5], nmv, projMat); memcpy(nmv, cpy, sizeof nmv); // Callisto - rotate(nmv, a / 5.0f, 0.0f, 0.1f, 0.0f); - translate(nmv, 11.0f, 0.0f, 0.0f); + rotate(nmv, r / 5.0f, 0.0f, 0.1f, 0.0f); + translate(nmv, 6.0f, 0.0f, 0.0f); scale(nmv, (1/10.0f), (1/10.0f), (1/10.0f)); transform_n_raster(_moon[6], nmv, projMat); // SATURN memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ - rotate(nmv, a / (30 * 365.2425f), 0.0f, 1.0f, 0.0f); - translate(nmv, 95.4f, 1.0f, 0.0f); + rotate(nmv, _a / (30 * 365.2425f), 0.0f, 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); - 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); memcpy(cpy, nmv, sizeof cpy); // 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); scale(nmv, (1/20.0f), (1/20.0f), (1/20.0f)); transform_n_raster(_moon[7], nmv, projMat); memcpy(nmv, cpy, sizeof nmv); - + // 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); scale(nmv, (1/18.0f), (1/18.0f), (1/18.0f)); transform_n_raster(_moon[8], nmv, projMat); memcpy(nmv, cpy, sizeof nmv); - + // 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); scale(nmv, (1/15.0f), (1/15.0f), (1/15.0f)); transform_n_raster(_moon[9], nmv, projMat); memcpy(nmv, cpy, sizeof nmv); - + // 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); scale(nmv, (1/10.0f), (1/10.0f), (1/10.0f)); transform_n_raster(_moon[10], nmv, projMat); memcpy(nmv, cpy, sizeof nmv); - + // 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); scale(nmv, (1/14.0f), (1/14.0f), (1/14.0f)); transform_n_raster(_moon[11], nmv, projMat); // URANUS memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ - rotate(nmv, a / (84 * 365.2425f), 0.0f, 1.0f, 0.0f); - translate(nmv, 192.0f, 1.0f, 0.0f); + rotate(nmv, _a / (84 * 365.2425f), 0.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); - 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); memcpy(cpy, nmv, sizeof cpy); // 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); scale(nmv, (1/20.0f), (1/20.0f), (1/20.0f)); transform_n_raster(_moon[12], nmv, projMat); @@ -352,7 +433,7 @@ void draw(void) { memcpy (nmv, cpy, sizeof nmv); // 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); scale(nmv, (1/20.0f), (1/20.0f), (1/20.0f)); transform_n_raster(_moon[13], nmv, projMat); @@ -360,7 +441,7 @@ void draw(void) { memcpy (nmv, cpy, sizeof nmv); // 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); scale(nmv, (1/17.0f), (1/17.0f), (1/17.0f)); transform_n_raster(_moon[14], nmv, projMat); @@ -368,35 +449,35 @@ void draw(void) { memcpy (nmv, cpy, sizeof nmv); // 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); scale(nmv, (1/17.0f), (1/17.0f), (1/17.0f)); transform_n_raster(_moon[15], nmv, projMat); // NEPTUNE memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ - rotate(nmv, a / (165 * 365.2425f), 0.0f, 1.0f, 0.0f); - translate(nmv, 301.0f, 1.0f, 0.0f); + rotate(nmv, _a / (165 * 365.2425f), 0.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); - 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); - + // 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); scale(nmv, (1/10.0f), (1/10.0f), (1/10.0f)); transform_n_raster(_moon[16], nmv, projMat); // PLUTO memcpy(nmv, mvMat, sizeof nmv); /* copie mvMat dans nmv */ - rotate(nmv, a / (248 * 365.2425f), 0.0f, 1.0f, 0.0f); - translate(nmv, 394.0f, 1.0f, 0.0f); + rotate(nmv, _a / (248 * 365.2425f), 0.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); - 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); // 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); scale(nmv, (1/13.0f), (1/13.0f), (1/13.0f)); transform_n_raster(_moon[16], nmv, projMat); @@ -405,40 +486,52 @@ void draw(void) { gl4dpScreenHasChanged(); /* fonction permettant de raffraîchir l'ensemble de la fenêtre*/ gl4dpUpdateScreen(NULL); - if (_pause != 1) - a += ((360.0 * dt) / 60) * _s; // 360 in 1 minute so 1 day = 1 min + if (_pause != 1){ + _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. */ void key(int keycode) { - double dtheta = M_PI, step = 5.0; + double step = 5.0; int i; switch(keycode) { case GL4DK_UP: - _cam.y += 5 * dtheta; + if (_movement) + _cam.y += 5; break; case GL4DK_DOWN: - _cam.y -= 5 * dtheta; + if (_movement) + _cam.y -= 5; break; case GL4DK_RIGHT: - _s += 60.0f; + if (!_pause) + _s += 30.0f; break; case GL4DK_LEFT: - _s -= 60.0f; + if (!_pause) + _s -= 30.0f; break; case GL4DK_w: - _cam.x += -_v * step * sin(_cam.theta); - _cam.z += -_v * step * cos(_cam.theta); + if (_movement) { + _cam.x += -_v * step * sin(_cam.theta); + _cam.z += -_v * step * cos(_cam.theta); + } break; case GL4DK_s: - _cam.x += _v * step * sin(_cam.theta); - _cam.z += _v * step * cos(_cam.theta); + if (_movement) { + _cam.x += _v * step * sin(_cam.theta); + _cam.z += _v * step * cos(_cam.theta); + } break; case GL4DK_a: - _cam.theta += _v * step; + if (_movement) + _cam.theta += _v * step; break; case GL4DK_d: - _cam.theta -= _v * step; + if (_movement) + _cam.theta -= _v * step; break; case GL4DK_p: if (_pause == 0) @@ -458,19 +551,100 @@ void key(int keycode) { _v = 0.5f; } 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; case GL4DK_z: break; case GL4DK_0: - _cam.x = 0; - _cam.y = 1.0f; - _cam.z = 10; - _cam.theta = 0; + _p = 0; + _pause = 1; + _movement = 0; + _cam.x = (int)_cam.x; + _cam.y = (int)_cam.y; + _cam.z = (int)_cam.z; break; 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; 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; case GL4DK_t: /* 't' la texture */ _use_tex = !_use_tex; @@ -525,19 +699,23 @@ void key(int keycode) { } static void pmotion(int x, int y) { - _xm = x; - _ym = y; - _cam.theta = -(_xm - (_wW >> 1)) / (float)_wW*10; + if (_movement){ + _xm = x; + _ym = y; + _cam.theta = -(_xm - (_wW >> 1)) / (float)_wW*10; + } } static void mouse(int button, int state, int x, int y) { - double dtheta = M_PI; - if (button == GL4D_BUTTON_LEFT) - _cam.y += 10 * dtheta; - if (button == GL4D_BUTTON_RIGHT) - _cam.y -= 10 * dtheta; - if (button == GL4D_BUTTON_MIDDLE) - _cam.y = 1.0f; + 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; + } } /*!\brief à appeler à la sortie du programme. */