public override int GetInputState(ref XDevicePlugin.ControllerState state) { state.handle = this.handle; ResetStatePose(ref state); transform.TransformState(ref state); return(0); }
// public override int GetInputState(ref XDevicePlugin.ControllerState state) { if (m_Device.connected) { Vector2 v2; // v2 = m_Device.GetAxis(EVRButtonId.k_EButton_Axis1); state.axes[(int)ControllerAxis.PrimaryTrigger] = v2.x; v2 = m_Device.GetAxis(EVRButtonId.k_EButton_Axis0); state.axes[(int)ControllerAxis.PrimaryThumbX] = v2.x; state.axes[(int)ControllerAxis.PrimaryThumbY] = v2.y; // state.buttons = 0; if (m_Device.GetHairTrigger()) { state.buttons |= (uint)XimmerseButton.Trigger; } if (m_Device.GetPress(SteamVR_Controller.ButtonMask.Grip)) { state.buttons |= (uint)XimmerseButton.Grip; } if (m_Device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { state.buttons |= (uint)XimmerseButton.Touch; } if (m_Device.GetPress(SteamVR_Controller.ButtonMask.Touchpad)) { state.buttons |= (uint)XimmerseButton.Click; } if (m_Device.GetPress(SteamVR_Controller.ButtonMask.ApplicationMenu)) { state.buttons |= (uint)XimmerseButton.App; } if (m_Device.GetPress(SteamVR_Controller.ButtonMask.System)) { state.buttons |= (uint)XimmerseButton.Home; } // TrackedDevicePose_t pose = m_UseOnNewPoses?m_Pose:m_Device.GetPose(); XDevicePlugin.SetInt(handle, XDevicePlugin.kField_TrackingResultInt, (int)(pose.bPoseIsValid?TrackingResult.PoseTracked:TrackingResult.NotTracked)); SteamVR_Utils.RigidTransform rt = new SteamVR_Utils.RigidTransform(pose.mDeviceToAbsoluteTracking); Vector3 v3 = rt.pos; state.position[0] = v3.x; state.position[1] = v3.y; state.position[2] = -v3.z; Quaternion q = rt.rot; state.rotation[0] = -q.x; state.rotation[1] = -q.y; state.rotation[2] = q.z; state.rotation[3] = q.w; // } return(0); }
public static int OnHmdUpdate(int which, ref XDevicePlugin.ControllerState state) { if (main != null) { Quaternion q = s_Main.GetHmdRotation(); int i = 0; state.rotation[i] = -q[i]; ++i; state.rotation[i] = -q[i]; ++i; state.rotation[i] = q[i]; ++i; state.rotation[i] = q[i]; ++i; return(0); } else { return(-1); } }
public static int OnHmdUpdate(int which, ref XDevicePlugin.ControllerState state) { if (s_Main != null) { Quaternion q = (s_Main.vrDevice == null)?Quaternion.identity:s_Main.vrDevice.GetRotation(); int i = 0; state.rotation[i] = -q[i]; ++i; state.rotation[i] = -q[i]; ++i; state.rotation[i] = q[i]; ++i; state.rotation[i] = q[i]; ++i; return(0); } else { return(-1); } }
public override int GetInputState(ref XDevicePlugin.ControllerState state) { if (m_ControllerProvider == null) { return(-1); } m_ControllerProvider.ReadState(m_State); // state.axes[(int)ControllerAxis.PrimaryThumbX] = (m_State.touchPos.x - .5f) * 2f; state.axes[(int)ControllerAxis.PrimaryThumbY] = (m_State.touchPos.y - .5f) * -2f; // state.buttons = 0; if (m_State.isTouching) { state.buttons |= (uint)DaydreamButton.Touch; } if (m_State.clickButtonState) { state.buttons |= (uint)DaydreamButton.Click; } if (m_State.appButtonState) { state.buttons |= (uint)DaydreamButton.App; } if (m_State.recentering) { state.buttons |= (uint)DaydreamButton.Home; } // int i; i = 4; while (i-- > 0) { state.rotation[i] = m_State.orientation[i]; } i = 3; while (i-- > 0) { state.accelerometer[i] = m_State.accel[i]; } i = 3; while (i-- > 0) { state.gyroscope[i] = m_State.gyro[i]; } // return(0); }
protected virtual void Update() { if (m_ControllerInput != null) { OnPoseUpdated( m_ControllerInput.GetPosition(), GetYawPitchRoll(m_ControllerInput.GetRotation()) ); XDevicePlugin.ControllerState state = m_ControllerInput.GetState(); XDevicePlugin.ControllerState prevState = m_ControllerInput.GetPrevState(); OnInputUpdated( prevState.buttons, state.buttons, IsShiftMode() ); } }
public override int GetInputState(ref XDevicePlugin.ControllerState state) { CVRSystem system = OpenVR.System; if (system != null) { int i; if (/*valid=*/ system.GetControllerStateWithPose(SteamVR_Render.instance.trackingSpace, m_Index, ref m_State, ref m_Pose)) { // i = 0; state.axes[i++] = m_State.rAxis1.x; // trigger ++i; state.axes[i++] = m_State.rAxis0.x; state.axes[i++] = m_State.rAxis0.y; ++i; ++i; if (m_InputTransform != null) { state.buttons = TransformButton(m_InputTransform, m_State.ulButtonPressed, m_State.ulButtonTouched); } else { // You needs an InputTransform to convert ulong buttons to uint buttons. state.buttons = 0; } // SteamVR_Utils.RigidTransform t = new SteamVR_Utils.RigidTransform(m_Pose.mDeviceToAbsoluteTracking); for (i = 0; i < 3; ++i) { state.position[i] = t.pos[i]; } state.position[i] = 1.0f; for (i = 0; i < 4; ++i) { state.rotation[i] = t.rot[i]; } return(0); } } return(-1); }
public virtual void TransformState(ref XDevicePlugin.ControllerState state) { // state.buttons = GetButtons(); // int i = 0; state.axes[i++] = Input.GetAxis(LeftTrigger.name); state.axes[i++] = Input.GetAxis(RightTrigger.name); state.axes[i++] = Input.GetAxis(LeftThumbstickX.name); state.axes[i++] = Input.GetAxis(LeftThumbstickY.name); state.axes[i++] = Input.GetAxis(RightThumbstickX.name); state.axes[i++] = Input.GetAxis(RightThumbstickY.name); // Vector3 pos = InputTracking.GetLocalPosition(node); Quaternion rot = InputTracking.GetLocalRotation(node); // TrackingResult trackingResult = TrackingResult.NotTracked; if (pos != Vector3.zero) { trackingResult |= TrackingResult.PositionTracked; } if (rot != Quaternion.identity) { trackingResult |= TrackingResult.RotationTracked; } XDevicePlugin.SetInt(state.handle, XDevicePlugin.kField_TrackingResult, (int)trackingResult); // i = 0; state.position[i] = pos[i]; ++i; state.position[i] = pos[i]; ++i; state.position[i] = -pos[i]; ++i; i = 0; state.rotation[i] = -rot[i]; ++i; state.rotation[i] = -rot[i]; ++i; state.rotation[i] = rot[i]; ++i; state.rotation[i] = rot[i]; ++i; }
/// <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); }
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); }