Пример #1
0
        /// <summary>
        /// Returns the main color of the atmosphere
        /// </summary>
        public Color GetColor1ForAtmosphere(CelestialBody celestialBody)
        {
            System.Random random = new System.Random(celestialBody.seed);
            Color         color  = Color.white;

            CelestialType type = celestialBody.type;

            if (type is CelestialType.Moon)
            {
                type = (type as CelestialType.Moon).originalType;
            }

            if (type is CelestialType.WaterPlanet || type is CelestialType.IcePlanet)
            {
                color = Utility.GetRandomColorInRange(random, 0, 128, 70, 200, 200, 255);
            }
            else if (type is CelestialType.MoltenPlanet)
            {
                color = Utility.GetRandomColorInRange(random, 255, 255, 150, 230, 0, 90);
            }
            else if (type is CelestialType.RockPlanet)
            {
                color = (celestialBody as RockPlanet).rockColor1;
            }

            return(color);
        }
Пример #2
0
        public override string ToString()
        {
            string str = string.Format("{0}RP\t{1}\t{2}\t{3}",
                                       ResourceValue,
                                       StringExtensions.SpaceUppercaseLetters(CelestialType.ToString()),
                                       StringExtensions.SpaceUppercaseLetters(TerraformingTier.ToString()),
                                       StringExtensions.SpaceUppercaseLetters(StageOfLife.ToString()));

            if (Sentients.Count > 0)
            {
                //str += "\n\tSentients";
                str += "\n";
                foreach (var sentient in Sentients)
                {
                    str += string.Format("\t{0}\n", sentient);
                }
            }

            if (OrbitingSatellites.Count > 0)
            {
                //str += "\n\tSatellites";
                str += "\n";
                foreach (var satellite in OrbitingSatellites)
                {
                    str += string.Format("\t{0}\n", satellite);
                }
            }

            return(str);
        }
Пример #3
0
        /// <summary>
        /// Get the noise value for a point on the sphere
        /// </summary>
        public float GetNoise(Vector3 P, int LOD = 0)
        {
            P = P.normalized * frequency;
            float v    = 0;
            float mask = 1;

            int octaves = Mathf.Clamp(10 - LOD, 4, 10);

            //generate different noise depending on the planet type
            CelestialType type = (planet.type is CelestialType.Moon) ? (planet.type as CelestialType.Moon).originalType : planet.type;

            if (type is CelestialType.WaterPlanet || type is CelestialType.IcePlanet)
            {
                float v1 = tn1.GetValueFractal(P);
                mask = Mathf.Pow(Mathf.Clamp(v1 + 1, 0, 1), 10); //-1 is 0, 0 is 1
                float blend = (tn3.GetValueFractal(P * 3) + 1) / 2f;
                float amp   = blend * 0.8f + 0.2f;

                float w1 = 1;
                float w2 = 4;

                float v2 = tn2.GetValueRidged(P * 3, octaves) * amp;

                v2 = Mathf.Pow(v2, 3) * mask;

                v = Mathf.Clamp((v1 * w1 + v2 * w2) / (w1 + w2), -1, 1);
            }
            else if (type is CelestialType.RockPlanet)
            {
                float v1 = tn1.GetValueFractal(P);

                float w1 = 1;
                float w2 = 4;

                float v2 = Mathf.Clamp(tn2.GetValueRidged(P * 3, octaves) / 1.2f, -1, 1);
                v2 = Mathf.Pow(v2, 3);

                v = (v1 * w1 + v2 * w2) / (w1 + w2);
            }
            else if (type is CelestialType.MoltenPlanet)
            {
                float v2 = tn2.GetValueFractal(P * 5);
                v2 = Mathf.Clamp(1 - Mathf.Abs(v2), 0, 1);
                v2 = (v2 - 0.5f) * 0.7f;
                v  = v2;
            }


            return(1 + (v * amplitude / planet.radius) + GetCraterValue(P) * craterStrength * mask);
        }
