Ejemplo n.º 1
0
            private void RenderUpcomingEvents()
            {
                string vessel_guid  = vessel_.id.ToString();
                double current_time = plugin.CurrentTime();

                Style.HorizontalLine();
                if (first_future_manœuvre_.HasValue)
                {
                    int first_future_manœuvre    = first_future_manœuvre_.Value;
                    NavigationManoeuvre manœuvre =
                        plugin.FlightPlanGetManoeuvre(vessel_guid, first_future_manœuvre);
                    if (manœuvre.burn.initial_time > current_time)
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            UnityEngine.GUILayout.Label("Upcoming manœuvre #" +
                                                        (first_future_manœuvre + 1) + ":");
                            UnityEngine.GUILayout.Label(
                                "Ignition " + FormatTimeSpan(TimeSpan.FromSeconds(
                                                                 current_time - manœuvre.burn.initial_time)),
                                style: Style.RightAligned(UnityEngine.GUI.skin.label));
                        }
                    }
                    else
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            UnityEngine.GUILayout.Label("Ongoing manœuvre #" +
                                                        (first_future_manœuvre + 1) + ":");
                            UnityEngine.GUILayout.Label(
                                "Cutoff " + FormatTimeSpan(TimeSpan.FromSeconds(
                                                               current_time - manœuvre.final_time)),
                                style: Style.RightAligned(UnityEngine.GUI.skin.label));
                        }
                    }
                    // In career mode, the patched conic solver may be null.  In that case
                    // we do not offer the option of showing the manœuvre on the navball,
                    // even though the flight planner is still available to plan it.
                    // TODO(egg): We may want to consider setting the burn vector directly
                    // rather than going through the solver.
                    if (vessel_.patchedConicSolver != null)
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            show_guidance_ =
                                UnityEngine.GUILayout.Toggle(show_guidance_, "Show on navball");
                            if (UnityEngine.GUILayout.Button("Warp to manœuvre"))
                            {
                                TimeWarp.fetch.WarpTo(manœuvre.burn.initial_time - 60);
                            }
                        }
                    }
                }
                else
                {
                    // Reserve some space to avoid the UI changing shape if we have
                    // nothing to say.
                    UnityEngine.GUILayout.Label("All manœuvres are in the past",
                                                Style.Warning(UnityEngine.GUI.skin.label));
                    UnityEngine.GUILayout.Space(Width(1));
                }
            }
Ejemplo n.º 2
0
            // Returns true iff the guidance node should be cleared.
            internal bool ShowGuidance(NavigationManoeuvre manoeuvre,
                                       int manoeuvre_index)
            {
                string vessel_guid = vessel_.id.ToString();
                XYZ    guidance    = plugin.FlightPlanGetGuidance(vessel_guid, manoeuvre_index);

                if (show_guidance_ &&
                    !double.IsNaN(guidance.x + guidance.y + guidance.z))
                {
                    if (guidance_node_ == null ||
                        !vessel_.patchedConicSolver.maneuverNodes.Contains(
                            guidance_node_))
                    {
                        while (vessel_.patchedConicSolver.maneuverNodes.Count > 0)
                        {
                            vessel_.patchedConicSolver.maneuverNodes.Last().RemoveSelf();
                        }
                        guidance_node_ = vessel_.patchedConicSolver.AddManeuverNode(
                            manoeuvre.burn.initial_time);
                    }
                    else if (vessel_.patchedConicSolver.maneuverNodes.Count > 1)
                    {
                        while (vessel_.patchedConicSolver.maneuverNodes.Count > 1)
                        {
                            if (vessel_.patchedConicSolver.maneuverNodes.First() ==
                                guidance_node_)
                            {
                                vessel_.patchedConicSolver.maneuverNodes.Last().RemoveSelf();
                            }
                            else
                            {
                                vessel_.patchedConicSolver.maneuverNodes.First().RemoveSelf();
                            }
                        }
                    }
                    var      stock_orbit = guidance_node_.patch;
                    Vector3d stock_velocity_at_node_time =
                        stock_orbit.getOrbitalVelocityAtUT(
                            manoeuvre.burn.initial_time).xzy;
                    Vector3d stock_displacement_from_parent_at_node_time =
                        stock_orbit.getRelativePositionAtUT(
                            manoeuvre.burn.initial_time).xzy;
                    UnityEngine.Quaternion stock_frenet_frame_to_world =
                        UnityEngine.Quaternion.LookRotation(
                            stock_velocity_at_node_time,
                            Vector3d.Cross(
                                stock_velocity_at_node_time,
                                stock_displacement_from_parent_at_node_time));
                    guidance_node_.DeltaV =
                        ((Vector3d)manoeuvre.burn.delta_v).magnitude *
                        (Vector3d)(UnityEngine.Quaternion.Inverse(
                                       stock_frenet_frame_to_world) *
                                   (Vector3d)guidance);
                    guidance_node_.UT = manoeuvre.burn.initial_time;
                    vessel_.patchedConicSolver.UpdateFlightPlan();
                    return(false);
                }
                return(true);
            }
