Example #1
0
        /// <summary>
        ///
        /// </summary>
        public override int GetInputState(ref XDevicePlugin.ControllerState state)
        {
            int i;
            //
            int ret = SixensePluginLite.sixenseGetNewestData(index, ref rawData);

            if (ret == 0)
            {
                // Axes
                i = 0;
                state.axes[i++] = rawData.trigger;
                i++;
                state.axes[i++] = rawData.joystick_x;
                state.axes[i++] = rawData.joystick_y;
                // Buttons
                //
                if (inputTransform == null)
                {
                    state.buttons = rawData.buttons;
                }
                else
                {
                    state.buttons = inputTransform.TransformButtons(rawData.buttons);
                }
                // Position
                i = 3;
                while (i-- > 0)               // i==3
                {
                    state.position[i] = rawData.pos[i] * manager.sensitivity[i];
                }
                // Rotation
                i = 4;
                while (i-- > 0)
                {
                    state.rotation[i] = rawData.rot_quat[i];
                }
            }
            return(ret);
        }
Example #2
0
        public override int GetInputState(ref XDevicePlugin.ControllerState state)
        {
            int ret = manager.impl.XInputGetState(dwUserIndex, ref xinputState);

            if (ret == 0)
            {
                state.handle = this.handle;
                ++state.timestamp;
                ResetStatePose(ref state);
                //
                if (manager.impl.XInputGetBatteryInformation != null)
                {
                    manager.impl.XInputGetBatteryInformation(dwUserIndex, 0, ref xinputBatteryInformation);
                    XDevicePlugin.SetInt(handle, XDevicePlugin.kField_BatteryLevel,
                                         (xinputBatteryInformation.BatteryType == XInputPlugin.XINPUT_BATTERY_TYPE.BATTERY_TYPE_DISCONNECTED ||
                                          xinputBatteryInformation.BatteryType == XInputPlugin.XINPUT_BATTERY_TYPE.BATTERY_TYPE_UNKNOWN)?
                                         -1:
                                         (int)(100f * (float)xinputBatteryInformation.BatteryLevel / (float)XInputPlugin.XINPUT_BATTERY_LEVEL.BATTERY_LEVEL_FULL)
                                         );
                }
                //
                if (inputTransform == null)
                {
                    state.buttons = (uint)xinputState.Gamepad.wButtons;
                }
                else
                {
                    state.buttons = inputTransform.TransformButtons((uint)xinputState.Gamepad.wButtons);
                }
                //
                state.axes[(int)ControllerRawAxis.LeftTrigger]  = Mathf.Lerp(0f, 1f, MathUtil.Normalize(0, 255, xinputState.Gamepad.bLeftTrigger));
                state.axes[(int)ControllerRawAxis.RightTrigger] = Mathf.Lerp(0f, 1f, MathUtil.Normalize(0, 255, xinputState.Gamepad.bRightTrigger));
                state.axes[(int)ControllerRawAxis.LeftThumbX]   = Mathf.Lerp(-1f, 1f, MathUtil.Normalize(-32767, 32767, xinputState.Gamepad.sThumbLX));
                state.axes[(int)ControllerRawAxis.LeftThumbY]   = Mathf.Lerp(-1f, 1f, MathUtil.Normalize(-32767, 32767, xinputState.Gamepad.sThumbLY));
                state.axes[(int)ControllerRawAxis.RightThumbX]  = Mathf.Lerp(-1f, 1f, MathUtil.Normalize(-32767, 32767, xinputState.Gamepad.sThumbRX));
                state.axes[(int)ControllerRawAxis.RightThumbY]  = Mathf.Lerp(-1f, 1f, MathUtil.Normalize(-32767, 32767, xinputState.Gamepad.sThumbRY));
            }
            return(ret);
        }