changing how the dt are calculated
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 10 Nov 2020 01:11:50 +0000 (19:11 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 10 Nov 2020 01:11:50 +0000 (19:11 -0600)
src/sim.cpp

index b132a52d9c36bef356336bc41b87ff43c9b43269..cda4e1aa4c063e2511b94ebf301be9673c9c6769 100644 (file)
 #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);