Ejemplo n.º 3
0
            public void Reset(NavigationManoeuvre manoeuvre)
            {
                Burn burn = manoeuvre.burn;

                Δv_tangent_.value   = burn.delta_v.x;
                Δv_normal_.value    = burn.delta_v.y;
                Δv_binormal_.value  = burn.delta_v.z;
                initial_time_.value = burn.initial_time;
                reference_frame_selector_.Reset(burn.frame);
                duration_ = manoeuvre.duration;
                initial_mass_in_tonnes_ = manoeuvre.initial_mass_in_tonnes;
            }
Ejemplo n.º 4
0
            public void Reset(NavigationManoeuvre manœuvre)
            {
                Burn burn = manœuvre.burn;

                Δv_tangent_.value  = burn.delta_v.x;
                Δv_normal_.value   = burn.delta_v.y;
                Δv_binormal_.value = burn.delta_v.z;
                initial_time_      = burn.initial_time;
                reference_frame_selector_.SetFrameParameters(burn.frame);
                is_inertially_fixed_    = burn.is_inertially_fixed;
                duration_               = manœuvre.duration;
                initial_mass_in_tonnes_ = manœuvre.initial_mass_in_tonnes;
            }
Ejemplo n.º 5
0
 public void Reset(NavigationManoeuvre manoeuvre)
 {
     Burn burn = manoeuvre.burn;
     Δv_tangent_.value = burn.delta_v.x;
     Δv_normal_.value = burn.delta_v.y;
     Δv_binormal_.value = burn.delta_v.z;
     initial_time_.value = burn.initial_time;
     reference_frame_selector_.Reset(burn.frame);
     duration_ = manoeuvre.duration;
     initial_mass_in_tonnes_ = manoeuvre.initial_mass_in_tonnes;
 }
Ejemplo n.º 6
0
            private void RenderUpcomingEvents()
            {
                string vessel_guid  = predicted_vessel.id.ToString();
                double current_time = plugin.CurrentTime();

                Style.HorizontalLine();
                if (first_future_manœuvre_.HasValue)
                {
                    int first_future_manœuvre    = first_future_manœuvre_.Value;
                    NavigationManoeuvre manœuvre =
                        plugin.FlightPlanGetManoeuvre(vessel_guid, first_future_manœuvre);
                    if (manœuvre.burn.initial_time > current_time)
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            UnityEngine.GUILayout.Label(
                                L10N.CacheFormat("#Principia_FlightPlan_UpcomingManœuvre",
                                                 first_future_manœuvre + 1));
                            UnityEngine.GUILayout.Label(
                                L10N.CacheFormat("#Principia_FlightPlan_IgnitionCountdown",
                                                 FormatTimeSpan(
                                                     current_time - manœuvre.burn.initial_time)),
                                style: Style.RightAligned(UnityEngine.GUI.skin.label));
                        }
                    }
                    else
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            UnityEngine.GUILayout.Label(
                                L10N.CacheFormat("#Principia_FlightPlan_OngoingManœuvre",
                                                 first_future_manœuvre + 1));
                            UnityEngine.GUILayout.Label(
                                L10N.CacheFormat("#Principia_FlightPlan_CutoffCountdown",
                                                 FormatTimeSpan(
                                                     current_time - manœuvre.final_time)),
                                style: Style.RightAligned(UnityEngine.GUI.skin.label));
                        }
                    }
                    // In career mode, the patched conic solver may be null.  In that case
                    // we do not offer the option of showing the manœuvre on the navball,
                    // even though the flight planner is still available to plan it.
                    // TODO(egg): We may want to consider setting the burn vector directly
                    // rather than going through the solver.
                    if (predicted_vessel.patchedConicSolver != null)
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            show_guidance_ = UnityEngine.GUILayout.Toggle(
                                show_guidance_,
                                L10N.CacheFormat("#Principia_FlightPlan_ShowManœuvreOnNavball"));
                            if (UnityEngine.GUILayout.Button(
                                    L10N.CacheFormat("#Principia_FlightPlan_WarpToManœuvre")))
                            {
                                TimeWarp.fetch.WarpTo(manœuvre.burn.initial_time - 60);
                            }
                        }
                    }
                }
                else
                {
                    // Reserve some space to avoid the UI changing shape if we have
                    // nothing to say.
                    UnityEngine.GUILayout.Label(
                        L10N.CacheFormat(
                            "#Principia_FlightPlan_Warning_AllManœuvresInThePast"),
                        Style.Warning(UnityEngine.GUI.skin.label));
                    UnityEngine.GUILayout.Space(Width(1));
                }
            }
