예제 #1
0
        public void MeasureProperties(Vector3d dir, double height, out double pressure, out double density, out double temperature, out double c)
        {
            double x = Math.Min(Math.Max((height - Planet.Radius) / (Radius - Planet.Radius), 0), 1.5); // height as [0, 1.5]

            double exp = Math.Exp(-4.0 * x);

            pressure = SurfacePressure * exp;
            density  = SurfaceDensity * exp;

            double temp = Planet.GetTemperature(dir);

            temperature = temp * (-10 * (x - .0714) * (x - .4714) * (x - .6857) + .7692);

            c = 331.3 + (.6 * temperature);
        }
예제 #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"]);
        }