Skip to content

Commit 909dd35

Browse files
committed
added more visibility to the spawn method
1 parent b7128cc commit 909dd35

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

Assets/Scripts/Barnes-Hut/GalaxySimulationBH.cs

+20-8
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,29 @@ public void Spawn()
2121
Delete();
2222
UiValues = new Dictionary<string, float>();
2323
sliders.ForEach(slider => UiValues.Add(slider.name, slider.value));
24-
root = new TreeNode(50,new Vector3(-UiValues["GalaxyRadius"] * 3 / 2f, -UiValues["GalaxyRadius"] * 3 / 2f),UiValues["GalaxyRadius"]*3f);
24+
25+
float galaxyRadius = UiValues["GalaxyRadius"];
26+
float galaxyThickness = UiValues["GalaxyThickness"];
27+
float starInitialVelocity = UiValues["StarInitialVelocity"];
28+
int starCount = (int)UiValues["StarCount"];
29+
30+
root = new TreeNode(50, new Vector3(-galaxyRadius * 3 / 2f, -galaxyRadius * 3 / 2f), galaxyRadius * 3f);
2531
List<Star> stars = new List<Star>();
26-
for (int i = 0; i < UiValues["StarCount"]; i++)
32+
33+
for (int i = 0; i < starCount; i++)
2734
{
28-
stars.Add(Instantiate(starPrefab, DiscPos(Random.Range(0f, 360f), Random.Range(-UiValues["GalaxyThickness"], UiValues["GalaxyThickness"]), Random.Range(-UiValues["GalaxyRadius"], UiValues["GalaxyRadius"])), starPrefab.transform.rotation, transform));
29-
stars[i].velocity = new Vector3((stars[i].transform.position.x * Mathf.Cos(90f)) - (stars[i].transform.position.z * Mathf.Sin(90f)), 0f, (stars[i].transform.position.z * Mathf.Cos(90f)) + (stars[i].transform.position.x * Mathf.Sin(90f))).normalized * UiValues["StarInitialVelocity"];
30-
root.InsertToNode(stars[i]);
35+
Vector3 randomPosition = DiscPos(Random.Range(0f, 360f), Random.Range(-galaxyThickness, galaxyThickness), Random.Range(-galaxyRadius, galaxyRadius));
36+
Quaternion rotation = starPrefab.transform.rotation;
37+
38+
Star star = Instantiate(starPrefab, randomPosition, rotation, transform);
39+
star.velocity = new Vector3((star.transform.position.x * Mathf.Cos(90f)) - (star.transform.position.z * Mathf.Sin(90f)), Random.Range(-1f, 1f), (star.transform.position.z * Mathf.Cos(90f)) + (star.transform.position.x * Mathf.Sin(90f))).normalized * starInitialVelocity;
40+
41+
stars.Add(star);
42+
root.InsertToNode(star);
3143
}
32-
galaxy = new Galaxy(stars, UiValues["GalaxyRadius"], UiValues["GalaxyRadius"], UiValues["StarInitialVelocity"]);
33-
simulationStarted = true;
3444

45+
galaxy = new Galaxy(stars, galaxyRadius, galaxyRadius, starInitialVelocity);
46+
simulationStarted = true;
3547
}
3648
public void Delete()
3749
{
@@ -60,7 +72,7 @@ public void Update()
6072
setStarColor(star);
6173
}
6274
root.ComputeMassDistribution(UiValues["BlackHoleMass"]);
63-
// center_galaxy();
75+
// center_galaxy();
6476
displayInfoCount();
6577

6678
}

0 commit comments

Comments
 (0)