Beispiel #1
0
        protected override void RenderShip(Graphics graphics, Camera camera, RectangleF screenBounds)
        {
            foreach (Skid skid in _skids)
            {
                if (skid.IsDeploying() || skid.IsDeployed())
                {
                    skid.RenderGdi(graphics, camera);
                }
            }

            double drawingRotation = Pitch + Math.PI * 0.5;

            var offset = new PointF(screenBounds.X + screenBounds.Width * 0.5f,
                                    screenBounds.Y + screenBounds.Height * 0.5f);

            graphics.TranslateTransform(offset.X, offset.Y);

            float pitchAngle  = (float)(drawingRotation * 180 / Math.PI);
            float rollFactor  = (float)Math.Cos(Roll);
            float alphaAngle  = (float)(GetAlpha() * 180 / Math.PI);
            float rotateAngle = (pitchAngle - alphaAngle) + alphaAngle * rollFactor;

            if (this.MissionName.Contains("EDL") || this.MissionName.Contains("Aerocapture") || this.MissionName.Contains("Direct"))
            {
                graphics.RotateTransform(rotateAngle);
            }
            else
            {
                graphics.RotateTransform(pitchAngle);
            }

            graphics.TranslateTransform(-offset.X, -offset.Y);

            // Normalize the angle to [0,360]
            int rollAngle = (int)(Roll * MathHelper.RadiansToDegrees) % 360;

            int heatingRate = Math.Min((int)this.HeatingRate, 2000000);

            if (heatingRate > 100000)
            {
                Random     rnd        = new Random();
                float      noise      = (float)rnd.NextDouble();
                float      width      = screenBounds.Width / (3 + noise);
                float      height     = screenBounds.Height / (18 + noise);
                RectangleF plasmaRect = screenBounds;
                plasmaRect.Inflate(new SizeF(width, height));

                int   alpha = Math.Min(heatingRate / 7800, 255);
                int   red   = alpha;
                int   green = Math.Max(red - 128, 0) * 2;
                int   blue  = 0;
                Color glow  = Color.FromArgb(alpha, red, green, blue);

                float penWidth = width / 12;
                Pen   glowPen  = new Pen(glow, penWidth);
                glowPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
                glowPen.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
                graphics.DrawArc(glowPen, plasmaRect, 220, 100);

                glowPen.Color = Color.FromArgb((int)(alpha * 0.75), glow);
                plasmaRect.Inflate(-penWidth, -penWidth);
                graphics.DrawArc(glowPen, plasmaRect, 200, 140);

                glowPen.Color = Color.FromArgb((int)(alpha * 0.5), glow);
                plasmaRect.Inflate(-penWidth, -penWidth);
                graphics.DrawArc(glowPen, plasmaRect, 180, 180);

                glowPen.Color = Color.FromArgb((int)(alpha * 0.25), glow);
                plasmaRect.Inflate(-penWidth, -penWidth);
                graphics.DrawArc(glowPen, plasmaRect, 160, 220);
            }

            // Index into the sprite
            int ships       = _spriteSheet.Cols * _spriteSheet.Rows;
            int spriteIndex = (rollAngle * ships) / 360;

            while (spriteIndex < 0)
            {
                spriteIndex += ships;
            }

            _spriteSheet.Draw(spriteIndex, graphics, screenBounds);

            graphics.ResetTransform();

            if (_drogueChute.IsDeploying() || _drogueChute.IsDeployed())
            {
                _drogueChute.RenderGdi(graphics, camera);
            }

            if (_parachute.IsDeploying() || _parachute.IsDeployed())
            {
                _parachute.RenderGdi(graphics, camera);
            }

            if (Settings.Default.WriteCsv && (DateTime.Now - timestamp > TimeSpan.FromSeconds(1)))
            {
                string filename = MissionName + ".csv";

                if (!File.Exists(filename))
                {
                    File.AppendAllText(filename, "Velocity, Acceleration, Altitude, Alpha\r\n");
                }

                timestamp = DateTime.Now;

                string contents = string.Format("{0}, {1}, {2}, {3}\r\n",
                                                this.GetRelativeVelocity().Length(),
                                                this.GetRelativeAcceleration().Length() * 100,
                                                this.GetRelativeAltitude() / 10,
                                                this.GetAlpha() * 10);
                File.AppendAllText(filename, contents);
            }
        }
