From c89f47c37bbe0912a23b9357df472617d8b9cffc Mon Sep 17 00:00:00 2001 From: BobLeHibou <owldev@bluewin.ch> Date: Mon, 20 Dec 2021 11:25:52 +0100 Subject: [PATCH] EDIT: vec2.normalize: ... E NON DIVIDE PER ZERO ! --- planet/planet.c | 3 +-- vec2/vec2.c | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/planet/planet.c b/planet/planet.c index fcc1e57..371fa86 100755 --- a/planet/planet.c +++ b/planet/planet.c @@ -65,7 +65,7 @@ void show_system(struct gfx_context_t* ctxt, system_t* system) { // draw planets for (uint32_t i = 0; i < system->nb_planets; ++i) { const coordinates xy = vec2_to_coordinates_centered( - vec2_normalize(system->planets[i].pos), + vec2_mul(vec2_norm(system->planets[i].pos) / (PER_MARS * 1.25), vec2_normalize(system->planets[i].pos)), ctxt->width, ctxt->height); draw_full_circle(ctxt, xy.column, xy.row, 20, COLOR_BLUE); @@ -95,7 +95,6 @@ void update_system(system_t* system, double delta_t) { 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/vec2/vec2.c b/vec2/vec2.c index b8991e6..60a972b 100755 --- a/vec2/vec2.c +++ b/vec2/vec2.c @@ -67,6 +67,7 @@ double vec2_norm(vec2 v) { /// @return The new normalized vector. vec2 vec2_normalize(vec2 v) { double norm = vec2_norm(v); + if (0 == norm) { return vec2_create_zero(); } return (vec2) {.x = v.x / norm, .y = v.y / norm}; } -- GitLab