Beispiel #1
0
        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 physics simulation to the service.
              _simulation = new Simulation();
              // We do not add the standard force effects because our bodies should only
              // be modified by Kinect data!
              //_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 RigidBodyRenderer(this, _simulation)); // Renders rigid bodies for debugging.
              Components.Add(new Help(this) { DrawOrder = 30 });        // Draws help text.
              Components.Add(new KinectWrapper(this));                  // Wraps the Kinect sensor.

              // Initialize the sample factory methods. All samples must be added to this
              // array to be shown.
              _createSampleDelegates = new Func<SampleBase>[]
              {
            () => new SkeletonMappingSample(this),
            () => new RagdollMarionetteSample(this),
              };

              // Start the first sample in the array.
              _activeSampleIndex = 0;
              _activeSample = _createSampleDelegates[0]();
              Components.Add(_activeSample);

              base.Initialize();
        }
Beispiel #2
0
        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);
              }
        }