};
void nocheckin_init_other_bodies();
-void body_accumulate_move(Body* body, QuadTree<Body>& other_bodies, f64 dt);
-void body_apply_move(Body* body);
+void body_accumulate_move(Body* body, QuadTree<Body>* qt_bodies, f64 dt);
+void body_apply_move(Body* body, f64 dt);
#endif //PHYSICS_H
\ No newline at end of file
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 } },
+ /* Red */ { { 1.0f, 300.0f }, { 0.0f, 0.0f }, { 10.0f, -100.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 } },
+ /* Blue */ { { 4.0f, 200.0f }, { 0.0f, 0.0f }, { 3.0f, -100.0f }, { 0.0f, 0.0f } },
/* White */ { { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f }, { 0.0f, 0.0f } },
};
}
void
-body_accumulate_move(Body* body, QuadTree<Body>& qt_bodies, f64 dt)
+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 - 300, body->pos.y - 300, 600, 600 }, &other_bodies);
+ qt_bodies->query(AABB { body->pos.x - 300, body->pos.y - 300, 600, 600 }, &other_bodies);
For (other_bodies)
{
}
void
-body_apply_move(Body* body)
+body_apply_move(Body* body, f64 dt)
{
- body->pos += body->vel;
+ body->pos += body->vel * dt;
}
\ No newline at end of file
#define WINDOW_HEIGHT 900
#define WINDOW_TITLE "N-Body Simulation"
+// TODO(Brendan): Remove this
+#define PARTICLE_COUNT 512
+
internal void
glfw_key_handler(GLFWwindow* window, i32 key, i32 scancode, i32 action, i32 mods)
{
{
// NOTE(Brendan): Need to initialize the array since it does not get constructed because I refuse to use the 'new' keyword. alloc<T> uses malloc under the hood and cannot initialize the result.
state->bodies.init();
- state->bodies.ensure_capacity(2048);
+ state->bodies.ensure_capacity(PARTICLE_COUNT);
- foreach (i, 0, 2048)
+ foreach (i, 0, PARTICLE_COUNT)
{
Body tmp_body;
tmp_body.pos = V2f{ randf(0, 1200), randf(0, 1200) };
state->bodies.push(tmp_body);
}
- state->qt_body_allocator.init(2048);
+ state->qt_body_allocator.init(PARTICLE_COUNT);
}
-internal f64 left_over_dt = 0.0;
// NOTE(Brendan): dt is expected to be in units of "per second".
internal void
update(SimState* state, f64 dt)
{
- const f64 step = 0.01;
+ persist const f64 step = 0.01;
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;
-
- 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; 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; }
-*/
- }
+ For (state->bodies) body_accumulate_move(&it, &state->qt_bodies, step);
+ For (state->bodies) body_apply_move(&it, step);
}
// NOTE CLEANUP(Brendan): Bunch of graphics state that should go elsewhere.