Browse Source

Fix orbit rendering to use local_velocity for nested orbits

main
cinnaboot 6 months ago
parent
commit
8278cb0366
  1. 19
      src/renderer.cpp

19
src/renderer.cpp

@ -301,7 +301,8 @@ void render_orbit(CelestialBody* body, CelestialBody* parent, RenderState* rende
Vec3 r_vec = vec3_sub(body->position, parent->position); Vec3 r_vec = vec3_sub(body->position, parent->position);
double r = vec3_magnitude(r_vec); double r = vec3_magnitude(r_vec);
double v = vec3_magnitude(body->velocity); Vec3 v_vec = body->local_velocity;
double v = vec3_magnitude(v_vec);
if (r < 1.0) return; if (r < 1.0) return;
@ -309,11 +310,11 @@ void render_orbit(CelestialBody* body, CelestialBody* parent, RenderState* rende
double specific_energy = (v * v) / 2.0 - mu / r; double specific_energy = (v * v) / 2.0 - mu / r;
double v_squared = v * v; double v_squared = v * v;
double r_dot_v = r_vec.x * body->velocity.x + r_vec.y * body->velocity.y + r_vec.z * body->velocity.z; double r_dot_v = r_vec.x * v_vec.x + r_vec.y * v_vec.y + r_vec.z * v_vec.z;
Vec3 e_vec = { Vec3 e_vec = {
(v_squared - mu / r) * r_vec.x - r_dot_v * body->velocity.x, (v_squared - mu / r) * r_vec.x - r_dot_v * v_vec.x,
(v_squared - mu / r) * r_vec.y - r_dot_v * body->velocity.y, (v_squared - mu / r) * r_vec.y - r_dot_v * v_vec.y,
(v_squared - mu / r) * r_vec.z - r_dot_v * body->velocity.z (v_squared - mu / r) * r_vec.z - r_dot_v * v_vec.z
}; };
double e = vec3_magnitude(e_vec) / mu; double e = vec3_magnitude(e_vec) / mu;
@ -324,7 +325,7 @@ void render_orbit(CelestialBody* body, CelestialBody* parent, RenderState* rende
128 128
}; };
OrbitalBasis basis = calculate_orbital_basis(r_vec, body->velocity, e_vec); OrbitalBasis basis = calculate_orbital_basis(r_vec, v_vec, e_vec);
if (e < 0.98) { if (e < 0.98) {
double a = -mu / (2.0 * specific_energy); double a = -mu / (2.0 * specific_energy);
@ -340,9 +341,9 @@ void render_orbit(CelestialBody* body, CelestialBody* parent, RenderState* rende
render_hyperbolic_orbit(p, e, basis, parent->position, render_state, orbit_color); render_hyperbolic_orbit(p, e, basis, parent->position, render_state, orbit_color);
} else { } else {
Vec3 h_vec = { Vec3 h_vec = {
r_vec.y * body->velocity.z - r_vec.z * body->velocity.y, r_vec.y * v_vec.z - r_vec.z * v_vec.y,
r_vec.z * body->velocity.x - r_vec.x * body->velocity.z, r_vec.z * v_vec.x - r_vec.x * v_vec.z,
r_vec.x * body->velocity.y - r_vec.y * body->velocity.x r_vec.x * v_vec.y - r_vec.y * v_vec.x
}; };
double h_squared = h_vec.x * h_vec.x + h_vec.y * h_vec.y + h_vec.z * h_vec.z; double h_squared = h_vec.x * h_vec.x + h_vec.y * h_vec.y + h_vec.z * h_vec.z;
double p = h_squared / mu; double p = h_squared / mu;

Loading…
Cancel
Save