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); } }
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>(); }
public override void Initialize() { float aspectRatio = game.GraphicsDevice.Viewport.AspectRatio; #region Load Models //Load Models Vector3 initPlayerPosition = new Vector3(-500, 550, 500); player = new Player(game, initPlayerPosition, 5f); terrain = new Terrain(game); game.Components.Add(player); game.Components.Add(terrain); #endregion #region Load Cameras //Load Cameras thirdPersonCam = new _3rdPersonCam(game, (player.getPosition()), player, Vector3.Up, aspectRatio); flyByCam = new StaticCam(game, player, Vector3.Up, aspectRatio); firstPersonCam = new FirstPersonCam(game, player.getPosition(), Vector3.Up, aspectRatio); availableCameras = new Queue<Camera>(); availableCameras.Enqueue(thirdPersonCam); availableCameras.Enqueue(flyByCam); currentCam = availableCameras.Dequeue(); #endregion #region setup game objects cameras and draw order player.setCamera(currentCam); player.DrawOrder = 3; terrain.setCamera(currentCam); terrain.DrawOrder = 2; skybox = new Skybox(game, currentCam, "Space"); skybox.DrawOrder = 1; game.Components.Add(skybox); #endregion #region initialize controls input = new Control(game, player, thirdPersonCam, false); game.Components.Add(input); #endregion collisionDetector = new Collision(game); game.Components.Add(collisionDetector); terrainCollisionDetector = new TerrainCollision(game, terrain); game.Components.Add(terrainCollisionDetector); #region Records //places records on the land scape randomly Random rand = new Random(); for (int i = 0; i < 10; i++) { Vector3 pos = new Vector3(rand.Next(-255*30, 0), 0, rand.Next(0, 255*30 )); pos.Y = terrain.getTerrainHeight(pos) + 30; Record newRecord = new Record(game, pos); recordList.Add(newRecord); newRecord.setCamera(currentCam); newRecord.DrawOrder = 3; game.Components.Add(newRecord); } #endregion optionsHaveChanged(); }