예제 #1
0
        private void UpdateViveControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            bool    menuButton         = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
            bool    primaryAxisClick   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisClick);
            bool    triggerButton      = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);
            bool    primary2DAxisTouch = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisTouch);
            bool    gripButton         = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);
            float   trigger            = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);
            Vector2 primary2DAxis      = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxis);

            state.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuButton);
            state.SetButtonPress(VRModuleRawButton.Touchpad, primaryAxisClick);
            state.SetButtonPress(VRModuleRawButton.Grip, gripButton);
            state.SetButtonPress(VRModuleRawButton.CapSenseGrip, gripButton);
            state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);

            state.SetButtonTouch(VRModuleRawButton.Trigger, triggerButton);
            state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);

            state.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxis.x);
            state.SetAxisValue(VRModuleRawAxis.TouchpadY, primary2DAxis.y);

            if (KnownActiveInputSubsystem == VRModuleKnownXRInputSubsystem.OpenXR)
            {
                bool  systemButton = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("SystemButton")); // Always false
                float grip         = GetDeviceFeatureValueOrDefault(device, CommonUsages.grip);                            // 0 or 1

                state.SetButtonPress(VRModuleRawButton.System, systemButton);
                state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
            }
        }
예제 #2
0
        private static void Update_R_MicrosoftMR(IVRModuleDeviceState prevState, IVRModuleDeviceStateRW currState)
        {
            var menuPress    = GetUnityButton(0);
            var padPress     = GetUnityButton(9);
            var triggerPress = GetUnityButton(15);
            var padTouch     = GetUnityButton(17);

            var stickX  = GetUnityAxis(4);
            var stickY  = GetUnityAxis(5);
            var trigger = GetUnityAxis(10);
            var grip    = GetUnityAxis(12);
            var padX    = GetUnityAxis(19);
            var padY    = GetUnityAxis(20);

            currState.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuPress);
            currState.SetButtonPress(VRModuleRawButton.Touchpad, padPress);
            currState.SetButtonPress(VRModuleRawButton.Trigger, triggerPress);
            currState.SetButtonPress(VRModuleRawButton.Grip, grip >= 1f);

            currState.SetButtonTouch(VRModuleRawButton.Touchpad, padTouch);
            currState.SetButtonTouch(VRModuleRawButton.Trigger, AxisToPress(prevState.GetButtonPress(VRModuleRawButton.Trigger), trigger, 0.25f, 0.20f));

            currState.SetAxisValue(VRModuleRawAxis.TouchpadX, padX);
            currState.SetAxisValue(VRModuleRawAxis.TouchpadY, -padY);
            currState.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            currState.SetAxisValue(VRModuleRawAxis.JoystickX, stickX);
            currState.SetAxisValue(VRModuleRawAxis.JoystickY, -stickY);
        }
        private static void Update_L_OculusTouch(IVRModuleDeviceState prevState, IVRModuleDeviceStateRW currState)
        {
            var xPress       = GetUnityButton(2);
            var yPress       = GetUnityButton(3);
            var stickPress   = GetUnityButton(8);
            var gripPress    = GetUnityButton(4);
            var xTouch       = GetUnityButton(12);
            var yTouch       = GetUnityButton(13);
            var triggerTouch = GetUnityButton(14);
            var stickTouch   = GetUnityButton(16);

            var stickX  = GetUnityAxis(1);
            var stickY  = GetUnityAxis(2);
            var trigger = GetUnityAxis(9);
            var grip    = GetUnityAxis(11);

            currState.SetButtonPress(VRModuleRawButton.ApplicationMenu, yPress);
            currState.SetButtonPress(VRModuleRawButton.A, xPress);
            currState.SetButtonPress(VRModuleRawButton.Touchpad, stickPress);
            currState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(prevState.GetButtonPress(VRModuleRawButton.Trigger), trigger, 0.55f, 0.45f));
            currState.SetButtonPress(VRModuleRawButton.Grip, gripPress);
            currState.SetButtonPress(VRModuleRawButton.CapSenseGrip, gripPress);

            currState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, yTouch);
            currState.SetButtonTouch(VRModuleRawButton.A, xTouch);
            currState.SetButtonTouch(VRModuleRawButton.Touchpad, stickTouch);
            currState.SetButtonTouch(VRModuleRawButton.Trigger, triggerTouch);
            currState.SetButtonTouch(VRModuleRawButton.Grip, grip >= 0.05f);
            currState.SetButtonTouch(VRModuleRawButton.CapSenseGrip, grip >= 0.05f);

            currState.SetAxisValue(VRModuleRawAxis.TouchpadX, stickX);
            currState.SetAxisValue(VRModuleRawAxis.TouchpadY, -stickY);
            currState.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            currState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
        }
예제 #4
0
        private void UpdateTrackingState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            Vector3 position = Vector3.zero;

            if (device.TryGetFeatureValue(CommonUsages.devicePosition, out position))
            {
                state.position = position;
            }

            Quaternion rotation = Quaternion.identity;

            if (device.TryGetFeatureValue(CommonUsages.deviceRotation, out rotation))
            {
                state.rotation = rotation;
            }

            Vector3 velocity = Vector3.zero;

            if (device.TryGetFeatureValue(CommonUsages.deviceVelocity, out velocity))
            {
                state.velocity = velocity;
            }

            Vector3 angularVelocity = Vector3.zero;

            if (device.TryGetFeatureValue(CommonUsages.deviceAngularVelocity, out angularVelocity))
            {
                state.angularVelocity = angularVelocity;
            }
        }
