public override void OnServerStart() { DarkLog.Normal("[ModdedVesselPositions] Starting..."); Config.SetupConfig(); string[] OutDatedFileList = Directory.GetFiles(VesselPositions.VesselPosFolder); foreach (string vesselFile in OutDatedFileList) { if (File.Exists(vesselFile)) { File.Delete(vesselFile); } } DarkLog.Debug("[ModdedVesselPositions] Reset 'PluginData/DMPServerMap-FrostBird347/VesselPos'"); if (inited) { return; } PlanetInfo.Init(); ServerTime.Init(); foreach (string file in Directory.GetFiles(Path.Combine(Server.universeDirectory, "Vessels"))) { string croppedName = Path.GetFileNameWithoutExtension(file); if (Guid.TryParse(croppedName, out Guid vesselID)) { byte[] vesselData = File.ReadAllBytes(file); UpdateVessel(null, vesselID, vesselData); } } inited = true; DarkLog.Normal("[ModdedVesselPositions] Started! - Version " + PluginV + "."); CommandHandler.RegisterCommand("reloadpos", ReloadConfig, "Reload the ModdedVesselPositions plugin config."); }
public void PositionVessel(ClientObject client, VesselUpdate update) { if (update.isSurfaceUpdate) { VesselInfo vi = GetVesselInfo(update.vesselID); vi.UpdateLanded(update.position[0], update.position[1], update.position[2], Vector.Length(update.velocity)); } else { VesselInfo vi = GetVesselInfo(update.vesselID); int planetReference = PlanetInfo.GetReference(update.bodyName); if (planetReference != -1) { Orbit o = new Orbit(update.orbit, planetReference); vi.UpdateOrbit(o); } } }
public void Solve() { SolveKepler(); if (eccentricity < 1) { SolveNormal(); } else { SolveHyperbolic(); } //Convert TrueAnomaly to state vectors double GM = PlanetInfo.GetGM(referenceBody); double num = semiMajorAxis * (1.0 - eccentricity * eccentricity); double cosTA = Math.Cos(trueAnomaly); double sinTA = Math.Sin(trueAnomaly); distanceToCB = num / (1.0 + eccentricity * cosTA); double[] orbitFramePosition = new double[] { cosTA *distanceToCB, sinTA *distanceToCB, 0 }; double velocityScale = Math.Sqrt(GM / num); double[] orbitFrameVelocity = new double[] { -sinTA * velocityScale, (cosTA + eccentricity) * velocityScale, 0 }; //Rotation from orbital plane to body non-rotating double sinW = Math.Sin(argumentOfPeriapsis / Constants.DEGREES_IN_RADIANS); double cosW = Math.Cos(argumentOfPeriapsis / Constants.DEGREES_IN_RADIANS); double sinO = Math.Sin(LAN / Constants.DEGREES_IN_RADIANS); double cosO = Math.Cos(LAN / Constants.DEGREES_IN_RADIANS); double sinI = Math.Sin(inclination / Constants.DEGREES_IN_RADIANS); double cosI = Math.Cos(inclination / Constants.DEGREES_IN_RADIANS); double X1 = cosW * cosO - sinW * cosI * sinO; double X2 = sinW * cosO + cosW * cosI * sinO; double Y1 = cosW * sinO + sinW * cosI * cosO; double Y2 = cosW * cosI * cosO - sinW * sinO; double Z1 = sinW * sinI; double Z2 = cosW * sinI; position[0] = orbitFramePosition[0] * X1 - orbitFramePosition[1] * X2; position[1] = orbitFramePosition[0] * Y1 + orbitFramePosition[1] * Y2; position[2] = orbitFramePosition[0] * Z1 + orbitFramePosition[1] * Z2; velocity[0] = orbitFrameVelocity[0] * X1 - orbitFrameVelocity[1] * X2; velocity[1] = orbitFrameVelocity[0] * Y1 + orbitFrameVelocity[1] * Y2; velocity[2] = orbitFrameVelocity[0] * Z1 + orbitFrameVelocity[1] * Z2; }
private void UpdateOrbit() { double x = orbit.position[0]; double y = orbit.position[1]; double z = orbit.position[2]; double x2 = x * x; double y2 = y * y; double z2 = z * z; this.altitude = Math.Sqrt(x2 + y2 + z2); double planetRotation = Constants.DEGREES_IN_RADIANS * PlanetInfo.GetRotation(orbit.referenceBody, orbit.epoch); this.longitude = (360 + (Constants.DEGREES_IN_RADIANS * Math.Atan2(y, x)) - planetRotation) % 360; if (this.longitude > 180) { this.longitude -= 360; } this.latitude = Constants.DEGREES_IN_RADIANS * Math.Asin(z / this.altitude); this.altitude -= PlanetInfo.GetRadius(orbit.referenceBody); this.velocity = Vector.Length(orbit.velocity); }
public void UpdateToUT(double universeTime) { double deltaTime = (universeTime - epoch); if (eccentricity < 1) { period = Constants.TAU * Math.Sqrt(Math.Pow(semiMajorAxis, 3) / PlanetInfo.GetGM(referenceBody)); deltaTime = deltaTime % period; while (deltaTime < 0) { deltaTime += period; } } else { period = Double.PositiveInfinity; } double GM = PlanetInfo.GetGM(referenceBody); double positiveSMA = Math.Abs(semiMajorAxis); double meanMotion = Math.Sqrt(GM / (positiveSMA * positiveSMA * positiveSMA)); meanAnomalyAtEpoch = meanAnomalyAtEpoch + deltaTime * meanMotion; if (eccentricity < 1) { //Normalise meanAnomaly meanAnomalyAtEpoch = meanAnomalyAtEpoch % Constants.TAU; while (meanAnomalyAtEpoch < -Math.PI) { meanAnomalyAtEpoch += Constants.TAU; } while (meanAnomalyAtEpoch > Math.PI) { meanAnomalyAtEpoch -= Constants.TAU; } } epoch = universeTime; Solve(); }
public void UpdatePlanet(int id) { planet = PlanetInfo.GetName(id); }