コード例 #1
0
ファイル: Program.cs プロジェクト: nlhans/TelemetryVideo
 private static TrackThumbnail CreateTrackThumbnail(string sTrack, TelemetryInfo data, string file)
 {
     TrackThumbnail t = new TrackThumbnail();
     var track =
         new SimTelemetry.Game.Rfactor.Garage.rFactorTrack(sTrack);
     track.Scan();
     track.ScanRoute();
     t.Create(file, "Spa Franchorchamps", "", track.Route, data.TrackMapSize.Width, data.TrackMapSize.Height);
     return t;
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: nlhans/TelemetryVideo
        static void Main(string[] args)
        {
            rFactorReplayFile replay = new rFactorReplayFile(@"C:\Users\Hans\Documents\Monte Carlo  1988 Williams_2.Vcr\Monte Carlo  1988 Williams_2.Vcr");
            replay.Read();
            return;
            /******* SPA ********/
            /*TelemetryInfo telemetryData = new TelemetryInfo
                                              {
                                                  FinalTime1 = "01:44.368",
                                                  Circuit = @"C:\Program Files (x86)\rFactor\GameData\Locations\F108_Spa\F108_Spa.gdb",
                                                  DataFile1 = @"..\..\..\Telemetry\Spa 1.44.368.gz",
                                                  PicturesInput = @"H:\Input",
                                                  PicturesOutput = @"H:\Output",

                TrackMapSize = new Size(525, 525),

                NewTrackFormat = false,

                                                  FramesFade = 10,
                                                  FramesOffset = 92,
                                                  FramesTotal = 3261,

                                                  SplitScreen = true,
                                                  PointGauge1 = new Point(150, 310),
                                                  PointTrack = new Point(1450, 300)
                                              };*/

            /******* F1 Monaco 1991 vs 2010 ******/
            TelemetryInfo telemetryData = new TelemetryInfo
            {
                Title = "F1 1991 vs F1 2010",

                FinalTime1 = "01:24.021",
                FinalTime2 = "01:15.130",
                Circuit = @"C:\Program Files (x86)\rFactor\GameData\Locations\F1_1988_C4\03_MonteCarlo\MonteCarlo_1988_C4.gdb",
                Circuit2 = @"C:\Program Files (x86)\rFactor\GameData\Locations\F1WCP\2009\Monaco\MonteCarlo2009\MonteCarlo2009.gdb",
                DataFile1 = @"..\..\..\Telemetry\F1 1991 Monaco.gz",
                DataFile2 = @"..\..\..\Telemetry\F1 2010 Monaco.gz",
                PicturesInput = @"H:\Input",
                PicturesOutput = @"G:\Output",

                FramesFade = 10,
                FramesOffset = 94,
                FramesTotal = 2657,

                TimeOffsetA = 3.15,
                TimeOffsetB = 0,

                LapTimeA = 84.021 * 1000,
                LapTimeB = 75.13 * 1000,

                RepeatDriverA = true,
                RepeatDriverB = true,

                NewTrackFormat = true,

                TrackMapSize = new Size(400, 400),

                SplitScreen = true,
                PointGauge1 = new Point(50, 700),
                PointGauge2 = new Point(1010, 700),

                PointAnnotation1 = new Point(50, 1010),
                PointAnnotation2 = new Point(1010, 1010),

                PointTrack = new Point(760, 500),
                PointTitle = new Point(510, 10),

                AnnotationLeft = "Williams F1 1991 -- Nigel Mansell",
                AnnotationRight = "Williams F1 2010 -- Rubens Barichello",

                RPM_Max1 = 14000,
                RPM_Max2 = 17500,

                RPM_Redline1 = 12000,
                RPM_Redline2 = 16000
            };

            var TrackThumbnail2 = CreateTrackThumbnail(telemetryData.Circuit2, telemetryData, "circuit2.png");
            var TrackThumbnail = CreateTrackThumbnail(telemetryData.Circuit, telemetryData, "circuit.png");
            var imgTrack = Image.FromFile("circuit.png");

            var read1 = new TelemetryLogReader(telemetryData.DataFile1);
            read1.ReadPolling();
            var read2 = read1;
            if (telemetryData.SplitScreen)
            {
                read2 = new TelemetryLogReader(telemetryData.DataFile2);
                read2.ReadPolling();
            }

            var files = Directory.GetFiles(telemetryData.PicturesInput, "*.png");

            var fadeStart = telemetryData.FramesOffset;
            var fadeLength = telemetryData.FramesFade;
            var fadeEnd = telemetryData.FramesTotal - telemetryData.FramesFade;

            for (int frameNumber = 720; frameNumber < files.Length; frameNumber += 10)
            {
                var frame = files[frameNumber];
                var file = telemetryData.PicturesOutput + "\\img-" + frameNumber.ToString("0000") + ".png";
                var time = (frameNumber - telemetryData.FramesOffset) * 1000.0 / 30.0;

                double alpha = 1.0 * (frameNumber - telemetryData.FramesOffset) / telemetryData.FramesFade;
                if (frameNumber >= fadeEnd) alpha = 1 - 1.0 * (frameNumber - fadeEnd) / telemetryData.FramesFade;
                if (alpha > 1) alpha = 1;

                if (frameNumber >= fadeEnd + fadeLength || frameNumber < fadeStart)
                {
                    using (var imIn = Image.FromFile(frame))
                    using (var imOut = new Bitmap(1920, 1080))
                    {
                        Graphics g = Graphics.FromImage(imOut);
                        GraphicsFast(g);
                        g.FillRectangle(Brushes.Black, 0, 0, 1920, 1080);
                        g.DrawImage(imIn, (1920 - imIn.Width) / 2, (1080 - imIn.Height) / 2);
                        GraphicsSlow(g);
                        if (telemetryData.SplitScreen)
                        {
                            if (frameNumber >= fadeEnd + fadeLength)
                                g.DrawString(telemetryData.FinalTime2, new Font("Tahoma", 48), Brushes.White,
                                         telemetryData.PointGauge2.X + 50, telemetryData.PointGauge2.Y + 450);

                            g.DrawString(telemetryData.AnnotationLeft, new Font("Tahoma", 30), Brushes.White, telemetryData.PointAnnotation1);
                            g.DrawString(telemetryData.AnnotationRight, new Font("Tahoma", 30), Brushes.White, telemetryData.PointAnnotation2);
                        }

                        if (frameNumber >= fadeEnd + fadeLength)
                            g.DrawString(telemetryData.FinalTime1, new Font("Tahoma", 48), Brushes.White,
                                         telemetryData.PointGauge1.X + 50, telemetryData.PointGauge1.Y + 450);

                        g.DrawString(telemetryData.Title, new Font("Tahoma", 72), Brushes.White, telemetryData.PointTitle);

                        imOut.Save(file);
                    }
                    continue;
                }
                var timeA = time - telemetryData.TimeOffsetA * 1000;
                var timeB = time - telemetryData.TimeOffsetB * 1000;
                var sample1 = 1.0;
                var sample2 = 1.0;

                if (telemetryData.RepeatDriverA)
                {
                    sample1 = read1.Samples
                        .Where(x =>
                                   {
                                       if (timeA <= 0)
                                           return x.Value.Time <=
                                                  (timeA + telemetryData.LapTimeA);
                                       else
                                           return x.Value.Time <= timeA;
                                   })
                        .OrderBy(x => -1 * x.Value.Time)
                        .FirstOrDefault().Key;
                }
                else
                {
                    sample1 = read1.Samples
                        .Where(x => x.Value.Time <= timeA)
                        .OrderBy(x => -1 * x.Value.Time)
                        .FirstOrDefault().Key;

                }

                sample2 = sample1;

                if (telemetryData.SplitScreen)
                {

                    if (telemetryData.RepeatDriverB)
                    {
                        sample2 = read2.Samples
                            .Where(x =>
                            {
                                if (timeB <= 0)
                                    return x.Value.Time <=
                                           (timeB + telemetryData.LapTimeB);
                                else
                                    return x.Value.Time <= timeB;
                            })
                            .OrderBy(x => -1 * x.Value.Time)
                            .FirstOrDefault().Key;
                    }
                    else
                    {
                        sample2 = read2.Samples
                            .Where(x => x.Value.Time <= timeB)
                            .OrderBy(x => -1 * x.Value.Time)
                            .FirstOrDefault().Key;

                    }
                }

                using (var imIn = Image.FromFile(frame))
                using (var imOut = new Bitmap(1920, 1080))
                {
                    Graphics g = Graphics.FromImage(imOut);
                    GraphicsFast(g);

                    g.FillRectangle(Brushes.Black, 0, 0, 1920, 1080);
                    g.DrawImage(imIn, (1920 - imIn.Width) / 2, (1080 - imIn.Height) / 2);

                    /******* TRACK ******/
                    GraphicsSlow(g);
                    g.DrawImage(imgTrack, telemetryData.PointTrack.X, telemetryData.PointTrack.Y);

                    double xA = 0, yA = 0;
                    double xB = 0, yB = 0;
                    if (sample1 != 0)
                    {

                        var DriverBrushA = GetBrush(alpha, 255, 100, 255, 0);
                        try
                        {
                            xA = read1.GetDouble(sample1, "Driver.CoordinateX");
                            if (telemetryData.NewTrackFormat)
                                yA = read1.GetDouble(sample1, "Driver.CoordinateY");
                            else
                                yA = read1.GetDouble(sample1, "Driver.CoordinateZ");

                            var pxA = telemetryData.PointTrack.X + TrackThumbnail.GetX(xA);
                            var pyA = telemetryData.PointTrack.Y + TrackThumbnail.GetY(yA);

                            g.FillEllipse(DriverBrushA, pxA - 6, pyA - 6, 13, 13);
                        }
                        catch (Exception)
                        {

                        }
                    }

                    if (sample2 != 0 && telemetryData.SplitScreen)
                    {
                        try
                        {
                            var DriverBrushB = GetBrush(alpha, 255, 255, 100, 0);

                            xB = read2.GetDouble(sample2, "Driver.CoordinateX");
                            if (telemetryData.NewTrackFormat)
                                yB = read2.GetDouble(sample2, "Driver.CoordinateZ");
                            else
                                yB = read2.GetDouble(sample2, "Driver.CoordinateZ");

                            var pxB = telemetryData.PointTrack.X + TrackThumbnail2.GetX(xB);
                            var pyB = telemetryData.PointTrack.Y + TrackThumbnail2.GetY(yB);

                            g.FillEllipse(DriverBrushB, pxB - 6, pyB - 6, 13, 13);
                        }
                        catch (Exception)
                        {

                        }
                    }

                    if (telemetryData.SplitScreen)
                    {
                        var BrushBackground = GetBrush(alpha, 150, 0, 0, 0);

                        g.FillRectangle(BrushBackground, 0, 844, 1920, 80);

                        DrawSlimGauges(read1, alpha, frameNumber, telemetryData.PointGauge1, sample1, time, telemetryData.LapTimeA, g, telemetryData.RPM_Max1, telemetryData.RPM_Redline1);
                        DrawSlimGauges(read2, alpha, frameNumber, telemetryData.PointGauge2, sample2, time, telemetryData.LapTimeB, g, telemetryData.RPM_Max2, telemetryData.RPM_Redline2);
                        g.DrawString(telemetryData.AnnotationLeft, new Font("Tahoma", 30), Brushes.White, telemetryData.PointAnnotation1);
                        g.DrawString(telemetryData.AnnotationRight, new Font("Tahoma", 30), Brushes.White, telemetryData.PointAnnotation2);
                    }
                    else
                    {
                        DrawGauges(read1, alpha, frameNumber, telemetryData.PointGauge1, sample1, g, imgTrack,
                                   TrackThumbnail);
                    }
                    g.DrawString(telemetryData.Title, new Font("Tahoma", 72), Brushes.White, telemetryData.PointTitle);
                    imOut.Save(file);
                }
                Console.WriteLine(("frame " + frameNumber));
            }

            //Console.ReadLine();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: llenroc/TelemetryVideo
        static void Main(string[] args)
        {
            rFactorReplayFile replay = new rFactorReplayFile(@"C:\Users\Hans\Documents\Monte Carlo  1988 Williams_2.Vcr\Monte Carlo  1988 Williams_2.Vcr");

            replay.Read();
            return;

            /******* SPA ********/

            /*TelemetryInfo telemetryData = new TelemetryInfo
             *                                {
             *                                    FinalTime1 = "01:44.368",
             *                                    Circuit = @"C:\Program Files (x86)\rFactor\GameData\Locations\F108_Spa\F108_Spa.gdb",
             *                                    DataFile1 = @"..\..\..\Telemetry\Spa 1.44.368.gz",
             *                                    PicturesInput = @"H:\Input",
             *                                    PicturesOutput = @"H:\Output",
             *
             *
             *  TrackMapSize = new Size(525, 525),
             *
             *  NewTrackFormat = false,
             *
             *                                    FramesFade = 10,
             *                                    FramesOffset = 92,
             *                                    FramesTotal = 3261,
             *
             *                                    SplitScreen = true,
             *                                    PointGauge1 = new Point(150, 310),
             *                                    PointTrack = new Point(1450, 300)
             *                                };*/

            /******* F1 Monaco 1991 vs 2010 ******/
            TelemetryInfo telemetryData = new TelemetryInfo
            {
                Title = "F1 1991 vs F1 2010",

                FinalTime1     = "01:24.021",
                FinalTime2     = "01:15.130",
                Circuit        = @"C:\Program Files (x86)\rFactor\GameData\Locations\F1_1988_C4\03_MonteCarlo\MonteCarlo_1988_C4.gdb",
                Circuit2       = @"C:\Program Files (x86)\rFactor\GameData\Locations\F1WCP\2009\Monaco\MonteCarlo2009\MonteCarlo2009.gdb",
                DataFile1      = @"..\..\..\Telemetry\F1 1991 Monaco.gz",
                DataFile2      = @"..\..\..\Telemetry\F1 2010 Monaco.gz",
                PicturesInput  = @"H:\Input",
                PicturesOutput = @"G:\Output",

                FramesFade   = 10,
                FramesOffset = 94,
                FramesTotal  = 2657,

                TimeOffsetA = 3.15,
                TimeOffsetB = 0,

                LapTimeA = 84.021 * 1000,
                LapTimeB = 75.13 * 1000,

                RepeatDriverA = true,
                RepeatDriverB = true,

                NewTrackFormat = true,

                TrackMapSize = new Size(400, 400),

                SplitScreen = true,
                PointGauge1 = new Point(50, 700),
                PointGauge2 = new Point(1010, 700),

                PointAnnotation1 = new Point(50, 1010),
                PointAnnotation2 = new Point(1010, 1010),

                PointTrack = new Point(760, 500),
                PointTitle = new Point(510, 10),

                AnnotationLeft  = "Williams F1 1991 -- Nigel Mansell",
                AnnotationRight = "Williams F1 2010 -- Rubens Barichello",

                RPM_Max1 = 14000,
                RPM_Max2 = 17500,

                RPM_Redline1 = 12000,
                RPM_Redline2 = 16000
            };

            var TrackThumbnail2 = CreateTrackThumbnail(telemetryData.Circuit2, telemetryData, "circuit2.png");
            var TrackThumbnail  = CreateTrackThumbnail(telemetryData.Circuit, telemetryData, "circuit.png");
            var imgTrack        = Image.FromFile("circuit.png");

            var read1 = new TelemetryLogReader(telemetryData.DataFile1);

            read1.ReadPolling();
            var read2 = read1;

            if (telemetryData.SplitScreen)
            {
                read2 = new TelemetryLogReader(telemetryData.DataFile2);
                read2.ReadPolling();
            }

            var files = Directory.GetFiles(telemetryData.PicturesInput, "*.png");

            var fadeStart  = telemetryData.FramesOffset;
            var fadeLength = telemetryData.FramesFade;
            var fadeEnd    = telemetryData.FramesTotal - telemetryData.FramesFade;

            for (int frameNumber = 720; frameNumber < files.Length; frameNumber += 10)
            {
                var frame = files[frameNumber];
                var file  = telemetryData.PicturesOutput + "\\img-" + frameNumber.ToString("0000") + ".png";
                var time  = (frameNumber - telemetryData.FramesOffset) * 1000.0 / 30.0;

                double alpha = 1.0 * (frameNumber - telemetryData.FramesOffset) / telemetryData.FramesFade;
                if (frameNumber >= fadeEnd)
                {
                    alpha = 1 - 1.0 * (frameNumber - fadeEnd) / telemetryData.FramesFade;
                }
                if (alpha > 1)
                {
                    alpha = 1;
                }

                if (frameNumber >= fadeEnd + fadeLength || frameNumber < fadeStart)
                {
                    using (var imIn = Image.FromFile(frame))
                        using (var imOut = new Bitmap(1920, 1080))
                        {
                            Graphics g = Graphics.FromImage(imOut);
                            GraphicsFast(g);
                            g.FillRectangle(Brushes.Black, 0, 0, 1920, 1080);
                            g.DrawImage(imIn, (1920 - imIn.Width) / 2, (1080 - imIn.Height) / 2);
                            GraphicsSlow(g);
                            if (telemetryData.SplitScreen)
                            {
                                if (frameNumber >= fadeEnd + fadeLength)
                                {
                                    g.DrawString(telemetryData.FinalTime2, new Font("Tahoma", 48), Brushes.White,
                                                 telemetryData.PointGauge2.X + 50, telemetryData.PointGauge2.Y + 450);
                                }

                                g.DrawString(telemetryData.AnnotationLeft, new Font("Tahoma", 30), Brushes.White, telemetryData.PointAnnotation1);
                                g.DrawString(telemetryData.AnnotationRight, new Font("Tahoma", 30), Brushes.White, telemetryData.PointAnnotation2);
                            }

                            if (frameNumber >= fadeEnd + fadeLength)
                            {
                                g.DrawString(telemetryData.FinalTime1, new Font("Tahoma", 48), Brushes.White,
                                             telemetryData.PointGauge1.X + 50, telemetryData.PointGauge1.Y + 450);
                            }

                            g.DrawString(telemetryData.Title, new Font("Tahoma", 72), Brushes.White, telemetryData.PointTitle);

                            imOut.Save(file);
                        }
                    continue;
                }
                var timeA   = time - telemetryData.TimeOffsetA * 1000;
                var timeB   = time - telemetryData.TimeOffsetB * 1000;
                var sample1 = 1.0;
                var sample2 = 1.0;

                if (telemetryData.RepeatDriverA)
                {
                    sample1 = read1.Samples
                              .Where(x =>
                    {
                        if (timeA <= 0)
                        {
                            return(x.Value.Time <=
                                   (timeA + telemetryData.LapTimeA));
                        }
                        else
                        {
                            return(x.Value.Time <= timeA);
                        }
                    })
                              .OrderBy(x => - 1 * x.Value.Time)
                              .FirstOrDefault().Key;
                }
                else
                {
                    sample1 = read1.Samples
                              .Where(x => x.Value.Time <= timeA)
                              .OrderBy(x => - 1 * x.Value.Time)
                              .FirstOrDefault().Key;
                }

                sample2 = sample1;

                if (telemetryData.SplitScreen)
                {
                    if (telemetryData.RepeatDriverB)
                    {
                        sample2 = read2.Samples
                                  .Where(x =>
                        {
                            if (timeB <= 0)
                            {
                                return(x.Value.Time <=
                                       (timeB + telemetryData.LapTimeB));
                            }
                            else
                            {
                                return(x.Value.Time <= timeB);
                            }
                        })
                                  .OrderBy(x => - 1 * x.Value.Time)
                                  .FirstOrDefault().Key;
                    }
                    else
                    {
                        sample2 = read2.Samples
                                  .Where(x => x.Value.Time <= timeB)
                                  .OrderBy(x => - 1 * x.Value.Time)
                                  .FirstOrDefault().Key;
                    }
                }

                using (var imIn = Image.FromFile(frame))
                    using (var imOut = new Bitmap(1920, 1080))
                    {
                        Graphics g = Graphics.FromImage(imOut);
                        GraphicsFast(g);

                        g.FillRectangle(Brushes.Black, 0, 0, 1920, 1080);
                        g.DrawImage(imIn, (1920 - imIn.Width) / 2, (1080 - imIn.Height) / 2);

                        /******* TRACK ******/
                        GraphicsSlow(g);
                        g.DrawImage(imgTrack, telemetryData.PointTrack.X, telemetryData.PointTrack.Y);

                        double xA = 0, yA = 0;
                        double xB = 0, yB = 0;
                        if (sample1 != 0)
                        {
                            var DriverBrushA = GetBrush(alpha, 255, 100, 255, 0);
                            try
                            {
                                xA = read1.GetDouble(sample1, "Driver.CoordinateX");
                                if (telemetryData.NewTrackFormat)
                                {
                                    yA = read1.GetDouble(sample1, "Driver.CoordinateY");
                                }
                                else
                                {
                                    yA = read1.GetDouble(sample1, "Driver.CoordinateZ");
                                }

                                var pxA = telemetryData.PointTrack.X + TrackThumbnail.GetX(xA);
                                var pyA = telemetryData.PointTrack.Y + TrackThumbnail.GetY(yA);

                                g.FillEllipse(DriverBrushA, pxA - 6, pyA - 6, 13, 13);
                            }
                            catch (Exception)
                            {
                            }
                        }

                        if (sample2 != 0 && telemetryData.SplitScreen)
                        {
                            try
                            {
                                var DriverBrushB = GetBrush(alpha, 255, 255, 100, 0);

                                xB = read2.GetDouble(sample2, "Driver.CoordinateX");
                                if (telemetryData.NewTrackFormat)
                                {
                                    yB = read2.GetDouble(sample2, "Driver.CoordinateZ");
                                }
                                else
                                {
                                    yB = read2.GetDouble(sample2, "Driver.CoordinateZ");
                                }

                                var pxB = telemetryData.PointTrack.X + TrackThumbnail2.GetX(xB);
                                var pyB = telemetryData.PointTrack.Y + TrackThumbnail2.GetY(yB);

                                g.FillEllipse(DriverBrushB, pxB - 6, pyB - 6, 13, 13);
                            }
                            catch (Exception)
                            {
                            }
                        }

                        if (telemetryData.SplitScreen)
                        {
                            var BrushBackground = GetBrush(alpha, 150, 0, 0, 0);

                            g.FillRectangle(BrushBackground, 0, 844, 1920, 80);

                            DrawSlimGauges(read1, alpha, frameNumber, telemetryData.PointGauge1, sample1, time, telemetryData.LapTimeA, g, telemetryData.RPM_Max1, telemetryData.RPM_Redline1);
                            DrawSlimGauges(read2, alpha, frameNumber, telemetryData.PointGauge2, sample2, time, telemetryData.LapTimeB, g, telemetryData.RPM_Max2, telemetryData.RPM_Redline2);
                            g.DrawString(telemetryData.AnnotationLeft, new Font("Tahoma", 30), Brushes.White, telemetryData.PointAnnotation1);
                            g.DrawString(telemetryData.AnnotationRight, new Font("Tahoma", 30), Brushes.White, telemetryData.PointAnnotation2);
                        }
                        else
                        {
                            DrawGauges(read1, alpha, frameNumber, telemetryData.PointGauge1, sample1, g, imgTrack,
                                       TrackThumbnail);
                        }
                        g.DrawString(telemetryData.Title, new Font("Tahoma", 72), Brushes.White, telemetryData.PointTitle);
                        imOut.Save(file);
                    }
                Console.WriteLine(("frame " + frameNumber));
            }


            //Console.ReadLine();
        }