Пример #4
0
        /// <summary>
        /// Returns the color for a point on the sphere; this color is a noise used by the gpu in the shader
        /// </summary>
        public Color GetColor(Vector3 P)
        {
            //different frequencies per type
            CelestialType type = (planet.type is CelestialType.Moon) ? (planet.type as CelestialType.Moon).originalType : planet.type;

            if (type is CelestialType.RockPlanet)
            {
                P = P.normalized * frequency * 1f;
            }
            else
            {
                P = P.normalized * frequency * 6f;
            }

            float r = (cn1.GetValueFractal(P) + 1f) / 2f;
            float g = 0;
            float b = 0;

            float rThreshold = 0.5f;
            float rPadding   = 0.02f;

            if (r < rThreshold - rPadding)
            {
                r = 0;
            }
            else if (r > rThreshold + rPadding)
            {
                r = 1;
            }
            else
            {
                float ease = r - (rThreshold - rPadding);
                r = ease * (1f / (2 * rPadding));
            }

            return(new Color(r, g, b, 1));
        }
Пример #5
0
    /* adds a satellite in orbit around an existing body */
    public void AddSatellite(CelestialType type)
    {
        /*
         * TODO:
         * 1) get larger radius of primary's furthest orbital path
         * 2) min valid orbit rad = furthestOrbit.region.upperLimit + minDist (for now)
         * 3) add satellite at some radius s.t. not overlapping with former furthest
         */

        if (!_sceneIsEditable)
        {
            return;
        }

        CelestialBody primary;

        if (!user || !user.isActiveAndEnabled)
        {
            if (debugMode && debugSelectedObject)
            {
                primary = debugSelectedObject;
            }
            else
            {
                primary = initialStar;
            }
        }
        else if ((primary = user.selectedObject.GetComponent <CelestialBody> ()) == null)
        {
            return;
        }

        float furthestRegionLimit;

        if (primary.NumSatellites <= 0)
        {
            furthestRegionLimit = primary.naturalMaxSize / 2;
        }
        else
        {
            furthestRegionLimit = primary.FurthestSatellite.Region.Max;
        }

        float     orbitRadius = furthestRegionLimit + CelestialBody.MinimumSeparatingDistance + templates[type].naturalMaxSize / 2;
        OrbitPath path        = Instantiate(orbitPathTemplate);

        Debug.Log("orbit radius is " + orbitRadius);

        /*
         * TODO: spawn satellite at path's north position
         * set satellite's path
         * add satellite to SM's list of CBs
         */

        OrbitingBody satellite = Instantiate(templates[type]);

        satellite.InitSatellite(primary, path, orbitRadius, orbitRadius);
        bodies.Add(satellite);

        primary.AddOrbitingBody(satellite);

        if (debugMode)
        {
            UpdateDisplayInfo();
        }
    }
Пример #6
0
        public DynamicPlanet(SystemController controller, GameObject gameObject, int seed, CelestialType type, CelestialBody host = null) : base(controller, gameObject, seed, type, host)
        {
            this.seed       = seed;
            this.gameObject = gameObject;
            position        = gameObject.transform.position;
            regions         = new List <Region>();
            terrain         = new TerrainNoise(this, seed);
            craters         = new List <Crater>();
            Vector3[] vertices  = null;
            int[]     triangles = null;
            Octahedron.GetVerticesAndTriangles(ref vertices, ref triangles);
            for (int i = 0; i < triangles.Length; i += 3)
            {
                int t1 = triangles[i + 0];
                int t2 = triangles[i + 1];
                int t3 = triangles[i + 2];

                Vector3 A = vertices[t1].normalized * radius;
                Vector3 B = vertices[t2].normalized * radius;
                Vector3 C = vertices[t3].normalized * radius;

                regions.Add(new Region(this, null, A, B, C, 0));
            }
        }