Exemplo n.º 1
0
    // Create children that fill a single orbit, equally spaced
    // https://en.wikipedia.org/wiki/Klemperer_rosette
    public void ExpandRosette(ref Random random, int vertices)
    {
        //Debug.Log("Expanding Rosette");

        // Rosette children replace the parent, parent orbital node is left empty
        Empty = true;

        // Masses in a rosette alternate, so every sequential pair has the same shared mass
        var sharedMass = Mass / vertices * 2;

        // Proportion of the masses of sequential pairs is random, but only for even vertex counts
        var proportion = vertices % 2 == 0 ? random.NextFloat(.5f, .95f) : .5f;

        // Place children at a fixed distance in the center of the range
        var dist = (ChildDistanceMinimum + ChildDistanceMaximum) / 2;

        // Position of first child
        var p0 = new float2(0, dist);

        // Position of second child
        var p1 = OrbitData.Evaluate(1.0f / vertices) * dist;

        // Maximum child distance is half the distance to the neighbor minus the neighbor's radius
        var p0ChildDist = (distance(p0, p1) * proportion - Settings.PlanetSafetyRadius.Evaluate(sharedMass * (1 - proportion))) * .75f;
        var p1ChildDist = (distance(p0, p1) * (1 - proportion) - Settings.PlanetSafetyRadius.Evaluate(sharedMass * proportion)) * .75f;

        for (int i = 0; i < vertices; i++)
        {
            var child = new GeneratorPlanet
            {
                Settings             = Settings,
                Parent               = this,
                Mass                 = sharedMass * (i % 2 == 0 ? proportion : 1 - proportion), // Masses alternate
                Distance             = dist,
                Phase                = (float)i / vertices,
                ChildDistanceMaximum = (i % 2 == 0 ? p0ChildDist : p1ChildDist)
            };
            child.ChildDistanceMinimum = Settings.PlanetSafetyRadius.Evaluate(child.Mass) * 2;
            //child.Period = Settings..Evaluate(child.Distance);
            Children.Add(child);
        }

        ChildDistanceMinimum = dist + p0ChildDist;
    }