Ejemplo n.º 7
0
            private void UpdateVesselAndBurnEditors()
            {
                {
                    string vessel_guid = predicted_vessel?.id.ToString();
                    if (vessel_guid == null ||
                        previous_predicted_vessel_ != predicted_vessel ||
                        !plugin.FlightPlanExists(vessel_guid) ||
                        plugin.FlightPlanNumberOfManoeuvres(vessel_guid) !=
                        burn_editors_?.Count)
                    {
                        if (burn_editors_ != null)
                        {
                            ClearBurnEditors();
                        }
                        previous_predicted_vessel_ = predicted_vessel;
                    }
                }

                if (burn_editors_ == null)
                {
                    string vessel_guid = predicted_vessel?.id.ToString();
                    if (vessel_guid != null &&
                        plugin.FlightPlanExists(vessel_guid))
                    {
                        burn_editors_ = new List <BurnEditor>();
                        final_time_.value_if_different =
                            plugin.FlightPlanGetDesiredFinalTime(vessel_guid);
                        for (int i = 0;
                             i < plugin.FlightPlanNumberOfManoeuvres(vessel_guid);
                             ++i)
                        {
                            // Dummy initial time, we call |Reset| immediately afterwards.
                            burn_editors_.Add(new BurnEditor(adapter_,
                                                             predicted_vessel,
                                                             initial_time: 0,
                                                             index: i,
                                                             get_burn_at_index: burn_editors_.
                                                             ElementAtOrDefault));
                            burn_editors_.Last().Reset(
                                plugin.FlightPlanGetManoeuvre(vessel_guid, i));
                        }
                    }
                }

                if (burn_editors_ != null)
                {
                    string vessel_guid  = predicted_vessel?.id.ToString();
                    double current_time = plugin.CurrentTime();
                    first_future_manœuvre_ = null;
                    for (int i = 0; i < burn_editors_.Count; ++i)
                    {
                        NavigationManoeuvre manœuvre =
                            plugin.FlightPlanGetManoeuvre(vessel_guid, i);
                        if (current_time < manœuvre.final_time)
                        {
                            first_future_manœuvre_ = i;
                            break;
                        }
                    }
                    // Must be computed during layout as it affects the layout of some of the
                    // differential sliders.
                    number_of_anomalous_manœuvres_ =
                        plugin.FlightPlanNumberOfAnomalousManoeuvres(vessel_guid);
                }
            }