예제 #5
0
        private static void UpdateDeviceJoints(IVRModuleDeviceStateRW state, ref HandResultData resultData, bool isLeft)
        {
            var joints    = resultData.rawData.points;
            var rotations = resultData.rawData.rotations;

            state.pose = new RigidPose(joints[0], rotations[0] * rotOffset);

            state.handJoints[HandJointName.Wrist] = new JointPose(new RigidPose(joints[0], rotations[0] * rotOffset));

            state.handJoints[HandJointName.ThumbMetacarpal] = new JointPose(new RigidPose(joints[1], rotations[1] * rotOffset));
            state.handJoints[HandJointName.ThumbProximal]   = new JointPose(new RigidPose(joints[2], rotations[2] * rotOffset));
            state.handJoints[HandJointName.ThumbDistal]     = new JointPose(new RigidPose(joints[3], rotations[3] * rotOffset));
            state.handJoints[HandJointName.ThumbTip]        = new JointPose(new RigidPose(joints[4], rotations[4] * rotOffset));

            state.handJoints[HandJointName.IndexProximal]     = new JointPose(new RigidPose(joints[5], rotations[5] * rotOffset));
            state.handJoints[HandJointName.IndexIntermediate] = new JointPose(new RigidPose(joints[6], rotations[6] * rotOffset));
            state.handJoints[HandJointName.IndexDistal]       = new JointPose(new RigidPose(joints[7], rotations[7] * rotOffset));
            state.handJoints[HandJointName.IndexTip]          = new JointPose(new RigidPose(joints[8], rotations[8] * rotOffset));

            state.handJoints[HandJointName.MiddleProximal]     = new JointPose(new RigidPose(joints[9], rotations[9] * rotOffset));
            state.handJoints[HandJointName.MiddleIntermediate] = new JointPose(new RigidPose(joints[10], rotations[10] * rotOffset));
            state.handJoints[HandJointName.MiddleDistal]       = new JointPose(new RigidPose(joints[11], rotations[11] * rotOffset));
            state.handJoints[HandJointName.MiddleTip]          = new JointPose(new RigidPose(joints[12], rotations[12] * rotOffset));

            state.handJoints[HandJointName.RingProximal]     = new JointPose(new RigidPose(joints[13], rotations[13] * rotOffset));
            state.handJoints[HandJointName.RingIntermediate] = new JointPose(new RigidPose(joints[14], rotations[14] * rotOffset));
            state.handJoints[HandJointName.RingDistal]       = new JointPose(new RigidPose(joints[15], rotations[15] * rotOffset));
            state.handJoints[HandJointName.RingTip]          = new JointPose(new RigidPose(joints[16], rotations[16] * rotOffset));

            state.handJoints[HandJointName.PinkyProximal]     = new JointPose(new RigidPose(joints[17], rotations[17] * rotOffset));
            state.handJoints[HandJointName.PinkyIntermediate] = new JointPose(new RigidPose(joints[18], rotations[18] * rotOffset));
            state.handJoints[HandJointName.PinkyDistal]       = new JointPose(new RigidPose(joints[19], rotations[19] * rotOffset));
            state.handJoints[HandJointName.PinkyTip]          = new JointPose(new RigidPose(joints[20], rotations[20] * rotOffset));
        }
예제 #6
0
        private void UpdateViveFocusFinchControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            bool    primary2DAxisClick   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisClick);                      // Touchpad
            bool    primary2DAxisTouch   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisTouch);                      // Touchpad
            bool    secondary2DAxisClick = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("Secondary2DAxisClick")); // No data
            bool    secondary2DAxisTouch = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("Secondary2DAxisTouch")); // No data
            bool    gripButton           = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);                              // Trigger
            bool    menuButton           = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);                              // No Data
            float   trigger         = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);                                      // No Data
            Vector2 primary2DAxis   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxis);                                // Touchpad
            Vector2 secondary2DAxis = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxis);                              // No data
            Vector2 dPad            = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <Vector2>("DPad"));                   // No Data

            state.SetButtonPress(VRModuleRawButton.Touchpad, primary2DAxisClick);
            state.SetButtonPress(VRModuleRawButton.Trigger, gripButton);
            state.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuButton);
            state.SetButtonPress(VRModuleRawButton.DPadUp, dPad.y > 0);
            state.SetButtonPress(VRModuleRawButton.DPadDown, dPad.y < 0);
            state.SetButtonPress(VRModuleRawButton.DPadLeft, dPad.x < 0);
            state.SetButtonPress(VRModuleRawButton.DPadRight, dPad.x > 0);

            state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);

            state.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxis.x);
            state.SetAxisValue(VRModuleRawAxis.TouchpadY, primary2DAxis.y);
        }
예제 #7
0
        private void UpdateMagicLeapControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            bool    menuButton         = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
            bool    secondaryButton    = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondaryButton); // Bumper
            bool    triggerButton      = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);
            bool    primary2DAxisTouch = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisTouch);
            uint    MLControllerType   = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <uint>("MLControllerType"));                             // Not in use
            uint    MLControllerDOF    = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <uint>("MLControllerDOF"));                              // Not in use
            uint    MLControllerCalibrationAccuracy = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <uint>("MLControllerCalibrationAccuracy")); // Not in use
            float   trigger = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);
            float   MLControllerTouch1Force = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <float>("MLControllerTouch1Force"));                // Not in use
            float   MLControllerTouch2Force = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <float>("MLControllerTouch2Force"));                // Not in use
            Vector2 primary2DAxis           = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxis);
            Vector2 secondary2DAxis         = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxis);                                            // Not in use

            state.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuButton);
            state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);
            state.SetButtonPress(VRModuleRawButton.Bumper, secondaryButton);

            state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);

            state.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxis.x);
            state.SetAxisValue(VRModuleRawAxis.TouchpadY, primary2DAxis.y);
        }
예제 #8
0
        private static void Update_R_Vive(IVRModuleDeviceState prevState, IVRModuleDeviceStateRW currState)
        {
            var primaryButtonPress = GetUnityButton(1);
            var menuPress          = GetUnityButton(0);
            var padPress           = GetUnityButton(9);
            var triggerTouch       = GetUnityButton(15);
            var padTouch           = GetUnityButton(17);

            var padX    = GetUnityAxis(4);
            var padY    = GetUnityAxis(5);
            var trigger = GetUnityAxis(10);
            var grip    = GetUnityAxis(12);

            currState.SetButtonPress(VRModuleRawButton.A, primaryButtonPress);
            currState.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuPress);
            currState.SetButtonPress(VRModuleRawButton.Touchpad, padPress);
            currState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(prevState.GetButtonPress(VRModuleRawButton.Trigger), trigger, 0.55f, 0.45f));
            currState.SetButtonPress(VRModuleRawButton.Grip, grip >= 1.0f);

            currState.SetButtonTouch(VRModuleRawButton.Touchpad, padTouch);
            currState.SetButtonTouch(VRModuleRawButton.Trigger, triggerTouch);

            currState.SetAxisValue(VRModuleRawAxis.TouchpadX, padX);
            currState.SetAxisValue(VRModuleRawAxis.TouchpadY, -padY);
            currState.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
        }
예제 #9
0
        private void HandleDeviceInput(IVRModuleDeviceStateRW deviceState)
        {
            var leftPressed  = Input.GetMouseButton(0);
            var rightPressed = Input.GetMouseButton(1);
            var midPressed   = Input.GetMouseButton(2);

            deviceState.SetButtonPress(VRModuleRawButton.Trigger, leftPressed);
            deviceState.SetButtonTouch(VRModuleRawButton.Trigger, leftPressed);
            deviceState.SetAxisValue(VRModuleRawAxis.Trigger, leftPressed ? 1f : 0f);

            deviceState.SetButtonPress(VRModuleRawButton.Grip, midPressed);
            deviceState.SetButtonTouch(VRModuleRawButton.Grip, midPressed);
            deviceState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, midPressed ? 1f : 0f);

            deviceState.SetButtonPress(VRModuleRawButton.Touchpad, rightPressed);

            deviceState.SetButtonPress(VRModuleRawButton.ApplicationMenu, IsMenuKeyDown());
            deviceState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, IsMenuKeyDown());

            if (VIUSettings.simulateTrackpadTouch && IsShiftKeyPressed())
            {
                deviceState.SetButtonTouch(VRModuleRawButton.Touchpad, true);
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadX, deviceState.GetAxisValue(VRModuleRawAxis.TouchpadX) + (Input.GetAxisRaw("Mouse X") * 0.1f));
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadY, deviceState.GetAxisValue(VRModuleRawAxis.TouchpadY) + (Input.GetAxisRaw("Mouse Y") * 0.1f));
            }
            else
            {
                deviceState.SetButtonTouch(VRModuleRawButton.Touchpad, rightPressed);
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadX, 0f);
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadY, 0f);
            }
        }
예제 #10
0
        private static void Update_R_OculusTouch(IVRModuleDeviceState prevState, IVRModuleDeviceStateRW currState)
        {
            var aPress       = GetUnityButton(0);
            var bPress       = GetUnityButton(1);
            var stickPress   = GetUnityButton(9);
            var gripPress    = GetUnityButton(5);
            var aTouch       = GetUnityButton(10);
            var bTouch       = GetUnityButton(11);
            var triggerTouch = GetUnityButton(15);
            var stickTouch   = GetUnityButton(17);

            var stickX  = GetUnityAxis(4);
            var stickY  = GetUnityAxis(5);
            var trigger = GetUnityAxis(10);
            var grip    = GetUnityAxis(12);

            currState.SetButtonPress(VRModuleRawButton.ApplicationMenu, bPress);
            currState.SetButtonPress(VRModuleRawButton.A, aPress);
            currState.SetButtonPress(VRModuleRawButton.Touchpad, stickPress);
            currState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(prevState.GetButtonPress(VRModuleRawButton.Trigger), trigger, 0.55f, 0.45f));
            currState.SetButtonPress(VRModuleRawButton.Grip, gripPress);
            currState.SetButtonPress(VRModuleRawButton.CapSenseGrip, gripPress);

            currState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, bTouch);
            currState.SetButtonTouch(VRModuleRawButton.A, aTouch);
            currState.SetButtonTouch(VRModuleRawButton.Touchpad, stickTouch);
            currState.SetButtonTouch(VRModuleRawButton.Trigger, triggerTouch);
            currState.SetButtonTouch(VRModuleRawButton.Grip, grip >= 0.05f);
            currState.SetButtonTouch(VRModuleRawButton.CapSenseGrip, grip >= 0.05f);

            currState.SetAxisValue(VRModuleRawAxis.TouchpadX, stickX);
            currState.SetAxisValue(VRModuleRawAxis.TouchpadY, -stickY);
            currState.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            currState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
        }
예제 #11
0
        private static void Update_R_Knuckles(IVRModuleDeviceState prevState, IVRModuleDeviceStateRW currState)
        {
            var innerPress   = GetUnityButton(0);
            var outerPress   = GetUnityButton(1);
            var padPress     = GetUnityButton(9);
            var triggerTouch = GetUnityButton(15);
            var padTouch     = GetUnityButton(17);

            var padX    = GetUnityAxis(4);
            var padY    = GetUnityAxis(5);
            var trigger = GetUnityAxis(10);
            var grip    = GetUnityAxis(12);
            var index   = GetUnityAxis(21);
            var middle  = GetUnityAxis(23);
            var ring    = GetUnityAxis(25);
            var pinky   = GetUnityAxis(27);

            currState.SetButtonPress(VRModuleRawButton.ApplicationMenu, outerPress);
            currState.SetButtonPress(VRModuleRawButton.A, innerPress);
            currState.SetButtonPress(VRModuleRawButton.Touchpad, padPress);
            currState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(prevState.GetButtonPress(VRModuleRawButton.Trigger), trigger, 0.55f, 0.45f));
            currState.SetButtonPress(VRModuleRawButton.Grip, grip >= 1.0f);

            currState.SetButtonTouch(VRModuleRawButton.Touchpad, padTouch);
            currState.SetButtonTouch(VRModuleRawButton.Trigger, triggerTouch);

            currState.SetAxisValue(VRModuleRawAxis.TouchpadX, padX);
            currState.SetAxisValue(VRModuleRawAxis.TouchpadY, -padY);
            currState.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            currState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
            currState.SetAxisValue(VRModuleRawAxis.IndexCurl, index);
            currState.SetAxisValue(VRModuleRawAxis.MiddleCurl, middle);
            currState.SetAxisValue(VRModuleRawAxis.RingCurl, ring);
            currState.SetAxisValue(VRModuleRawAxis.PinkyCurl, pinky);
        }
예제 #12
0
 public override void OnDeactivated()
 {
     m_headState  = null;
     m_rightState = null;
     m_leftState  = null;
     ResetTouchState();
 }
예제 #13
0
        private void UpdateWaveCRControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            bool    primary2DAxisClick   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisClick);
            bool    primary2DAxisTouch   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisTouch);
            bool    secondary2DAxisClick = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("Secondary2DAxisClick"));
            bool    secondary2DAxisTouch = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("Secondary2DAxisTouch"));
            bool    primaryButton        = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryButton);
            bool    secondaryButton      = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondaryButton);
            bool    menuButton           = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
            bool    triggerButton        = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);
            bool    triggerTouch         = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("TriggerTouch"));
            bool    gripButton           = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);
            bool    gripTouch            = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("GripTouch"));
            float   trigger         = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);
            float   grip            = GetDeviceFeatureValueOrDefault(device, CommonUsages.grip);
            Vector2 primary2DAxis   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxis);
            Vector2 secondary2DAxis = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxis);
            Vector2 dPad            = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <Vector2>("DPad"));

            state.SetButtonPress(VRModuleRawButton.Touchpad, primary2DAxisClick);
            state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);
            state.SetButtonPress(VRModuleRawButton.A, primaryButton);
            state.SetButtonPress(VRModuleRawButton.ApplicationMenu, secondaryButton);
            state.SetButtonPress(VRModuleRawButton.System, menuButton);
            state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);
            state.SetButtonTouch(VRModuleRawButton.Trigger, triggerTouch);
            state.SetButtonPress(VRModuleRawButton.Grip, gripButton);
            state.SetButtonTouch(VRModuleRawButton.Grip, gripTouch);
            state.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
            state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxis.x);
            state.SetAxisValue(VRModuleRawAxis.TouchpadY, primary2DAxis.y);
        }
        private static void UpdateDeviceJoints(IVRModuleDeviceStateRW state, Vector3[] rawJoints, bool isLeft)
        {
            var hmdPose = VRModule.GetDeviceState(VRModule.HMD_DEVICE_INDEX).pose;

            GestureInterface.SetCameraTransform(hmdPose.pos, hmdPose.rot);
            var roomSpaceWrist2index  = rawJoints[5] - rawJoints[0];
            var roomSpaceWrist2middle = rawJoints[9] - rawJoints[0];
            var roomSpaceWrist2pinky  = rawJoints[17] - rawJoints[0];
            var roomSpaceWristUp      = isLeft ? Vector3.Cross(roomSpaceWrist2pinky, roomSpaceWrist2index) : Vector3.Cross(roomSpaceWrist2index, roomSpaceWrist2pinky);
            var roomSpaceWristPose    = new RigidPose(rawJoints[0], Quaternion.LookRotation(roomSpaceWrist2middle, roomSpaceWristUp));

            state.pose = roomSpaceWristPose;
            state.handJoints[HandJointName.Wrist] = new JointPose(roomSpaceWristPose);
            state.handJoints[HandJointName.Palm]  = new JointPose(new RigidPose((rawJoints[0] + rawJoints[9]) * 0.5f, roomSpaceWristPose.rot));

            var        camSpaceFingerRight = roomSpaceWristPose.rot * Vector3.right;
            Quaternion roomSpaceRot;

            roomSpaceRot = CalculateJointRot(rawJoints, 1, 2, roomSpaceWristPose.rot * (isLeft ? new Vector3(0.1f, -5.67f, -0.1f) : new Vector3(0.1f, 5.67f, 0.1f)));
            state.handJoints[HandJointName.ThumbMetacarpal] = new JointPose(new RigidPose(rawJoints[1], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 2, 3, roomSpaceWristPose.rot * (isLeft ? new Vector3(0.1f, -5.67f, -0.1f) : new Vector3(0.1f, 5.67f, 0.1f)));
            state.handJoints[HandJointName.ThumbProximal] = new JointPose(new RigidPose(rawJoints[2], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 3, 4, roomSpaceWristPose.rot * (isLeft ? new Vector3(1.72f, -5.67f, -3.55f) : new Vector3(1.72f, 5.67f, 3.55f)));
            state.handJoints[HandJointName.ThumbDistal] = new JointPose(new RigidPose(rawJoints[3], roomSpaceRot));
            state.handJoints[HandJointName.ThumbTip]    = new JointPose(new RigidPose(rawJoints[4], roomSpaceRot));

            roomSpaceRot = CalculateJointRot(rawJoints, 5, 6, camSpaceFingerRight);
            state.handJoints[HandJointName.IndexProximal] = new JointPose(new RigidPose(rawJoints[5], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 6, 7, camSpaceFingerRight);
            state.handJoints[HandJointName.IndexIntermediate] = new JointPose(new RigidPose(rawJoints[6], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 7, 8, camSpaceFingerRight);
            state.handJoints[HandJointName.IndexDistal] = new JointPose(new RigidPose(rawJoints[7], roomSpaceRot));
            state.handJoints[HandJointName.IndexTip]    = new JointPose(new RigidPose(rawJoints[8], roomSpaceRot));

            roomSpaceRot = CalculateJointRot(rawJoints, 9, 10, camSpaceFingerRight);
            state.handJoints[HandJointName.MiddleProximal] = new JointPose(new RigidPose(rawJoints[9], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 10, 11, camSpaceFingerRight);
            state.handJoints[HandJointName.MiddleIntermediate] = new JointPose(new RigidPose(rawJoints[10], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 11, 12, camSpaceFingerRight);
            state.handJoints[HandJointName.MiddleDistal] = new JointPose(new RigidPose(rawJoints[11], roomSpaceRot));
            state.handJoints[HandJointName.MiddleTip]    = new JointPose(new RigidPose(rawJoints[12], roomSpaceRot));

            roomSpaceRot = CalculateJointRot(rawJoints, 13, 14, camSpaceFingerRight);
            state.handJoints[HandJointName.RingProximal] = new JointPose(new RigidPose(rawJoints[13], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 14, 15, camSpaceFingerRight);
            state.handJoints[HandJointName.RingIntermediate] = new JointPose(new RigidPose(rawJoints[14], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 15, 16, camSpaceFingerRight);
            state.handJoints[HandJointName.RingDistal] = new JointPose(new RigidPose(rawJoints[15], roomSpaceRot));
            state.handJoints[HandJointName.RingTip]    = new JointPose(new RigidPose(rawJoints[16], roomSpaceRot));

            roomSpaceRot = CalculateJointRot(rawJoints, 17, 18, camSpaceFingerRight);
            state.handJoints[HandJointName.PinkyProximal] = new JointPose(new RigidPose(rawJoints[17], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 18, 19, camSpaceFingerRight);
            state.handJoints[HandJointName.PinkyIntermediate] = new JointPose(new RigidPose(rawJoints[18], roomSpaceRot));
            roomSpaceRot = CalculateJointRot(rawJoints, 19, 20, camSpaceFingerRight);
            state.handJoints[HandJointName.PinkyDistal] = new JointPose(new RigidPose(rawJoints[19], roomSpaceRot));
            state.handJoints[HandJointName.PinkyTip]    = new JointPose(new RigidPose(rawJoints[20], roomSpaceRot));
        }
예제 #15
0
        protected override void UpdateInputDevicesControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            var updateFunc = updateControllerStateDelegates[state.deviceIndex];

            if (updateFunc != null)
            {
                updateFunc(state, device);
            }
        }
예제 #16
0
            public void UpdateDeviceInput(IVRModuleDeviceStateRW state, bool isLeft)
            {
                var pinch   = isLeft ? pinchData.left : pinchData.right;
                var pinched = pinch.pinch.strength >= 0.95f;

                state.SetButtonPress(VRModuleRawButton.GestureIndexPinch, pinched);
                state.SetButtonTouch(VRModuleRawButton.GestureIndexPinch, pinched);
                state.SetAxisValue(VRModuleRawAxis.Trigger, pinch.pinch.strength);
            }
예제 #17
0
        private void HandleDeviceInput(IVRModuleDeviceStateRW deviceState)
        {
            //var leftPressed = Input.GetMouseButton(0);
            //var rightPressed = Input.GetMouseButton(1);
            //var midPressed = Input.GetMouseButton(2);

            bool leftPressed;
            bool rightPressed;
            bool midPressed;

            if ((PlatformType)Enum.Parse(typeof(PlatformType), PlayerPrefs.GetString("CurrentPlateform", "PC")) == PlatformType.PC)
            {
                leftPressed  = Input.GetMouseButton(0);
                rightPressed = Input.GetMouseButton(1);
                midPressed   = Input.GetMouseButton(2);
            }
            else if ((PlatformType)Enum.Parse(typeof(PlatformType), PlayerPrefs.GetString("CurrentPlateform", "PC")) == PlatformType.zSpace)
            {
                ZCore _zCore = GameObject.FindObjectOfType <ZCore>();
                midPressed   = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 1);
                leftPressed  = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 0);
                rightPressed = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 2);
            }
            else
            {
                leftPressed  = Input.GetMouseButton(0);
                rightPressed = Input.GetMouseButton(1);
                midPressed   = Input.GetMouseButton(2);
            }
            //Debug.LogError(leftPressed+"|" + midPressed + "|" + midPressed);
            deviceState.SetButtonPress(VRModuleRawButton.Trigger, leftPressed);
            deviceState.SetButtonTouch(VRModuleRawButton.Trigger, leftPressed);
            deviceState.SetAxisValue(VRModuleRawAxis.Trigger, leftPressed ? 1f : 0f);

            deviceState.SetButtonPress(VRModuleRawButton.Grip, midPressed);
            deviceState.SetButtonTouch(VRModuleRawButton.Grip, midPressed);
            deviceState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, midPressed ? 1f : 0f);

            deviceState.SetButtonPress(VRModuleRawButton.Touchpad, rightPressed);

            deviceState.SetButtonPress(VRModuleRawButton.ApplicationMenu, IsMenuKeyDown());
            deviceState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, IsMenuKeyDown());

            if (VIUSettings.simulateTrackpadTouch && IsShiftKeyPressed())
            {
                deviceState.SetButtonTouch(VRModuleRawButton.Touchpad, true);
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadX, deviceState.GetAxisValue(VRModuleRawAxis.TouchpadX) + (Input.GetAxisRaw("Mouse X") * 0.1f));
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadY, deviceState.GetAxisValue(VRModuleRawAxis.TouchpadY) + (Input.GetAxisRaw("Mouse Y") * 0.1f));
            }
            else
            {
                deviceState.SetButtonTouch(VRModuleRawButton.Touchpad, rightPressed);
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadX, 0f);
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadY, 0f);
            }
        }
