/// <summary>
        /// Create new replay for a specific track number.
        /// </summary>
        /// <param name="setTrackNum">Set track number</param>
        public Replay(bool createNew, Track track)
        {
            // If not creating new, load it from file!
            if (createNew == false)
            {
                // Load if possible
                if (File.Exists(Path.Combine(
                    Directories.ContentDirectory, ReplayFilename)))
                {
                    FileStream stream = FileHelper.LoadGameContentFile(
                        "Content\\"+ReplayFilename);
                    BinaryReader reader = new BinaryReader(stream);

                    // Load total lap time
                    lapTime = reader.ReadSingle();

                    // Load matrix values
                    int numOfMatrixValues = reader.ReadInt32();
                    for (int num = 0; num < numOfMatrixValues; num++)
                        trackMatrixValues.Add(
                            FileHelper.ReadMatrix(reader));

                    // Load checkpoint times
                    int numOfCheckpointTimes = reader.ReadInt32();
                    for (int num = 0; num < numOfCheckpointTimes; num++)
                        checkpointTimes.Add(reader.ReadSingle());

                    // Loading complete, close.
                    stream.Close();
                } // if
                else
                {
                    // Create new default replay for this track!
                    // Get all track positions based on the current top highscore time!
                    lapTime = Highscores.GetTopLapTime();
                    int numOfMatrixValues = 1 + (int)(lapTime / TrackMatrixIntervals);

                    float lastTrackPos = 0.0f;
                    int oldTrackSegmentNumber = 0;

                    // Go twice as long and abort when we reach the finish line!
                    for (int num = 0; num < numOfMatrixValues*2; num++)
                    {
                        // See Landscape.TestRenderLandscape for more details.
                        float carTrackPos = 0.00001f +
                            ((float)num / (float)(numOfMatrixValues - 1));
                        float difference = carTrackPos - lastTrackPos;
                        carTrackPos = lastTrackPos + difference * 0.1f;
                        lastTrackPos = carTrackPos;

                        float roadWidth, nextRoadWidth;
                        Matrix carMatrix =
                            track.GetTrackPositionMatrix(carTrackPos,
                            out roadWidth, out nextRoadWidth);

                        // Store
                        trackMatrixValues.Add(carMatrix);

                        // Also check if we passed a checkpoint
                        int trackSegmentNumber = (int)(carTrackPos * track.NumberOfSegments);
                        // Segment changed
                        if (trackSegmentNumber != oldTrackSegmentNumber)
                        {
                            // Check if we passed a checkpoint.
                            for (int checkpointNum = 0; checkpointNum < track.
                                CheckpointSegmentPositions.Count; checkpointNum++)
                            {
                                // We have to check if we are between the old and the current
                                // track segement numbers, we might skip one or two in 200ms.
                                if (track.CheckpointSegmentPositions[checkpointNum] >
                                    oldTrackSegmentNumber &&
                                    track.CheckpointSegmentPositions[checkpointNum] <=
                                    trackSegmentNumber)
                                {
                                    // We passed that checkpoint, add the simulated time
                                    checkpointTimes.Add(
                                        lapTime * (float)num / (float)(numOfMatrixValues - 1));
                                    break;
                                } // if
                            } // for
                        } // if
                        oldTrackSegmentNumber = trackSegmentNumber;

                        // Reached finish?
                        if (carTrackPos >= 1.0f)
                            // Then abort, do not add more.
                            break;
                    } // for (all matrix values)

                    // Add the final checkpoint for the laptime
                    checkpointTimes.Add(lapTime);
                } // else (not loading)
            } // if (createNew == false)
        }
        /// <summary>
        /// Test render track
        /// </summary>
        //[Test]
        public static void TestRenderTrack()
        {
            Track track = null;
            Model testModel = null;

            TestGame.Start(
                delegate
                {
                    track = new Track("TrackSimple", null);
                    testModel = new Model("AlphaPalm2");
                },
                delegate
                {
                    //SpeedyRacerManager.Player.SetCarPosition(track.points[0].pos,
                    //	new Vector3(0, 1, 0), new Vector3(0, 0, 1));

                    //ShowGroundGrid();
                    //ShowTrackLines(track);

                    ShowUpVectors(track);
                    track.Render();

                    //testModel.Render(track.StartPosition);
                });
        }
        public static void TestTrackScreenshot()
        {
            Track track = null;
            Model testModel = null;

            TestGame.Start(
                delegate
                {
                    track = new Track("TrackSimple", null);
                    testModel = new Model("SpeedyRacer");
                },
                delegate
                {
                    SpeedyRacerManager.Player.SetCarPosition(
                        track.points[(int)(track.points.Count*0.93f)].pos +
                        new Vector3(0, -50, 0),
                        new Vector3(0, 1, 0), new Vector3(0, 0, 1));
                    track.roadMaterial.ambientColor = Color.Gray;

                    track.Render();

                    /*
                    testModel.RenderCar(0, Color.White,
                        Matrix.CreateRotationX(Input.MousePos.X/400.0f) *
                        Matrix.CreateTranslation(
                        track.points[(int)(track.points.Count * 0.95f)].pos));
                     */
                });
        }
        /// <summary>
        /// Reload level before starting a game
        /// </summary>
        public void ReloadLevel()
        {
            // Load track
            if (track == null)
                track = new Track("TrackSimple", this);
            else
                track.Reload("TrackSimple", this);

            // Load replay for this track to show best player
            bestReplay = new Replay(false, track);
            newReplay = new Replay(true, track);

            // Kill brake tracks
            brakeTracksVertices.Clear();
            brakeTracksVerticesArray = null;

            // Set car at start pos
            SetCarToStartPosition();
        }