Пример #1
0
        void Initialize()
        {
            skybox = new Skybox("Data/Textures/Background", renderer.Device);
            StarSystem.ActiveSystem = new StarSystem(renderer.Device);

            renderer.MainCamera.FieldOfView = MathUtil.DegreesToRadians(80);
            renderer.MainCamera.AspectRatio = renderForm.ClientSize.Width / (float)renderForm.ClientSize.Width;

            player         = new Player();
            player.Camera  = renderer.MainCamera;
            player.Vehicle = new Ship(renderer.Device);
            player.Vehicle.CockpitCameraPosition = new Vector3(0, 2.6f, 7.6f);
            player.DisablePhysics = true;
            StarSystem.ActiveSystem.physics.AddBody(player);
            StarSystem.ActiveSystem.physics.AddBody(player.Vehicle);

            #region build UI
            float         h           = 35;
            float         cpanelWidth = 235;
            RawRectangleF bounds      = new RawRectangleF(0, 300, cpanelWidth, 300 + h);
            ControlPanel           = new UI.Frame(null, "Panel1", bounds, renderer.CreateBrush(new Color(.5f, .5f, .5f, .5f)));
            ControlPanel.Draggable = true;

            new UI.TextLabel(ControlPanel, "Title", new RawRectangleF(0, 0, 235, h), "NAVIGATOR", renderer.SegoeUI24, renderer.Brushes["White"]);
            float    y = h;
            Vector3d d = Vector3d.Normalize(new Vector3d(.25, .85, -.33));
            foreach (CelestialBody p in StarSystem.ActiveSystem.bodies)
            {
                new UI.TextLabel(ControlPanel, p.Name + "label", new RawRectangleF(2, y, cpanelWidth - 2, y + h - 2), p.Name, renderer.SegoeUI24, renderer.Brushes["White"]);
                y += 30;
                new UI.TextButton(ControlPanel, p.Name + "SurfaceButton", new RawRectangleF(5, y, (cpanelWidth - 10) * .333f - 1, y + h), "Surface", renderer.SegoeUI14, renderer.Brushes["Black"], renderer.Brushes["LightGray"],
                                  () => {
                    double hh = p.GetHeight(d);
                    if (p is Planet)
                    {
                        Planet planet = p as Planet;
                        if (planet.HasOcean)
                        {
                            hh = Math.Max(hh, planet.Radius + planet.TerrainHeight * planet.OceanHeight);
                        }
                    }
                    player.MoveTo(p.Position + d * (hh + 50));
                    player.Velocity = p.Velocity + p.VelocityOnPoint(player.Position - p.Position);
                    if (player.Vehicle != null)
                    {
                        player.Vehicle.Velocity = player.Velocity;
                    }
                });
                new UI.TextButton(ControlPanel, p.Name + "LowOrbitButton", new RawRectangleF((cpanelWidth - 10) * .333f + 1, y, (cpanelWidth - 10) * .666f - 1, y + h), "Low Orbit", renderer.SegoeUI14, renderer.Brushes["Black"], renderer.Brushes["LightGray"],
                                  () => {
                    player.MoveTo(p.Position + d * (p.Radius + (p.SOI - p.Radius) * .2));
                    player.Velocity = p.Velocity;
                    if (player.Vehicle != null)
                    {
                        player.Vehicle.Velocity = p.Velocity;
                    }
                });
                new UI.TextButton(ControlPanel, p.Name + "HighOrbitButton", new RawRectangleF((cpanelWidth - 10) * .666f + 1, y, cpanelWidth - 2, y + h), "High Orbit", renderer.SegoeUI14, renderer.Brushes["Black"], renderer.Brushes["LightGray"],
                                  () => {
                    player.MoveTo(p.Position + d * (p.Radius + (p.SOI - p.Radius) * .8));
                    player.Velocity = p.Velocity;
                    if (player.Vehicle != null)
                    {
                        player.Vehicle.Velocity = p.Velocity;
                    }
                });
                y += h + 2;
            }
            bounds.Bottom = bounds.Top + y;

            ControlPanel.LocalBounds = bounds;
            #endregion

            (ControlPanel["EarthSurfaceButton"] as UI.TextButton).Click();
        }
