diff --git a/src/game.cpp b/src/game.cpp index 32c1d69..893b601 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -126,18 +126,18 @@ selectOrbit(GameState* gs, GameOrbit* orbit) bool addManeuver(GameOrbit* orbit, - double anomaly, - vec3 impulse_vector, + ImpulseType impulse_type, + double true_anomaly, double impulse_delta_v) { - assert(orbit); + ManeuverNode& node = orbit->maneuver; - if (anomaly < -M_PI || anomaly > M_PI) { - LOGF(Error, "invalid true anomaly: %f\n", anomaly); + if (true_anomaly < -M_PI || true_anomaly > M_PI) { + LOGF(Error, "invalid true true_anomaly: %f\n", true_anomaly); return false; } - if (orbit->maneuver.active) { + if (node.active) { LOGF(Warning, "cannot add multiple maneuvers (yet)\n"); return false; } @@ -147,21 +147,34 @@ addManeuver(GameOrbit* orbit, return false; } - orbit->maneuver.true_anomaly = anomaly; - //orbit->maneuver.impulse_vector = ... - orbit->maneuver.impulse_delta_v = impulse_delta_v; - orbit->maneuver.active = true; + node.impulse_type = impulse_type; + // TODO: thrust calculations + //double flight_path_angle = orbit->system.sat.gamma; + //node.impulse_vector.x = ... - return true; + if (node.impulse_type == ImpulseType::PROGRADE) { + LOGF(Debug, "adding prograde maneuver\n"); + node.true_anomaly = true_anomaly; + node.impulse_delta_v = impulse_delta_v; + node.active = true; + + return true; + } + + LOGF(Warning, "failed to add maneuver\n"); + assert(0); + return false; } void removeManeuver(GameOrbit* orbit) { - assert(orbit); // TODO: multiple maneuver nodes - // NOTE: implicitly sets orbit->maneuver.active to false - orbit->maneuver = {0}; + ManeuverNode& node = orbit->maneuver; + node.impulse_type = ImpulseType::NONE; + node.true_anomaly = 0.f; + node.impulse_delta_v = 0.f; + node.active = false; } // NOTE: test if the maneuver node would have occured between 2 orbit positions @@ -194,7 +207,7 @@ applyManeuver(GameOrbit* orbit) LOGF(Debug, "applying maneuver\n"); // FIXME: assuming prograde impulse vector - assert(orbit->maneuver.impulse_type == ManeuverType::PROGRADE); + assert(orbit->maneuver.impulse_type == ImpulseType::PROGRADE); // re-calculate state vectors at the maneuver node TwoBodySystem& sys = orbit->system; @@ -223,8 +236,6 @@ applyManeuver(GameOrbit* orbit) assert(utilCStrMatch(buf->name, "position")); assert(buf->data_size == orbit->e3d.vert_count * sizeof(vec3)); updateGLBuffer(buf, orbit->e3d.vertices); - - removeManeuver(orbit); } // internal diff --git a/src/game.h b/src/game.h index c82e0c5..b69a390 100644 --- a/src/game.h +++ b/src/game.h @@ -19,8 +19,9 @@ struct Ellipse3D uint vert_count; }; -enum struct ManeuverType +enum struct ImpulseType { + NONE, PROGRADE, RETROGRADE, INCLINATION_CHANGE, @@ -31,13 +32,13 @@ enum struct ManeuverType struct ManeuverNode { + ImpulseType impulse_type; double true_anomaly; - vec3 impulse_vector; - ManeuverType impulse_type; double impulse_delta_v; - // TODO: thrust calculations - bool active; + + // TODO: thrust calculations + //vec3 impulse_vector; }; struct GameOrbit @@ -86,7 +87,9 @@ void ellipse3DUpdate(EllipseParameters ep, Ellipse3D& e3d); void selectOrbit(GameState* gs, GameOrbit* orbit); -bool addManeuver(GameOrbit* orbit, double anomaly, vec3 impulse_vector, +bool addManeuver(GameOrbit* orbit, + ImpulseType impulse_type, + double true_anomaly, double impulse_delta_v); void removeManeuver(GameOrbit* orbit); diff --git a/src/gooey.cpp b/src/gooey.cpp index feba60d..662808a 100644 --- a/src/gooey.cpp +++ b/src/gooey.cpp @@ -249,6 +249,7 @@ drawManeuverWindow(GameState* gs) SliderScalar("maneuver anomaly", ImGuiDataType_Double, &anom, &min_anom, &max_anom, "%.19f"); + // FIXME: map ImpulseType to strings for UI // select maneuver vector const char* items[] = { "prograde", @@ -262,7 +263,7 @@ drawManeuverWindow(GameState* gs) InputFloat("impulse dv, km/s", &dv, 0.1, 4.0, "%.1f"); if (Button("apply")) { - if (!addManeuver(orbit, anom, vec3(), dv)) { + if (!addManeuver(orbit, ImpulseType::PROGRADE, anom, dv)) { // flash a color or something? } } diff --git a/src/main.cpp b/src/main.cpp index 76d463b..352733d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -205,7 +205,7 @@ loadScene(GameState* gs, RenderState* rs) double a = 26564.5; // semi-major axis in km double e = 0.7411; // eccentricity GameOrbit* go_1 = loadOrbit(gs, rs, body, orbitInit(a, e), rg, "sat_01"); - addManeuver(go_1, M_PI / 4, vec3(), 0.1); + addManeuver(go_1, ImpulseType::PROGRADE, M_PI / 4, 0.2); double a_2 = r + 10000; double e_2 = 0; @@ -270,6 +270,7 @@ updateOrbit(GameOrbit* orbit, bool running, double time_step) orbit->system.sat.theta)) { applyManeuver(orbit); + removeManeuver(orbit); } } }