// 0 < d < 1: (1 / d) - 1
// 1 <= d < distance_range + 1: (-4 * max_force / (distance_range ^ 2)) * (d - (distance_range / 2) - 1) ^ 2 + max_force,
// otherwise: 0
-//
+// }
struct BodyRelation
{
f32 distance_range;
{
if (0 < d && d < 1)
{
- return (1.0f / d) - 1.0f;
+ // TEMP(Brendan)
+ persist const f32 repulsion_force = 100.0f;
+ return repulsion_force * (1 - d) / d;
}
if (1 <= d && d < br.distance_range + 1)
return 0;
}
-internal const
-BodyRelation body_relations[(i32) BodyType::Count][(i32) BodyType::Count] = {
- // Red Green Blue White
- /* 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, 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 } },
-};
+internal BodyRelation body_relations[(i32) BodyType::Count][(i32) BodyType::Count];
internal bool
bodies_collide(Body* b1, Body* b2)
return true;
}
-// TODO(Brendan): REMOVE THIS
-internal Array<Body *> other_bodies;
+// TODO(Brendan): :Parallel This is used to allow for a statically allocated array for the quad tree results. This will need to be a thread local variable.
+thread_local internal Array<Body *> other_bodies;
void nocheckin_init_other_bodies()
{
+ foreach (i, 0, (i32) BodyType::Count)
+ {
+ foreach (j, 0, (i32) BodyType::Count)
+ {
+ body_relations[i][j].max_force = randf(-200.0f, 200.0f);
+ body_relations[i][j].distance_range = randf(2.0f, 5.0f);
+ }
+ }
+
other_bodies.init();
other_bodies.ensure_capacity(1024);
}
force += norm_dir * force_mag;
}
- force += body->vel * -5.f;
+ force += body->vel * -6.f;
body->acc = force * (1.0f / body->mass);
body->vel += body->acc * dt;
#define WINDOW_TITLE "N-Body Simulation"
// TODO(Brendan): Remove this
-#define PARTICLE_COUNT 512
+#define PARTICLE_COUNT 1500
internal void
glfw_key_handler(GLFWwindow* window, i32 key, i32 scancode, i32 action, i32 mods)
Body tmp_body;
tmp_body.pos = V2f{ randf(0, 1200), randf(0, 1200) };
tmp_body.vel = V2f{ 0.0f, 0.0f };
- tmp_body.mass = randf(5.0f, 7.0f);
- tmp_body.body_type = static_cast<BodyType> ((rand() % 2) * 2);
+ tmp_body.mass = randf(3.0f, 6.0f);
+ tmp_body.body_type = static_cast<BodyType> ((rand() % 4));
state->bodies.push(tmp_body);
}