Пример #2
0
        public void DrawHUD(Renderer renderer)
        {
            // time warp rect
            renderer.D2DContext.FillRectangle(
                new RawRectangleF(0, 0, 100, 40),
                renderer.Brushes["White"]);
            // time warp
            renderer.D2DContext.DrawText("x" + TimeWarp.ToString("N0"), renderer.SegoeUI24,
                                         new RawRectangleF(10, 0, 100, 40),
                                         renderer.Brushes["Black"]);

            // center rect
            float xmid = renderer.ResolutionX * .5f;

            renderer.D2DContext.FillRectangle(
                new RawRectangleF(xmid - 150, 0, xmid + 150, 50),
                renderer.Brushes["White"]);

            renderer.SegoeUI24.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;
            renderer.SegoeUI14.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;

            // get nearest body/star
            CelestialBody cb  = StarSystem.ActiveSystem.GetCurrentSOI(player.Position);
            Vector3d      dir = cb.Position - player.Position;
            double        h   = dir.Length();

            dir /= h;
            if (h > cb.SOI)
            {
                cb = StarSystem.ActiveSystem.GetStar();
            }

            Vector3d relative = cb.Velocity;
            string   vlbl     = "Orbit";

            double r             = cb.Radius;
            double radarAltitude = h - cb.GetHeight(dir);

            if (radarAltitude < 10000)
            {
                vlbl     = "Surface";
                relative = cb.VelocityOnPoint(player.Position - cb.Position) + cb.Velocity;
            }

            if (cb is Planet)
            {
                Planet p = cb as Planet;
                r = p.Radius + p.OceanHeight * p.TerrainHeight;

                #region surface info
                double temp  = p.GetTemperature(dir);
                double humid = p.GetHumidity(dir) * 100;

                renderer.D2DContext.FillRectangle(
                    new RawRectangleF(xmid + 155, 0, xmid + 260, 80),
                    renderer.Brushes["White"]);

                renderer.D2DContext.DrawText("Surface: ", renderer.SegoeUI14,
                                             new RawRectangleF(xmid + 155, 3, xmid + 240, 10),
                                             renderer.Brushes["Black"]);

                renderer.D2DContext.DrawText(temp.ToString("F1") + "°C", renderer.SegoeUI14,
                                             new RawRectangleF(xmid + 165, 15, xmid + 240, 30),
                                             renderer.Brushes["Black"]);

                renderer.D2DContext.DrawText(humid.ToString("F1") + "%", renderer.SegoeUI14,
                                             new RawRectangleF(xmid + 165, 30, xmid + 240, 45),
                                             renderer.Brushes["Black"]);
                #endregion
                #region atmosphere info
                Atmosphere a = p.Atmosphere;
                if (a != null && h < a.Radius * 1.5)
                {
                    double atemp;
                    double pressure;
                    double density;
                    double c;
                    a.MeasureProperties(dir, h, out pressure, out density, out atemp, out c);
                    if (pressure > .1)
                    {
                        renderer.D2DContext.FillRectangle(
                            new RawRectangleF(xmid - 260, 0, xmid - 155, 80),
                            renderer.Brushes["White"]);

                        renderer.D2DContext.DrawText("Atmosphere: ", renderer.SegoeUI14,
                                                     new RawRectangleF(xmid - 250, 3, xmid - 155, 10),
                                                     renderer.Brushes["Black"]);

                        renderer.D2DContext.DrawText(atemp.ToString("F1") + "°C", renderer.SegoeUI14,
                                                     new RawRectangleF(xmid - 240, 15, xmid - 155, 30),
                                                     renderer.Brushes["Black"]);

                        renderer.D2DContext.DrawText(pressure.ToString("F1") + " kPa", renderer.SegoeUI14,
                                                     new RawRectangleF(xmid - 240, 30, xmid - 155, 45),
                                                     renderer.Brushes["Black"]);

                        renderer.D2DContext.DrawText(density.ToString("F1") + " kg/m^3", renderer.SegoeUI14,
                                                     new RawRectangleF(xmid - 240, 45, xmid - 155, 60),
                                                     renderer.Brushes["Black"]);

                        renderer.D2DContext.DrawText("Mach " + (player.Velocity.Length() / c).ToString("F2"), renderer.SegoeUI14,
                                                     new RawRectangleF(xmid - 240, 60, xmid - 155, 75),
                                                     renderer.Brushes["Black"]);
                    }
                }
                #endregion
            }

            // altitude
            renderer.D2DContext.DrawText(Physics.FormatDistance(h - r), renderer.SegoeUI24,
                                         new RawRectangleF(xmid, 0, xmid + 150, 40),
                                         renderer.Brushes["Black"]);
            // body label
            renderer.D2DContext.DrawText(cb.Name, renderer.SegoeUI14,
                                         new RawRectangleF(xmid, 30, xmid + 150, 50),
                                         renderer.Brushes["Black"]);

            Orbit o = new Orbit(player.Position - cb.Position, player.Velocity - cb.Velocity, cb);

            renderer.SegoeUI14.ParagraphAlignment = SharpDX.DirectWrite.ParagraphAlignment.Far;
            renderer.SegoeUI14.TextAlignment      = SharpDX.DirectWrite.TextAlignment.Leading;
            renderer.D2DContext.DrawText(o.ToString(), renderer.SegoeUI14,
                                         new RawRectangleF(renderer.ResolutionX * .5f, renderer.ResolutionY, renderer.ResolutionX * .5f, renderer.ResolutionY),
                                         renderer.Brushes["White"]);

            // TODO: fix keplerian orbits
            //List<Vector3d> pts = new List<Vector3d>();
            //Vector3d op, ov;
            //for (double t = 0; t < o.T; t += o.T * .05) {
            //    o.ToCartesian(cb, t, out op, out ov);
            //    pts.Add(cb.Position + op);
            //}
            //o.ToCartesian(cb, o.T, out op, out ov);
            //pts.Add(cb.Position + op);
            //Debug.DrawLine(Color.CornflowerBlue, pts.ToArray());
            //
            //foreach (Vector3d p in pts) {
            //    Vector3d pos;
            //    double scale;
            //    renderer.Camera.GetScaledSpace(p + cb.Position, out pos, out scale);
            //    Debug.DrawBox(Color.Green, new OrientedBoundingBox(pos - (Vector3d)Vector3.One * 10000 * scale, pos + (Vector3d)Vector3.One * 10000 * scale));
            //}

            // velocity
            renderer.D2DContext.DrawText(Physics.FormatSpeed((player.Velocity - relative).Length()), renderer.SegoeUI24,
                                         new RawRectangleF(xmid - 130, 0, xmid, 40),
                                         renderer.Brushes["Black"]);
            renderer.D2DContext.DrawText(vlbl, renderer.SegoeUI14,
                                         new RawRectangleF(xmid - 130, 35, xmid, 50),
                                         renderer.Brushes["Black"]);
        }
