diff --git a/main.c b/main.c index b7e82e2ee7e34d9c74ceaab298a9b7cbe1e92c63..f3e36496d22a88c19027a28dc5a5d5581d6f8801 100755 --- a/main.c +++ b/main.c @@ -11,7 +11,7 @@ #define SUN_RADIUS 50 -#define DELTA_T 3600.0 +#define DELTA_T 8000.0 int main() { srand(time(NULL)); @@ -32,7 +32,6 @@ int main() { // end : draw state of system // begin : update your system update_system(&sys, DELTA_T); - usleep(100000); // end : update system if (gfx_keypressed() == SDLK_ESCAPE) { break; } } diff --git a/planet/constants.h b/planet/constants.h index 7e90817a807a43b70e356b7d0f990c527a16d8a6..78eda772952ec3ebbbf07c74e46d197ae3769d9f 100644 --- a/planet/constants.h +++ b/planet/constants.h @@ -2,6 +2,10 @@ #define PLANET_CONSTANTS_H +// display +#define DISPLAY_RADIUS_DIV 1.0e23 + + #define G 6.67e-11 #define M_SOLEIL 1.989e30 diff --git a/planet/planet.c b/planet/planet.c index b10f6f70800bd9e91d65fc060cc99e5b8ce66989..fcc1e5790ff9dc41f6ed71ee033530bf4ce77fbc 100755 --- a/planet/planet.c +++ b/planet/planet.c @@ -20,22 +20,22 @@ system_t create_system(double delta_t) { system.star = create_planet(M_SOLEIL, vec2_create_zero()); system.nb_planets = 4; system.planets = malloc(system.nb_planets * sizeof(planet_t)); - double masses[NB_PLANETS] = { + double masses[] = { M_MERCURE, M_VENUS, M_TERRE, M_MARS}; - vec2 positions[NB_PLANETS] = { + vec2 positions[] = { vec2_create(PER_MERCURE, 0.0), vec2_create(PER_VENUS, 0.0), vec2_create(PER_TERRE, 0.0), vec2_create(PER_MARS, 0.0)}; - double eccentricities[NB_PLANETS] = { + double eccentricities[] = { E_MERCURE, E_VENUS, E_TERRE, E_MARS}; - double axis_major[NB_PLANETS] = { + double axis_major[] = { A_MERCURE, A_VENUS, A_TERRE, @@ -55,9 +55,12 @@ system_t create_system(double delta_t) { } -void show_system(struct gfx_context_t* ctxt, system_t* system, const uint32_t width, const uint32_t height) { +void show_system(struct gfx_context_t* ctxt, system_t* system) { // draw sun - const coordinates xy_sun = vec2_to_coordinates_centered(vec2_normalize(system->star.pos), width, height); + const coordinates xy_sun = vec2_to_coordinates_centered( + vec2_normalize(system->star.pos), + ctxt->width, + ctxt->height); draw_full_circle(ctxt, xy_sun.column, xy_sun.row, 50, COLOR_YELLOW); // draw planets for (uint32_t i = 0; i < system->nb_planets; ++i) { @@ -85,12 +88,14 @@ void update_system(system_t* system, double delta_t) { const vec2 a_k = vec2_mul(a_norm, u); a = vec2_add(a, a_k); } + a = vec2_mul(-1.0, a); // correct sign: towards center // update position vec2 next_pos = vec2_mul(2.0, system->planets[i].pos); next_pos = vec2_sub(next_pos, system->planets[i].prec_pos); next_pos = vec2_add(next_pos, vec2_mul(delta_t * delta_t, a)); system->planets[i].prec_pos = system->planets[i].pos; system->planets[i].pos = next_pos; + printf("%lf %lf %lf\n", system->planets[i].pos.x, system->planets[i].pos.y, vec2_norm(a)); } } diff --git a/planet/planet.h b/planet/planet.h index 8db31c9d78cb9b6e17f05f93f414566849ea5e57..4995e1ededb667ab5ecddd648409fd7261434b30 100755 --- a/planet/planet.h +++ b/planet/planet.h @@ -22,8 +22,7 @@ planet_t create_planet(double mass, vec2 pos); system_t create_system(double delta_t); -//void show_system(struct gfx_context_t *ctxt, system_t *system); -void show_system(struct gfx_context_t* ctxt, system_t* system, const uint32_t width, const uint32_t height); +void show_system(struct gfx_context_t* ctxt, system_t* system); void update_system(system_t* system, double delta_t);