コード例 #1
0
        private void LoadData()
        {
            string saveFile = Path.Combine(KSPUtil.ApplicationRootPath, "pathData.txt");

            if (!File.Exists(saveFile))
            {
                return;
            }
            pathData = new List <OrbitalData>();
            using (FileStream fs = new FileStream(saveFile, FileMode.Open))
            {
                using (BinaryReader br = new BinaryReader(fs))
                {
                    int entries = br.ReadInt32();
                    for (int i = 0; i < entries; i++)
                    {
                        int         entryLength = br.ReadInt32();
                        byte[]      entryData   = br.ReadBytes(entryLength);
                        OrbitalData entry       = new OrbitalData(entryData);
                        pathData.Add(entry);
                    }
                }
            }
            ScreenMessages.PostScreenMessage("Loaded " + pathData.Count + " entries.", 5f, ScreenMessageStyle.UPPER_CENTER);
        }
コード例 #2
0
 public void FixedUpdate()
 {
     if (FlightGlobals.ready && FlightGlobals.ActiveVessel != null)
     {
         Vessel ourVessel = FlightGlobals.ActiveVessel;
         if (recording)
         {
             OrbitalData newEntry = new OrbitalData(ourVessel);
             pathData.Add(newEntry);
         }
         if (playback)
         {
             if (freezeFrame == -1)
             {
                 if (playbackStart)
                 {
                     playbackStart = false;
                     ourVessel.GoOnRails();
                     Planetarium.SetUniversalTime(pathData[0].t - 5f);
                 }
                 if (pathData[playPos].t < Planetarium.GetUniversalTime())
                 {
                     if (playPos % 10 == 0)
                     {
                         ApplyOrbit(pathData[playPos]);
                     }
                     else
                     {
                         posError                 = CompareOrbit();
                         predictVectorSpace       = ExtrapolateOrbitVectorSpace();
                         predictOrbitalComponents = ExtrapolateOrbitParameters();
                     }
                     playPos++;
                     if (pathData.Count == playPos)
                     {
                         playback = false;
                     }
                 }
             }
             else
             {
                 if (lastFreezeFrame != freezeFrame)
                 {
                     lastFreezeFrame          = freezeFrame;
                     posError                 = CompareFreezePos();
                     predictVectorSpace       = ExtrapolateOrbitVectorSpace();
                     predictOrbitalComponents = ExtrapolateOrbitParameters();
                 }
                 ourVessel.GoOnRails();
                 Planetarium.SetUniversalTime(pathData[freezeFrame].t);
                 ApplyOrbit(pathData[freezeFrame]);
             }
         }
     }
 }
コード例 #3
0
        private void ApplyOrbit(OrbitalData orbitData)
        {
            Vessel updateVessel = FlightGlobals.ActiveVessel;

            updateVessel.GoOnRails();
            CelestialBody updateBody = FlightGlobals.GetBodyByName(orbitData.celestialBody);

            Orbit updateOrbit = orbitData.GetOrbit();

            updateOrbit.Init();
            updateOrbit.UpdateFromUT(Planetarium.GetUniversalTime());

            //Positional Error Tracking
            double latitude  = updateBody.GetLatitude(updateOrbit.pos);
            double longitude = updateBody.GetLongitude(updateOrbit.pos);
            double altitude  = updateBody.GetAltitude(updateOrbit.pos);

            updateVessel.latitude              = latitude;
            updateVessel.longitude             = longitude;
            updateVessel.altitude              = altitude;
            updateVessel.protoVessel.latitude  = latitude;
            updateVessel.protoVessel.longitude = longitude;
            updateVessel.protoVessel.altitude  = altitude;
            VesselUtil.CopyOrbit(updateOrbit, updateVessel.orbitDriver.orbit);
            updateVessel.orbitDriver.updateFromParameters();

            /*
             * if (!updateVessel.packed)
             * {
             *  var fudgeVel = updateBody.inverseRotation ? updateBody.getRFrmVelOrbit(updateVessel.orbitDriver.orbit) : Vector3d.zero;
             *  updateVessel.SetWorldVelocity(updateVessel.orbitDriver.orbit.vel.xzy - fudgeVel - Krakensbane.GetFrameVelocity());
             * }
             */

            updateVessel.SetRotation(updateVessel.mainBody.bodyTransform.rotation * orbitData.rot);
            if (updateVessel.packed)
            {
                updateVessel.srfRelRotation       = orbitData.rot;
                updateVessel.protoVessel.rotation = updateVessel.srfRelRotation;
            }
        }
