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(); } } } }
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); }
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); }