public static SimulationSettings GetSimulationSettings()
        {
            var result = new SimulationSettings();

            string xmlText = ParseHelper.GetResourceText(@"Resources/Scenarios.xml");
            var reader = new StringReader(xmlText);

            var doc = new XmlDocument();
            doc.Load(reader);
            XmlNode nav = doc.SelectSingleNode("/root");

            var renderModeNode = nav.SelectSingleNode("RenderMode");
            result.RenderMode = renderModeNode != null
                                    ? (RenderModes)Enum.Parse(typeof(RenderModes), renderModeNode.InnerText, true)
                                    : RenderModes.Normal;

            var swapStereoNode = nav.SelectSingleNode("SwapStereo");

            result.SwapStereo = swapStereoNode != null
                                    ? bool.Parse(swapStereoNode.InnerText)
                                    : false;

            reader.Close();

            return result;
        }
        public void Test()
        {
            var simSettings = new SimulationSettings();
            simSettings.RenderMode = RenderModes.Normal;

            var game = new SimulatorGame(simSettings, IntPtr.Zero);
            _collision = new TerrainCollision(game, game);
            _collision.Initialize();
            _collision.TmpBuildScene();

            // Find new position and velocity from a constant acceleration over timestep
            const float dt = 0.017f;

            var a = new Vector3(0, 9.81f, 0);
            var startCondition1 = new TimestepStartingCondition(Vector3.Zero, Vector3.Zero, a,
                                                                Quaternion.Identity, TimeSpan.Zero);
            TimestepStartingCondition startCondition2 = startCondition1;

            var joystickOutput = new JoystickOutput(0.1f, 0.1f, 0, 0.5f);

            for (int i = 0; i < 100; i++)
            {
                TimestepResult jitterResult = ByJitter(startCondition1, joystickOutput,
                                                       startCondition1.StartTime + TimeSpan.FromSeconds(dt), dt);

                TimestepResult physicsResult = ByPhysics(startCondition2, joystickOutput,
                                                         startCondition2.StartTime + TimeSpan.FromSeconds(dt), dt);

                Vector3 dPos = jitterResult.Position - physicsResult.Position;
                Vector3 dVel = jitterResult.Velocity - physicsResult.Velocity;

                if (jitterResult.Orientation != physicsResult.Orientation)
                {
                    float dPitchDeg =
                        MathHelper.ToDegrees(VectorHelper.GetPitchAngle(jitterResult.Orientation) -
                                             VectorHelper.GetPitchAngle(physicsResult.Orientation));

                    float dRollDeg =
                        MathHelper.ToDegrees(VectorHelper.GetRollAngle(jitterResult.Orientation) -
                                             VectorHelper.GetRollAngle(physicsResult.Orientation));

                    float dYawDeg =
                        MathHelper.ToDegrees(VectorHelper.GetHeadingAngle(jitterResult.Orientation) -
                                             VectorHelper.GetHeadingAngle(physicsResult.Orientation));

                    Console.WriteLine("YPR delta " + dPitchDeg + " " + dRollDeg + " " + dYawDeg);
                }

                TimeSpan nextStartTime = physicsResult.EndTime;
                startCondition1 = new TimestepStartingCondition(jitterResult.Position, jitterResult.Velocity,
                                                                a, jitterResult.Orientation, nextStartTime);

                startCondition2 = new TimestepStartingCondition(physicsResult.Position, physicsResult.Velocity,
                                                                a, physicsResult.Orientation, nextStartTime);
            }
        }
        internal static void Run(string[] runtimeArgs)
        {
            if (runtimeArgs == null || runtimeArgs.Length != 3)
            {
                MessageBox.Show(@"Expected arguments to be '-test <config file path> <output directory path>'.");
                return;
            }

            string testConfigurationFilePath = runtimeArgs[1];
            if (!File.Exists(testConfigurationFilePath))
            {
                MessageBox.Show(@"No test configuration file found at: " + testConfigurationFilePath);
                return;
            }

            string relativeOutputPath = runtimeArgs[2];

            try
            {
                TestConfiguration testConf = SimulatorResources.GetTestConfiguration(testConfigurationFilePath);
                var simSettings = new SimulationSettings();
                simSettings.RenderMode = RenderModes.Normal;

                // Start the simulator game entry point
                using (var game = new SimulatorGame(simSettings, IntPtr.Zero, testConf, relativeOutputPath))
                {
                    // Enables cameras (poor design, I know..)
                    game.IsCapturingMouse = true;

                    // Make sure the XNA game window (left eye) displays as a full screen window
                    // just as the one we just created for the right eye
                    var gameForm = (Form)System.Windows.Forms.Control.FromHandle(game.Window.Handle);
                    gameForm.FormBorderStyle = FormBorderStyle.None;
                    gameForm.Text = @"A²DS Test Mode";

                    gameForm.LostFocus += (sender, e) => game.IsCapturingMouse = false;
                    gameForm.GotFocus += (sender, e) => game.IsCapturingMouse = true;

                    // Run the game code
                    game.Run();
                }

                string configfileCopy = Path.Combine(relativeOutputPath, @"TestConfiguration.xml");
                File.Copy(testConfigurationFilePath, configfileCopy);
            }
            catch (Exception e)
            {
                MessageBox.Show(@"Error occured." + e);
            }
        }
        public static void Run()
        {
            try
            {
            //            SimulationSettings simSettings = SimulatorResources.GetSimulationSettings();
                var simSettings = new SimulationSettings();
                simSettings.RenderMode = RenderModes.Normal;

                // Start the simulator game entry point
                using (var game = new SimulatorGame(simSettings, IntPtr.Zero))
                {
                    game.Run();
                }
            }
            catch (Exception e)
            {
                string msg = "Error occured!\n\n" + e;
                Console.WriteLine(e);
            //                MessageBox.Show(msg);
            }
        }
        /// <summary>
        /// Create the simulation object using a test configuration run batch tests.
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="handle"></param>
        /// <param name="testConfiguration"></param>
        /// <param name="relativeOutputPath"></param>
        public SimulatorGame(SimulationSettings settings, IntPtr handle, TestConfiguration testConfiguration, string relativeOutputPath)
            : this()
        {
            _settings = settings;
            _relativeOutputPath = relativeOutputPath;
            _testConfiguration = testConfiguration ?? TestConfiguration.Default;
#if !XBOX
            _stereoRightHandle = handle;
#endif

        }
 /// <summary>
 /// Create the simulation object.
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="handle"></param>
 public SimulatorGame(SimulationSettings settings, IntPtr handle)
     : this(settings, handle, null, "Test Results")
 {
 }