From 146c14c81cec51fdf408bbbf3c83afd7babc2871 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 9 Nov 2020 19:11:50 -0600 Subject: [PATCH] changing how the dt are calculated --- src/sim.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/sim.cpp b/src/sim.cpp index b132a52..cda4e1a 100644 --- a/src/sim.cpp +++ b/src/sim.cpp @@ -19,13 +19,6 @@ #include "ui.h" #include "log.h" -// TODO(Brendan): Move this -#define PI 3.141592653589793238462643383 - -#define WINDOW_WIDTH 1600 -#define WINDOW_HEIGHT 900 -#define WINDOW_TITLE "N-Body Simulation" - // :ArbitraryConstant #define PARTICLE_COUNT 2500 @@ -55,7 +48,7 @@ init_glfw() if (!glfwInit()) panic_and_die("Failed to initalize GLFW."); glfwSetErrorCallback(glfw_error_handler); - window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE, NULL, NULL); + window = glfwCreateWindow(1600, 900, "N-Body Simulation", NULL, NULL); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); glfwMakeContextCurrent(window); @@ -81,7 +74,7 @@ deinit_glfw() glfwTerminate(); } -#define CIRCLE_POINT_COUNT 36 // NOTE(Brendan): Treat a circle as a many-sided polygon. +#define CIRCLE_POINT_COUNT 12 // NOTE(Brendan): Treat a circle as a many-sided polygon. // NOTE(Brendan): Returns the VAO where the mesh data was bound. internal GLuint @@ -97,8 +90,8 @@ create_circle_mesh() foreach (i, 0, CIRCLE_POINT_COUNT) { f32 t = (f32) i / (f32) CIRCLE_POINT_COUNT; - circle_points[i].x = cos(t * 2 * PI); - circle_points[i].y = sin(t * 2 * PI); + circle_points[i].x = cos(t * 2 * 3.1415926535897); + circle_points[i].y = sin(t * 2 * 3.1415926535897); } GLuint vertex_buffer; @@ -142,6 +135,8 @@ struct SimState ThreadData thread_data[NUM_THREADS - 1]; }; +internal f64 TEMP_dt = 0; + internal void update_bodies_partial(SimState *state, i32 index) { @@ -150,8 +145,8 @@ update_bodies_partial(SimState *state, i32 index) persist const f64 step = 0.01; - foreach (i, low, high) body_accumulate_move(&state->bodies[i], &state->qt_bodies, step); - foreach (i, low, high) body_apply_move(&state->bodies[i], step); + foreach (i, low, high) body_accumulate_move(&state->bodies[i], &state->qt_bodies, TEMP_dt); + foreach (i, low, high) body_apply_move(&state->bodies[i], TEMP_dt); } internal void* @@ -222,6 +217,7 @@ update(SimState* state, f64 dt) if (glfwGetKey(window, GLFW_KEY_Q)) state->camera.scale *= 1.02f; if (glfwGetKey(window, GLFW_KEY_A)) state->camera.scale /= 1.02f; + TEMP_dt = dt; pthread_barrier_wait(&state->thread_sync_barrier); update_bodies_partial(state, 0); -- 2.25.1