Ejemplo n.º 8
0
            private void RenderUpcomingEvents()
            {
                string vessel_guid           = vessel_.id.ToString();
                double current_time          = plugin_.CurrentTime();
                bool   should_clear_guidance = true;

                for (int i = 0; i < burn_editors_.Count; ++i)
                {
                    NavigationManoeuvre manoeuvre =
                        plugin_.FlightPlanGetManoeuvre(vessel_guid, i);
                    if (manoeuvre.final_time > current_time)
                    {
                        if (manoeuvre.burn.initial_time > current_time)
                        {
                            UnityEngine.GUILayout.TextArea("Upcoming manœuvre: #" + (i + 1));
                            UnityEngine.GUILayout.Label(
                                "Ignition " + FormatTimeSpan(TimeSpan.FromSeconds(
                                                                 current_time - manoeuvre.burn.initial_time)));
                        }
                        else
                        {
                            UnityEngine.GUILayout.TextArea("Ongoing manœuvre: #" + (i + 1));
                            UnityEngine.GUILayout.Label(
                                "Cutoff " + FormatTimeSpan(TimeSpan.FromSeconds(
                                                               current_time - manoeuvre.final_time)));
                        }
                        UnityEngine.GUILayout.BeginHorizontal();
                        show_guidance_ =
                            UnityEngine.GUILayout.Toggle(show_guidance_, "Show on navball");
                        if (UnityEngine.GUILayout.Button("Warp to manœuvre"))
                        {
                            TimeWarp.fetch.WarpTo(manoeuvre.burn.initial_time - 60);
                        }
                        UnityEngine.GUILayout.EndHorizontal();
                        if (show_guidance_ &&
                            !double.IsNaN(manoeuvre.inertial_direction.x +
                                          manoeuvre.inertial_direction.y +
                                          manoeuvre.inertial_direction.z))
                        {
                            if (guidance_node_ == null ||
                                !vessel_.patchedConicSolver.maneuverNodes.Contains(
                                    guidance_node_))
                            {
                                while (vessel_.patchedConicSolver.maneuverNodes.Count > 0)
                                {
                                    vessel_.patchedConicSolver.maneuverNodes.Last().RemoveSelf();
                                }
                                guidance_node_ = vessel_.patchedConicSolver.AddManeuverNode(
                                    manoeuvre.burn.initial_time);
                            }
                            else if (vessel_.patchedConicSolver.maneuverNodes.Count > 1)
                            {
                                while (vessel_.patchedConicSolver.maneuverNodes.Count > 1)
                                {
                                    if (vessel_.patchedConicSolver.maneuverNodes.First() ==
                                        guidance_node_)
                                    {
                                        vessel_.patchedConicSolver.maneuverNodes.Last().RemoveSelf();
                                    }
                                    else
                                    {
                                        vessel_.patchedConicSolver.maneuverNodes.First().RemoveSelf();
                                    }
                                }
                            }
                            Vector3d stock_velocity_at_node_time =
                                vessel_.orbit.getOrbitalVelocityAtUT(
                                    manoeuvre.burn.initial_time).xzy;
                            Vector3d stock_displacement_from_parent_at_node_time =
                                vessel_.orbit.getRelativePositionAtUT(
                                    manoeuvre.burn.initial_time).xzy;
                            UnityEngine.Quaternion stock_frenet_frame_to_world =
                                UnityEngine.Quaternion.LookRotation(
                                    stock_velocity_at_node_time,
                                    Vector3d.Cross(stock_velocity_at_node_time,
                                                   stock_displacement_from_parent_at_node_time));
                            guidance_node_.OnGizmoUpdated(
                                ((Vector3d)manoeuvre.burn.delta_v).magnitude *
                                (Vector3d)(UnityEngine.Quaternion.Inverse(
                                               stock_frenet_frame_to_world) *
                                           (Vector3d)manoeuvre.inertial_direction),
                                manoeuvre.burn.initial_time);
                            should_clear_guidance = false;
                        }
                        break;
                    }
                }
                if (should_clear_guidance && guidance_node_ != null)
                {
                    guidance_node_.RemoveSelf();
                    guidance_node_ = null;
                }
            }
Ejemplo n.º 9
0
            private void UpdateVesselAndBurnEditors()
            {
                {
                    string vessel_guid = vessel_?.id.ToString();
                    if (vessel_guid == null ||
                        vessel_ != FlightGlobals.ActiveVessel ||
                        !plugin.HasVessel(vessel_guid) ||
                        !plugin.FlightPlanExists(vessel_guid) ||
                        plugin.FlightPlanNumberOfManoeuvres(vessel_guid) !=
                        burn_editors_?.Count)
                    {
                        if (burn_editors_ != null)
                        {
                            foreach (BurnEditor editor in burn_editors_)
                            {
                                editor.Close();
                            }
                            burn_editors_ = null;
                            Shrink();
                        }
                        vessel_ = FlightGlobals.ActiveVessel;
                    }
                }

                if (burn_editors_ == null)
                {
                    string vessel_guid = vessel_?.id.ToString();
                    if (vessel_guid != null &&
                        plugin.HasVessel(vessel_guid) &&
                        plugin.FlightPlanExists(vessel_guid))
                    {
                        burn_editors_     = new List <BurnEditor>();
                        final_time_.value = plugin.FlightPlanGetDesiredFinalTime(vessel_guid);
                        for (int i = 0;
                             i < plugin.FlightPlanNumberOfManoeuvres(vessel_guid);
                             ++i)
                        {
                            // Dummy initial time, we call |Reset| immediately afterwards.
                            burn_editors_.Add(
                                new BurnEditor(adapter_,
                                               vessel_,
                                               initial_time: 0,
                                               index: burn_editors_.Count,
                                               previous_burn: burn_editors_.LastOrDefault()));
                            burn_editors_.Last().Reset(
                                plugin.FlightPlanGetManoeuvre(vessel_guid, i));
                        }
                    }
                }

                if (burn_editors_ != null)
                {
                    string vessel_guid  = vessel_?.id.ToString();
                    double current_time = plugin.CurrentTime();
                    first_future_manœuvre_ = null;
                    for (int i = 0; i < burn_editors_.Count; ++i)
                    {
                        NavigationManoeuvre manœuvre =
                            plugin.FlightPlanGetManoeuvre(vessel_guid, i);
                        if (current_time < manœuvre.final_time)
                        {
                            first_future_manœuvre_ = i;
                            break;
                        }
                    }
                }
            }
