From 0a1512f6e1201bfaf3e41d0f9fcf6e7b027aab0f Mon Sep 17 00:00:00 2001 From: Cassius Date: Sun, 19 Apr 2026 21:57:12 -0400 Subject: [PATCH 1/4] Modernize Unity C# scripts for current API compatibility --- version2/Assets/Editor/MakeLayers.cs | 8 ++-- version2/Assets/Scripts/tests/BodyElements.cs | 1 - .../Assets/Scripts/tests/CreateCameras.cs | 15 ++----- .../Assets/Scripts/tests/CreateElements.cs | 2 - .../Scripts/tests/CreateSolarSystems.cs | 42 ++++++++++--------- version2/Assets/Scripts/tests/Elements.cs | 21 ++++++++-- version2/Assets/Scripts/tests/ImportData.cs | 14 ++++--- version2/Assets/Scripts/tests/Maths.cs | 6 +-- .../Assets/Scripts/tests/SystemScaleState.cs | 1 + 9 files changed, 58 insertions(+), 52 deletions(-) diff --git a/version2/Assets/Editor/MakeLayers.cs b/version2/Assets/Editor/MakeLayers.cs index fe3dc036..738e66ff 100644 --- a/version2/Assets/Editor/MakeLayers.cs +++ b/version2/Assets/Editor/MakeLayers.cs @@ -3,16 +3,16 @@ using UnityEditor; [InitializeOnLoad] -public class Tags { +public static class MakeLayers { // STARTUP - static Tags() { + static MakeLayers() { CreateLayer(); } // Creates a new layer - static void CreateLayer() { + private static void CreateLayer() { SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]); SerializedProperty it = tagManager.GetIterator(); @@ -37,4 +37,4 @@ static void CreateLayer() { tagManager.ApplyModifiedProperties(); } -} \ No newline at end of file +} diff --git a/version2/Assets/Scripts/tests/BodyElements.cs b/version2/Assets/Scripts/tests/BodyElements.cs index ab13dbda..ab8c4a40 100644 --- a/version2/Assets/Scripts/tests/BodyElements.cs +++ b/version2/Assets/Scripts/tests/BodyElements.cs @@ -1,6 +1,5 @@ using UnityEngine; using System; -using System.Collections; using System.Collections.Generic; using Elements; diff --git a/version2/Assets/Scripts/tests/CreateCameras.cs b/version2/Assets/Scripts/tests/CreateCameras.cs index 02537c6b..8c4dfc57 100644 --- a/version2/Assets/Scripts/tests/CreateCameras.cs +++ b/version2/Assets/Scripts/tests/CreateCameras.cs @@ -1,21 +1,14 @@ using UnityEngine; -using System.Collections; -using System.Collections.Generic; -using Elements; -using SimpleJSON; -using BodyElements; -using ImportData; -using System.IO; -using CustomMath; +[DisallowMultipleComponent] public class CreateCameras : MonoBehaviour { - int camDepth = 20; + [SerializeField] private int camDepth = 20; void Awake () { for (int i=1; i<19; i++) { Camera cam = new GameObject().AddComponent(); cam.depth = camDepth - i; - cam.transform.parent = transform; + cam.transform.SetParent(transform, true); cam.transform.position = new Vector3(0f,0f,0f); cam.name = "Camera "+i; cam.farClipPlane = 20000f; @@ -24,7 +17,7 @@ void Awake () { cam.clearFlags = CameraClearFlags.Depth; // Add as a camera layer else cam.clearFlags = CameraClearFlags.Nothing; // Background layer - cam.camera.cullingMask = 1 << i+7; + cam.cullingMask = 1 << i+7; cam.gameObject.layer = i+7; cam.tag = "MainCamera"; Rigidbody _cameraRigidbody = cam.gameObject.AddComponent(); diff --git a/version2/Assets/Scripts/tests/CreateElements.cs b/version2/Assets/Scripts/tests/CreateElements.cs index c5968845..d55f462a 100644 --- a/version2/Assets/Scripts/tests/CreateElements.cs +++ b/version2/Assets/Scripts/tests/CreateElements.cs @@ -1,6 +1,4 @@ using UnityEngine; -using System.Collections; -using Elements; public class CreateElements : MonoBehaviour { diff --git a/version2/Assets/Scripts/tests/CreateSolarSystems.cs b/version2/Assets/Scripts/tests/CreateSolarSystems.cs index 841d35ff..9085cd04 100644 --- a/version2/Assets/Scripts/tests/CreateSolarSystems.cs +++ b/version2/Assets/Scripts/tests/CreateSolarSystems.cs @@ -1,13 +1,12 @@ using UnityEngine; using System; -using System.Collections; using System.Collections.Generic; -using Elements; -using SimpleJSON; +using System.Globalization; using BodyElements; -using ImportData; -using System.IO; using CustomMath; +using Elements; +using ImportData; +using SimpleJSON; [System.Serializable] @@ -34,6 +33,7 @@ public class MoonList { } +[DisallowMultipleComponent] public class CreateSolarSystems : MonoBehaviour { public List stars = new List(); @@ -44,8 +44,7 @@ public class CreateSolarSystems : MonoBehaviour { string JSONData; // Holds the data.json file data void Awake () { - JSONData = Data.data.ReadToEnd (); // Read from the data.json file - Data.data.Close (); + JSONData = Data.LoadJson(); // Read from the data.json file importedData = JSON.Parse(JSONData); // Parse the data into a formatted string variable @@ -57,12 +56,12 @@ void Awake () { _star.Name = importedData ["star"] [iteratorA] ["name"]; _star.RightAscension = importedData ["star"] [iteratorA] ["rightAscension"]; _star.Declination = importedData ["star"] [iteratorA] ["declination"]; - _star.Mass = new Element ("Stellar Mass", double.Parse(importedData ["star"] [iteratorA]["stellarMass"]), "Kg", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); - _star.Radius = new Element ("Stellar Radius", double.Parse(importedData ["star"] [iteratorA] ["stellarRadius"]), "meter", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Mass = new Element ("Stellar Mass", ParseDouble(importedData ["star"] [iteratorA]["stellarMass"]), "Kg", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Radius = new Element ("Stellar Radius", ParseDouble(importedData ["star"] [iteratorA] ["stellarRadius"]), "meter", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); //_star.Radius.Value *= 100d; // An example of how to multiply by Stellar Radii - _star.Distance = new Element("Distance", double.Parse(importedData ["star"] [iteratorA] ["distance"]), "meter", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); - _star.Luminosity = new Element("Optical Magnitude", double.Parse(importedData ["star"] [iteratorA] ["opticalMagnitude"]), "lum", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); - _star.Temperature = new Element("Temperature", double.Parse(importedData ["star"] [iteratorA] ["temperature"]), "celcius", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Distance = new Element("Distance", ParseDouble(importedData ["star"] [iteratorA] ["distance"]), "meter", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Luminosity = new Element("Optical Magnitude", ParseDouble(importedData ["star"] [iteratorA] ["opticalMagnitude"]), "lum", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); + _star.Temperature = new Element("Temperature", ParseDouble(importedData ["star"] [iteratorA] ["temperature"]), "celcius", 0.0d, "SI", "StarTography 1.0", _star.DateLastUpdated); _star.Distance.ToM(); @@ -130,6 +129,11 @@ void Awake () { } + + private static double ParseDouble(JSONNode node) { + return double.Parse(node.Value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture); + } + void Start() { @@ -138,14 +142,14 @@ void Start() { star.value.transform.position = star.positionInSpace; GameObject _starGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Create the Star object _starGameObject.name = "Star: "+star.name; - _starGameObject.transform.parent = star.value.transform; + _starGameObject.transform.SetParent(star.value.transform, true); _starGameObject.transform.position = star.value.transform.position; SphereCollider sphereCollider = _starGameObject.GetComponent(); sphereCollider.isTrigger = false; sphereCollider.radius = 1f; GameObject _starDistanceColliders = new GameObject("Star: "+star.name+": Distance Colliders"); - _starDistanceColliders.transform.parent = star.value.transform; + _starDistanceColliders.transform.SetParent(star.value.transform, true); _starDistanceColliders.transform.position = star.value.transform.position; Element _starSize = new Element("Radius of the Star", star.key.Radius.Value, "stellarRadius", 0.0d, "si", "Allen's Astrophysical Quantities 4th Edition", star.key.DateLastUpdated); @@ -166,7 +170,7 @@ void Start() { colliderRadiusScale = 10f * Mathf.Exp ((i-3)/2f); GameObject _starDistanceCollider = new GameObject("Star: "+star.name+": Distance Collider "+i); - _starDistanceCollider.transform.parent = _starDistanceColliders.transform; + _starDistanceCollider.transform.SetParent(_starDistanceColliders.transform, true); _starDistanceCollider.transform.position = star.value.transform.position; _starDistanceCollider.transform.localScale = new Vector3(1f,1f,1f); Rigidbody _sphereRigidbody = _starDistanceCollider.AddComponent(); @@ -180,11 +184,11 @@ void Start() { // Prepare the planetary system parent foreach (PlanetList planet in planets) { - planet.value.transform.parent = planet.key.ParentStar.transform; + planet.value.transform.SetParent(planet.key.ParentStar.transform, true); planet.value.transform.position = planet.key.ParentStar.transform.position; GameObject _planetGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Create the Planet object _planetGameObject.name = "Planet: "+planet.name; - _planetGameObject.transform.parent = planet.value.transform; + _planetGameObject.transform.SetParent(planet.value.transform, true); _planetGameObject.transform.position = planet.value.transform.position; SphereCollider sphereCollider = _planetGameObject.GetComponent(); sphereCollider.isTrigger = false; @@ -194,11 +198,11 @@ void Start() { // Prepare the moon system parent foreach (MoonList moon in moons) { - moon.value.transform.parent = moon.key.ParentPlanet.transform; + moon.value.transform.SetParent(moon.key.ParentPlanet.transform, true); moon.value.transform.position = moon.key.ParentPlanet.transform.position; GameObject _moonGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Create the Moon object _moonGameObject.name = "Moon: "+moon.name; - _moonGameObject.transform.parent = moon.value.transform; + _moonGameObject.transform.SetParent(moon.value.transform, true); _moonGameObject.transform.position = moon.value.transform.position; SphereCollider sphereCollider = _moonGameObject.GetComponent(); sphereCollider.isTrigger = false; diff --git a/version2/Assets/Scripts/tests/Elements.cs b/version2/Assets/Scripts/tests/Elements.cs index ad536bfe..d94b7b0e 100644 --- a/version2/Assets/Scripts/tests/Elements.cs +++ b/version2/Assets/Scripts/tests/Elements.cs @@ -1,6 +1,7 @@ using UnityEngine; using System; using System.Collections; +using System.Globalization; using CustomMath; using System.Linq; @@ -43,17 +44,17 @@ public RightAscension(string HourMinSec) { _words = HourMinSec.Split (new char[] { 'h', 'm', 's' }); } else if(HourMinSec.Split (new char[] { 'h', '.', 'm' }).Length == 4) { _words = HourMinSec.Split (new char[] { 'h', '.', 'm' }); - _words[2] = ((Convert.ToDouble(_words[2])/10) * 60).ToString(); // Convert fraction of minute to seconds + _words[2] = ((Convert.ToDouble(_words[2], CultureInfo.InvariantCulture)/10) * 60).ToString(CultureInfo.InvariantCulture); // Convert fraction of minute to seconds } else if(HourMinSec.Split (new char[] { ':', '.' }).Length == 3) { _words = HourMinSec.Split (new char[] { ':', '.' }); - _words[2] = ((Convert.ToDouble(_words[2])/10) * 60).ToString(); // Convert fraction of minute to seconds + _words[2] = ((Convert.ToDouble(_words[2], CultureInfo.InvariantCulture)/10) * 60).ToString(CultureInfo.InvariantCulture); // Convert fraction of minute to seconds } else if(HourMinSec.Split (new char[] { ' ' }).Length == 3) { _words = HourMinSec.Split (new char[] { ' ' }); } for (int i=0; i<_words.Length; i++) { if(_words[i] != "") - _values [i] = Convert.ToDouble (_words [i]); + _values [i] = Convert.ToDouble (_words [i], CultureInfo.InvariantCulture); } this.Hours = _values[0]; @@ -106,7 +107,7 @@ public Declination(string Deg_DegMin_DegSec) { int b = 0; for (int i=0; i<_words.Length; i++) { if(_words[i] != "" && _words[i] != " " && _words[i] != null) { // Check that it's not an empty value - _values[b] = Convert.ToDouble (_words [i]); // Convert to a double and add to the array + _values[b] = Convert.ToDouble (_words [i], CultureInfo.InvariantCulture); // Convert to a double and add to the array b++; } } @@ -452,6 +453,18 @@ public double Length() { return System.Math.Sqrt(this.x*this.x + this.y*this.y + this.z*this.z); } + + public override bool Equals(object obj) { + if (obj is not Vector3d other) + return false; + + return this == other; + } + + public override int GetHashCode() { + return HashCode.Combine(x, y, z); + } + // Allow direct casting of Type. // vector3 = (Vector3)vector3d public static implicit operator Vector3(Vector3d convert) { diff --git a/version2/Assets/Scripts/tests/ImportData.cs b/version2/Assets/Scripts/tests/ImportData.cs index ae262e08..09140a01 100644 --- a/version2/Assets/Scripts/tests/ImportData.cs +++ b/version2/Assets/Scripts/tests/ImportData.cs @@ -1,7 +1,6 @@ -using UnityEngine; -using System.Collections; -using System.IO; +using System.IO; using SimpleJSON; +using UnityEngine; namespace ImportData @@ -9,14 +8,17 @@ namespace ImportData public class Data { - static string fileName = "Assets/Scripts/data.json"; - public static StreamReader data = File.OpenText(fileName); + private static readonly string FileName = Path.Combine(Application.dataPath, "Scripts/data.json"); public static JSONNode importedData; [HideInInspector] public string JSONData; // Holds the data.json file data public int numberOfStars; + public static string LoadJson() { + return File.ReadAllText(FileName); + } + /*void Awake () { StreamReader data = File.OpenText(fileName); @@ -37,4 +39,4 @@ public class Data { }*/ } -} \ No newline at end of file +} diff --git a/version2/Assets/Scripts/tests/Maths.cs b/version2/Assets/Scripts/tests/Maths.cs index 382bf35c..a933dcf2 100644 --- a/version2/Assets/Scripts/tests/Maths.cs +++ b/version2/Assets/Scripts/tests/Maths.cs @@ -1,15 +1,11 @@ using UnityEngine; using System; -using System.Collections; using Elements; -using BodyElements; using System.Linq; namespace CustomMath { - - [System.Serializable] // Show it in the Inspector - public class Maths + public static class Maths { /************************************************************ diff --git a/version2/Assets/Scripts/tests/SystemScaleState.cs b/version2/Assets/Scripts/tests/SystemScaleState.cs index 258db9e3..2bed8f71 100644 --- a/version2/Assets/Scripts/tests/SystemScaleState.cs +++ b/version2/Assets/Scripts/tests/SystemScaleState.cs @@ -3,6 +3,7 @@ using System.Collections; using CustomMath; +[DisallowMultipleComponent] public class SystemScaleState : MonoBehaviour { public enum State { ScaleNull, ScaleLayer1, ScaleLayer2, ScaleLayer3, ScaleLayer4, ScaleLayer5, ScaleLayer6, ScaleLayer7, ScaleLayer8, ScaleLayer9, ScaleLayer10, ScaleLayer11, ScaleLayer12, ScaleLayer13, ScaleLayer14, ScaleLayer15, ScaleLayer16, ScaleLayer17, ScaleLayer18 } From c941ab4b02fa2c8a7bf5929da5dff458941fcf70 Mon Sep 17 00:00:00 2001 From: Cassius John-Adams Date: Sun, 19 Apr 2026 22:16:06 -0400 Subject: [PATCH 2/4] Fix astronomy parsing and coordinate conversions --- version2/Assets/Editor/MakeLayers.cs | 14 ++-- version2/Assets/Scripts/tests/Elements.cs | 98 ++++++++++++----------- version2/Assets/Scripts/tests/Maths.cs | 8 +- 3 files changed, 62 insertions(+), 58 deletions(-) diff --git a/version2/Assets/Editor/MakeLayers.cs b/version2/Assets/Editor/MakeLayers.cs index 738e66ff..9e93f6ad 100644 --- a/version2/Assets/Editor/MakeLayers.cs +++ b/version2/Assets/Editor/MakeLayers.cs @@ -24,14 +24,14 @@ private static void CreateLayer() { it.stringValue = "Camera Layer "+(a-7); } } + } - for(int i=0;i<32;i++) { - for(int b=0;b<32;b++) { - if(b != i && b != 0) - Physics.IgnoreLayerCollision (b, i, true);//Physics.GetIgnoreLayerCollision (b,i)); - else if (b == 0) - Physics.IgnoreLayerCollision (b, i, false); - } + for(int i=0;i<32;i++) { + for(int b=0;b<32;b++) { + if(b != i && b != 0) + Physics.IgnoreLayerCollision (b, i, true);//Physics.GetIgnoreLayerCollision (b,i)); + else if (b == 0) + Physics.IgnoreLayerCollision (b, i, false); } } tagManager.ApplyModifiedProperties(); diff --git a/version2/Assets/Scripts/tests/Elements.cs b/version2/Assets/Scripts/tests/Elements.cs index d94b7b0e..6f400848 100644 --- a/version2/Assets/Scripts/tests/Elements.cs +++ b/version2/Assets/Scripts/tests/Elements.cs @@ -37,29 +37,29 @@ public RightAscension(string HourMinSec) { * '00:42.5' * '00 42 30' */ - string[] _words = new string[] { "" }; - double[] _values = new double[4]; - - if (HourMinSec.Split (new char[] { 'h', 'm', 's' }).Length == 4) { - _words = HourMinSec.Split (new char[] { 'h', 'm', 's' }); - } else if(HourMinSec.Split (new char[] { 'h', '.', 'm' }).Length == 4) { - _words = HourMinSec.Split (new char[] { 'h', '.', 'm' }); - _words[2] = ((Convert.ToDouble(_words[2], CultureInfo.InvariantCulture)/10) * 60).ToString(CultureInfo.InvariantCulture); // Convert fraction of minute to seconds - } else if(HourMinSec.Split (new char[] { ':', '.' }).Length == 3) { - _words = HourMinSec.Split (new char[] { ':', '.' }); - _words[2] = ((Convert.ToDouble(_words[2], CultureInfo.InvariantCulture)/10) * 60).ToString(CultureInfo.InvariantCulture); // Convert fraction of minute to seconds - } else if(HourMinSec.Split (new char[] { ' ' }).Length == 3) { - _words = HourMinSec.Split (new char[] { ' ' }); - } + string cleaned = HourMinSec.Trim().ToLowerInvariant(); + cleaned = cleaned.Replace("h", " ").Replace("m", " ").Replace("s", " ").Replace(":", " "); + string[] parts = cleaned.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + double hours = 0d; + double minutes = 0d; + double seconds = 0d; + + if (parts.Length > 0) + hours = Convert.ToDouble(parts[0], CultureInfo.InvariantCulture); - for (int i=0; i<_words.Length; i++) { - if(_words[i] != "") - _values [i] = Convert.ToDouble (_words [i], CultureInfo.InvariantCulture); + if (parts.Length > 1) { + double minuteValue = Convert.ToDouble(parts[1], CultureInfo.InvariantCulture); + minutes = Math.Truncate(minuteValue); + seconds += Math.Abs(minuteValue - minutes) * 60d; } - this.Hours = _values[0]; - this.Minutes = _values[1]; - this.Seconds = _values[2]; + if (parts.Length > 2) + seconds += Convert.ToDouble(parts[2], CultureInfo.InvariantCulture); + + this.Hours = hours; + this.Minutes = minutes; + this.Seconds = seconds; } } @@ -91,30 +91,31 @@ public Declination(string Deg_DegMin_DegSec) { * '+41:12' * '+41 12 00' */ - string[] _words = new string[] { "" }; - double[] _values = new double[3]; - - if (Deg_DegMin_DegSec.Split (new char[] {'+','d','m','s'} ).Length == 5) { - _words = Deg_DegMin_DegSec.Split (new char[] {'+','d','m','s'} ); - } else if(Deg_DegMin_DegSec.Split (new char[] {'+','d','m'} ).Length == 4) { - _words = Deg_DegMin_DegSec.Split (new char[] {'+','d','m'} ); - } else if(Deg_DegMin_DegSec.Split (new char[] {'+',':'} ).Length == 3) { - _words = Deg_DegMin_DegSec.Split (new char[] {'+',':'} ); - } else if(Deg_DegMin_DegSec.Split (new char[] {'+',' '} ).Length == 4) { - _words = Deg_DegMin_DegSec.Split (new char[] {'+',' '} ); + string cleaned = Deg_DegMin_DegSec.Trim().ToLowerInvariant(); + int sign = cleaned.StartsWith("-") ? -1 : 1; + cleaned = cleaned.TrimStart('+', '-'); + cleaned = cleaned.Replace("d", " ").Replace("m", " ").Replace("s", " ").Replace(":", " "); + string[] parts = cleaned.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + double degrees = 0d; + double degreeMinutes = 0d; + double degreeSeconds = 0d; + + if (parts.Length > 0) + degrees = Convert.ToDouble(parts[0], CultureInfo.InvariantCulture); + + if (parts.Length > 1) { + double minuteValue = Convert.ToDouble(parts[1], CultureInfo.InvariantCulture); + degreeMinutes = Math.Truncate(minuteValue); + degreeSeconds += Math.Abs(minuteValue - degreeMinutes) * 60d; } - int b = 0; - for (int i=0; i<_words.Length; i++) { - if(_words[i] != "" && _words[i] != " " && _words[i] != null) { // Check that it's not an empty value - _values[b] = Convert.ToDouble (_words [i], CultureInfo.InvariantCulture); // Convert to a double and add to the array - b++; - } - } + if (parts.Length > 2) + degreeSeconds += Convert.ToDouble(parts[2], CultureInfo.InvariantCulture); - this.Degrees = _values[0]; - this.DegreeMinutes = _values[1]; - this.DegreeSeconds = _values[2]; + this.Degrees = sign * Math.Abs(degrees); + this.DegreeMinutes = degreeMinutes; + this.DegreeSeconds = degreeSeconds; } } @@ -224,8 +225,6 @@ double SetMeasurementTo(double value, string measurement) { value *= Maths.zetameter; else if (measurement == "yottameter") value *= Maths.yottameter; - else if (measurement == "yottameter") - value *= Maths.yottameter; /* Size, Radius & Mass Conversion */ } else if(Maths.othersArray.Contains (measurement)) { @@ -252,13 +251,13 @@ double SetMeasurementTo(double value, string measurement) { value *= Maths.second; else if (measurement == "minute") value *= Maths.minute; - else if (measurement == "sidrealMinute") + else if (measurement == "sidrealMinute" || measurement == "siderealMinute") value *= Maths.siderealMinute; else if (measurement == "hour") value *= Maths.hour; else if (measurement == "day") value *= Maths.day; - else if (measurement == "sidrealDay") + else if (measurement == "sidrealDay" || measurement == "siderealDay") value *= Maths.siderealDay; else if (measurement == "year") value *= Maths.year; @@ -440,12 +439,16 @@ public static double Distance(Vector3d first, Vector3d second) { // Comparison of two Vector3d variables. Checks their values instead of checking if it's the same reference public static bool operator == (Vector3d first, Vector3d second) { + if (ReferenceEquals(first, second)) + return true; + if (ReferenceEquals(first, null) || ReferenceEquals(second, null)) + return false; return (first.x == second.x && first.y == second.y && first.z == second.z); } // Comparison of two Vector3d variables. Checks their values instead of checking if it's the same reference public static bool operator !=(Vector3d first, Vector3d second) { - return (first.x != second.x || first.y != second.y || first.z != second.z); + return !(first == second); } // Calculate the length of the Vector3d variable (from 0,0,0) @@ -455,7 +458,8 @@ public double Length() { public override bool Equals(object obj) { - if (obj is not Vector3d other) + Vector3d other = obj as Vector3d; + if (ReferenceEquals(other, null)) return false; return this == other; diff --git a/version2/Assets/Scripts/tests/Maths.cs b/version2/Assets/Scripts/tests/Maths.cs index a933dcf2..3903035d 100644 --- a/version2/Assets/Scripts/tests/Maths.cs +++ b/version2/Assets/Scripts/tests/Maths.cs @@ -267,7 +267,7 @@ public static double InMillennium(Element element) { public static double RightAscensionToDegrees(RightAscension rightAscension) { - return (rightAscension.Hours * 15d) + (rightAscension.Minutes * 0.25d) + (rightAscension.Seconds * 0.004166d); + return (rightAscension.Hours * 15d) + (rightAscension.Minutes * 0.25d) + (rightAscension.Seconds * (1d / 240d)); } public static double DeclinationToDegrees(Declination declination) { return (Math.Abs (declination.Degrees) + (declination.DegreeMinutes / 60d) + (declination.DegreeSeconds / 3600d)) * Math.Sign (declination.Degrees); @@ -282,9 +282,9 @@ public static Vector3d SphericalToCartesianCoords(double distance, RightAscensio // Convert to cartesian values // We divide by megameter so we have the base conversion. Ex: 13,000,000meter = 13u - double _x = (distance/megameter) * Math.Sin(Maths.Deg2Rad * _declinationDegrees) * Math.Cos(Maths.Deg2Rad * _rightAscensionDegrees); - double _y = (distance/megameter) * Math.Sin(Maths.Deg2Rad * _declinationDegrees) * Math.Sin(Maths.Deg2Rad * _rightAscensionDegrees); - double _z = (distance/megameter) * Math.Cos(Maths.Deg2Rad * _declinationDegrees); + double _x = (distance/megameter) * Math.Cos(Maths.Deg2Rad * _declinationDegrees) * Math.Cos(Maths.Deg2Rad * _rightAscensionDegrees); + double _y = (distance/megameter) * Math.Cos(Maths.Deg2Rad * _declinationDegrees) * Math.Sin(Maths.Deg2Rad * _rightAscensionDegrees); + double _z = (distance/megameter) * Math.Sin(Maths.Deg2Rad * _declinationDegrees); return new Vector3d (_x, _y, _z ); } From 85c31eb71e8502dc98c5d570c1ed9100e7f4dcce Mon Sep 17 00:00:00 2001 From: Cassius John-Adams Date: Sun, 19 Apr 2026 22:25:48 -0400 Subject: [PATCH 3/4] Update Unity project metadata --- version2/Packages/manifest.json | 37 +++ version2/Packages/packages-lock.json | 268 ++++++++++++++++++ .../ProjectSettings/DynamicsManager.asset | Bin 4280 -> 2524 bytes .../ProjectSettings/GraphicsSettings.asset | Bin 4128 -> 6030 bytes 4 files changed, 305 insertions(+) create mode 100644 version2/Packages/manifest.json create mode 100644 version2/Packages/packages-lock.json diff --git a/version2/Packages/manifest.json b/version2/Packages/manifest.json new file mode 100644 index 00000000..2a101301 --- /dev/null +++ b/version2/Packages/manifest.json @@ -0,0 +1,37 @@ +{ + "dependencies": { + "com.unity.multiplayer.center": "1.0.0", + "com.unity.modules.accessibility": "1.0.0", + "com.unity.modules.ai": "1.0.0", + "com.unity.modules.androidjni": "1.0.0", + "com.unity.modules.animation": "1.0.0", + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.cloth": "1.0.0", + "com.unity.modules.director": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0", + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.particlesystem": "1.0.0", + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.physics2d": "1.0.0", + "com.unity.modules.screencapture": "1.0.0", + "com.unity.modules.terrain": "1.0.0", + "com.unity.modules.terrainphysics": "1.0.0", + "com.unity.modules.tilemap": "1.0.0", + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.uielements": "1.0.0", + "com.unity.modules.umbra": "1.0.0", + "com.unity.modules.unityanalytics": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.unitywebrequestassetbundle": "1.0.0", + "com.unity.modules.unitywebrequestaudio": "1.0.0", + "com.unity.modules.unitywebrequesttexture": "1.0.0", + "com.unity.modules.unitywebrequestwww": "1.0.0", + "com.unity.modules.vehicles": "1.0.0", + "com.unity.modules.video": "1.0.0", + "com.unity.modules.vr": "1.0.0", + "com.unity.modules.wind": "1.0.0", + "com.unity.modules.xr": "1.0.0" + } +} diff --git a/version2/Packages/packages-lock.json b/version2/Packages/packages-lock.json new file mode 100644 index 00000000..d0360bfe --- /dev/null +++ b/version2/Packages/packages-lock.json @@ -0,0 +1,268 @@ +{ + "dependencies": { + "com.unity.multiplayer.center": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.uielements": "1.0.0" + } + }, + "com.unity.modules.accessibility": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.ai": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.androidjni": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.animation": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.assetbundle": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.audio": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.cloth": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0" + } + }, + "com.unity.modules.director": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.animation": "1.0.0" + } + }, + "com.unity.modules.hierarchycore": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.imageconversion": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.imgui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.jsonserialize": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.particlesystem": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.physics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.physics2d": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.screencapture": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.subsystems": { + "version": "1.0.0", + "depth": 1, + "source": "builtin", + "dependencies": { + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.terrain": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.terrainphysics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.terrain": "1.0.0" + } + }, + "com.unity.modules.tilemap": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics2d": "1.0.0" + } + }, + "com.unity.modules.ui": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.uielements": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.imgui": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.hierarchycore": "1.0.0" + } + }, + "com.unity.modules.umbra": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.unityanalytics": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0" + } + }, + "com.unity.modules.unitywebrequest": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.unitywebrequestassetbundle": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" + } + }, + "com.unity.modules.unitywebrequestaudio": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.audio": "1.0.0" + } + }, + "com.unity.modules.unitywebrequesttexture": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.unitywebrequestwww": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.unitywebrequest": "1.0.0", + "com.unity.modules.unitywebrequestassetbundle": "1.0.0", + "com.unity.modules.unitywebrequestaudio": "1.0.0", + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.assetbundle": "1.0.0", + "com.unity.modules.imageconversion": "1.0.0" + } + }, + "com.unity.modules.vehicles": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0" + } + }, + "com.unity.modules.video": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.audio": "1.0.0", + "com.unity.modules.ui": "1.0.0", + "com.unity.modules.unitywebrequest": "1.0.0" + } + }, + "com.unity.modules.vr": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.xr": "1.0.0" + } + }, + "com.unity.modules.wind": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": {} + }, + "com.unity.modules.xr": { + "version": "1.0.0", + "depth": 0, + "source": "builtin", + "dependencies": { + "com.unity.modules.physics": "1.0.0", + "com.unity.modules.jsonserialize": "1.0.0", + "com.unity.modules.subsystems": "1.0.0" + } + } + } +} diff --git a/version2/ProjectSettings/DynamicsManager.asset b/version2/ProjectSettings/DynamicsManager.asset index 5262bcf62f0cc98f00ce9191cc28550e5baa45f4..f9eb8fbd4ae86d2f49f342d9610e5c013909db20 100644 GIT binary patch literal 2524 zcmaKuO>7%Q6vt=tLEZ2bpg69REc;RLxLRHSm@22yVb^Z(Dz+M8sDhD5v*O>;Xk=L+FOZH#H@-hvy0o`2z47MF zkDOmBUpxcvjVU4SCWc_z5FsP|WvHz-maxQU(_;9gC5AKbFeNn=@;|`ugyS|SQbLN_ z(pd29Aol|pGk%)R9KHZAIW>Ziz?Wdk)I=Z_#{Wxc+Zge+@3?J_bc8u!)c_ zVgFTpEg0R;ExrFsV2nQw%?j&heOqvn&t)OTDgVImTaVx$8_pWC!g%igD>#||_AJCW zn!q9$?qk%vwT{g&jNCAeO?r#8jFRFWBvI8~$JxVx00H3}>HbCFQ>xzDQ^f$5Y68zh-f<*c-eD zLKL;7Ie5Pw)}*K{P0G{z#k-OhpWd(HA)cJi39QfaJEi%=aDVL2GloA(WFO`)8h(0$ z^eC-=4ID=x9y@|NhCfbjPbQ`7zhm-0k;8YezxNG4GYQor#J<#6Wz z(eS4a@M?PyxlXhxec4i>=v-b4W#5elVp|Nv+oD>H!}H@gu?k)3UBIkW)s#Ii-js<8 zo{H#J}bo6w1(gCxzoZ^mmql%b+m+;~MgTTSUG#!bBS&~4!?=)CC5 zE1oJfWH)yEsuF~bg177iDAC8N<-qgY2qmn#Q7lnyKCQ)Wv+1jdDL3RG6Ndu~-EFvQ zZl~wzA~u5t)0BE~P#gG8J(Pab48jhBUst_IjTbFT&%1&WNY?#+u$7N;wp&wi?E0;! z9<*BCc+=^lM}^68SEU<9WttH94w_ew)Y8SXDTkj_bQo zhnwqk!=SGkXbq>G#=)OFK9gYFQrjiJg|i52U8UGHH3v`EX|ME}O`Kf2=WmtKS?q#x zFASBhAEWXc>zrJXQM?)GeT^HBEzi44&B{O7FaIi3;1s4`{@+41br9E-#`}briFiA7GCfcUT{_sYD0%m z{Wk?W11&)3p+%?-9YS@ADSXaA3($FJ5o$w`0Tb{?Iie2Dgt%^F3u5-qum2v6u3r5Q D1Gu4P literal 4280 zcmeHKO>Yx15S?uUg!0hOMzaa!%R=4 zIlwu%xLs&r-Jb5Q2szC%jiY)mik`@AzOU?&QA6C>+^xL17?SwG#9cfDy%mKtyP4K1 zM}9bFqo(eb`*-0t#T#R^j1fio&oAL#IbZqt-g5rAx{xm0`2;5(KDt%#vV?JOP zY>|0+%rBN7CL>r-ASe(N2nqxRf&xK-pg>R{C=e9*4+Vbwe)RnkJ^AwaVe{#S%_h;W zWaHX{2su6`Z^E#MOnMF2{m2(>2{vk^+DC2DslE{%b%T YXaF&g05iZXv4*w=)PV*N0|_wu3nRI{q5uE@ diff --git a/version2/ProjectSettings/GraphicsSettings.asset b/version2/ProjectSettings/GraphicsSettings.asset index f14fb85631d88bcddaaa465ad54ab75f29f609c9..f9b6bb6cc53bf5adf9d5a2f0a96a6f4faee85bec 100644 GIT binary patch literal 6030 zcmaKwO>i7X6~}uOnS>A=2*C*iutQ8B0c_b0;ValHtz>B(DcNXcCE+7V?`~^%;@O$a z%&a8^LWY7HDXJ)P<3OdTKv7h2AQiZ}iVIx0aU>K6E~#9of&&~7|NnINsAp!!uRJ}k z->>`i>+aXRBMXtsiChyW?$-J}Khp0L9m^hFSXel-aOT4K-E-o9hlhua2FNE!4-a4a z+3%h`{{26lTUq^E`{mbyd%p+k&M_fAKn(e!5GlGGW|cH6v!Wpy;up7w^tTO>&ci~N ze5{av5S35kp|3d$%)0^0+wgrJb@sny2LCc_m+{{a%HgjC<`$IljAG2)!KNhbp`nACtQ{esO<4 zT;Y2CehNF|a}Ek>dVDwk?#Zl2MLE8Ek5HzS_xB^P-YmY4R=AGu*RV6b`|!9@UcZmI z5PCVjk5_nc{dnAO7T?JV*YW)xcE)!Kk1OT)?sp;da(thx@M3%qWPQ@SRXP7oS9l{k z|9^m;=l@fAPp$C&`3uhfUs2`#^&rhD3oVGRaSj$fk*{+~1cAI*DerR*QSbEWu;{=Zb=dVW(gKjwlfoZml?JFlAYzmmaI zc@vKRI(GEurvF!K_#1{lR>Oa3_}402$M-A4FXkg_h4JzJyJ7gH89X~b;LN`!dCEcy z;xC+^MVfDD#UBH{jjuXO<8DRelfoPpbhh9*@6fd zLwI<1^E;yG|5)b#5z~LQ(qHo{hOgD|XAE!G@aGM`GJ~%pq8J=g6pz>NpBRp|1!>@m zhy8zJ_(p-!r{-@N{zMJ`qv1SfuGs!>8{Tmtbj$x`_)|6f(C|(2=20W=FXMjzAAX#F zm#E1?i_Ooo;N1T$3rf6Y_|+P|Y4~;x9~u7i49@uWz!@LEBVA#9Ki&_Qz8pa=>4Y?vpS!h9i7Vf8Am>W$4spBsK z-Y@p|eVEyb966nGe6HW9!si8YD)lfvzmL4E>#3|{!SnGtcnFSvoCj>DP-?OKMZ>Sb zJd4MM`!#%O__)I7v+?%~5A?8k$@OD=KQKHbY33NQG{ir_e+>KXUxU440=!q~IOP|$^kgd1TDU4WO_lBcnP5L2q6~vc)87b)7-av&q zg18;@{pmnuF^+c@{XKbLZ3EK;Jvx!{L(DKYIn&vektc(s75XMz&d+o(9+qU%A8mPK zweF3*1h_kiyhO#As+{`ChD;QE_yDbGoP^^|6<{?x-bDFcz=*dZ8N?GrAM_8pVU(C~ z%jU&>FGk89h?mgEIM=?gS6tvD^G4Xi%9r7m=WJr3GTz}%54L19RGa~!U{TJ9m4S!l zM~gfe;zR}m8JV?vYASs%IS`l&=4j&@4WevLk&;NKv081nI#;j8a;U^KMwm7gI#JkD zOW{7=FX-f$#eMjOXQH*`O}>^@B0XQH%7&cK)RJ-EZfUp&V=N{Sv-ZOIB`?uQmRVIG zd%jxlbha~3UNTbAhK#RW4x>eXGLlOiPN#-W%f%`7P$pgrzyxT0f5~HR<@$3mo6HEqhTb9QTkeJaTU9<%2+uz5dKj8rAo;s}Nr+ zIqgn+NhEPPuQNR{A;z$d(IvOu)K~T=h01x<7X6+Ygxx)!h<30W#-eNy2v>=I=p&0F zF%&%^#n=nhrzo&Y7*Fmyl^vbK_OPt_VNd!t_qf$&HR7u=jvoVT2MI0%=AeUce8Xr< zjVCIS$uzqr*2Ce`BiuRJ)z*%&yb~Ome0j4}d~%w^xJ}lkzK_krIUdq$3p0r1rt*;l z*D)%tp%z-`-7iAD!j|&3&3=yD-y|9@ItE7-;!aW{n<@^cQD4Pprvaw7)6;kJj@n0P zwo&m-Uwl@K+19U=>djL9VySNbjrvC%nSz=%S literal 4128 zcmeH~O-{ow5QV4wvjTB|Dr*)+NWcmq6`?{`jno4~Zag$bsf%m}2zTRZgqgUODB=iX z$$k^(&5ZM9Wq`pKz-a~m$D||xSEHNJ_46fscU?E2=ON8Ur(P>l`Z&n#`U{u{nVCqqfyT* zrP2AmTk4WhSjWz(cC+${cK?*+96pFQpV;^2{yb64 From 2715a88c2ca1fd333866b136e04292a1fc3abf4f Mon Sep 17 00:00:00 2001 From: Cassius John-Adams Date: Sun, 19 Apr 2026 22:39:58 -0400 Subject: [PATCH 4/4] Position planets and moons from orbit data --- .../Scripts/tests/CreateSolarSystems.cs | 135 +++++++++++++++--- version2/Assets/Scripts/tests/Elements.cs | 6 + version2/Assets/Scripts/tests/Maths.cs | 5 +- 3 files changed, 125 insertions(+), 21 deletions(-) diff --git a/version2/Assets/Scripts/tests/CreateSolarSystems.cs b/version2/Assets/Scripts/tests/CreateSolarSystems.cs index 9085cd04..a23ec252 100644 --- a/version2/Assets/Scripts/tests/CreateSolarSystems.cs +++ b/version2/Assets/Scripts/tests/CreateSolarSystems.cs @@ -22,6 +22,7 @@ public class PlanetList { public string name; public Planet key; public GameObject value; + public Vector3d positionInOrbit; } @@ -30,6 +31,7 @@ public class MoonList { public string name; public Moon key; public GameObject value; + public Vector3d positionInOrbit; } @@ -92,10 +94,13 @@ void Awake () { // Generate Planets - for (int iteratorB=0; iteratorB < importedData["star"][iteratorA]["planets"].Count; iteratorB++) { + JSONNode planetDataList = importedData["star"][iteratorA]["planets"]; + for (int iteratorB=0; iteratorB < planetDataList.Count; iteratorB++) { + JSONNode planetData = planetDataList[iteratorB]; Planet _planet = new Planet(); - _planet.Name = importedData["star"][iteratorA]["planets"][iteratorB]["name"]; - _planet.DateLastUpdated = importedData["star"][iteratorA]["planets"][iteratorB]["dateLastUpdate"]; + _planet.Name = planetData["name"]; + _planet.DateLastUpdated = GetString(planetData, "dateLastUpdate", _star.DateLastUpdated); + SetOrbitElements(_planet, planetData, "Planet"); GameObject _planetSystem = new GameObject("Planetary System: "+_planet.Name); _star.ChildPlanets.Add (_planetSystem); @@ -105,12 +110,16 @@ void Awake () { _planets_.name = _planet.Name; _planets_.key = _planet; _planets_.value = _planetSystem; + _planets_.positionInOrbit = CalculateOrbitPosition(_planet, iteratorB, planetDataList.Count); planets.Add (_planets_); - for (int iteratorC=0; iteratorC < importedData["star"][iteratorA]["planets"][iteratorB]["moons"].Count; iteratorC++) { + JSONNode moonDataList = planetData["moons"]; + for (int iteratorC=0; iteratorC < moonDataList.Count; iteratorC++) { + JSONNode moonData = moonDataList[iteratorC]; Moon _moon = new Moon(); - _moon.Name = importedData["star"][iteratorA]["planets"][iteratorB]["moons"][iteratorC]["name"]; - _moon.DateLastUpdated = importedData["star"][iteratorA]["planets"][iteratorB]["moons"][iteratorC]["dateLastUpdate"]; + _moon.Name = moonData["name"]; + _moon.DateLastUpdated = GetString(moonData, "dateLastUpdate", _planet.DateLastUpdated); + SetOrbitElements(_moon, moonData, "Moon"); GameObject _moonSystem = new GameObject("Moon System: "+_moon.Name); _planet.ChildMoons.Add(_moonSystem); @@ -122,6 +131,7 @@ void Awake () { _moons_.name = _moon.Name; _moons_.key = _moon; _moons_.value = _moonSystem; + _moons_.positionInOrbit = CalculateOrbitPosition(_moon, iteratorC, moonDataList.Count); moons.Add (_moons_); } } @@ -130,10 +140,95 @@ void Awake () { } + private static string GetString(JSONNode source, string key, string fallback) { + JSONNode node = source[key]; + if (HasJsonValue(node)) + return node.Value; + return string.IsNullOrEmpty(fallback) ? "Unknown" : fallback; + } + + private static void SetOrbitElements(OrbitElement orbitElement, JSONNode source, string bodyType) { + string lastUpdated = string.IsNullOrEmpty(orbitElement.DateLastUpdated) ? "Unknown" : orbitElement.DateLastUpdated; + + orbitElement.SemiMajorAxis = CreateElement(source, "semiMajorAxis", bodyType + " Semi-major Axis", "au", lastUpdated); + orbitElement.Eccentricity = CreateElement(source, "eccentricity", bodyType + " Eccentricity", "ratio", lastUpdated); + orbitElement.Inclination = CreateElement(source, "inclination", bodyType + " Inclination", "degree", lastUpdated); + orbitElement.ArgumentOfPariapsis = CreateElement(source, "argumentOfPariapsis", bodyType + " Argument of Pariapsis", "degree", lastUpdated); + orbitElement.Longitude = CreateElement(source, "longitude", bodyType + " Longitude of Ascending Node", "degree", lastUpdated); + orbitElement.MeanAnomaly = CreateElement(source, "meanAnomaly", bodyType + " Mean Anomaly", "degree", lastUpdated); + orbitElement.Period = CreateElement(source, "orbitalPeriod", bodyType + " Orbital Period", "day", lastUpdated); + orbitElement.EccentricAnomaly = CreateElement(source, "eccentricAnomaly", bodyType + " Eccentric Anomaly", "degree", lastUpdated); + orbitElement.TrueAnomaly = CreateElement(source, "trueAnomaly", bodyType + " True Anomaly", "degree", lastUpdated); + } + + private static Element CreateElement(JSONNode source, string key, string name, string measurement, string lastUpdated) { + JSONNode node = source[key]; + if (!HasJsonValue(node)) + return null; + + return new Element(name, ParseDouble(node), measurement, 0.0d, "SI", "StarTography 1.0", lastUpdated); + } + + private static bool HasJsonValue(JSONNode node) { + return node != null && !string.IsNullOrEmpty(node.Value); + } + private static double ParseDouble(JSONNode node) { return double.Parse(node.Value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture); } + private static Vector3d CalculateOrbitPosition(OrbitElement orbitElement, int siblingIndex, int siblingCount) { + if (orbitElement == null || orbitElement.SemiMajorAxis == null) + return new Vector3d(); + + double semiMajorAxis = Maths.InMM(orbitElement.SemiMajorAxis); + double eccentricity = ClampEccentricity(GetElementValue(orbitElement.Eccentricity, 0d)); + double inclination = GetElementValue(orbitElement.Inclination, 0d) * Maths.Deg2Rad; + double longitude = GetElementValue(orbitElement.Longitude, 0d) * Maths.Deg2Rad; + double argumentOfPariapsis = GetElementValue(orbitElement.ArgumentOfPariapsis, 0d) * Maths.Deg2Rad; + double trueAnomaly = GetOrbitAngleDegrees(orbitElement, siblingIndex, siblingCount) * Maths.Deg2Rad; + + double orbitalRadius = semiMajorAxis * (1d - (eccentricity * eccentricity)) / (1d + (eccentricity * Math.Cos(trueAnomaly))); + double angleInOrbit = argumentOfPariapsis + trueAnomaly; + + double cosLongitude = Math.Cos(longitude); + double sinLongitude = Math.Sin(longitude); + double cosInclination = Math.Cos(inclination); + double sinInclination = Math.Sin(inclination); + double cosAngle = Math.Cos(angleInOrbit); + double sinAngle = Math.Sin(angleInOrbit); + + return new Vector3d( + orbitalRadius * ((cosLongitude * cosAngle) - (sinLongitude * sinAngle * cosInclination)), + orbitalRadius * ((sinLongitude * cosAngle) + (cosLongitude * sinAngle * cosInclination)), + orbitalRadius * (sinAngle * sinInclination) + ); + } + + private static double GetOrbitAngleDegrees(OrbitElement orbitElement, int siblingIndex, int siblingCount) { + if (orbitElement.TrueAnomaly != null) + return orbitElement.TrueAnomaly.Value; + if (orbitElement.MeanAnomaly != null) + return orbitElement.MeanAnomaly.Value; + if (orbitElement.EccentricAnomaly != null) + return orbitElement.EccentricAnomaly.Value; + if (siblingCount <= 0) + return 0d; + + return (360d * siblingIndex) / siblingCount; + } + + private static double GetElementValue(Element element, double fallback) { + return element == null ? fallback : element.Value; + } + + private static double ClampEccentricity(double eccentricity) { + if (double.IsNaN(eccentricity)) + return 0d; + + return Math.Min(Math.Max(eccentricity, 0d), 0.999999d); + } + void Start() { @@ -142,15 +237,15 @@ void Start() { star.value.transform.position = star.positionInSpace; GameObject _starGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Create the Star object _starGameObject.name = "Star: "+star.name; - _starGameObject.transform.SetParent(star.value.transform, true); - _starGameObject.transform.position = star.value.transform.position; + _starGameObject.transform.SetParent(star.value.transform, false); + _starGameObject.transform.localPosition = Vector3.zero; SphereCollider sphereCollider = _starGameObject.GetComponent(); sphereCollider.isTrigger = false; sphereCollider.radius = 1f; GameObject _starDistanceColliders = new GameObject("Star: "+star.name+": Distance Colliders"); - _starDistanceColliders.transform.SetParent(star.value.transform, true); - _starDistanceColliders.transform.position = star.value.transform.position; + _starDistanceColliders.transform.SetParent(star.value.transform, false); + _starDistanceColliders.transform.localPosition = Vector3.zero; Element _starSize = new Element("Radius of the Star", star.key.Radius.Value, "stellarRadius", 0.0d, "si", "Allen's Astrophysical Quantities 4th Edition", star.key.DateLastUpdated); Debug.Log ("Before: "+_starSize.Name+" "+_starSize.Value+" "+_starSize.Measurement); @@ -170,8 +265,8 @@ void Start() { colliderRadiusScale = 10f * Mathf.Exp ((i-3)/2f); GameObject _starDistanceCollider = new GameObject("Star: "+star.name+": Distance Collider "+i); - _starDistanceCollider.transform.SetParent(_starDistanceColliders.transform, true); - _starDistanceCollider.transform.position = star.value.transform.position; + _starDistanceCollider.transform.SetParent(_starDistanceColliders.transform, false); + _starDistanceCollider.transform.localPosition = Vector3.zero; _starDistanceCollider.transform.localScale = new Vector3(1f,1f,1f); Rigidbody _sphereRigidbody = _starDistanceCollider.AddComponent(); _sphereRigidbody.useGravity = false; @@ -184,12 +279,12 @@ void Start() { // Prepare the planetary system parent foreach (PlanetList planet in planets) { - planet.value.transform.SetParent(planet.key.ParentStar.transform, true); - planet.value.transform.position = planet.key.ParentStar.transform.position; + planet.value.transform.SetParent(planet.key.ParentStar.transform, false); + planet.value.transform.localPosition = planet.positionInOrbit; GameObject _planetGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Create the Planet object _planetGameObject.name = "Planet: "+planet.name; - _planetGameObject.transform.SetParent(planet.value.transform, true); - _planetGameObject.transform.position = planet.value.transform.position; + _planetGameObject.transform.SetParent(planet.value.transform, false); + _planetGameObject.transform.localPosition = Vector3.zero; SphereCollider sphereCollider = _planetGameObject.GetComponent(); sphereCollider.isTrigger = false; sphereCollider.radius = 1f; @@ -198,12 +293,12 @@ void Start() { // Prepare the moon system parent foreach (MoonList moon in moons) { - moon.value.transform.SetParent(moon.key.ParentPlanet.transform, true); - moon.value.transform.position = moon.key.ParentPlanet.transform.position; + moon.value.transform.SetParent(moon.key.ParentPlanet.transform, false); + moon.value.transform.localPosition = moon.positionInOrbit; GameObject _moonGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); // Create the Moon object _moonGameObject.name = "Moon: "+moon.name; - _moonGameObject.transform.SetParent(moon.value.transform, true); - _moonGameObject.transform.position = moon.value.transform.position; + _moonGameObject.transform.SetParent(moon.value.transform, false); + _moonGameObject.transform.localPosition = Vector3.zero; SphereCollider sphereCollider = _moonGameObject.GetComponent(); sphereCollider.isTrigger = false; sphereCollider.radius = 1f; diff --git a/version2/Assets/Scripts/tests/Elements.cs b/version2/Assets/Scripts/tests/Elements.cs index 6f400848..ae9d1fe5 100644 --- a/version2/Assets/Scripts/tests/Elements.cs +++ b/version2/Assets/Scripts/tests/Elements.cs @@ -225,6 +225,8 @@ double SetMeasurementTo(double value, string measurement) { value *= Maths.zetameter; else if (measurement == "yottameter") value *= Maths.yottameter; + else if (measurement == "au" || measurement == "astronomicalUnit") + value *= Maths.au; /* Size, Radius & Mass Conversion */ } else if(Maths.othersArray.Contains (measurement)) { @@ -307,6 +309,10 @@ public virtual void ToYM() { this.Value = SetMeasurementTo (this.Value, this.Measurement) / Maths.yottameter; this.Measurement = "yottameter"; } + public virtual void ToAU() { + this.Value = SetMeasurementTo (this.Value, this.Measurement) / Maths.au; + this.Measurement = "au"; + } /* Time Conversions */ public virtual void ToSecond() { this.Value = SetMeasurementTo (this.Value, this.Measurement) / Maths.second; diff --git a/version2/Assets/Scripts/tests/Maths.cs b/version2/Assets/Scripts/tests/Maths.cs index 3903035d..8652de05 100644 --- a/version2/Assets/Scripts/tests/Maths.cs +++ b/version2/Assets/Scripts/tests/Maths.cs @@ -60,6 +60,9 @@ public static Element GetMeasurementIn(Element element) { } else if (_element.Measurement == "yottameter") { _element.Value *= yottameter; _measurement = "yottameter"; + } else if (_element.Measurement == "au" || _element.Measurement == "astronomicalUnit") { + _element.Value *= au; + _measurement = "meter"; } /* Time Conversion */ @@ -207,7 +210,7 @@ public static double InMillennium(Element element) { * We statically assign the size of each scale so that we can * quickly access the different scale sizes */ - public static string[] distanceArray = new string[]{"meter", "kilometer", "megameter", "gigameter", "terameter", "petameter", "exameter", "zetameter", "yottameter"}; + public static string[] distanceArray = new string[]{"meter", "kilometer", "megameter", "gigameter", "terameter", "petameter", "exameter", "zetameter", "yottameter", "au", "astronomicalUnit"}; public const double meter = 1d; public const double layer1 = 0.001d; public const double kilometer = 1000d;