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); } }
/// <summary> /// Fired when game once again receives focus (by clicking, alt-tabbing...) /// </summary> /// <param name="game"></param> private static void Game_GotFocus(SimulatorGame game) { // Allow cameras (among other things) to start capturing the mouse again game.IsCapturingMouse = true; // Hide settings form and mouse cursor game.IsMouseVisible = false; _settingsController.HideSettingsDialog(); }
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); } }
public static void Run() { try { int numScreens = Screen.AllScreens.Length; if (numScreens != 1 && numScreens != 2) throw new NotImplementedException("Only supports single and dual monitor setup!"); SimulationSettings simSettings = SimulatorResources.GetSimulationSettings(); if (simSettings.RenderMode == RenderModes.Stereo && numScreens < 2) { Console.WriteLine(@"Could not run stereo mode. Can't find two monitors connected?"); simSettings.RenderMode = RenderModes.Normal; } IntPtr rightEyeWindow = IntPtr.Zero; if (simSettings.RenderMode == RenderModes.Stereo) rightEyeWindow = SpawnRightEyeWindow(); // Start the simulator game entry point using (var game = new SimulatorGame(simSettings, rightEyeWindow)) { // 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.LostFocus += (sender, e) => game.IsCapturingMouse = false; gameForm.GotFocus += (sender, e) => Game_GotFocus(game); gameForm.MouseClick += (sender, e) => { if (e.Button == MouseButtons.Right) Game_MouseRightClick(game); }; // Name the window according to mode gameForm.Text = (simSettings.RenderMode == RenderModes.Stereo) ? "A²DS Stereoscopy (left eye)" : "A²DS"; _settingsController = new SettingsController(gameForm); // Hook the settings controller to the simulator by events, so changes in PID settings causes // autopilot to use new PID settings. _settingsController.PIDSettingsChanged += () => game.SetPIDSetup(_settingsController.CurrentPIDSetup); // Run the game code game.Run(); } } catch (Exception e) { string msg = "Error occured!\n\n" + e; Console.WriteLine(e); MessageBox.Show(msg); } }