Beispiel #2
0
        protected override void RenderShip(Graphics graphics, Camera camera, RectangleF screenBounds)
        {
            double drawingRotation = Pitch + Math.PI * 0.5;

            var offset = new PointF(screenBounds.X + screenBounds.Width * 0.5f,
                                    screenBounds.Y + screenBounds.Height * 0.5f);

            camera.ApplyScreenRotation(graphics);
            camera.ApplyRotationMatrix(graphics, offset, drawingRotation);

            // Normalize the angle to [0,360]
            int rollAngle = (int)(Roll * MathHelper.RadiansToDegrees) % 360;

            int heatingRate = Math.Min((int)this.HeatingRate, 600000);

            if (heatingRate > 100000)
            {
                Random     rnd        = new Random();
                float      noise      = (float)rnd.NextDouble();
                float      width      = screenBounds.Width / (3 + noise);
                float      height     = screenBounds.Height / (18 + noise);
                RectangleF plasmaRect = screenBounds;
                plasmaRect.Inflate(new SizeF(width, height));

                if (Roll != 0)
                {
                    float foreshortening = (float)Math.Pow(Math.Cos(Roll), 0.4);
                    plasmaRect.Y      += plasmaRect.Height * (1 - foreshortening);
                    plasmaRect.Height *= foreshortening;
                }

                int   alpha = 255;
                int   blue  = Math.Min(heatingRate / 2000, 255);
                int   green = 0;
                int   red   = Math.Max(blue - 64, 0);
                Color glow  = Color.FromArgb(alpha, red, green, blue);

                float penWidth = width / 12;
                Pen   glowPen  = new Pen(glow, penWidth);
                glowPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
                glowPen.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
                graphics.DrawArc(glowPen, plasmaRect, 220, 100);

                glowPen.Color = Color.FromArgb((int)(alpha * 0.75), glow);
                plasmaRect.Inflate(-penWidth, -penWidth);
                graphics.DrawArc(glowPen, plasmaRect, 200, 140);

                glowPen.Color = Color.FromArgb((int)(alpha * 0.5), glow);
                plasmaRect.Inflate(-penWidth, -penWidth);
                graphics.DrawArc(glowPen, plasmaRect, 180, 180);

                glowPen.Color = Color.FromArgb((int)(alpha * 0.25), glow);
                plasmaRect.Inflate(-penWidth, -penWidth);
                graphics.DrawArc(glowPen, plasmaRect, 160, 220);
            }

            graphics.DrawImage(this.Texture, screenBounds.X, screenBounds.Y, screenBounds.Width, screenBounds.Height);

            // Index into the sprite
            //int ships = _spriteSheet.Cols * _spriteSheet.Rows;
            //int spriteIndex = (rollAngle * ships) / 360;
            //while (spriteIndex < 0)
            //    spriteIndex += ships;

            //_spriteSheet.Draw(spriteIndex, graphics, screenBounds);

            graphics.ResetTransform();

            if (_parachute.IsDeploying() || _parachute.IsDeployed())
            {
                _parachute.RenderGdi(graphics, camera);
            }
            else
            {
                if (_drogueChute.IsDeploying() || _drogueChute.IsDeployed())
                {
                    _drogueChute.RenderGdi(graphics, camera);
                }
            }

            if (_las != null)
            {
                _las.RenderGdi(graphics, camera);
            }

            if (Settings.Default.WriteCsv && (DateTime.Now - timestamp > TimeSpan.FromSeconds(1)))
            {
                string filename = MissionName + ".csv";

                if (!File.Exists(filename))
                {
                    File.AppendAllText(filename, "Velocity, Acceleration, Altitude, Throttle, Pressure, Heating\r\n");
                }

                timestamp = DateTime.Now;

                double targetVelocity  = this.GetRelativeVelocity().Length();
                double density         = this.GravitationalParent.GetAtmosphericDensity(this.GetRelativeAltitude());
                double dynamicPressure = 0.5 * density * targetVelocity * targetVelocity;

                string contents = string.Format("{0}, {1}, {2}, {3}, {4}, {5}\r\n",
                                                targetVelocity,
                                                this.GetRelativeAcceleration().Length() * 100,
                                                this.GetRelativeAltitude() / 100,
                                                this.Throttle * 10,
                                                dynamicPressure / 10,
                                                this.HeatingRate / 10);

                File.AppendAllText(filename, contents);
            }
        }