|
|
|
|
@ -301,7 +301,8 @@ void render_orbit(CelestialBody* body, CelestialBody* parent, RenderState* rende
|
|
|
|
|
|
|
|
|
|
Vec3 r_vec = vec3_sub(body->position, parent->position); |
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
@ -309,11 +310,11 @@ void render_orbit(CelestialBody* body, CelestialBody* parent, RenderState* rende
|
|
|
|
|
double specific_energy = (v * v) / 2.0 - mu / r; |
|
|
|
|
|
|
|
|
|
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 = { |
|
|
|
|
(v_squared - mu / r) * r_vec.x - r_dot_v * body->velocity.x, |
|
|
|
|
(v_squared - mu / r) * r_vec.y - r_dot_v * body->velocity.y, |
|
|
|
|
(v_squared - mu / r) * r_vec.z - r_dot_v * body->velocity.z |
|
|
|
|
(v_squared - mu / r) * r_vec.x - r_dot_v * v_vec.x, |
|
|
|
|
(v_squared - mu / r) * r_vec.y - r_dot_v * v_vec.y, |
|
|
|
|
(v_squared - mu / r) * r_vec.z - r_dot_v * v_vec.z |
|
|
|
|
}; |
|
|
|
|
double e = vec3_magnitude(e_vec) / mu; |
|
|
|
|
|
|
|
|
|
@ -324,7 +325,7 @@ void render_orbit(CelestialBody* body, CelestialBody* parent, RenderState* rende
|
|
|
|
|
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) { |
|
|
|
|
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); |
|
|
|
|
} else { |
|
|
|
|
Vec3 h_vec = { |
|
|
|
|
r_vec.y * body->velocity.z - r_vec.z * body->velocity.y, |
|
|
|
|
r_vec.z * body->velocity.x - r_vec.x * body->velocity.z, |
|
|
|
|
r_vec.x * body->velocity.y - r_vec.y * body->velocity.x |
|
|
|
|
r_vec.y * v_vec.z - r_vec.z * v_vec.y, |
|
|
|
|
r_vec.z * v_vec.x - r_vec.x * v_vec.z, |
|
|
|
|
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 p = h_squared / mu; |
|
|
|
|
|