private void CalculateSatelitePosition(SatelliteSimData satellite, double time) { double meanAnomaly = satellite.ArgumentOfPeriapsis; meanAnomaly += (2 * Math.PI) * time / satellite.Periode; meanAnomaly %= Math.PI * 2; //Calc aproximated true anomaly double trueAnomaly = meanAnomaly; trueAnomaly += 2 * satellite.Eccentricity * Math.Sin(meanAnomaly); trueAnomaly += 5.0f / 4.0f * (satellite.Eccentricity * satellite.Eccentricity * Math.Sin(2 * meanAnomaly)); double distance = satellite.SemiMajorAxis; distance *= (1 - satellite.Eccentricity * satellite.Eccentricity) / (1 + satellite.Eccentricity * Math.Cos(trueAnomaly)); //Convert polar coordinates to cartesian coordinates satellite.Position.X = (float)(distance * Math.Sin(trueAnomaly)); satellite.Position.Y = 0; satellite.Position.Z = (float)(distance * Math.Cos(trueAnomaly)); //Rotation for inclination and longitude of the acending node satellite.Position = Vector3.Transform( Matrix3.CreateRotationX(satellite.Inclenation) * Matrix3.CreateRotationY(satellite.LongitudeOfAscendingNode), satellite.Position); //Scale to the universe size satellite.Position = Vector3.Transform(Matrix3.CreateScale((float)gameData.SimulationData.SimulationSizeScalar), satellite.Position); }
// // simulation stuff // private void InitSimulationData(SimData simData) { simData.CurrentEarthRotation = 0; simData.SimulationSpeed = 1000.0f; simData.SimulationSizeScalar = 0.001f; var satelites = new List <SatelliteSimData>(); var satDataStream = Utils.OpenEmbeddedResource("vissatellite.simdata.UCS_Satellite_Database_9-1-2017.txt"); var streamReader = new System.IO.StreamReader(satDataStream); streamReader.ReadLine(); string line; var rand = new Random(); while ((line = streamReader.ReadLine()) != null) { string[] elements = line.Split('\t'); var satelite = new SatelliteSimData(); satelite.IsVisible = true; satelite.IsSelected = false; satelite.Name = elements[0]; switch (elements[4]) { case "Civil": satelite.Users = SatelliteUsers.CIVIL; break; case "Military": satelite.Users = SatelliteUsers.MILITARY; break; case "Government": satelite.Users = SatelliteUsers.GOVERNMENT; break; case "Commercial": satelite.Users = SatelliteUsers.COMMERCIAL; break; default: satelite.Users = SatelliteUsers.MIXED; break; } switch (elements[7]) { case "LEO": satelite.ClassOfOrbit = OrbitType.LEO; break; case "MEO": satelite.ClassOfOrbit = OrbitType.MEO; break; case "GEO": satelite.ClassOfOrbit = OrbitType.GEO; break; case "Elliptical": satelite.ClassOfOrbit = OrbitType.ELLIPTICAL; break; } //Read all the data we have if (!elements[9].Equals("")) { satelite.LongitudeOfGeo = float.Parse(elements[9], CultureInfo.InvariantCulture); } satelite.Perigee = float.Parse(elements[10].Replace("\"", "").Replace(",", "")); satelite.Apogee = float.Parse(elements[11].Replace("\"", "").Replace(",", "")); satelite.Eccentricity = float.Parse(elements[12], CultureInfo.InvariantCulture); satelite.Inclenation = float.Parse(elements[13], CultureInfo.InvariantCulture) * (float)Math.PI / 180; satelite.Periode = float.Parse(elements[14].Replace("\"", ""), CultureInfo.InvariantCulture) * 60; //Calculated what we need satelite.SemiMajorAxis = (float)(satelite.Apogee + satelite.Perigee + simData.RealEarthDiameter) / 2; //Generate random values for needed object elements that are not in the dataset satelite.LongitudeOfAscendingNode = (float)(rand.NextDouble() * Math.PI * 2); satelite.ArgumentOfPeriapsis = (float)(rand.NextDouble() * Math.PI * 2); satelite.Position = new Vector3(0, 0, 0); satelites.Add(satelite); } simData.Satellites = satelites.ToArray(); }
private ImageAssetData GetSatteliteTexture(SatelliteSimData satellite) { ImageAssetData texture = null; switch (this.gameData.ColorCodeMode) { case ColorCodeMode.NONE: texture = this.gameData.SatelliteTextureDefault; break; case ColorCodeMode.USERS: switch (satellite.Users) { case SatelliteUsers.CIVIL: texture = this.gameData.SatelliteTextures[1]; break; case SatelliteUsers.MILITARY: texture = this.gameData.SatelliteTextures[2]; break; case SatelliteUsers.COMMERCIAL: texture = this.gameData.SatelliteTextures[3]; break; case SatelliteUsers.GOVERNMENT: texture = this.gameData.SatelliteTextures[4]; break; case SatelliteUsers.MIXED: texture = this.gameData.SatelliteTextures[5]; break; } break; case ColorCodeMode.ORBITTYPE: switch (satellite.ClassOfOrbit) { case OrbitType.LEO: texture = this.gameData.SatelliteTextures[1]; break; case OrbitType.MEO: texture = this.gameData.SatelliteTextures[2]; break; case OrbitType.GEO: texture = this.gameData.SatelliteTextures[3]; break; case OrbitType.ELLIPTICAL: texture = this.gameData.SatelliteTextures[4]; break; } break; } if (satellite.IsSelected) { texture = this.gameData.SatelliteTextureSelected; } return(texture); }