|
|
|
@ -154,10 +154,10 @@ static bool has_target_changed(RenderState* render_state) { |
|
|
|
static void update_camera_target(RenderState* render_state, SimulationState* sim) { |
|
|
|
static void update_camera_target(RenderState* render_state, SimulationState* sim) { |
|
|
|
if (render_state->selected_body_index >= 0) { |
|
|
|
if (render_state->selected_body_index >= 0) { |
|
|
|
CelestialBody* body = &sim->bodies[render_state->selected_body_index]; |
|
|
|
CelestialBody* body = &sim->bodies[render_state->selected_body_index]; |
|
|
|
|
|
|
|
|
|
|
|
// Camera target is at origin for selected body
|
|
|
|
// Camera target is at origin for selected body
|
|
|
|
render_state->camera.target = (Vector3){0, 0, 0}; |
|
|
|
render_state->camera.target = (Vector3){0, 0, 0}; |
|
|
|
|
|
|
|
|
|
|
|
// Set initial camera position based on children distance
|
|
|
|
// Set initial camera position based on children distance
|
|
|
|
float distance = get_initial_camera_distance(body, sim, render_state); |
|
|
|
float distance = get_initial_camera_distance(body, sim, render_state); |
|
|
|
render_state->camera.position = (Vector3){0, distance * 0.3f, distance}; |
|
|
|
render_state->camera.position = (Vector3){0, distance * 0.3f, distance}; |
|
|
|
@ -267,11 +267,11 @@ void update_camera(RenderState* render_state, SimulationState* sim) { |
|
|
|
// Calculate initial camera distance based on children of the selected body
|
|
|
|
// Calculate initial camera distance based on children of the selected body
|
|
|
|
float get_initial_camera_distance(CelestialBody* body, SimulationState* sim, RenderState* render_state) { |
|
|
|
float get_initial_camera_distance(CelestialBody* body, SimulationState* sim, RenderState* render_state) { |
|
|
|
int body_index = body - sim->bodies; |
|
|
|
int body_index = body - sim->bodies; |
|
|
|
|
|
|
|
|
|
|
|
// Calculate average distance to children (bodies and spacecraft)
|
|
|
|
// Calculate average distance to children (bodies and spacecraft)
|
|
|
|
int child_count = 0; |
|
|
|
int child_count = 0; |
|
|
|
double total_distance = 0.0; |
|
|
|
double total_distance = 0.0; |
|
|
|
|
|
|
|
|
|
|
|
// Check body children
|
|
|
|
// Check body children
|
|
|
|
for (int i = 0; i < sim->body_count; i++) { |
|
|
|
for (int i = 0; i < sim->body_count; i++) { |
|
|
|
if (sim->bodies[i].parent_index == body_index) { |
|
|
|
if (sim->bodies[i].parent_index == body_index) { |
|
|
|
@ -280,7 +280,7 @@ float get_initial_camera_distance(CelestialBody* body, SimulationState* sim, Ren |
|
|
|
total_distance += dist * render_state->distance_scale; |
|
|
|
total_distance += dist * render_state->distance_scale; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check spacecraft children
|
|
|
|
// Check spacecraft children
|
|
|
|
for (int i = 0; i < sim->craft_count; i++) { |
|
|
|
for (int i = 0; i < sim->craft_count; i++) { |
|
|
|
if (sim->spacecraft[i].parent_index == body_index) { |
|
|
|
if (sim->spacecraft[i].parent_index == body_index) { |
|
|
|
@ -289,11 +289,11 @@ float get_initial_camera_distance(CelestialBody* body, SimulationState* sim, Ren |
|
|
|
total_distance += dist * render_state->distance_scale; |
|
|
|
total_distance += dist * render_state->distance_scale; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (child_count > 0) { |
|
|
|
if (child_count > 0) { |
|
|
|
return (float)(total_distance / child_count); |
|
|
|
return (float)(total_distance / child_count); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// No children - use 100x body radius as fallback
|
|
|
|
// No children - use 100x body radius as fallback
|
|
|
|
float body_radius = scale_radius(body->radius, render_state->distance_scale); |
|
|
|
float body_radius = scale_radius(body->radius, render_state->distance_scale); |
|
|
|
return body_radius * 100.0f; |
|
|
|
return body_radius * 100.0f; |
|
|
|
|