Last active
May 4, 2019 02:36
-
-
Save Vercidium/8a80c3cc8048f8101352461a0ccb939f to your computer and use it in GitHub Desktop.
Part 1 - Generating Galaxy Axis and Arms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vector3 GetPoint() | |
{ | |
Vector3 v; | |
double armDivisor = Math.PI / armCount; | |
while (true) | |
{ | |
// Generate a random normalised point with a weighting | |
// towards the center controlled by the gravity variable | |
v = NextV3(-1, 1).Normalized() * Math.Pow(Next(0, 1.0), gravity); | |
// Some points will not conform to the parameters | |
if (random.NextDouble() > conformChance) | |
break; | |
bool valid = false; | |
// Calculate the global angle of the point around the axis | |
var d = Math.Atan2(v.X, v.Z); | |
// Check if this point lands on an arm | |
for (double j = -Math.PI; j <= Math.PI; j += armDivisor) | |
{ | |
// A point lands on an arm if its distance | |
// from the start of the arm is less than angle * armDistance | |
if (d > j && d < j + armDivisor * armSpread) | |
{ | |
valid = true; | |
break; | |
} | |
} | |
if (valid) | |
break; | |
} | |
v.Y = 0; | |
return v * galaxySize; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment