// 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); }
// Update is called once per frame void Update() { var newPos = new Vector3(Controller.transform.position.x, Controller.transform.position.y, Controller.transform.position.z); var newRot = new Quaternion(Controller.transform.rotation.x, Controller.transform.rotation.y, Controller.transform.rotation.z, Controller.transform.rotation.w); SteamVR_Controller.Device controllerDevice = SteamVR_Controller.Input((int)Controller.controllerIndex); var controllerPose = controllerDevice.GetPose(); //Controller.Get //hand.transform.SetPositionAndRotation(newPos, newRot); //hand.transform.SetPositionAndRotation(new Vector3(controllerPose.vVelocity.v0, controllerPose.vVelocity.v1, controllerPose.vVelocity.v2), newRot); var rot = Quaternion.LookRotation(Controller.transform.forward, Controller.transform.up); hand.transform.SetPositionAndRotation(controllerDevice.transform.pos, rot); }