예제 #18
0
        public override void OnDeactivated()
        {
            WaveVR_Utils.Event.Remove(WaveVR_Utils.Event.NEW_POSES, OnNewPoses);

            m_headState  = null;
            m_rightState = null;
            m_leftState  = null;
            ResetTouchState();

            s_moduleInstance = null;
        }
예제 #19
0
        private void UpdateOculusControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            bool    primaryButton      = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryButton);   // X/A
            bool    secondaryButton    = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondaryButton); // Y/B
            bool    triggerButton      = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);
            bool    gripButton         = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);
            bool    primaryTouch       = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryTouch);       // X/A
            bool    secondaryTouch     = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondaryTouch);     // Y/B
            bool    primary2DAxisClick = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisClick); // Joystick
            bool    primary2DAxisTouch = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisTouch); // Joystick
            float   trigger            = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);
            float   grip          = GetDeviceFeatureValueOrDefault(device, CommonUsages.grip);
            Vector2 primary2DAxis = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxis); // Joystick

            state.SetButtonPress(VRModuleRawButton.A, primaryButton);
            state.SetButtonPress(VRModuleRawButton.ApplicationMenu, secondaryButton);
            state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);
            state.SetButtonPress(VRModuleRawButton.Grip, gripButton);
            state.SetButtonPress(VRModuleRawButton.CapSenseGrip, gripButton);
            state.SetButtonPress(VRModuleRawButton.Axis0, primary2DAxisClick);

            state.SetButtonTouch(VRModuleRawButton.A, primaryTouch);
            state.SetButtonTouch(VRModuleRawButton.ApplicationMenu, secondaryTouch);
            state.SetButtonTouch(VRModuleRawButton.Grip, grip >= 0.05f);
            state.SetButtonTouch(VRModuleRawButton.CapSenseGrip, grip >= 0.05f);
            state.SetButtonTouch(VRModuleRawButton.Axis0, primary2DAxisTouch);

            state.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
            state.SetAxisValue(VRModuleRawAxis.JoystickX, primary2DAxis.x);
            state.SetAxisValue(VRModuleRawAxis.JoystickY, primary2DAxis.y);

            if (m_currentInputSubsystemType == XRInputSubsystemType.OpenVR)
            {
                bool triggerTouch = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("TriggerTouch"));
                state.SetButtonTouch(VRModuleRawButton.Trigger, triggerTouch);
            }
            else if (m_currentInputSubsystemType == XRInputSubsystemType.Oculus)
            {
                bool  thumbrest  = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("Thumbrest"));
                float indexTouch = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <float>("IndexTouch"));
                float thumbTouch = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <float>("ThumbTouch")); // Not in use

                state.SetButtonTouch(VRModuleRawButton.Touchpad, thumbrest);
                state.SetButtonTouch(VRModuleRawButton.Trigger, indexTouch >= 1.0f);

                if ((device.characteristics & InputDeviceCharacteristics.Left) != 0)
                {
                    bool menuButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
                    state.SetButtonPress(VRModuleRawButton.System, menuButton);
                }
            }
        }
