reverting some things to how they were
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 27 Oct 2020 02:18:56 +0000 (21:18 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 27 Oct 2020 02:18:56 +0000 (21:18 -0500)
src/physics.cpp
src/sim.cpp

index 2a21459f1e51958a74fa3176cbde0b184b950755..a2a43fc39c4961f16607bb947f2507b900656bbb 100644 (file)
@@ -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<Body>& 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)
     {
index 93eceedf4822d65a6520f566c9e30aa7fe6a86a7..7a3abd8d646e9504df02bb21adeff19338baedd1 100644 (file)
@@ -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; }
+*/
     }
 }