From: Brendan Hansen Date: Tue, 27 Oct 2020 20:21:09 +0000 (-0500) Subject: randomization X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b49c64cc707d57e0bc3c301a2dccff84d6d54eb6;p=csc718.git randomization --- diff --git a/src/physics.cpp b/src/physics.cpp index 9b973d5..a627cf8 100644 --- a/src/physics.cpp +++ b/src/physics.cpp @@ -8,7 +8,7 @@ // 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; @@ -20,7 +20,9 @@ get_force_magnitude_at_distance(BodyRelation br, f32 d) { 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) @@ -35,14 +37,7 @@ get_force_magnitude_at_distance(BodyRelation br, f32 d) 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) @@ -69,10 +64,19 @@ body_can_move(Body* body, const Array other_bodies, V2f d) return true; } -// TODO(Brendan): REMOVE THIS -internal Array 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 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); } @@ -99,7 +103,7 @@ body_accumulate_move(Body* body, QuadTree* qt_bodies, f64 dt) 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; diff --git a/src/sim.cpp b/src/sim.cpp index 878b109..8e53d26 100644 --- a/src/sim.cpp +++ b/src/sim.cpp @@ -27,7 +27,7 @@ #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) @@ -209,8 +209,8 @@ sim_state_init(SimState* state) 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 ((rand() % 2) * 2); + tmp_body.mass = randf(3.0f, 6.0f); + tmp_body.body_type = static_cast ((rand() % 4)); state->bodies.push(tmp_body); }