예제 #20
0
        private IVRModuleDeviceStateRW UpdateDevicePose(uint deviceIndex, WaveVR.Device content)
        {
            IVRModuleDeviceState   prevState;
            IVRModuleDeviceStateRW currState;

            EnsureValidDeviceState(deviceIndex, out prevState, out currState);

            var deviceConnected = content.type == WVR_DeviceType.WVR_DeviceType_HMD ? true : content.connected;

            if (!deviceConnected)
            {
                if (prevState.isConnected)
                {
                    currState.Reset();

                    switch (content.type)
                    {
                    case WVR_DeviceType.WVR_DeviceType_HMD: m_headState = null; break;

                    case WVR_DeviceType.WVR_DeviceType_Controller_Right: m_rightState = null; break;

                    case WVR_DeviceType.WVR_DeviceType_Controller_Left: m_leftState = null; break;
                    }
                }
            }
            else
            {
                if (!prevState.isConnected)
                {
                    currState.isConnected     = true;
                    currState.deviceClass     = s_type2class[(int)content.type];
                    currState.deviceModel     = s_type2model[(int)content.type];
                    currState.serialNumber    = content.type.ToString();
                    currState.modelNumber     = content.type.ToString();
                    currState.renderModelName = content.type.ToString();
                }

                // update pose
                var devicePose = content.pose.pose;
                currState.velocity        = new Vector3(devicePose.Velocity.v0, devicePose.Velocity.v1, -devicePose.Velocity.v2);
                currState.angularVelocity = new Vector3(-devicePose.AngularVelocity.v0, -devicePose.AngularVelocity.v1, devicePose.AngularVelocity.v2);

                var rigidTransform = content.rigidTransform;
                currState.position = rigidTransform.pos;
                currState.rotation = rigidTransform.rot;

                currState.isPoseValid = devicePose.IsValidPose;
            }

            return(currState);
        }
예제 #21
0
        private void UpdateKhronosSimpleControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            bool primaryButton = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryButton);
            bool menuButton    = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);

            state.SetButtonPress(VRModuleRawButton.A, primaryButton);
            state.SetButtonPress(VRModuleRawButton.ApplicationMenu, menuButton);

            // Unused
            // [Vector3] PointerPosition
            // [Quaternion] PointerRotation
            // [Vector3] PointerVelocity
            // [Vector3] PointerAngularVelocity
        }
예제 #22
0
        private void UpdateControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            switch (state.deviceModel)
            {
            case VRModuleDeviceModel.ViveController:
                UpdateViveControllerState(state, device);
                break;

            case VRModuleDeviceModel.ViveCosmosControllerLeft:
            case VRModuleDeviceModel.ViveCosmosControllerRight:
                UpdateViveCosmosControllerState(state, device);
                break;

            case VRModuleDeviceModel.ViveTracker:
                UpdateViveTrackerState(state, device);
                break;

            case VRModuleDeviceModel.OculusTouchLeft:
            case VRModuleDeviceModel.OculusTouchRight:
            case VRModuleDeviceModel.OculusGoController:
            case VRModuleDeviceModel.OculusQuestControllerLeft:
            case VRModuleDeviceModel.OculusQuestControllerRight:
                UpdateOculusControllerState(state, device);
                break;

            case VRModuleDeviceModel.WMRControllerLeft:
            case VRModuleDeviceModel.WMRControllerRight:
                UpdateWMRControllerState(state, device);
                break;

            case VRModuleDeviceModel.KnucklesLeft:
            case VRModuleDeviceModel.KnucklesRight:
            case VRModuleDeviceModel.IndexControllerLeft:
            case VRModuleDeviceModel.IndexControllerRight:
                UpdateIndexControllerState(state, device);
                break;

            case VRModuleDeviceModel.MagicLeapController:
                UpdateMagicLeapControllerState(state, device);
                break;

            case VRModuleDeviceModel.ViveFocusChirp:
                UpdateViveFocusChirpControllerState(state, device);
                break;

            case VRModuleDeviceModel.ViveFocusFinch:
                UpdateViveFocusFinchControllerState(state, device);
                break;
            }
        }
예제 #23
0
            public void UpdateGestureInput(IVRModuleDeviceStateRW state, bool isLeft)
            {
                var gesture = isLeft ? gestureData.left : gestureData.right;

                state.SetButtonPress(VRModuleRawButton.GestureFist, gesture == WVR_HandGestureType.WVR_HandGestureType_Fist);
                state.SetButtonPress(VRModuleRawButton.GestureFive, gesture == WVR_HandGestureType.WVR_HandGestureType_Five);
                state.SetButtonPress(VRModuleRawButton.GestureIndexUp, gesture == WVR_HandGestureType.WVR_HandGestureType_IndexUp);
                state.SetButtonPress(VRModuleRawButton.GestureOk, gesture == WVR_HandGestureType.WVR_HandGestureType_OK);
                state.SetButtonPress(VRModuleRawButton.GestureThumbUp, gesture == WVR_HandGestureType.WVR_HandGestureType_ThumbUp);
                state.SetButtonTouch(VRModuleRawButton.GestureFist, gesture == WVR_HandGestureType.WVR_HandGestureType_Fist);
                state.SetButtonTouch(VRModuleRawButton.GestureFive, gesture == WVR_HandGestureType.WVR_HandGestureType_Five);
                state.SetButtonTouch(VRModuleRawButton.GestureIndexUp, gesture == WVR_HandGestureType.WVR_HandGestureType_IndexUp);
                state.SetButtonTouch(VRModuleRawButton.GestureOk, gesture == WVR_HandGestureType.WVR_HandGestureType_OK);
                state.SetButtonTouch(VRModuleRawButton.GestureThumbUp, gesture == WVR_HandGestureType.WVR_HandGestureType_ThumbUp);
            }
