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); |
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
var v = GetPoint(); | |
// Add some variance to each star | |
v += NextV3(-0.5, 0.5); | |
// Shift stars vertically as they get closer to the center of the galaxy | |
var s = beamHeight / v.Magnitude; | |
v.Y = Next(-s, s); |
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 = Vector3.Zero; | |
// Generate a point | |
... | |
// Calculate the global angle of the point around the axis | |
var a = Math.Atan2(v.X, v.Z); |
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() | |
{ | |
// Generate the point | |
... | |
// Calculate arm scaling | |
... | |
// Rotate the point around the galaxy proportional to its magnitude | |
v *= Matrix4.CreateRotationY(-v.Magnitude * rotationStrength); |
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 position = GetPoint(); | |
position.Y -= heightMagnitude * Math.Sin(position.Magnitude * heightFrequency); |
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 position = GetPoint(); | |
position.Y -= heightMagnitude * Math.Sin(position.Magnitude * heightFrequency); | |
// Colour each point based on their global angle around the axis | |
Color blendedColour; | |
var angle = Math.Atan2(position.X, position.Z); | |
// c1, c2, c3 and c4 are random colours generated at the start of the program | |
// Blend the colours of adjacent quadrants together | |
if (angle < -Math.PI / 2) |
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
// Create multiple layers | |
for (int o = 0; o < layers; o++) | |
{ | |
// Create the arms | |
for (int i = 0; i < 100000; i++) | |
{ | |
Vector3 position = GetPoint(); | |
position.Y -= heightMagnitude * Math.Sin(position.Magnitude * heightFrequency); | |
// Colour and store each point |
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
static Matrix4F identityF = Matrix4.Identity.ToFloat(); | |
// This is a combination of a scale, rotate and translate matrix. Rather than calculating three different matrices and multiplying | |
// them together, we can save float multiplications and additions by using this function | |
public static Matrix4F ParticleMatrix(float s, float rX, float rZ, Vector3 d) | |
{ | |
var sX = GetArrayedSinCheap(rX); | |
var sZ = GetArrayedSinCheap(rZ); | |
var cX = GetArrayedCosCheap(rX); | |
var cZ = GetArrayedCosCheap(rZ); |
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
// Code ported from https://0fps.net/2012/06/30/meshing-in-a-minecraft-game/ | |
// Note this implementation does not support different block types or block normals | |
// The original author describes how to do this here: https://0fps.net/2012/07/07/meshing-minecraft-part-2/ | |
const int CHUNK_SIZE = 32; | |
// These variables store the location of the chunk in the world, e.g. (0,0,0), (32,0,0), (64,0,0) |
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
byte[] fileData = r.ReadBytes(bytesRemaining); | |
var b = 0; | |
for (int x = 0; x < Constants.MapSizeX; x++) | |
{ | |
int chunkX = x / Constants.ChunkSize; | |
for (int z = 0; z < Constants.MapSizeZ; z++) | |
{ | |
int chunkZ = z / Constants.ChunkSize; |
OlderNewer