Skip to content
Snippets Groups Projects
Commit c89f47c3 authored by BobLeHibou's avatar BobLeHibou
Browse files

EDIT: vec2.normalize: ... E NON DIVIDE PER ZERO !

parent 95920e2e
No related branches found
No related tags found
No related merge requests found
......@@ -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));
}
}
......
......@@ -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};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment