コード例 #1
0
ファイル: Trajectory.cs プロジェクト: CalebJ2/KSPTrajectories
        public void Update()
        {
            computationTime_ = computationTime_ * 0.99f + frameTime_ * 0.01f;
            float offset = frameTime_ - computationTime_;

            frameTime_ = 0;

            if (gameFrameTime_ != null)
            {
                float t = (float)gameFrameTime_.ElapsedMilliseconds;
                averageGameFrameTime_ = averageGameFrameTime_ * 0.99f + t * 0.01f;
            }
            gameFrameTime_ = Stopwatch.StartNew();

            if (HighLogic.LoadedScene == GameScenes.FLIGHT && vessel_ != FlightGlobals.ActiveVessel)
            {
                TrajectoriesVesselSettings module = FlightGlobals.ActiveVessel == null ? null : FlightGlobals.ActiveVessel.Parts.SelectMany(p => p.Modules.OfType <TrajectoriesVesselSettings>()).FirstOrDefault();
                CelestialBody body = module == null ? null : FlightGlobals.Bodies.FirstOrDefault(b => b.name == module.targetReferenceBody);

                if (body == null || !module.hasTarget)
                {
                    SetTarget();
                }
                else
                {
                    SetTarget(body, body.transform.TransformDirection(module.targetLocation));
                }
            }

            if (HighLogic.LoadedScene == GameScenes.FLIGHT && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel.Parts.Count != 0 && ((MapView.MapIsEnabled && Settings.fetch.DisplayTrajectories) || Settings.fetch.AlwaysUpdate || targetPosition_.HasValue))
            {
                ComputeTrajectory(FlightGlobals.ActiveVessel, DescentProfile.fetch, true);
            }
        }
コード例 #2
0
        private void AttachVessel()
        {
            Util.DebugLog("Loading profiles for vessel");

            AttachedVessel = FlightGlobals.ActiveVessel;

            if (AttachedVessel == null)
            {
                Util.DebugLog("No vessel");
                DescentProfile.Clear();
                TargetProfile.Clear();
                TargetProfile.ManualText = "";
            }
            else
            {
                TrajectoriesVesselSettings module = AttachedVessel.Parts.SelectMany(p => p.Modules.OfType <TrajectoriesVesselSettings>()).FirstOrDefault();
                if (module == null)
                {
                    Util.DebugLog("No TrajectoriesVesselSettings module");
                    DescentProfile.Clear();
                    TargetProfile.Clear();
                    TargetProfile.ManualText = "";
                }
                else if (!module.Initialized)
                {
                    Util.DebugLog("Initializing TrajectoriesVesselSettings module");
                    DescentProfile.Clear();
                    DescentProfile.Save(module);
                    TargetProfile.Clear();
                    TargetProfile.ManualText = "";
                    TargetProfile.Save(module);
                    module.Initialized = true;
                    Util.Log("New vessel, profiles created");
                }
                else
                {
                    Util.DebugLog("Reading profile settings...");
                    // descent profile
                    if (DescentProfile.Ready)
                    {
                        DescentProfile.RetrogradeEntry        = module.RetrogradeEntry;
                        DescentProfile.AtmosEntry.AngleRad    = module.EntryAngle;
                        DescentProfile.AtmosEntry.Horizon     = module.EntryHorizon;
                        DescentProfile.HighAltitude.AngleRad  = module.HighAngle;
                        DescentProfile.HighAltitude.Horizon   = module.HighHorizon;
                        DescentProfile.LowAltitude.AngleRad   = module.LowAngle;
                        DescentProfile.LowAltitude.Horizon    = module.LowHorizon;
                        DescentProfile.FinalApproach.AngleRad = module.GroundAngle;
                        DescentProfile.FinalApproach.Horizon  = module.GroundHorizon;
                        DescentProfile.RefreshGui();
                    }

                    // target profile
                    TargetProfile.SetFromLocalPos(FlightGlobals.Bodies.FirstOrDefault(b => b.name == module.TargetBody),
                                                  new Vector3d(module.TargetPosition_x, module.TargetPosition_y, module.TargetPosition_z));
                    TargetProfile.ManualText = module.ManualTargetTxt;
                    Util.Log("Profiles loaded");
                }
            }
        }
コード例 #3
0
        public void Update()
        {
            if (HighLogic.LoadedScene == GameScenes.FLIGHT && attachedVessel != FlightGlobals.ActiveVessel)
            {
                //Debug.Log("Loading vessel descent profile");
                attachedVessel = FlightGlobals.ActiveVessel;

                if (attachedVessel == null)
                {
                    //Debug.Log("No vessel");
                    Reset();
                }
                else
                {
                    TrajectoriesVesselSettings module = attachedVessel.Parts.SelectMany(p => p.Modules.OfType <TrajectoriesVesselSettings>()).FirstOrDefault();
                    if (module == null)
                    {
                        //Debug.Log("No TrajectoriesVesselSettings module");
                        Reset();
                    }
                    else
                    {
                        //Debug.Log("Reading settings...");
                        entry.angle           = module.EntryAngle;
                        entry.horizon         = module.EntryHorizon;
                        highAltitude.angle    = module.HighAngle;
                        highAltitude.horizon  = module.HighHorizon;
                        lowAltitude.angle     = module.LowAngle;
                        lowAltitude.horizon   = module.LowHorizon;
                        finalApproach.angle   = module.GroundAngle;
                        finalApproach.horizon = module.GroundHorizon;

                        entry.RefreshSliderPos();
                        highAltitude.RefreshSliderPos();
                        lowAltitude.RefreshSliderPos();
                        finalApproach.RefreshSliderPos();

                        progradeEntry   = module.ProgradeEntry;
                        retrogradeEntry = module.RetrogradeEntry;
                        //Debug.Log("Descent profile loaded");
                    }
                }
            }
        }
コード例 #4
0
        public void Update()
        {
            Vessel activeVessel = HighLogic.LoadedScene == GameScenes.FLIGHT ? FlightGlobals.ActiveVessel : null;

            if (attachedVessel != activeVessel)
            {
                if (callback != null)
                {
                    attachedVessel.OnFlyByWire -= callback;
                    callback = null;
                }

                attachedVessel = activeVessel;

                if (attachedVessel != null)
                {
                    Strength = 5.0f;
                    Enabled  = false;
                    TrajectoriesVesselSettings module = attachedVessel.Parts.SelectMany(p => p.Modules.OfType <TrajectoriesVesselSettings>()).FirstOrDefault();
                    if (module != null)
                    {
                        Enabled  = module.AutoPilotEnabled;
                        Strength = module.AutoPilotStrength;
                        if (Strength < 0.5f)
                        {
                            Strength = 5.0f;
                        }
                    }

                    callback = new FlightInputCallback((controls) => autoPilot(this, controls));
                    //activeVessel.OnFlyByWire += callback; // this is disabled for now, because it breaks Remote Tech signal delay
                }
            }

            Save();
        }