protected override void Initialize() { // ----- Initialize Services. // The services are stored in Game.Services to make them accessible for all // game components. // Add the input service, which manages device input, button presses, etc. _inputManager = new InputManager(false); Services.AddService(typeof(IInputService), _inputManager); // Add the animation service. _animationManager = new AnimationManager(); Services.AddService(typeof(IAnimationService), _animationManager); // Add the physics simulation to the service. // (TODO: Create a IPhysicsService that owns the simulation.) _simulation = new Simulation(); // Add standard force effects: _simulation.ForceEffects.Add(new Gravity()); _simulation.ForceEffects.Add(new Damping()); Services.AddService(typeof(Simulation), _simulation); // ----- Add GameComponents Components.Add(new Camera(this)); // Controls the camera. Components.Add(new BallShooter(this)); // Shoot balls at the target position. Components.Add(new Grab(this)); // Allows to grab objects with the mouse/gamepad Components.Add(new RigidBodyRenderer(this) { DrawOrder = 10 }); // Renders all rigid bodies of the simulation. Components.Add(new Reticle(this) { DrawOrder = 20 }); // Draws a cross-hair for aiming. Components.Add(new Help(this) { DrawOrder = 30 }); // Draws help text. Components.Add(new Profiler(this) { DrawOrder = 40 }); // Displays profiling data. // Initialize the sample factory methods. All samples must be added to this // array to be shown. _createSampleDelegates = new Func<Sample>[] { () => new BindPoseSample(this), () => new SkeletonManipulationSample(this), () => new DudeWalkingSample(this), () => new AttachmentSample(this), () => new CrossFadeSample(this), () => new StressTestSample(this), () => new CompressionSample(this), () => new MixingSample(this), () => new BoneJiggleSample(this), () => new SkeletonMappingSample(this), () => new LookAtIKSample(this), () => new JacobianTransposeIKSample(this), () => new CcdIKSample(this), () => new ClosedFormIKSample(this), () => new TwoJointIKSample(this), () => new CollisionDetectionOnlyRagdollSample(this), () => new KinematicRagdollSample(this), () => new PassiveRagdollSample(this), () => new ActiveRagdollSample(this), }; // Start the first sample in the array. _activeSampleIndex = 0; _activeSample = _createSampleDelegates[0](); Components.Add(_activeSample); base.Initialize(); }
private void SwitchSamples() { // If left arrow or DPadLeft is pressed, we want to switch to the previous sample (index - 1). int sampleIndexIncrement = 0; if (_inputManager.IsPressed(Keys.Left, false) || _inputManager.IsPressed(Buttons.DPadLeft, false, PlayerIndex.One)) { sampleIndexIncrement = -1; } // If right arrow or DPadRight is pressed, we want to switch to the next sample (index + 1). if (_inputManager.IsPressed(Keys.Right, false) || _inputManager.IsPressed(Buttons.DPadRight, false, PlayerIndex.One)) { sampleIndexIncrement = +1; } if (sampleIndexIncrement != 0) { // Switch samples. // Stop current sample. Components.Remove(_activeSample); _activeSample.Dispose(); // Clean up memory. GC.Collect(); // Get index of next sample. _activeSampleIndex += sampleIndexIncrement; if (_activeSampleIndex >= _createSampleDelegates.Length) _activeSampleIndex = 0; else if (_activeSampleIndex < 0) _activeSampleIndex = _createSampleDelegates.Length - 1; // Add next sample. _activeSample = _createSampleDelegates[_activeSampleIndex](); Components.Add(_activeSample); } }