Beispiel #1
0
        internal override void Display()
        {
            if (IsActive)
            {
                var size = new System.Numerics.Vector2(200, 100);
                var pos  = new System.Numerics.Vector2(_state.MainWinSize.X / 2 - size.X / 2, _state.MainWinSize.Y / 2 - size.Y / 2);

                ImGui.SetNextWindowSize(size, ImGuiCond.FirstUseEver);
                ImGui.SetNextWindowPos(pos, ImGuiCond.FirstUseEver);

                if (ImGui.Begin(_displayText, ref IsActive, _flags))
                {
                    //put calcs that needs refreshing each frame in here. (ie calculations from mouse cursor position)
                    if (_orbitWidget != null)
                    {
                        switch (CurrentState)
                        {
                        case States.NeedsEntity:

                            break;

                        case States.NeedsTarget:
                        {
                        }

                        break;

                        case States.NeedsInsertionPoint:
                        {
                            var maxprogradeDV = _maxDV - Math.Abs(_radialDV);
                            var maxradialDV   = _maxDV - Math.Abs(_progradeDV);
                            if (ImGui.SliderFloat("Prograde DV", ref _progradeDV, -maxprogradeDV, maxprogradeDV))
                            {
                                InsertionCalcs();
                            }
                            if (ImGui.SliderFloat("Radial DV", ref _radialDV, -maxradialDV, maxradialDV))
                            {
                                InsertionCalcs();
                            }

                            var mousePos = ImGui.GetMousePos();

                            var mouseWorldPos = _state.Camera.MouseWorldCoordinate();
                            _targetInsertionPoint_AU = (mouseWorldPos - GetTargetPosition());         //ralitive to the target body

                            _moveWidget.SetArrivalPosition(_targetInsertionPoint_AU);

                            //var velAU = OrbitProcessor.PreciseOrbitalVector(sgpCBAU, ralPosCBAU, smaCurrOrbtAU);


                            var ke = OrbitMath.KeplerFromPositionAndVelocity(_stdGravParamTargetBody, _targetInsertionPoint_AU, _insertionOrbitalVelocity, _departureDateTime);
                            _ke = ke;

                            _orbitWidget.SetParametersFromKeplerElements(ke, _targetInsertionPoint_AU);
                            _apoapsisKm   = Distance.AuToKm(ke.Apoapsis);
                            _periapsisKM  = Distance.AuToKm(ke.Periapsis);
                            _eccentricity = ke.Eccentricity;
                            break;
                        }

                        /*
                         * case States.NeedsSecondApsis:
                         * {
                         *   TODO: when we've got newtonion engines, allow second apsis choice and expend Dv.
                         *  var mousePos = ImGui.GetMousePos();
                         *
                         *  var mouseWorldPos = _state.Camera.MouseWorldCoordinate();
                         *
                         *  var ralitivePos = (GetTargetPosition() - mouseWorldPos);
                         *  _orbitWidget.SetPeriapsis(ralitivePos.X, ralitivePos.Y);
                         *
                         *  //_periapsisKM = Distance.AuToKm((GetTargetPosition() - mouseWorldPos).Length());
                         *  var distanceSelected = Distance.AuToKm((GetTargetPosition() - mouseWorldPos).Length());
                         *  var d1 = Math.Max(_peMin, distanceSelected); //can't be lower than body radius
                         *  _periapsisKM = Math.Min(d1, _apoapsisKm);  //can't be higher than apoapsis.
                         *
                         *  break;
                         * }*/
                        case States.NeedsActioning:
                        {
                            var maxprogradeDV = _maxDV - Math.Abs(_radialDV);
                            var maxradialDV   = _maxDV - Math.Abs(_progradeDV);
                            if (ImGui.SliderFloat("Prograde DV", ref _progradeDV, -maxprogradeDV, maxprogradeDV))
                            {
                                InsertionCalcs();
                            }
                            if (ImGui.SliderFloat("Radial DV", ref _radialDV, -maxradialDV, maxradialDV))
                            {
                                InsertionCalcs();
                            }
                            var ke = OrbitMath.KeplerFromPositionAndVelocity(_stdGravParamTargetBody, _targetInsertionPoint_AU, _insertionOrbitalVelocity, _departureDateTime);
                            _ke = ke;
                            _orbitWidget.SetParametersFromKeplerElements(ke, _targetInsertionPoint_AU);
                            _apoapsisKm   = Distance.AuToKm(ke.Apoapsis);
                            _periapsisKM  = Distance.AuToKm(ke.Periapsis);
                            _eccentricity = ke.Eccentricity;
                            break;
                        }

                        default:
                            break;
                        }
                    }


                    ImGui.SetTooltip(_tooltipText);
                    ImGui.Text("Target: ");
                    if (TargetEntity != null)
                    {
                        ImGui.SameLine();
                        ImGui.Text(TargetEntity.Name);
                    }
                    ImGui.Text("Apoapsis: ");
                    ImGui.SameLine();
                    ImGui.Text(_apoapsisKm.ToString("g3") + " (Alt: " + _apAlt.ToString("g3") + ")");

                    ImGui.Text("Periapsis: ");
                    ImGui.SameLine();
                    ImGui.Text(_periapsisKM.ToString("g3") + " (Alt: " + _peAlt.ToString("g3") + ")");

                    ImGui.Text("DepartureVelocity: ");
                    //ImGui.SameLine();
                    ImGui.Text(_departureOrbitalSpeed.ToString() + " AU");
                    ImGui.Text(Distance.AuToKm(_departureOrbitalSpeed).ToString() + " KM");

                    ImGui.Text("InsertionVelocity: ");
                    //ImGui.SameLine();
                    ImGui.Text(_insertionOrbitalSpeed.ToString() + " AU");
                    ImGui.Text(Distance.AuToKm(_insertionOrbitalSpeed).ToString() + " KM");

                    ImGui.Text("Eccentricity: ");
                    ImGui.Text(_eccentricity.ToString("g3"));

                    ImGui.Text("Departure Vector: ");
                    ImGui.SameLine();
                    ImGui.Text(_departureOrbitalVelocity.ToString("g3"));
                    ImGui.Text(Distance.AuToMt(_departureOrbitalVelocity).ToString("N") + "m/s");

                    ImGui.Text("Departure Angle: ");
                    ImGui.SameLine();
                    ImGui.Text(_departureAngle.ToString("g3") + " radians or " + Angle.ToDegrees(_departureAngle).ToString("F") + " deg ");

                    var pc = OrbitProcessor.InstantaneousOrbitalVelocityPolarCoordinate(_orderEntityOrbit, _departureDateTime);

                    ImGui.Text("Departure Polar Coordinates: ");
                    ImGui.Text(pc.Item1.ToString() + " AU or " + Distance.AuToMt(pc.Item1).ToString("F") + " m/s");
                    ImGui.Text(pc.Item2.ToString("g3") + " radians or " + Angle.ToDegrees(pc.Item2).ToString("F") + " deg ");;


                    ImGui.Text("Insertion Vector: ");
                    ImGui.SameLine();
                    ImGui.Text(_insertionOrbitalVelocity.ToString("g3"));

                    ImGui.Text("LoAN: ");
                    ImGui.SameLine();
                    ImGui.Text(_ke.LoAN.ToString("g3"));

                    ImGui.Text("AoP: ");
                    ImGui.SameLine();
                    ImGui.Text(_ke.AoP.ToString("g3"));

                    ImGui.Text("LoP Angle: ");
                    ImGui.SameLine();
                    ImGui.Text((_ke.LoAN + _ke.AoP).ToString("g3") + " radians or " + Angle.ToDegrees(_ke.LoAN + _ke.AoP).ToString("F") + " deg ");

                    if (_orbitWidget != null)
                    {
                        ImGui.Text("Clockwise " + _orbitWidget.IsClockwiseOrbit.ToString());
                    }



                    //if (CurrentState != States.NeedsActioning) //use alpha on the button if it's not useable.
                    //ImGui.PushStyleVar(ImGuiStyleVar.Alpha, ImGui.GetStyle().Alpha * 0.5f);
                    if (ImGui.Button("Action Order") && CurrentState == States.NeedsActioning) //only do suff if clicked if it's usable.
                    {
                        fsm[(byte)CurrentState, (byte)Events.ClickedAction].Invoke();
                        //ImGui.PopStyleVar();
                    }

                    if (_smMode)
                    {
                        ImGui.SameLine();
                        if (ImGui.Button("Add OrbitDB"))
                        {
                            ActionAddDB();
                        }
                    }

                    ImGui.End();
                }
            }
        }