Browse Source
- Add TrackingMode and RenderFrameMode enums to renderer.h - Remove old state fields (was_following_body, previous_selected_body) - Add new state fields (camera_mode, frame_mode, last_target_index, local_frame_parent_index) - Update main.cpp and ui_renderer.cpp to use new field names - Refactor update_camera() with helper functions: - detect_camera_mode() - has_target_changed() - update_camera_target() - rotate_camera_orbitally() - zoom_camera() - update_last_target() - update_camera_frame_mode() - detect_render_frame_mode() - Add local frame transformation helpers: - get_local_frame_scale() - sim_to_render_local() - Add SOI_SCALE_TARGET constantmain
5 changed files with 326 additions and 104 deletions
@ -0,0 +1,119 @@
|
||||
#include <catch2/catch_test_macros.hpp> |
||||
#include "../src/physics.h" |
||||
#include "../src/simulation.h" |
||||
#include "../src/spacecraft.h" |
||||
#include "../src/config_loader.h" |
||||
#include <cmath> |
||||
#include <iostream> |
||||
|
||||
TEST_CASE("Debug orbit rendering coordinates", "[debug][rendering]") { |
||||
const double TIME_STEP = 60.0; |
||||
SimulationState* sim = create_simulation(10, 10, 0, TIME_STEP); |
||||
|
||||
REQUIRE(load_system_config(sim, "tests/test_orbit_rendering.toml")); |
||||
|
||||
Spacecraft* craft = &sim->spacecraft[0]; |
||||
CelestialBody* parent = &sim->bodies[craft->parent_index]; |
||||
|
||||
// Calculate orbit parameters (same as render_orbit() does)
|
||||
Vec3 r_vec = craft->local_position; |
||||
Vec3 velocity = craft->local_velocity; |
||||
Vec3 parent_pos = parent->global_position; |
||||
double r = vec3_magnitude(r_vec); |
||||
double v = vec3_magnitude(velocity); |
||||
double mu = G * parent->mass; |
||||
|
||||
// Calculate eccentricity vector
|
||||
double v_squared = v * v; |
||||
double r_dot_v = vec3_dot(r_vec, velocity); |
||||
Vec3 e_vec = { |
||||
(v_squared - mu / r) * r_vec.x - r_dot_v * velocity.x, |
||||
(v_squared - mu / r) * r_vec.y - r_dot_v * velocity.y, |
||||
(v_squared - mu / r) * r_vec.z - r_dot_v * velocity.z |
||||
}; |
||||
double e = vec3_magnitude(e_vec) / mu; |
||||
|
||||
// Calculate semi-major axis
|
||||
double specific_energy = (v * v) / 2.0 - mu / r; |
||||
double a = -mu / (2.0 * specific_energy); |
||||
|
||||
INFO("=== Orbit Parameters ==="); |
||||
INFO("Semi-major axis (a): " << a << " m"); |
||||
INFO("Eccentricity (e): " << e); |
||||
INFO("Orbital radius (r): " << r << " m"); |
||||
INFO("Velocity (v): " << v << " m/s"); |
||||
|
||||
// Calculate rendering scale factors
|
||||
double distance_scale = 1e-9; |
||||
double size_scale = 0.02; |
||||
|
||||
INFO(""); |
||||
INFO("=== Rendering Scale Factors ==="); |
||||
INFO("Distance scale (linear): " << distance_scale); |
||||
INFO("Size scale (log): " << size_scale); |
||||
|
||||
// Calculate Earth's rendered size
|
||||
float earth_render_radius = size_scale * log10(parent->radius); |
||||
INFO("Earth rendered radius: " << earth_render_radius << " units"); |
||||
|
||||
// Generate orbit points at 0°, 90°, 180°, 270°
|
||||
double b = a * sqrt(1.0 - e * e); |
||||
double c = a * e; |
||||
|
||||
INFO(""); |
||||
INFO("=== Orbit Point Coordinates ==="); |
||||
|
||||
for (int i = 0; i < 4; i++) { |
||||
double theta = (double)i / 4.0 * 2.0 * M_PI; |
||||
|
||||
// Orbital plane coordinates
|
||||
double x_orbit = a * cos(theta) - c; |
||||
double y_orbit = b * sin(theta); |
||||
|
||||
// Sim coordinates (using orbital_to_cartesian logic with circular orbit fix)
|
||||
Vec3 e_dir = vec3_normalize(e_vec); |
||||
Vec3 periapsis_dir; |
||||
|
||||
// For circular orbits, use position direction as periapsis direction
|
||||
if (vec3_magnitude(e_dir) < 0.001) { |
||||
periapsis_dir = vec3_normalize(r_vec); |
||||
} else { |
||||
periapsis_dir = e_dir; |
||||
} |
||||
|
||||
Vec3 h_vec = vec3_cross(r_vec, velocity); |
||||
Vec3 normal = vec3_normalize(h_vec); |
||||
Vec3 q_vec = vec3_cross(normal, periapsis_dir); |
||||
|
||||
Vec3 sim_pos = { |
||||
periapsis_dir.x * x_orbit + q_vec.x * y_orbit + parent_pos.x, |
||||
periapsis_dir.y * x_orbit + q_vec.y * y_orbit + parent_pos.y, |
||||
periapsis_dir.z * x_orbit + q_vec.z * y_orbit + parent_pos.z |
||||
}; |
||||
|
||||
// Render coordinates (using sim_to_render logic)
|
||||
double render_x = sim_pos.x * distance_scale; |
||||
double render_y = sim_pos.z * distance_scale; |
||||
double render_z = -sim_pos.y * distance_scale; |
||||
|
||||
double distance_from_center = sqrt(render_x*render_x + render_y*render_y + render_z*render_z); |
||||
|
||||
std::cout << "\nPoint " << i << " (" << (i * 90) << "°):" << std::endl; |
||||
std::cout << " Orbit plane: (" << x_orbit << ", " << y_orbit << ") m" << std::endl; |
||||
std::cout << " Sim pos: (" << sim_pos.x << ", " << sim_pos.y << ", " << sim_pos.z << ") m" << std::endl; |
||||
std::cout << " Render pos: (" << render_x << ", " << render_y << ", " << render_z << ") units" << std::endl; |
||||
std::cout << " Distance from center: " << distance_from_center << " units" << std::endl; |
||||
std::cout << " % of Earth radius: " << (distance_from_center / earth_render_radius * 100.0) << "%" << std::endl; |
||||
} |
||||
|
||||
INFO(""); |
||||
INFO("=== Scaling Diagnosis ==="); |
||||
double orbit_radius_render = r * distance_scale; |
||||
INFO("Orbital radius (render units): " << orbit_radius_render); |
||||
INFO("Ratio to Earth rendered radius: " << (orbit_radius_render / earth_render_radius)); |
||||
INFO("Earth rendered radius: " << earth_render_radius); |
||||
|
||||
REQUIRE(true); |
||||
|
||||
destroy_simulation(sim); |
||||
} |
||||
@ -0,0 +1,37 @@
|
||||
# Test Configuration: Orbit Rendering Debug |
||||
# Sun + Earth + LEO Satellite |
||||
# Used for diagnosing orbit coordinate generation and scaling |
||||
|
||||
[[bodies]] |
||||
name = "Sun" |
||||
mass = 1.989e30 |
||||
radius = 6.96e8 |
||||
parent_index = -1 |
||||
color = { r = 1.0, g = 1.0, b = 0.0 } |
||||
orbit = { |
||||
semi_major_axis = 0.0, |
||||
eccentricity = 0.0, |
||||
true_anomaly = 0.0 |
||||
} |
||||
|
||||
[[bodies]] |
||||
name = "Earth" |
||||
mass = 5.972e24 |
||||
radius = 6.371e6 |
||||
parent_index = 0 |
||||
color = { r = 0.0, g = 0.5, b = 1.0 } |
||||
orbit = { |
||||
semi_major_axis = 1.496e11, |
||||
eccentricity = 0.0, |
||||
true_anomaly = 0.0 |
||||
} |
||||
|
||||
[[spacecraft]] |
||||
name = "LEO_Satellite" |
||||
mass = 1000.0 |
||||
parent_index = 1 |
||||
orbit = { |
||||
altitude = 400000.0, |
||||
eccentricity = 0.0, |
||||
true_anomaly = 0.0 |
||||
} |
||||
Loading…
Reference in new issue