From 1cd8e46ff31f23bd6d45be05717aeaaabaa0c86e Mon Sep 17 00:00:00 2001 From: eliasnijs Date: Sat, 25 May 2024 20:41:51 +0200 Subject: [PATCH] bugfix: integers used in vector operations causing errors, now fixed, set to float32 --- src/boids.cpp | 2 ++ src/math/vectors.cpp | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/boids.cpp b/src/boids.cpp index 8d10c7c..c4b4b83 100644 --- a/src/boids.cpp +++ b/src/boids.cpp @@ -113,6 +113,7 @@ update_boid(BoidsApplication *app, Boid *b) { b->vel.x = Clamp(-p->max_vel, b->vel.x, p->max_vel); b->vel.y = Clamp(-p->max_vel, b->vel.y, p->max_vel); + b->pos = vec2_add(b->pos, b->vel); if (b->pos.x < 0) { @@ -125,6 +126,7 @@ update_boid(BoidsApplication *app, Boid *b) { } else if (b->pos.y > window_height) { b->vel.y = -Abs(b->vel.y); } + } internal void diff --git a/src/math/vectors.cpp b/src/math/vectors.cpp index bbcdbf5..a36dae5 100644 --- a/src/math/vectors.cpp +++ b/src/math/vectors.cpp @@ -16,12 +16,12 @@ vec2_sub(vec2 a, vec2 b) { } internal vec2 -vec2_div(vec2 a, int s) { +vec2_div(vec2 a, float32 s) { return (vec2){ a.x / s, a.y / s }; } internal vec2 -vec2_mul(vec2 a, int s) { +vec2_mul(vec2 a, float32 s) { return (vec2){ a.x * s, a.y * s }; }