예제 #24
0
            public void UpdateJoints(IVRModuleDeviceStateRW state, bool isLeft)
            {
                var data = isLeft ? trackingData.left : trackingData.right;
                var pose = isLeft ? s_NaturalHandJointsPoseLeft : s_NaturalHandJointsPoseRight;

                for (int i = 0; i < trackerInfo.jointCount; i++)
                {
                    var p = default(RigidPose);
                    Coordinate.GetVectorFromGL(pose[i].position, out p.pos);
                    Coordinate.GetQuaternionFromGL(pose[i].rotation, out p.rot);
                    state.handJoints[handJointMapping[s_NaturalHandJoints[i]]] = new JointPose(p);
                }

                state.isPoseValid = data.isValidPose;
                state.pose        = state.handJoints[HandJointName.Wrist].pose;
            }
예제 #25
0
        private void OnNewPoses(params object[] args)
        {
            if (WaveVR.Instance == null)
            {
                return;
            }

            FlushDeviceState();

            var headDevice = GetWVRDevice(WVR_DeviceType.WVR_DeviceType_HMD);

            m_headState = UpdateDevicePose(0, headDevice);
            var rightDevice = GetWVRDevice(WVR_DeviceType.WVR_DeviceType_Controller_Right);

            m_rightState = UpdateDevicePose(1, rightDevice);
            var leftDevice = GetWVRDevice(WVR_DeviceType.WVR_DeviceType_Controller_Left);

            m_leftState = UpdateDevicePose(2, leftDevice);

#if VIU_WAVEVR_3_0_0_OR_NEWER
            if (WaveVR_Controller.IsLeftHanded)
            {
                m_deviceHands[RIGHT_INDEX] = WaveVR_ControllerLoader.ControllerHand.Non_Dominant;
                m_deviceHands[LEFT_INDEX]  = WaveVR_ControllerLoader.ControllerHand.Dominant;
            }
            else
            {
                m_deviceHands[RIGHT_INDEX] = WaveVR_ControllerLoader.ControllerHand.Dominant;
                m_deviceHands[LEFT_INDEX]  = WaveVR_ControllerLoader.ControllerHand.Non_Dominant;
            }
#endif


            if (m_rightState != null && !rightDevice.pose.pose.Is6DoFPose)
            {
                ApplyVirtualArmAndSimulateInput(m_rightState, m_headState, RIGHT_ARM_MULTIPLIER);
            }

            if (m_leftState != null && !leftDevice.pose.pose.Is6DoFPose)
            {
                ApplyVirtualArmAndSimulateInput(m_leftState, m_headState, LEFT_ARM_MULTIPLIER);
            }

            ProcessConnectedDeviceChanged();
            ProcessDevicePoseChanged();
        }
예제 #26
0
        private void ControlCamera(IVRModuleDeviceStateRW deviceState)
        {
            var pose = deviceState.pose;
            var poseEuler = pose.rot.eulerAngles;
            var deltaKeyAngle = Time.unscaledDeltaTime * VIUSettings.simulatorKeyRotateSpeed;

            poseEuler.x = Mathf.Repeat(poseEuler.x + 180f, 360f) - 180f;

            if (Input.GetKey(KeyCode.K))
            {
                if (poseEuler.x < 90f && poseEuler.x > -180f)
                {
                    poseEuler.x = Mathf.Min(90f, poseEuler.x + deltaKeyAngle);
                }
            }

            if (Input.GetKey(KeyCode.I))
            {
                if (poseEuler.x < 180f && poseEuler.x > -90f)
                {
                    poseEuler.x = Mathf.Max(-90f, poseEuler.x - deltaKeyAngle);
                }
            }

            if (Input.GetKey(KeyCode.L)) { poseEuler.y += deltaKeyAngle; }
            if (Input.GetKey(KeyCode.J)) { poseEuler.y -= deltaKeyAngle; }

            if (Input.GetKey(KeyCode.N)) { poseEuler.z += deltaKeyAngle; }
            if (Input.GetKey(KeyCode.V)) { poseEuler.z -= deltaKeyAngle; }
            if (Input.GetKey(KeyCode.B)) { poseEuler.z = 0f; }

            pose.rot = Quaternion.Euler(poseEuler);

            var deltaMove = Time.unscaledDeltaTime * VIUSettings.simulatorKeyMoveSpeed;
            var moveForward = Quaternion.Euler(0f, poseEuler.y, 0f) * Vector3.forward;
            var moveRight = Quaternion.Euler(0f, poseEuler.y, 0f) * Vector3.right;
            if (Input.GetKey(KeyCode.H)) { pose.pos += moveRight * deltaMove; }
            if (Input.GetKey(KeyCode.F)) { pose.pos -= moveRight * deltaMove; }
            if (Input.GetKey(KeyCode.Y)) { pose.pos += Vector3.up * deltaMove; }
            if (Input.GetKey(KeyCode.R)) { pose.pos -= Vector3.up * deltaMove; }
            if (Input.GetKey(KeyCode.T)) { pose.pos += moveForward * deltaMove; }
            if (Input.GetKey(KeyCode.G)) { pose.pos -= moveForward * deltaMove; }

            deviceState.pose = pose;
        }
        private static void zSpaceDeviceInput(IVRModuleDeviceStateRW deviceState)
        {
            ZCore _zCore = GameObject.FindObjectOfType <ZCore>();

            if (_zCore == null)
            {
                return;
            }
            var midPressed   = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 1);
            var leftPressed  = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 0);
            var rightPressed = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 2);

            //Debug.LogError("拖拽VRModuleRawButton.Trigger:"+leftPressed + "      |复位VRModuleRawButton.Grip:" + rightPressed + "         |缩放VRModuleRawButton.Touchpad:" + midPressed);

            deviceState.SetButtonPress(VRModuleRawButton.Trigger, leftPressed);
            deviceState.SetButtonPress(VRModuleRawButton.Grip, rightPressed);
            deviceState.SetButtonPress(VRModuleRawButton.Touchpad, midPressed);
        }
