Example #1
0
    public void Build(OrbitalBodyDescription desc, OrbitalBody body)
    {
        this.body = body;

        Random.InitState(desc.RandomSeed);
        var period = 2 * Mathf.PI * body.OrbitRadius / body.OrbitalSpeed;

        if (maxDeltaTime > period / 10)
        {
            maxDeltaTime = (float)period / 10;
        }

        //build objects
        for (int i = 0; i < ASTEROIDS_COUNT; i++)
        {
            var ast  = Instantiate(AsteroidPrefab, this.transform);
            var info = new AsteroidInfo();
            info.Object       = ast;
            info.DeltaTime    = (Random.value * 2 - 1) * maxDeltaTime;
            info.DeltaTime2   = (3 + Random.value) * 3000;
            info.Offset       = Random.insideUnitSphere * (float)(200 * body.Radius / Constants.EARTH_RADIUS);
            info.Scale        = (0.05f + Random.value * Random.value) * 50;
            info.AddRotation  = Random.rotation;
            info.AddRotation2 = Random.insideUnitSphere * 30;
            asteroids.Add(info);

            InitShader(info.Object);
        }
    }
Example #2
0
        /// <summary>
        /// Build map for the root
        /// </summary>
        public void Build(OrbitalBodyDescription root)
        {
            const int SIZE = 1001;

            using (var img = new Bitmap(SIZE, SIZE))
                using (var gr = Graphics.FromImage(img))
                {
                    gr.SmoothingMode = SmoothingMode.HighQuality;

                    //max orbit
                    var max = root.GetMeAndChildren().Select(b => b.OrbitRadius).Max();

                    //scale
                    var scale = 0.5 * (SIZE - 5) / max;

                    //draw orbits
                    DrawOrbit(gr, scale, root);

                    //convert to png
                    using (var ms = new MemoryStream())
                    {
                        img.Save(ms, ImageFormat.Png);

                        //save to root body
                        root.Map      = ms.ToArray();
                        root.MapScale = scale;
                    }
                }
        }
Example #3
0
    public void Build(OrbitalBodyDescription desc, OrbitalBody body)
    {
        this.body = body;

        Random.InitState(desc.RandomSeed);
        var rend = GetComponent <MeshRenderer>();
        var mat  = rend.material;

        var type   = (int)(Random.value * 5);
        var height = Random.value * 4;

        if (type == 3)
        {
            height /= 10;
        }

        mat.SetFloat("_Smoothness", Random.value * Random.value * 0.7f);
        mat.SetFloat("_Frequency", 1 + Random.value * 4);
        mat.SetFloat("_WaterLevel", Random.value);
        mat.SetFloat("_RandomSeed", Random.value * 1000);
        mat.SetFloat("_HeightScale", height);
        mat.SetFloat("_Palette", Random.value * 16);
        mat.SetFloat("_WaterPalette", Random.value * 16);
        mat.SetFloat("_WaterSmoothness", 0.5f + Random.value * 0.5f);
        mat.SetFloat("_Type", type);

        if (Random.value > 0.3 || height < 0.5)
        {
            rend.materials = new Material[1] {
                mat
            }
        }
        ;
    }
}
Example #4
0
    public void Build(OrbitalBodyDescription desc, OrbitalBody body)
    {
        this.body = body;

        Random.InitState(desc.RandomSeed);
        switch (desc.SurfaceType)
        {
        case SurfaceType.RockPlanet: BuildRockPlanet(); break;

        case SurfaceType.GasPlanet: BuildGasPlanet(); break;
        }
    }
Example #5
0
        private OrbitalBodyDescription AddBody(OrbitalBodyDescription parent)
        {
            //create new body
            var newBody = new OrbitalBodyDescription {
                Name = "Planet " + DateTime.Now.Millisecond
            };

            parent.Add(newBody);
            newBody.Parent = parent;

            return(newBody);
        }
Example #6
0
    public void Build(OrbitalBodyDescription desc, OrbitalBody body)
    {
        this.body = body;
        //
        Random.InitState(desc.RandomSeed);
        var rend   = GetComponent <MeshRenderer>();
        var mat    = rend.material;
        var colors = new Color[]
        {
            //new Color(1, 0.95f, 0.37f),
            new Color(0.9622642f, 0.9327608f, 0.5492168f),
            new Color(0.365655f, 0.5355415f, 0.7830189f),
            new Color(0.8962264f, 0.3677911f, 0.3677911f),
            new Color(0.9f, 0.9f, 0.9f),
        };

        mat.color = colors[Random.Range(0, colors.Length)];
    }
