From d51f7b62311d9733f29ee44d6cabad40316ca6c4 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 26 Oct 2020 21:18:56 -0500 Subject: [PATCH] reverting some things to how they were --- src/physics.cpp | 12 ++++++------ src/sim.cpp | 42 +++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/physics.cpp b/src/physics.cpp index 2a21459..a2a43fc 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -20,7 +20,7 @@ get_force_magnitude_at_distance(BodyRelation br, f32 d) { if (0 < d && d < 1) { - return (1 / d) - 1; + return (1.0f / d) - 1.0f; } if (1 <= d && d < br.distance_range + 1) @@ -38,10 +38,10 @@ get_force_magnitude_at_distance(BodyRelation br, f32 d) internal const BodyRelation body_relations[(i32) BodyType::Count][(i32) BodyType::Count] = { // Red Green Blue White - /* Red */ { { 10.0f, 10.0f }, { 0.0f, 0.0f }, { 10.0f, -2.0f }, { 0.0f, 0.0f } }, - /* Green */ { { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f } }, - /* Blue */ { { 4.0f, 10.0f }, { 0.0f, 0.0f }, { 3.0f, -2.0f }, { 0.0f, 0.0f } }, - /* White */ { { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f } }, + /* Red */ { { 10.0f, 10.0f }, { 0.0f, 0.0f }, { 10.0f, -2.0f }, { 0.0f, 0.0f } }, + /* Green */ { { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f } }, + /* Blue */ { { 4.0f, 10.0f }, { 0.0f, 0.0f }, { 3.0f, -2.0f }, { 0.0f, 0.0f } }, + /* White */ { { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f } }, }; internal bool @@ -83,7 +83,7 @@ body_accumulate_move(Body* body, QuadTree& qt_bodies, f64 dt) V2f force = { 0.0f, 0.0f }; other_bodies.clear(); - qt_bodies.query(AABB { body->pos.x - 200, body->pos.y - 200, 400, 400 }, &other_bodies); + qt_bodies.query(AABB { body->pos.x - 300, body->pos.y - 300, 600, 600 }, &other_bodies); For (other_bodies) { diff --git a/src/sim.cpp b/src/sim.cpp index 93eceed..7a3abd8 100644 --- a/src/sim.cpp +++ b/src/sim.cpp @@ -219,34 +219,30 @@ internal f64 left_over_dt = 0.0; internal void update(SimState* state, f64 dt) { - left_over_dt += dt; const f64 step = 0.01; - while (left_over_dt >= step) - { - state->qt_bodies.init(AABB { -(f32) window_width, -(f32)window_height, (f32) window_width * 2, (f32) window_height * 2 }); - state->qt_body_allocator.reset(); - For (state->bodies) state->qt_bodies.insert(&it, &state->qt_body_allocator); + state->qt_bodies.init(AABB { -(f32) window_width, -(f32)window_height, (f32) window_width * 2, (f32) window_height * 2 }); + state->qt_body_allocator.reset(); + For (state->bodies) state->qt_bodies.insert(&it, &state->qt_body_allocator); + + For (state->bodies) body_accumulate_move(&it, state->qt_bodies, step); + For (state->bodies) { + body_apply_move(&it); + /* + if (it.pos.x < -window_width) it.pos.x = -window_width; + else if (it.pos.x >= window_width * 2) it.pos.x = window_width * 2; - For (state->bodies) body_accumulate_move(&it, state->qt_bodies, step); - For (state->bodies) { - body_apply_move(&it); - /* - if (it.pos.x < -window_width) it.pos.x = -window_width; - else if (it.pos.x >= window_width * 2) it.pos.x = window_width * 2; - - if (it.pos.y < -window_height) it.pos.y = -window_height; - else if (it.pos.y >= window_height * 2) it.pos.y = window_height * 2; + if (it.pos.y < -window_height) it.pos.y = -window_height; + else if (it.pos.y >= window_height * 2) it.pos.y = window_height * 2; */ - - if (it.pos.x < 0) it.pos.x = 0; - else if (it.pos.x >= window_width) it.pos.x = window_width; - - if (it.pos.y < 0) it.pos.y = 0; - else if (it.pos.y >= window_height) it.pos.y = window_height; - } - left_over_dt -= step; + /* + if (it.pos.x < 0) { it.pos.x = 0; it.vel.x = 0; } + else if (it.pos.x >= window_width) { it.pos.x = window_width; it.vel.x = 0; } + + if (it.pos.y < 0) { it.pos.y = 0; it.vel.y = 0; } + else if (it.pos.y >= window_height) { it.pos.y = window_height; it.vel.y = 0; } +*/ } } -- 2.25.1