예제 #28
0
        private void UpdateIndexControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            // TODO: Get finger curl values once OpenVR XR Plugin supports
            bool    primaryButton        = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryButton);
            bool    secondaryButton      = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondaryButton);                         // B
            bool    primary2DAxisClick   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisClick);
            bool    secondary2DAxisClick = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("Secondary2DAxisClick")); // Joystick
            bool    triggerButton        = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);                           // trigger >= 0.5
            bool    gripButton           = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);                              // grip force >= 0.5
            bool    primaryTouch         = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("PrimaryTouch"));
            bool    secondaryTouch       = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("SecondaryTouch"));
            bool    triggerTouch         = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("TriggerTouch"));
            bool    gripTouch            = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("GripTouch"));
            bool    gripGrab             = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("GripGrab"));             // gripCapacitive >= 0.7
            bool    primary2DAxisTouch   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisTouch);
            bool    secondary2DAxisTouch = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <bool>("Secondary2DAxisTouch")); // Joystick
            float   trigger         = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);
            float   grip            = GetDeviceFeatureValueOrDefault(device, CommonUsages.grip);                                         // grip force
            float   gripCapacitive  = GetDeviceFeatureValueOrDefault(device, new InputFeatureUsage <float>("GripCapacitive"));           // touch area on grip
            Vector2 primary2DAxis   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxis);
            Vector2 secondary2DAxis = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxis);

            state.SetButtonPress(VRModuleRawButton.A, primaryButton);
            state.SetButtonPress(VRModuleRawButton.ApplicationMenu, secondaryButton);
            state.SetButtonPress(VRModuleRawButton.Touchpad, primary2DAxisClick);
            state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);
            state.SetButtonPress(VRModuleRawButton.Grip, gripButton);
            state.SetButtonPress(VRModuleRawButton.Axis0, secondary2DAxisClick);

            state.SetButtonTouch(VRModuleRawButton.A, primaryTouch);
            state.SetButtonTouch(VRModuleRawButton.ApplicationMenu, secondaryTouch);
            state.SetButtonTouch(VRModuleRawButton.Trigger, triggerTouch);
            state.SetButtonTouch(VRModuleRawButton.Grip, gripTouch);
            state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);
            state.SetButtonTouch(VRModuleRawButton.Axis0, secondary2DAxisTouch);

            state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxis.x);
            state.SetAxisValue(VRModuleRawAxis.TouchpadY, primary2DAxis.y);
            state.SetAxisValue(VRModuleRawAxis.JoystickX, secondary2DAxis.x);
            state.SetAxisValue(VRModuleRawAxis.JoystickY, secondary2DAxis.y);
            state.SetAxisValue(VRModuleRawAxis.Trigger, trigger);
            // conflict with JoystickX
            //state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, grip);
        }
        private static void HandleDeviceInput(IVRModuleDeviceStateRW deviceState)
        {
            bool leftPressed;
            bool rightPressed;
            bool midPressed;

            leftPressed  = Input.GetMouseButton(0);
            rightPressed = Input.GetMouseButton(1);
            midPressed   = Input.GetMouseButton(2);
            //Debug.LogError("拖拽VRModuleRawButton.Trigger:" + leftPressed + "      |复位VRModuleRawButton.Grip:" + midPressed + "         |缩放VRModuleRawButton.Touchpad:" + rightPressed);
            deviceState.SetButtonPress(VRModuleRawButton.Trigger, leftPressed);
            //deviceState.SetButtonTouch(VRModuleRawButton.Trigger, leftPressed);
            deviceState.SetAxisValue(VRModuleRawAxis.Trigger, leftPressed ? 1f : 0f);

            deviceState.SetButtonPress(VRModuleRawButton.Grip, midPressed);
            //deviceState.SetButtonTouch(VRModuleRawButton.Grip, midPressed);
            deviceState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, midPressed ? 1f : 0f);

            deviceState.SetButtonPress(VRModuleRawButton.Touchpad, rightPressed);
        }
예제 #30
0
        private void UpdateUnknownControllerState(IVRModuleDeviceStateRW state, InputDevice device)
        {
            bool primaryButton        = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryButton);
            bool primaryTouch         = GetDeviceFeatureValueOrDefault(device, CommonUsages.primaryTouch);
            bool secondaryButton      = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondaryButton);
            bool secondaryTouch       = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondaryTouch);
            bool gripButton           = GetDeviceFeatureValueOrDefault(device, CommonUsages.gripButton);
            bool triggerButton        = GetDeviceFeatureValueOrDefault(device, CommonUsages.triggerButton);
            bool menuButton           = GetDeviceFeatureValueOrDefault(device, CommonUsages.menuButton);
            bool primary2DAxisClick   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisClick);
            bool primary2DAxisTouch   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxisTouch);
            bool secondary2DAxisClick = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxisClick);
            bool secondary2DAxisTouch = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxisTouch);

            float triggerValue = GetDeviceFeatureValueOrDefault(device, CommonUsages.trigger);
            float gripValue    = GetDeviceFeatureValueOrDefault(device, CommonUsages.grip);

            Vector2 primary2DAxisValue   = GetDeviceFeatureValueOrDefault(device, CommonUsages.primary2DAxis);
            Vector2 secondary2DAxisValue = GetDeviceFeatureValueOrDefault(device, CommonUsages.secondary2DAxis);

            state.SetButtonPress(VRModuleRawButton.A, primaryButton);
            state.SetButtonPress(VRModuleRawButton.ApplicationMenu, secondaryButton | menuButton);
            state.SetButtonPress(VRModuleRawButton.Trigger, triggerButton);
            state.SetButtonPress(VRModuleRawButton.Grip, gripButton);
            state.SetButtonPress(VRModuleRawButton.Touchpad, primary2DAxisClick);
            state.SetButtonPress(VRModuleRawButton.Joystick, secondary2DAxisClick);

            state.SetButtonTouch(VRModuleRawButton.A, primaryTouch);
            state.SetButtonTouch(VRModuleRawButton.ApplicationMenu, secondaryTouch | menuButton);
            state.SetButtonTouch(VRModuleRawButton.Trigger, triggerButton);
            state.SetButtonTouch(VRModuleRawButton.Grip, gripButton);
            state.SetButtonTouch(VRModuleRawButton.Touchpad, primary2DAxisTouch);
            state.SetButtonTouch(VRModuleRawButton.Joystick, secondary2DAxisTouch);

            state.SetAxisValue(VRModuleRawAxis.Trigger, triggerValue);
            state.SetAxisValue(VRModuleRawAxis.CapSenseGrip, gripValue);
            state.SetAxisValue(VRModuleRawAxis.TouchpadX, primary2DAxisValue.x);
            state.SetAxisValue(VRModuleRawAxis.TouchpadY, primary2DAxisValue.y);
            state.SetAxisValue(VRModuleRawAxis.JoystickX, secondary2DAxisValue.x);
            state.SetAxisValue(VRModuleRawAxis.JoystickY, secondary2DAxisValue.y);
        }