public override void Initialize()
        {
#if !XBOX
            string[] joystickNames = Joystick.FindJoysticks();
            if (joystickNames == null || joystickNames.Length == 0)
            {
                //                MessageBox.Show("No joysticks found.");
            }
            else
            {
                IList <JoystickSetup> joystickSetups = SimulatorResources.GetJoystickSetups();
                if (joystickSetups == null || joystickSetups.Count == 0)
                {
                    throw new Exception("No configured joysticks.");
                }

                _joystickSystem = new JoystickSystem(_game.Window.Handle, joystickSetups);
                _useJoystick    = true;
            }
#endif


            // Initialize stencil shadow transformation matrix
            Vector3 shadowLightDir = Vector3.Down;
            var     shadowPlane    = new Plane(Vector3.Zero, Vector3.Forward, Vector3.Right);
            _shadowTransform = Matrix.CreateShadow(shadowLightDir, shadowPlane) * Matrix.CreateTranslation(Vector3.Up / 100);

            base.Initialize();
        }
예제 #2
0
        public static TestConfiguration GetConfiguration(string xmlFilepath)
        {
            var result = new TestConfiguration();

            string xmlText = ParseHelper.GetResourceText(xmlFilepath);
            var    reader  = new StringReader(xmlText);

            var doc = new XmlDocument();

            doc.Load(reader);
            XmlNode nav = doc.SelectSingleNode("/root/TestConfiguration");

            // Parse configuration
            result.FlyBySensors      = bool.Parse(nav.SelectSingleNode("FlyBySensors").InnerText);
            result.UsePerfectSensors = bool.Parse(nav.SelectSingleNode("UsePerfectSensors").InnerText);
            result.UseRangeFinder    = bool.Parse(nav.SelectSingleNode("UseRangeFinder").InnerText);
            result.UseGPS            = bool.Parse(nav.SelectSingleNode("UseGPS").InnerText);
            result.UseINS            = bool.Parse(nav.SelectSingleNode("UseINS").InnerText);

            result.Sensors        = ParseSensorSpecifications(nav.SelectSingleNode("SensorSpecifications"));
            result.MaxHVelocities = ParseMaxHVelocities(nav.SelectNodes("MaxHVelocity"));

            List <string> scenarioNames = ParseScenarioNames(nav.SelectNodes("ScenarioName"));

            foreach (string scenarioName in scenarioNames)
            {
                result.TestScenarios.Add(SimulatorResources.GetScenario(scenarioName));
            }

            return(result);
        }
예제 #3
0
        public SettingsController(Form gameForm)
        {
            if (gameForm == null)
            {
                throw new ArgumentNullException("gameForm");
            }

            _gameForm = gameForm;

            // Create a settings form to enable the user to change settings in-game
            _settingsForm = new SettingsForm();
            _pidSetups    = SimulatorResources.GetPIDSetups();
            _scenarios    = SimulatorResources.GetScenarios();

            if (_pidSetups == null || _pidSetups.Count == 0)
            {
                throw new Exception("No PID setups were found!");
            }

            CurrentPIDSetup = _pidSetups[0];

            _pidSettings    = _settingsForm.PIDSettings;
            _pidListUI      = _pidSettings.PIDSetup;
            _scenarioListUI = _settingsForm.SimSettings.Scenarios;

            _scenarioListUI.SelectedValueChanged += Scenarios_SelectedValueChanged;
            _pidListUI.SelectedValueChanged      += SelectedPIDChanged;

            _pidSettings.PIDChanged += PIDValuesChanged;

            Populate();
        }
예제 #4
0
        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 HelicopterBase(Game game, TestConfiguration testConfiguration, TerrainCollision collision,
                              ICameraProvider cameraProvider, BasicEffect effect, SunlightParameters skyParams, HelicopterScenario scenario,
                              bool playEngineSound, bool isPlayerControlled, bool drawText)
            : base(game)
        {
            if (game == null || cameraProvider == null || effect == null || skyParams == null)
            {
                throw new ArgumentNullException("", @"One or several of the necessary arguments were null!");
            }



            _game = game;
            _testConfiguration    = testConfiguration;
            _sensorSpecifications = testConfiguration.Sensors;
            _collision            = collision;
            _flyBySensors         = testConfiguration.FlyBySensors;

            if (_collision != null)
            {
                _collision.CollidedWithTerrain += gameTime => Crashed(gameTime);
            }


            _basicEffect       = effect;
            _skyParams         = skyParams;
            _scenario          = scenario;
            _drawText          = drawText;
            _cameraProvider    = cameraProvider;
            IsPlayerControlled = isPlayerControlled;

            _playEngineSound = playEngineSound;

            _estimatedState = new HeliState();

            PIDSetup pidSetup = SimulatorResources.GetPIDSetups()[0];

            Autopilot = new Autopilot(_scenario.Task, pidSetup);
            Log       = new List <HelicopterLogSnapshot>();
        }
예제 #6
0
        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);
            }
        }