예제 #1
0
 /// <summary>
 /// Vibrates the controller.
 /// </summary>
 /// <param name="strength">The Strength.</param>
 /// <param name="length">The Length.</param>
 internal void Vibrate(XInputVibration strength, float length)
 {
     XInputInterops.XInputSetState(_playerIndex, ref strength);
     _vibrationStopped = false;
     _vibrationTime = length;
 }
예제 #2
0
        /// <summary>
        /// Updates the object.
        /// </summary>
        /// <param name="gameTime">The GameTime.</param>
        public void Update(GameTime gameTime)
        {
            int result = XInputInterops.XInputGetState(_playerIndex, ref _gamepadStateCurrent);
            IsAvailable = (result == 0);
            if (!IsAvailable) return;

            UpdateBatteryState();
            _gamepadStatePrev.Copy(_gamepadStateCurrent);

            if (_vibrationTime > 0)
            {
                _vibrationTime -= gameTime.ElapsedGameTime;
            }

            if (_vibrationTime <= 0 && !_vibrationStopped)
            {
                var stopStrength = new XInputVibration {LeftMotorSpeed = 0, RightMotorSpeed = 0};
                XInputInterops.XInputSetState(_playerIndex, ref stopStrength);
                _vibrationStopped = true;
            }
        }
예제 #3
0
        /// <summary>
        /// Vibrates the controller.
        /// </summary>
        /// <param name="leftMotor">The LeftMotor.</param>
        /// <param name="rightMotor">The RightMotor.</param>
        /// <param name="length">The Length.</param>
        public void Vibrate(float leftMotor, float rightMotor, float length)
        {
            leftMotor = (float) System.Math.Max(0d, System.Math.Min(1d, leftMotor));
            rightMotor = (float) System.Math.Max(0d, System.Math.Min(1d, rightMotor));

            var vibration = new XInputVibration
            {
                LeftMotorSpeed = (ushort) (65535d*leftMotor),
                RightMotorSpeed = (ushort) (65535d*rightMotor)
            };
            Vibrate(vibration, length);
        }
예제 #4
0
 /// <summary>
 /// Vibrates the controller.
 /// </summary>
 /// <param name="strength">The Strength.</param>
 /// <param name="length">The Length.</param>
 internal void Vibrate(XInputVibration strength, float length)
 {
     XInputInterops.XInputSetState(_playerIndex, ref strength);
     _vibrationStopped = false;
     _vibrationTime    = length;
 }