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>(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { _basicEffect = CreateBasicEffect(this); #region Load scenario / test scenarios _testMaxHVelocityIter = _testConfiguration.MaxHVelocities.GetEnumerator(); if (!_testMaxHVelocityIter.MoveNext()) throw new Exception("No maxHVelocities defined in _testConfiguration."); _testScenarioIter = _testConfiguration.TestScenarios.GetEnumerator(); if (IsTestMode) NextTestScenario(); else { _testScenarioIter.MoveNext(); _scenario = _testScenarioIter.Current; } if (_scenario == null) throw new Exception("Could not load scenario from XML."); #endregion #region Cameras // We must create a dummy camera target until the helicopter instance is created, to avoid exceptions var cameraOffset = new Vector3(0.0f, 0.5f, -0.5f); var startPos = _scenario.HelicopterScenarios[0].StartPosition + cameraOffset; _cockpitMesh = new SimpleModel("Models/apache-cockpit", this, this); InitCamera(MyCameraType, startPos + new Vector3(0, 0.5f, 4), new WorldDummy(Vector3.Zero)); #endregion #region Sunlight, skydome, terrain and trees // Initialize skydome and sunlight parameters _skydome = new SkydomeComponent(this, this); _terrain = new TerrainComponent(this, this, _skydome.Parameters); UpdateTerrain(_scenario); // Initialize trees // TODO Forest component does not support dynamic loading/unloading of components yet if (_scenario.SceneElements.Contains("Forest")) _forest = new Forest(this, this, _terrain.Mesh, _skydome.Parameters); #endregion #region Misc components _fpsUtil = new FPS(this); _barrels = GetBarrels(); _texturedGround = new FlatTexturedGround(this, this); _currentWaypoint = new WaypointMesh(this, this); _currentWaypoint.Position = new Vector3(0, 1, 0); #endregion #region Physics _terrainCollision = new TerrainCollision(this, this); // We implemented our own crash detection for whenever Jitter is disabled _terrainCollision.SetHeightValues(_heightmap.HeightValues); #endregion #region Helicopters // Initialize helicopter(s) InitHelicopters(_skydome.Parameters, _heightmap); Camera.LookAtTarget = _helicopter; _terrainCollision.Helicopter = _helicopter; // TODO Clean this up, non-intuitive usage _helicopter.Crashed += HelicopterCrashEventHandler; #endregion #region Test scenario results if (IsTestMode) { _testResults = new Dictionary<string, List<ScenarioTestResult>>(); } #endregion // Add game components to the game loop AddGameComponents(); Reset(); base.Initialize(); }
public HeliPhysics(TerrainCollision collision, bool useTerrainCollision) { _collision = collision; _useTerrainCollision = useTerrainCollision; }