Esempio n. 1
0
        private static void ApplyInterpolationsToLoadedVessel(Vessel vessel, VesselPositionUpdate update, VesselPositionUpdate target, CelestialBody lerpedBody, float percentage)
        {
            //Do not call vessel.orbitDriver.updateFromParameters()!!
            //It will set the vessel at the CURRENT position and ignore that the orbit is from the PAST!

            var currentSurfaceRelRotation = Quaternion.Slerp(update.SurfaceRelRotation, target.SurfaceRelRotation, percentage);

            //If you don't set srfRelRotation and vessel is packed it won't change it's rotation
            vessel.srfRelRotation = currentSurfaceRelRotation;
            vessel.SetRotation((Quaternion)lerpedBody.rotation * currentSurfaceRelRotation, true);

            vessel.Landed   = percentage < 0.5 ? update.Landed : target.Landed;
            vessel.Splashed = percentage < 0.5 ? update.Splashed : target.Splashed;

            vessel.latitude  = LunaMath.Lerp(update.LatLonAlt[0], target.LatLonAlt[0], percentage);
            vessel.longitude = LunaMath.Lerp(update.LatLonAlt[1], target.LatLonAlt[1], percentage);
            vessel.altitude  = LunaMath.Lerp(update.LatLonAlt[2], target.LatLonAlt[2], percentage);

            //var startLatLonAltPos = update.Body.GetWorldSurfacePosition(update.LatLonAlt[0], update.LatLonAlt[1], update.LatLonAlt[2]);
            //var targetLatLonAltPos = target.Body.GetWorldSurfacePosition(target.LatLonAlt[0], target.LatLonAlt[1], target.LatLonAlt[2]);

            //var startOrbitPos = startOrbit.getPositionAtUT(startOrbit.epoch);
            //var endOrbitPos = endOrbit.getPositionAtUT(endOrbit.epoch);

            vessel.SetPosition(vessel.orbit.getPositionAtUT(Planetarium.GetUniversalTime()));
            if (vessel.situation <= Vessel.Situations.PRELAUNCH)
            {
                vessel.SetPosition(lerpedBody.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude));
            }

            //Always run this at the end!!
            //Otherwise during docking, the orbital speeds are not displayed correctly and you won't be able to dock
            if (!vessel.packed)
            {
                var velBeforeCorrection = vessel.rootPart.rb.velocity;
                vessel.rootPart.ResumeVelocity();
                if (velBeforeCorrection != vessel.rootPart.rb.velocity)
                {
                    foreach (var part in vessel.Parts)
                    {
                        part.ResumeVelocity();
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sends the requested screenshot
        /// </summary>
        public static void SendScreenshot(ClientStructure client, ScreenshotDownloadRequestMsgData data)
        {
            var file = Path.Combine(ScreenshotPath, data.FolderName, $"{data.DateTaken}.png");

            if (FileHandler.FileExists(file))
            {
                var contents = FileHandler.ReadFile(file);
                var msgData  = ServerContext.ServerMessageFactory.CreateNewMessageData <ScreenshotDataMsgData>();
                msgData.Screenshot.DateTaken  = data.DateTaken;
                msgData.Screenshot.Data       = contents;
                msgData.Screenshot.NumBytes   = msgData.Screenshot.Data.Length;
                msgData.Screenshot.Height     = LunaMath.UShortFromBytes(contents[18], contents[19]);
                msgData.Screenshot.Width      = LunaMath.UShortFromBytes(contents[22], contents[23]);
                msgData.Screenshot.FolderName = data.FolderName;

                LunaLog.Debug($"Sending screenshot ({ByteSize.FromBytes(msgData.Screenshot.NumBytes).KiloBytes}{ByteSize.KiloByteSymbol}): {data.DateTaken} to: {client.PlayerName}.");
                MessageQueuer.SendToClient <ScreenshotSrvMsg>(client, msgData);
            }
        }
Esempio n. 3
0
 public static void LerpUnclamped(this FlightCtrlState fs, FlightCtrlState from, FlightCtrlState to, float lerpPercentage)
 {
     fs.X                 = LunaMath.LerpUnclamped(from.X, to.X, lerpPercentage);
     fs.Y                 = LunaMath.LerpUnclamped(from.Y, to.Y, lerpPercentage);
     fs.Z                 = LunaMath.LerpUnclamped(from.Z, to.Z, lerpPercentage);
     fs.pitch             = LunaMath.LerpUnclamped(from.pitch, to.pitch, lerpPercentage);
     fs.pitchTrim         = LunaMath.LerpUnclamped(from.pitchTrim, to.pitchTrim, lerpPercentage);
     fs.roll              = LunaMath.LerpUnclamped(from.roll, to.roll, lerpPercentage);
     fs.rollTrim          = LunaMath.LerpUnclamped(from.rollTrim, to.rollTrim, lerpPercentage);
     fs.yaw               = LunaMath.LerpUnclamped(from.yaw, to.yaw, lerpPercentage);
     fs.yawTrim           = LunaMath.LerpUnclamped(from.yawTrim, to.yawTrim, lerpPercentage);
     fs.mainThrottle      = LunaMath.LerpUnclamped(from.mainThrottle, to.mainThrottle, lerpPercentage);
     fs.wheelSteer        = LunaMath.LerpUnclamped(from.wheelSteer, to.wheelSteer, lerpPercentage);
     fs.wheelSteerTrim    = LunaMath.LerpUnclamped(from.wheelSteerTrim, to.wheelSteerTrim, lerpPercentage);
     fs.wheelThrottle     = LunaMath.LerpUnclamped(from.wheelThrottle, to.wheelThrottle, lerpPercentage);
     fs.wheelThrottleTrim = LunaMath.LerpUnclamped(from.wheelThrottleTrim, to.wheelThrottleTrim, lerpPercentage);
     fs.gearDown          = LunaMath.Lerp(from.gearDown, to.gearDown, lerpPercentage);
     fs.gearUp            = LunaMath.Lerp(from.gearUp, to.gearUp, lerpPercentage);
     fs.headlight         = LunaMath.Lerp(from.headlight, to.headlight, lerpPercentage);
     fs.killRot           = LunaMath.Lerp(from.killRot, to.killRot, lerpPercentage);
 }
Esempio n. 4
0
        private static void ApplyInterpolationsToVessel(Vessel vessel, VesselPositionUpdate update, VesselPositionUpdate target, CelestialBody lerpedBody, float percentage)
        {
            var currentSurfaceRelRotation = Quaternion.Slerp(update.SurfaceRelRotation, target.SurfaceRelRotation, percentage);

            //If you don't set srfRelRotation and vessel is packed it won't change it's rotation
            vessel.srfRelRotation = currentSurfaceRelRotation;

            vessel.Landed   = percentage < 0.5 ? update.Landed : target.Landed;
            vessel.Splashed = percentage < 0.5 ? update.Splashed : target.Splashed;

            vessel.latitude  = LunaMath.Lerp(update.LatLonAlt[0], target.LatLonAlt[0], percentage);
            vessel.longitude = LunaMath.Lerp(update.LatLonAlt[1], target.LatLonAlt[1], percentage);
            vessel.altitude  = LunaMath.Lerp(update.LatLonAlt[2], target.LatLonAlt[2], percentage);

            var rotation = (Quaternion)lerpedBody.rotation * currentSurfaceRelRotation;
            var position = vessel.situation <= Vessel.Situations.SUB_ORBITAL ?
                           lerpedBody.GetWorldSurfacePosition(vessel.latitude, vessel.longitude, vessel.altitude) :
                           vessel.orbit.getPositionAtUT(TimeSyncSystem.UniversalTime);

            SetVesselPositionAndRotation(vessel, position, rotation);
        }
Esempio n. 5
0
        /// <summary>
        /// Sends the screenshots in a folder
        /// </summary>
        public static void SendScreenshotList(ClientStructure client, ScreenshotListRequestMsgData data)
        {
            var screenshots = new List <ScreenshotInfo>();

            foreach (var file in FileHandler.GetFilesInPath(Path.Combine(ScreenshotPath, data.FolderName)).Where(f => thumbnail_handler(f)))
            {
                if (long.TryParse(Path.GetFileNameWithoutExtension(file).Replace("small_", string.Empty), out var dateTaken))
                {
                    if (data.AlreadyOwnedPhotoIds.Contains(dateTaken))
                    {
                        continue;
                    }

                    var contents = FileHandler.ReadFile(file);
                    LunaLog.Debug("IMG: " + LunaMath.UShortFromBytes(contents[18], contents[19]) + " X " + LunaMath.UShortFromBytes(contents[22], contents[23]));
                    screenshots.Add(new ScreenshotInfo
                    {
                        Data       = contents,
                        DateTaken  = dateTaken,
                        NumBytes   = contents.Length,
                        Height     = LunaMath.UShortFromBytes(contents[18], contents[19]),
                        Width      = LunaMath.UShortFromBytes(contents[22], contents[23]),
                        FolderName = data.FolderName,
                    });
                }
                else
                {
                    LunaLog.Error("Failed to parse data on screenshot: " + file);
                }
            }

            var msgData = ServerContext.ServerMessageFactory.CreateNewMessageData <ScreenshotListReplyMsgData>();

            msgData.FolderName     = data.FolderName;
            msgData.Screenshots    = screenshots.ToArray();
            msgData.NumScreenshots = screenshots.Count;

            LunaLog.Debug($"Sending {msgData.NumScreenshots} ({data.FolderName}) screenshots to: {client.PlayerName}");
            MessageQueuer.SendToClient <ScreenshotSrvMsg>(client, msgData);
        }