コード例 #4
0
        public void DrawWindow(int windowID)
        {
            GUI.DragWindow(dragRect);
            if (playback)
            {
                if (GUILayout.Button("Cancel"))
                {
                    playback = false;
                    playPos  = 0;
                }
                GUILayout.Label("Distance error: " + posError);
                GUILayout.Label("Vector predict error: " + predictVectorSpace);
                GUILayout.Label("Parameter predict error: " + predictOrbitalComponents);
                if (freezeFrame == -1)
                {
                    if (GUILayout.Button("Freeze"))
                    {
                        freezeFrame = playPos;
                    }
                }
                else
                {
                    if (GUILayout.Button("Unfreeze"))
                    {
                        freezeFrame = -1;
                    }
                    if (GUILayout.Button("-100"))
                    {
                        if (freezeFrame >= 100)
                        {
                            freezeFrame = freezeFrame - 100;
                            playPos     = freezeFrame;
                        }
                    }
                    if (GUILayout.Button("-10"))
                    {
                        if (freezeFrame >= 10)
                        {
                            freezeFrame = freezeFrame - 10;
                            playPos     = freezeFrame;
                        }
                    }
                    if (GUILayout.Button("-1"))
                    {
                        if (freezeFrame >= 1)
                        {
                            freezeFrame = freezeFrame - 1;
                            playPos     = freezeFrame;
                        }
                    }
                    if (GUILayout.Button("+1"))
                    {
                        if (freezeFrame + 1 < pathData.Count)
                        {
                            freezeFrame = freezeFrame + 1;
                            playPos     = freezeFrame;
                        }
                    }
                    if (GUILayout.Button("+10"))
                    {
                        if (freezeFrame + 10 < pathData.Count)
                        {
                            freezeFrame = freezeFrame + 10;
                            playPos     = freezeFrame;
                        }
                    }
                    if (GUILayout.Button("+100"))
                    {
                        if (freezeFrame + 100 < pathData.Count)
                        {
                            freezeFrame = freezeFrame + 100;
                            playPos     = freezeFrame;
                        }
                    }
                    GUILayout.Label("Orbital data:");
                    OrbitalData pathEntry = pathData[freezeFrame];
                    GUILayout.Label("inc: " + pathEntry.inclination);
                    GUILayout.Label("e: " + pathEntry.eccentricity);
                    GUILayout.Label("semiMajorAxis: " + pathEntry.semiMajorAxis);
                    GUILayout.Label("LAN: " + pathEntry.LAN);
                    GUILayout.Label("argumentOfPeriapsis: " + pathEntry.argumentOfPeriapsis);
                    GUILayout.Label("mep: " + pathEntry.meanAnomalyAtEpoch);
                    GUILayout.Label("t: " + pathEntry.t);
                    GUILayout.Label("longitude: " + pathEntry.lonPos);
                    GUILayout.Label("latitude: " + pathEntry.latPos);
                    GUILayout.Label("altitude: " + pathEntry.altPos);
                    GUILayout.Label("velX: " + pathEntry.vel.x);
                    GUILayout.Label("velY: " + pathEntry.vel.y);
                    GUILayout.Label("velZ: " + pathEntry.vel.z);
                }
            }
            else
            {
                if (recording)
                {
                    if (GUILayout.Button("Save"))
                    {
                        recording = false;
                        SaveData();
                    }
                    if (GUILayout.Button("Cancel"))
                    {
                        recording = false;
                        pathData  = new List <OrbitalData>();
                    }
                }
                else
                {
                    if (GUILayout.Button("Playback"))
                    {
                        LoadData();
                        playback      = true;
                        playbackStart = true;
                        playPos       = 0;
                    }

                    /*
                     * if (GUILayout.Button("Interpolate Stats"))
                     * {
                     *  LoadData();
                     *  showInterpolate = !showInterpolate;
                     *  if (showInterpolate)
                     *  {
                     *      PredictOrbit();
                     *  }
                     * }
                     */
                    if (GUILayout.Button("Record"))
                    {
                        recording = true;
                        pathData  = new List <OrbitalData>();
                    }
                }
            }
        }