Example #7
0
        public void Build(OrbitalBodyDescription desc)
        {
            this.desc = desc;

            //copy properties to controls
            updating++;

            tbName.Text                   = desc.Name;
            nudMass.Value                 = (decimal)(desc.Mass / Constants.EARTH_MASS);
            nudOrbitRadius.Value          = (decimal)(desc.OrbitRadius / Constants.AU);
            nudOrbitalSpeed.Value         = (decimal)desc.OrbitalSpeed / 1000;
            cbOrbitDirection.SelectedItem = desc.OrbitDirection;
            nudRadius.Value               = (decimal)(desc.Radius / Constants.EARTH_RADIUS);
            nudRandomSeed.Value           = desc.RandomSeed;
            cbSurfaceType.SelectedItem    = desc.SurfaceType;
            nudStartOrbitAngle.Value      = (decimal)(desc.StartOrbitAngle * 180 / Math.PI);

            updating--;
        }
Example #8
0
 private void DrawOrbit(Graphics gr, double scale, OrbitalBodyDescription parent)
 {
     if (parent.OrbitRadius > float.Epsilon &&
         parent.Mass > Constants.EARTH_MASS / 50)
     {
         //draw my orbit
         var cx = (int)(gr.VisibleClipBounds.Width / 2);
         var cy = (int)(gr.VisibleClipBounds.Height / 2);
         var r  = (int)(parent.OrbitRadius * scale);
         gr.DrawEllipse(Pens.White, cx - r, cy - r, r * 2, r * 2);
     }
     else
     {
         //draw children
         foreach (var child in parent)
         {
             DrawOrbit(gr, scale, child);
         }
     }
 }
Example #9
0
 public void Build(OrbitalBodyDescription desc, OrbitalBody body)
 {
     this.body = body;
 }
Example #10
0
    private void CreateBodyAndChildren(OrbitalBodyDescription desc, Body parent)
    {
        //create model body
        var modelBody = new OrbitalBody();

        modelBody.Name            = desc.Name;
        modelBody.Mass            = desc.Mass;
        modelBody.Radius          = desc.Radius;
        modelBody.OrbitalSpeed    = desc.OrbitalSpeed;
        modelBody.OrbitDirection  = desc.OrbitDirection;
        modelBody.OrbitRadius     = desc.OrbitRadius;
        modelBody.Parent          = parent;
        modelBody.StartOrbitAngle = desc.StartOrbitAngle;

        //add body to model
        StateBus.Model.Bodies.Add(modelBody);

        //build gameobject for body
        GameObject body = null;

        switch (desc.SurfaceType)
        {
        case SurfaceType.RockPlanet:
        {
            body = Instantiate(RockPlanetPrefab, LevelHolder.transform);
            body.GetComponent <PlanetController>().Build(desc, modelBody);
            break;
        }

        case SurfaceType.GasPlanet:
        {
            body = Instantiate(GasPlanetPrefab, LevelHolder.transform);
            body.GetComponent <PlanetController>().Build(desc, modelBody);
            break;
        }

        case SurfaceType.Star:
        {
            body = Instantiate(StarPrefab, LevelHolder.transform);
            body.GetComponent <StarController>().Build(desc, modelBody);
            break;
        }

        case SurfaceType.Ring:
        {
            body = Instantiate(RingPrefab, LevelHolder.transform);
            body.GetComponent <RingController>().Build(desc, modelBody);
            break;
        }

        case SurfaceType.AsteroidBelt:
        {
            body = Instantiate(AstBeltPrefab, LevelHolder.transform);
            body.GetComponent <AstBeltController>().Build(desc, modelBody);
            break;
        }

        case SurfaceType.Comet:
        {
            body = Instantiate(CometPrefab, LevelHolder.transform);
            body.GetComponent <CometController>().Build(desc, modelBody);
            break;
        }
        }

        //create buttons in GUI
        if (body != null)
        {
            if (desc.SurfaceType != SurfaceType.Ring)
            {
                var isSattellite = desc.Parent != null && desc.Parent.Parent != null;
                var bt           = Instantiate(PlanetButtonPrefab, PlanetPanel.transform);
                var y            = PlanetPanel.transform.childCount * 30;
                (bt.transform as RectTransform).localPosition = new Vector3(isSattellite ? 10 : 0, -y);

                bt.GetComponentInChildren <Text>().text = desc.Name;
                bt.onClick.AddListener(() =>
                {
                    StateBus.CameraTarget         = body.transform;
                    StateBus.CameraTargetBody     = modelBody;
                    StateBus.CameraTargetDesc     = desc;
                    StateBus.CameraTargetChanged += true;
                });

                if (StateBus.CameraTargetDesc != null && StateBus.CameraTargetDesc.Guid == desc.Guid)
                {
                    StateBus.CameraTarget         = body.transform;
                    StateBus.CameraTargetBody     = modelBody;
                    StateBus.CameraTargetDesc     = desc;
                    StateBus.CameraTargetChanged += true;
                }
            }
        }

        //create children
        foreach (var child in desc)
        {
            CreateBodyAndChildren(child, modelBody);
        }
    }