public static void SetSolarBody(SolarBody sbody, string line) { try { // String is e.g // Num Name Epoch a e i w Node M H G Ref // ------ ----------------- ----- ---------- ---------- --------- --------- --------- ----------- ----- ---- ---------- // 5 Astraea 57200 2.5734799 0.19118780 5.36855 358.96928 141.59578 307.8982858 6.85 0.15 JPL 97 // Column widths are important - since names can contain spaces sbody.name = line.Substring(7, 17).Trim(); // start and LENGTH string[] data = line.Substring(25).Trim().Split(new char[0], System.StringSplitOptions.RemoveEmptyEntries); sbody.epoch = SolarUtils.ConvertMJDtoAD(float.Parse(data[0])); sbody.a = float.Parse(data[1]); sbody.ecc = float.Parse(data[2]); sbody.inclination = float.Parse(data[3]); sbody.omega_lc = float.Parse(data[4]); sbody.omega_uc = float.Parse(data[5]); // TODO: Check this sbody.longitude = // OrbitEllipse.MeanToTrueAnomoly(float.Parse(data[6]), sbody.ecc); sbody.mass_1E24 = 0f; sbody.radiusKm = 2000f; // arbitrary to give them some visible size sbody.bodyType = SolarSystem.Type.ASTEROID; } catch { Debug.Log("Parse error:" + line); } }
/// <summary> /// Draws a satellite's interface /// </summary> /// <param name="satellite"></param> /// <returns></returns> bool DrawSatellite(SolarBody satellite) { if (satellite == null) { return(!REFRESH_EDITOR); } GUILayout.BeginHorizontal("box"); GUILayout.BeginVertical(); if (DrawRemoveSatelliteButton(satellite)) { return(REFRESH_EDITOR); } if (DrawSolarBodyMain(satellite)) { return(REFRESH_EDITOR); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); return(!REFRESH_EDITOR); }
/// <summary> /// Checks if the solarBody is null and removes it from the list if it is /// </summary> /// <param name="solarBody"></param> void CheckSolarBody(SolarBody solarBody) { if (solarBody == null) { solarBodies.Remove(solarBody); } }
public static Vector2 CalculateAllGravityVector(Vector2 position, float mass, SolarBody exlcude = null) { Vector2 gravityVector = Vector2.zero; int count = 0; foreach (SolarBody body in instance.bodies) { if (body == exlcude) { continue; } if (((Vector2)body.transform.position - position).magnitude < 1) { continue; } count++; gravityVector += OrbitMath.GravityForce(position, body.transform.position, mass, body.mass); } if (count == 0) { return(Vector2.zero); } gravityVector /= count; return(gravityVector); }
/// <summary> /// Adds a satellite to the solarBodies list /// </summary> /// <param name="solarBody"></param> void AddSatellites(SolarBody solarBody) { foreach (SolarBody satellite in solarBody.satellites) { solarBodies.Add(satellite.gameObject); } }
/// <summary> /// Removes the each sattelite orbiting the provided solar body /// </summary> /// <param name="solarBody"></param> void RemoveSatellites(SolarBody solarBody) { foreach (SolarBody body in solarBody.satellites) { RemoveSolarBody(body); } }
/// <summary> /// Sets the name of the planet based on it's place in the solar system /// </summary> /// <param name="newBody"></param> /// <param name="newSolar"></param> void SetPlanetName(GameObject newBody, SolarBody newSolar) { string newName = "Planet " + solarBodies.Count; newBody.name = newName; newSolar.name = newName; }
/// <summary> /// Sets the name of the satellite GameObject and SolarBody /// </summary> /// <param name="newBody"></param> /// <param name="newSolar"></param> /// <param name="parent"></param> void SetSatelliteName(GameObject newBody, SolarBody newSolar, SolarBody parent) { string newName = "Satellite " + parent.satellites.Count + " of " + parent.name; newBody.name = newName; newSolar.name = newName; }
/// <summary> /// Offsets the map of the sun texture to simulate movement /// </summary> /// <param name="solarBody"></param> public void MoveSunMap(SolarBody solarBody) { offset.x += 0.1f; offset.y += 0.1f; GenerateMap(solarBody); }
/// <summary> /// Parses the JPL asteroid string /// </summary> /// <returns>The JPL asteroid.</returns> /// <param name="line">Line.</param> public static void SetSolarBody(SolarBody sbody, string line) { // String is e.g //Num Name Epoch q e i w Node Tp Ref //------------------------------------------- ------- ----------- ---------- --------- --------- --------- -------------- ------------ // 1P/Halley 49400 0.58597811 0.96714291 162.26269 111.33249 58.42008 19860205.89532 JPL J863/77 // Column widths are important - since names can contain spaces try { sbody.name = line.Substring(1, 45).Trim(); // start and LENGTH // slashes end up making subdirs in list groups, so replace them sbody.name = sbody.name.Replace("/", " "); string[] data = line.Substring(46).Trim().Split(new char[0], System.StringSplitOptions.RemoveEmptyEntries); float q = float.Parse(data[1]); sbody.ecc = float.Parse(data[2]); sbody.a = q / (1 - sbody.ecc); sbody.inclination = float.Parse(data[3]); sbody.omega_lc = float.Parse(data[4]); sbody.omega_uc = float.Parse(data[5]); sbody.longitude = 0f; // Mis-use of epoch field. For asteroids it is used for time of elements (incl. mean anomoly) // For comets set epoch as time of perih. and set true anomoly to zero sbody.epoch = TimePerihelionToEpoch(data[6]); sbody.mass_1E24 = 0f; sbody.radiusKm = 2000f; // arbitrary to give them some visible size sbody.bodyType = SolarSystem.Type.COMET; } catch { Debug.Log("Parse error:" + line); } }
/// <summary> /// Takes the provided solarBody and updates their properties and sattelites /// </summary> /// <param name="solarBody"></param> void updateSolarBody(SolarBody solarBody) { CheckSolarBody(solarBody); solarBody.ScaleBodyMass(); updateSatellites(solarBody); }
void Awake() { sun = GameObject.Find("Sun").GetComponent <SolarBody>(); mapManager = GetComponent <MapManager>(); mapManager.GenerateMaps(); }
/// <summary> /// Draws the body type field for a solar body /// </summary> /// <param name="solarBody"></param> void DrawBodyTypeField(SolarBody solarBody) { GUILayout.BeginHorizontal(); solarBody.bodyType = (BodyType)EditorGUILayout.EnumPopup("Solar Body Type:", solarBody.bodyType); GUILayout.EndHorizontal(); }
public static void SetEllipse(float epoch, EllipseBase ellipseBase, SolarBody sb) { // orbital element variation is not provided - only phase to determine // What is the delat to the reference epoch? float deltaYears = epoch - sb.epoch; float period = SolarUtils.GetPeriodYears(sb); float numPeriod = deltaYears/period; ellipseBase.phase = OrbitEllipse.MeanToTrueAnomoly(NUtils.DegressMod360( sb.longitude + 360f*numPeriod), ellipseBase.ecc); }
/// <summary> /// Generates a colour map for the provided solarbody /// </summary> /// <param name="noiseMap"></param> /// <param name="solarBody"></param> /// <param name="falloffCurve"></param> /// <returns></returns> public static Color[] GetColourMap(float[,] noiseMap, SolarBody solarBody, AnimationCurve falloffCurve) { List <PaletteColour> colours = GetPalette(solarBody); ModifyMap(noiseMap, solarBody, falloffCurve); return(FillColourMap(noiseMap, colours)); }
/// <summary> /// Gets the period of a solar body around the Sun in Years /// </summary> /// <returns>The period.</returns> /// <param name="sbody">Sbody.</param> public static float GetPeriodYears(SolarBody sbody) { float a = sbody.a * AU_METERS; float mu = G * SolarSystem.mass_sun * 1e24f; float periodYrs = Mathf.Sqrt((4f * Mathf.PI * Mathf.PI * a * a * a) / mu) / SECS_PER_YEAR; return(periodYrs); }
/// <summary> /// Fetches the MapManager if it hasn't been already and /// calls the method to generate texture maps for the solar system /// </summary> /// <param name="solarBody"></param> void ApplyTexture(SolarBody solarBody) { if (mapManager == null) { mapManager = GetComponent <MapManager>(); } mapManager.GenerateMap(solarBody); }
/// <summary> /// Draws the name field for a solar body /// </summary> /// <param name="solarBody"></param> void DrawNameField(SolarBody solarBody) { GUILayout.BeginHorizontal(); GUILayout.Label("Name"); solarBody.name = GUILayout.TextField(solarBody.name, GUILayout.Width(135)); GUILayout.EndHorizontal(); }
/// <summary> /// Inits from solar body. /// </summary> /// <param name="sbody">Sbody.</param> public void InitFromSolarBody(SolarBody sbody) { a = sbody.a; ecc = sbody.ecc; omega_lc = sbody.omega_lc; omega_uc = sbody.omega_uc; inclination = sbody.inclination; phase = sbody.longitude; Init(); ApplyScale(GravityEngine.Instance().GetLengthScale()); }
float getSatelliteDistance(SolarBody parent) { float satelliteDistance = 0f; foreach (SolarBody satellite in parent.satellites) { satelliteDistance += satellite.mass + satellite.GetRadius() + 50; } return(satelliteDistance); }
/// <summary> /// Creates a noise map, uses it to make a colour map /// </summary> /// <param name="solarBody"></param> /// <returns></returns> Color[] DrawMap(SolarBody solarBody) { float[,] noiseMap = new float[mapSize, mapSize]; int satelitteSeed = GetSatelliteSeed(solarBody); NoiseGenerator.GenerateNoiseMap(noiseMap, satelitteSeed, noiseScale, octaves, persistance, lacunarity, offset); Color[] colourMap = ColourMapGenerator.GetColourMap(noiseMap, solarBody, falloffCurve); return(colourMap); }
/// <summary> /// Creates items and uses items based on the elapsed time /// </summary> /// <param name="elapsedTime">time elapsed (in seconds)</param> public void UpdateProduction(SolarBody parentBody) { if (isProducing) { if (RequiredComponentsAvailable(parentBody)) { } } }
/// <summary> /// Removes the game object from each list of planets, removes their sattelites and destroys the gameobject /// </summary> /// <param name="solarBody"></param> public void RemoveSolarBody(SolarBody solarBody) { if (solarBody == null) { return; } solarBodies.Remove(solarBody); RemoveSatellites(solarBody); DestroyImmediate(solarBody.gameObject); }
public void UpdatePlanetScale(float scale) { _planetScale = scale; foreach (EllipseBase ellipseBase in EllipsesInSystem()) { SolarBody sbody = ellipseBase.transform.gameObject.GetComponent <SolarBody>(); if (sbody != null) { ScaleModel(ellipseBase.transform.gameObject, sbody); } } }
private void ScaleModel(GameObject bodyGO, SolarBody sbody) { // is there a direct child with a sphere? If so, set scale from size MeshRenderer renderer = bodyGO.GetComponentInChildren <MeshRenderer>(); if (renderer != null && sbody.radiusKm > 0) { // scale is per 10^5 km float scaleSize = _planetScale * sbody.radiusKm / 10000f; renderer.transform.localScale = scaleSize * Vector3.one; } }
/// <summary> /// Draws a solarBody editor box /// </summary> bool DrawSunBox() { SolarBody sun = solarManager.getSun().GetComponent <SolarBody>(); GUILayout.BeginHorizontal("box"); if (DrawSolarBodyMain(sun)) { return(REFRESH_EDITOR); } GUILayout.EndHorizontal(); return(!REFRESH_EDITOR); }
/// <summary> /// Sets the starting epoch time and adjusts the phase parameters of all bodies in the system accordingly. /// /// Phase is set by using the original orbit data reference. Any hand-tuning of phase by manual changes /// in the editor will be lost. /// /// This method is typically called by the scene inspector. Not at run-time. /// </summary> /// <param name="newTime">New time.</param> public void UpdateEpochTime(float newTime) { _epochTime = newTime; foreach (EllipseBase ellipseBase in EllipsesInSystem()) { SolarBody sbody = ellipseBase.transform.gameObject.GetComponent <SolarBody>(); if (sbody != null) { SetPhase(ellipseBase, sbody); ellipseBase.Init(); } } }
/// <summary> /// Loops through the satellites of the provided solarbody /// </summary> /// <param name="solarBody"></param> void updateSatellites(SolarBody solarBody) { foreach (SolarBody satellite in solarBody.satellites) { if (satellite == null) { solarBody.satellites.Remove(satellite); return; } updateSolarBody(satellite); } }
/// <summary> /// Modifies the noise map values according to the solarbody type /// </summary> /// <param name="noiseMap"></param> /// <param name="solarBody"></param> /// <param name="falloffCurve"></param> static void ModifyMap(float[,] noiseMap, SolarBody solarBody, AnimationCurve falloffCurve) { bool useFalloff = true; if (solarBody.bodyType == BodyType.GasGiant) { GasGiantGenerator.ApplyGasGiantMap(noiseMap); } else if (useFalloff) { FalloffGenerator.ApplyFalloffMap(noiseMap, falloffCurve); } }
/// <summary> /// Generates a texture map for every solarbody in the system /// </summary> public void GenerateMaps() { if (solarManager == null) { solarManager = FindObjectOfType <SolarManager>(); } SolarBody sun = GameObject.Find("Sun").GetComponent <SolarBody>(); GenerateMap(sun); GenerateSatelliteMaps(solarManager.GetSolarBodies()); }