void Update() { GalaxySim.GetData(celestialBodies); Follow(); RenderBodies(); if (Input.GetKeyDown(KeyCode.T)) { foreach (var body in celestialBodies) { Debug.Log(body.ToString()); } } if (Input.GetKeyDown(KeyCode.S)) { IOUtil.SaveToFile(System.IO.Path.Combine(System.Environment.CurrentDirectory, "savedBodies.bin"), celestialBodies); } if (Input.GetKeyDown(KeyCode.L)) { var objArray = IOUtil.LoadFromFile(System.IO.Path.Combine(System.Environment.CurrentDirectory, "savedBodies.bin"), typeof(GalaxySim.BodyData)); celestialBodies = new GalaxySim.BodyData[objArray.Length]; for (int i = 0; i < objArray.Length; i++) { celestialBodies[i] = (GalaxySim.BodyData)objArray[i]; } GalaxySim.SetupSimulation(celestialBodies); timeElapsed = 0; } }
void Start() { bodyMaterial.enableInstancing = true; hintMaterial.enableInstancing = true; if (!SystemInfo.supportsComputeShaders) { Debug.LogError("Your system doesn't support compute shaders"); } if (!SystemInfo.supportsInstancing) { useInstancing = false; Debug.LogWarning("Your system doesn't support instancing"); } // add new celestial bodies into this List! List <GalaxySim.BodyData> bodiesList = new List <GalaxySim.BodyData>(); var sun = new GalaxySim.BodyData(new Vector3(0, 0, 0), new Vector3(0, 0, 0), 1.9891e30f, 6.955e8f, 6000, false, true); var earth = new GalaxySim.BodyData(new Vector3(149597870700, 0, 0), new Vector3(0, 0, 29783), 5.965e24f * 1, 6371e3f, 300, false); var jupiter = new GalaxySim.BodyData(new Vector3(816520800000, 0, 0), new Vector3(0, 0, 13070), 1.9e27f * 1, 71492e3f, 300, false); bodiesList.Add(sun); bodiesList.Add(earth); bodiesList.Add(jupiter); //some random asteroids near jupiter orbit for (int i = 0; i < 1000; i++) { float randomRadius = UnityEngine.Random.value * Mathf.PI * 2; float randomAltitude = UnityEngine.Random.Range(0.95f * 816520800000, 1.1f * 816520800000); float orbitVel = Mathf.Sqrt(G * sun.mass / randomAltitude); float randomVelocity = UnityEngine.Random.Range(orbitVel * 0.98f, orbitVel * 1.02f); bodiesList.Add(new GalaxySim.BodyData( new Vector3(Mathf.Cos(randomRadius), (-1 + 2 * UnityEngine.Random.value) * 0.1f, Mathf.Sin(randomRadius)) * randomAltitude, new Vector3(-Mathf.Sin(randomRadius), 0, Mathf.Cos(randomRadius)) * randomVelocity * 1f, 100000, 600, 300, true)); } celestialBodies = bodiesList.ToArray(); GalaxySim.SetupSimulation(celestialBodies); }