Пример #3
0
        public StarSystem(D3D11.Device device)
        {
            bodies  = new List <CelestialBody>();
            physics = new Physics();

            Star sun = new Star("Sol", new Vector3d(), 696000000, 1.989e30);

            sun.SetColormap("Data/Textures/Sun.dds", device);
            bodies.Add(sun);

            //Planet mercury = new Planet("Mercury", new Vector3d(0, 0, 57910000000), 2440000, 3.285e23, 10000);
            //mercury.SetColormap("Data/Textures/Mercury.dds", device);
            //bodies.Add(mercury);

            //Planet venus = new Planet("Venus",new Vector3d(0, 0, 108200000000), 6500000, 4.867e24, 40000);
            //venus.SetColormap("Data/Textures/Venus.dds", device);
            //bodies.Add(venus);

            Planet earth = new Planet(
                "Earth",
                new Vector3d(0, 0, 149600000000),
                6371000,
                5.972e24,
                20000,
                new Atmosphere(6371000 + 80000)
            {
                SurfacePressure = 6,     //kPa
                SurfaceDensity  = 1.2,   // kg/m^3
            })
            {
                HasOcean           = true,
                HasTrees           = true,
                SurfaceTemperature = 17,
                TemperatureRange   = 35
            };

            earth.Velocity = new Vector3d(30000, 0, 0);
            earth.SetColormap("Data/Textures/Earth.dds", device);
            earth.Rotation          = Matrix.RotationX(MathUtil.DegreesToRadians(23.5f));
            earth.AngularVelocity.Y = 2 * Math.PI / (24 * 60 * 60);
            bodies.Add(earth);

            Planet moon = new Planet(
                "Moon",
                earth.Position + new Vector3d(0, 0, 362570000),
                1737000,
                7.34767309e22,
                20000)
            {
                HasOcean           = false,
                HasTrees           = false,
                SurfaceTemperature = 0,
                TemperatureRange   = 15
            };

            moon.Velocity = earth.Velocity + new Vector3d(1022, 0, 0);
            moon.SetColormap("Data/Textures/moon.dds", device);
            moon.AngularVelocity.Y = 2 * Math.PI / (27 * 24 * 60 * 60);
            bodies.Add(moon);

            //Planet mars = new Planet("Mars", new Vector3d(0, 0, 227940000000), 3397000, 6.39e23, 10000,
            //    new Atmosphere(3397000 + 10000) {
            //        SurfacePressure = 100, //kPa
            //        SurfaceDensity = 1.2, // kg/m^3
            //    }) {
            //        SurfaceTemperature = -55,
            //        TemperatureRange = 65
            //    };
            //mars.SetColormap("Data/Textures/Mars.dds", device);
            //bodies.Add(mars);

            //// Gas giants
            //Planet jupiter = new Planet("Jupiter", new Vector3d(0, 0, 778330000000), 71400000, 1.898e27, 0, null);
            //jupiter.SetColormap("Data/Textures/Mars.dds", device);
            //bodies.Add(jupiter);

            //Planet saturn = new Planet("Saturn", new Vector3d(0, 0, 1424600000000), 60330000, 5.683e26, 0);
            //saturn.SetColormap("Data/Textures/Mars.dds", device);
            //bodies.Add(saturn);

            //Planet uranus = new Planet("Uranus", new Vector3d(0, 0, 2873550000000), 25900000, 8.681e25, 0);
            //uranus.SetColormap("Data/Textures/Mars.dds", device);
            //bodies.Add(uranus);

            //Planet neptune = new Planet("Neptune", new Vector3d(0, 0, 4501000000000), 24750000, 1.024e26, 0);
            //neptune.SetColormap("Data/Textures/Mars.dds", device);
            //bodies.Add(neptune);

            //Planet pluto = new Planet("Pluto", new Vector3d(0, 0, 5945900000000), 1650000, 1.309e22, 100);
            //pluto.SetColormap("Data/Textures/Mars.dds", device);
            //bodies.Add(pluto);

            foreach (CelestialBody b in bodies)
            {
                physics.AddBody(b);
            }
        }