From c3a46062d7f209fe515bdc667cc47ed62ad06624 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Sun, 18 Jan 2026 11:30:26 -0500 Subject: [PATCH] Initialize camera to follow root body on startup --- src/main.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 801c568..6a33426 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,12 +36,21 @@ void run_gui_simulation(SimulationState* sim) { RenderState render_state; setup_camera(&render_state); + // Find root body (body with parent_index == -1) + int root_body_index = -1; + for (int i = 0; i < sim->body_count; i++) { + if (sim->bodies[i].parent_index == -1) { + root_body_index = i; + break; + } + } + // Initialize UI state - render_state.selected_body_index = -1; // No selection initially + render_state.selected_body_index = root_body_index >= 0 ? root_body_index : -1; render_state.previous_selected_body = -1; // Previous selected body index render_state.body_list_scroll = 0; // Initial scroll position - render_state.body_list_active = -1; // No active item initially - render_state.camera_follow_body = false; // Camera not following initially + render_state.body_list_active = root_body_index >= 0 ? root_body_index : -1; // Sync with selected body + render_state.camera_follow_body = root_body_index >= 0; // Follow root body if found render_state.camera_offset = (Vector3){ 0, 50, 100 }; // Default offset render_state.was_following_body = false;