Ejemplo n.º 10
0
            private void RenderUpcomingEvents()
            {
                string vessel_guid           = vessel_.id.ToString();
                double current_time          = plugin_.CurrentTime();
                bool   should_clear_guidance = true;

                for (int i = 0; i < burn_editors_.Count; ++i)
                {
                    NavigationManoeuvre manoeuvre =
                        plugin_.FlightPlanGetManoeuvre(vessel_guid, i);
                    if (manoeuvre.final_time > current_time)
                    {
                        if (manoeuvre.burn.initial_time > current_time)
                        {
                            UnityEngine.GUILayout.TextArea("Upcoming manœuvre: #" + (i + 1));
                            UnityEngine.GUILayout.Label(
                                "Ignition " + FormatTimeSpan(TimeSpan.FromSeconds(
                                                                 current_time - manoeuvre.burn.initial_time)));
                        }
                        else
                        {
                            UnityEngine.GUILayout.TextArea("Ongoing manœuvre: #" + (i + 1));
                            UnityEngine.GUILayout.Label(
                                "Cutoff " + FormatTimeSpan(TimeSpan.FromSeconds(
                                                               current_time - manoeuvre.final_time)));
                        }
                        // In career mode, the patched conic solver may be null.  In that case
                        // we do not offer the option of showing the manœuvre on the navball,
                        // even though the flight planner is still available to plan it.
                        // TODO(egg): We may want to consider setting the burn vector directly
                        // rather than going through the solver.
                        if (vessel_.patchedConicSolver != null)
                        {
                            using (new HorizontalLayout()) {
                                show_guidance_ =
                                    UnityEngine.GUILayout.Toggle(show_guidance_, "Show on navball");
                                if (UnityEngine.GUILayout.Button("Warp to manœuvre"))
                                {
                                    TimeWarp.fetch.WarpTo(manoeuvre.burn.initial_time - 60);
                                }
                            }
                            XYZ guidance = plugin_.FlightPlanGetGuidance(vessel_guid, i);
                            if (show_guidance_ &&
                                !double.IsNaN(guidance.x + guidance.y + guidance.z))
                            {
                                if (guidance_node_ == null ||
                                    !vessel_.patchedConicSolver.maneuverNodes.Contains(
                                        guidance_node_))
                                {
                                    while (vessel_.patchedConicSolver.maneuverNodes.Count > 0)
                                    {
                                        vessel_.patchedConicSolver.maneuverNodes.Last().RemoveSelf();
                                    }
                                    guidance_node_ = vessel_.patchedConicSolver.AddManeuverNode(
                                        manoeuvre.burn.initial_time);
                                }
                                else if (vessel_.patchedConicSolver.maneuverNodes.Count > 1)
                                {
                                    while (vessel_.patchedConicSolver.maneuverNodes.Count > 1)
                                    {
                                        if (vessel_.patchedConicSolver.maneuverNodes.First() ==
                                            guidance_node_)
                                        {
                                            vessel_.patchedConicSolver.maneuverNodes.Last().RemoveSelf();
                                        }
                                        else
                                        {
                                            vessel_.patchedConicSolver.maneuverNodes.First().RemoveSelf();
                                        }
                                    }
                                }
                                Vector3d stock_velocity_at_node_time =
                                    vessel_.orbit.getOrbitalVelocityAtUT(
                                        manoeuvre.burn.initial_time).xzy;
                                Vector3d stock_displacement_from_parent_at_node_time =
                                    vessel_.orbit.getRelativePositionAtUT(
                                        manoeuvre.burn.initial_time).xzy;
                                UnityEngine.Quaternion stock_frenet_frame_to_world =
                                    UnityEngine.Quaternion.LookRotation(
                                        stock_velocity_at_node_time,
                                        Vector3d.Cross(
                                            stock_velocity_at_node_time,
                                            stock_displacement_from_parent_at_node_time));
                                guidance_node_.DeltaV =
                                    ((Vector3d)manoeuvre.burn.delta_v).magnitude *
                                    (Vector3d)(UnityEngine.Quaternion.Inverse(
                                                   stock_frenet_frame_to_world) *
                                               (Vector3d)guidance);
                                guidance_node_.UT = manoeuvre.burn.initial_time;
                                vessel_.patchedConicSolver.UpdateFlightPlan();
                                should_clear_guidance = false;
                            }
                            break;
                        }
                    }
                }
                if (should_clear_guidance && guidance_node_ != null)
                {
                    guidance_node_.RemoveSelf();
                    guidance_node_ = null;
                }
            }