예제 #1
0
        private bool TryGetAndTouchDeviceIndexByType(WVR_DeviceType type, out uint deviceIndex)
        {
            if (type < 0 || (int)type >= s_type2index.Length)
            {
                deviceIndex = INVALID_DEVICE_INDEX;
                return(false);
            }

            deviceIndex = s_type2index[(int)type];
            if (VRModule.IsValidDeviceIndex(deviceIndex))
            {
                m_index2deviceTouched[deviceIndex] = true;
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public override void BeforeRenderUpdate()
        {
            var roleChanged = false;
            var rightIndex  = INVALID_DEVICE_INDEX;
            var leftIndex   = INVALID_DEVICE_INDEX;

            FlushDeviceState();

            if (XRSettings.isDeviceActive && XRDevice.isPresent)
            {
                InputTracking.GetNodeStates(m_nodeStateList);
            }

            for (int i = 0, imax = m_nodeStateList.Count; i < imax; ++i)
            {
                uint deviceIndex;
                if (!TryGetAndTouchNodeDeviceIndex(m_nodeStateList[i], out deviceIndex))
                {
                    continue;
                }

                switch (m_nodeStateList[i].nodeType)
                {
                case XRNode.RightHand: rightIndex = deviceIndex; break;

                case XRNode.LeftHand: leftIndex = deviceIndex; break;
                }

                IVRModuleDeviceState   prevState;
                IVRModuleDeviceStateRW currState;
                EnsureValidDeviceState(deviceIndex, out prevState, out currState);

                if (m_rightIndex != rightIndex || m_leftIndex != leftIndex)
                {
                    m_rightIndex = rightIndex;
                    m_leftIndex  = leftIndex;
                    roleChanged  = true;
                }

                if (!prevState.isConnected)
                {
                    currState.isConnected = true;
                    currState.deviceClass = s_nodeType2DeviceClass[(int)m_nodeStateList[i].nodeType];
                    // FIXME: getting wrong name in Unity 2017.1f1
                    //currDeviceState.serialNumber = InputTracking.GetNodeName(m_nodeStateList[i].uniqueID) ?? string.Empty;
                    //Debug.Log("connected " + InputTracking.GetNodeName(m_nodeStateList[i].uniqueID));

                    if (!XRDevice.model.Equals("None"))
                    {
                        currState.serialNumber    = XRDevice.model + " " + m_nodeStateList[i].uniqueID.ToString("X8");
                        currState.modelNumber     = XRDevice.model + " " + m_nodeStateList[i].nodeType;
                        currState.renderModelName = XRDevice.model + " " + m_nodeStateList[i].nodeType;
                    }
                    else
                    {
                        currState.serialNumber    = XRSettings.loadedDeviceName + " " + m_nodeStateList[i].uniqueID.ToString("X8");
                        currState.modelNumber     = XRSettings.loadedDeviceName + " " + m_nodeStateList[i].nodeType;
                        currState.renderModelName = XRSettings.loadedDeviceName + " " + m_nodeStateList[i].nodeType;
                    }

                    SetupKnownDeviceModel(currState);
                }

                // update device status
                currState.isPoseValid = m_nodeStateList[i].tracked;

                var velocity = default(Vector3);
                if (m_nodeStateList[i].TryGetVelocity(out velocity))
                {
                    currState.velocity = velocity;
                }

                var position = default(Vector3);
                if (m_nodeStateList[i].TryGetPosition(out position))
                {
                    currState.position = position;
                }

                var rotation = default(Quaternion);
                if (m_nodeStateList[i].TryGetRotation(out rotation))
                {
                    currState.rotation = rotation;
                }
            }

            m_nodeStateList.Clear();

            // update right hand input
            if (VRModule.IsValidDeviceIndex(rightIndex))
            {
                IVRModuleDeviceState   rightPrevState;
                IVRModuleDeviceStateRW rightCurrState;
                EnsureValidDeviceState(rightIndex, out rightPrevState, out rightCurrState);
                UpdateRightControllerInput(rightPrevState, rightCurrState);
            }

            //// update left hand input
            if (VRModule.IsValidDeviceIndex(leftIndex))
            {
                IVRModuleDeviceState   leftPrevState;
                IVRModuleDeviceStateRW leftCurrState;
                EnsureValidDeviceState(leftIndex, out leftPrevState, out leftCurrState);
                UpdateLeftControllerInput(leftPrevState, leftCurrState);
            }

            TrimUntouchedNodes(trimmedIndex =>
            {
                IVRModuleDeviceState ps;
                IVRModuleDeviceStateRW cs;
                if (TryGetValidDeviceState(trimmedIndex, out ps, out cs))
                {
                    cs.Reset();
                }
            });

            ProcessConnectedDeviceChanged();

            if (roleChanged)
            {
                InvokeControllerRoleChangedEvent();
            }

            ProcessDevicePoseChanged();
            ProcessDeviceInputChanged();
        }
예제 #3
0
            private void OnGUI()
            {
                if (!VIUSettings.enableSimulatorKeyboardMouseControl)
                {
                    return;
                }

                if (!showGUI || simulator == null)
                {
                    return;
                }

                var hints = string.Empty;

                if (simulator.hasControlFocus)
                {
                    GUI.skin.box.stretchWidth     = false;
                    GUI.skin.box.stretchHeight    = false;
                    GUI.skin.box.alignment        = TextAnchor.UpperLeft;
                    GUI.skin.button.alignment     = TextAnchor.MiddleCenter;
                    GUI.skin.box.normal.textColor = Color.white;

                    // device status grids
                    GUI.skin.box.padding = new RectOffset(10, 10, 5, 5);

                    GUILayout.BeginArea(new Rect(5f, 5f, Screen.width, 30f));
                    GUILayout.BeginHorizontal();

                    for (uint i = 0u; i < SIMULATOR_MAX_DEVICE_COUNT; ++i)
                    {
                        var isHmd            = i == VRModule.HMD_DEVICE_INDEX;
                        var isSelectedDevice = i == simulator.selectedDeviceIndex;
                        var isConndected     = VRModule.GetCurrentDeviceState(i).isConnected;

                        var deviceName = isHmd ? "HMD 0" : i.ToString();
                        var colorName  = !isConndected ? "grey" : isSelectedDevice ? "lime" : "white";

                        GUILayout.Box(SetColor(Bold(deviceName), colorName));
                    }

                    GUILayout.EndHorizontal();
                    GUILayout.EndArea();

                    var selectedDeviceClass = VRModule.GetCurrentDeviceState(simulator.selectedDeviceIndex).deviceClass;
                    // instructions
                    if (selectedDeviceClass == VRModuleDeviceClass.Invalid)
                    {
                        hints += "Pause simulator: " + Bold("ESC") + "\n";
                        hints += "Toggle instructions: " + Bold("F1") + "\n";
                        hints += "Align devices to HMD: " + Bold("F2") + "\n";
                        hints += "Reset all devices to initial state: " + Bold("F3") + "\n\n";

                        hints += "Move: " + Bold("WASD / QE") + "\n";
                        hints += "Rotate: " + Bold("Mouse") + "\n";
                        hints += "Add and select a device: \n";
                        hints += "    [N] " + Bold("Num 0~9") + "\n";
                        hints += "    [10+N] " + Bold("` + Num 0~5") + "\n";
                        hints += "Remove and deselect a device: \n";
                        hints += "    [N] " + Bold("Shift + Num 0~9") + "\n";
                        hints += "    [10+N] " + Bold("Shift + ` + Num 0~5") + "\n";
                    }
                    else
                    {
                        hints += "Toggle instructions: " + Bold("F1") + "\n";
                        hints += "Align devices with HMD: " + Bold("F2") + "\n";
                        hints += "Reset all devices to initial state: " + Bold("F3") + "\n\n";

                        hints += "Currently controlling ";
                        hints += SetColor(Bold("Device " + simulator.selectedDeviceIndex.ToString()) + " " + Bold("(" + selectedDeviceClass.ToString() + ")") + "\n", "lime");
                        if (simulator.selectedDeviceIndex <= 9)
                        {
                            hints += "Deselect this device: " + Bold("ESC") + " / " + Bold("Num " + simulator.selectedDeviceIndex) + "\n";
                        }
                        else
                        {
                            hints += "Deselect this device: " + Bold("ESC") + " / " + Bold("` + Num " + simulator.selectedDeviceIndex) + "\n";
                        }
                        hints += "Add and select a device: \n";
                        hints += "    [N] " + Bold("Num 0~9") + "\n";
                        hints += "    [10+N] " + Bold("` + Num 0~5") + "\n";
                        hints += "Remove and deselect a device: \n";
                        hints += "    [N] " + Bold("Shift + Num 0~9") + "\n";
                        hints += "    [10+N] " + Bold("Shift + ` + Num 0~5") + "\n";

                        hints += "\n";
                        hints += "Move: " + Bold("WASD / QE") + "\n";
                        hints += "Rotate (pitch and yaw): " + Bold("Mouse") + " or " + Bold("Arrow Keys") + "\n";
                        hints += "Rotate (roll): " + Bold("ZC") + "\n";
                        hints += "Reset roll: " + Bold("X") + "\n";

                        if (selectedDeviceClass == VRModuleDeviceClass.Controller || selectedDeviceClass == VRModuleDeviceClass.GenericTracker)
                        {
                            hints += "\n";
                            hints += "Trigger press: " + Bold("Mouse Left") + "\n";
                            hints += "Grip press: " + Bold("Mouse Middle") + "\n";
                            hints += "Trackpad press: " + Bold("Mouse Right") + "\n";
                            hints += "Trackpad touch: " + Bold("Hold Shift") + " + " + Bold("Mouse") + "\n";
                            hints += "Menu button press: " + Bold("M") + "\n";
                        }
                    }

                    hints += "\n";
                    hints += "HMD Move: " + Bold("TFGH / RY") + "\n";
                    hints += "HMD Rotate (pitch and yaw): " + Bold("IJKL") + "\n";
                    hints += "HMD Rotate (roll): " + Bold("VN") + "\n";
                    hints += "HMD Reset roll: " + Bold("B");

                    GUI.skin.box.padding = new RectOffset(10, 10, 10, 10);

                    GUILayout.BeginArea(new Rect(5f, 35f, Screen.width, Screen.height));
                    GUILayout.Box(hints);
                    GUILayout.EndArea();
                }
                else
                {
                    // simulator resume button
                    int  buttonHeight = 30;
                    int  buttonWidth  = 130;
                    Rect ButtonRect   = new Rect((Screen.width * 0.5f) - (buttonWidth * 0.5f), (Screen.height * 0.5f) - buttonHeight, buttonWidth, buttonHeight);

                    if (GUI.Button(ButtonRect, Bold("Back to simulator")))
                    {
                        simulator.hasControlFocus = true;
                    }

                    GUI.skin.box.padding = new RectOffset(10, 10, 5, 5);

                    GUILayout.BeginArea(new Rect(5f, 5f, Screen.width, 30f));
                    GUILayout.BeginHorizontal();

                    hints += "Toggle instructions: " + Bold("F1");
                    GUILayout.Box(hints);

                    GUILayout.EndHorizontal();
                    GUILayout.EndArea();
                }
            }
예제 #4
0
 private bool IsDeviceSelected()
 {
     return(VRModule.IsValidDeviceIndex(selectedDeviceIndex));
 }
예제 #5
0
        public void InternalUpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState)
        {
            if (VIUSettings.enableSimulatorKeyboardMouseControl && hasControlFocus)
            {
                if (IsEscapeKeyDown())
                {
                    if (IsDeviceSelected())
                    {
                        DeselectDevice();
                    }
                    else
                    {
                        //SetSimulatorActive(false);
                        hasControlFocus = false;
                    }
                }

                // reset to default state
                if (m_resetDevices || IsResetAllKeyDown())
                {
                    m_resetDevices = false;

                    foreach (var state in currState)
                    {
                        switch (state.deviceIndex)
                        {
                        case VRModule.HMD_DEVICE_INDEX:
                        case RIGHT_INDEX:
                        case LEFT_INDEX:
                            InitializeDevice(currState[VRModule.HMD_DEVICE_INDEX], state);
                            break;

                        default:
                            if (state.isConnected)
                            {
                                state.Reset();
                            }
                            break;
                        }
                    }

                    DeselectDevice();
                }

                // align devices with hmd
                if (IsResetDevicesKeyDown())
                {
                    foreach (var state in currState)
                    {
                        switch (state.deviceIndex)
                        {
                        case VRModule.HMD_DEVICE_INDEX:
                            break;

                        case RIGHT_INDEX:
                            state.pose = currState[VRModule.HMD_DEVICE_INDEX].pose * s_offsetRightController;
                            break;

                        case LEFT_INDEX:
                            state.pose = currState[VRModule.HMD_DEVICE_INDEX].pose * s_offsetLeftController;
                            break;

                        default:
                            if (state.isConnected)
                            {
                                state.pose = currState[VRModule.HMD_DEVICE_INDEX].pose * s_offsetTracker;
                            }
                            break;
                        }
                    }
                }

                // select/deselect device
                IVRModuleDeviceStateRW keySelectDevice;
                if (GetDeviceByInputDownKeyCode(currState, out keySelectDevice))
                {
                    if (IsShiftKeyPressed())
                    {
                        // remove device
                        if (keySelectDevice.isConnected && keySelectDevice.deviceIndex != VRModule.HMD_DEVICE_INDEX)
                        {
                            if (IsSelectedDevice(keySelectDevice))
                            {
                                DeselectDevice();
                            }

                            keySelectDevice.Reset();
                        }
                    }
                    else
                    {
                        if (IsSelectedDevice(keySelectDevice))
                        {
                            DeselectDevice();
                        }
                        else
                        {
                            // select device
                            if (!keySelectDevice.isConnected)
                            {
                                InitializeDevice(currState[VRModule.HMD_DEVICE_INDEX], keySelectDevice);
                            }

                            SelectDevice(keySelectDevice);
                        }
                    }
                }

                var selectedDevice = VRModule.IsValidDeviceIndex(selectedDeviceIndex) && currState[selectedDeviceIndex].isConnected ? currState[selectedDeviceIndex] : null;
                if (selectedDevice != null)
                {
                    // control selected device
                    ControlDevice(selectedDevice);

                    if (selectedDevice.deviceClass == VRModuleDeviceClass.Controller || selectedDevice.deviceClass == VRModuleDeviceClass.GenericTracker)
                    {
                        HandleDeviceInput(selectedDevice);
                    }
                }
                else if (hasControlFocus)
                {
                    // control device group
                    ControlDeviceGroup(currState);
                }

                // control camera (TFGH)
                if (currState[VRModule.HMD_DEVICE_INDEX].isConnected)
                {
                    ControlCamera(currState[VRModule.HMD_DEVICE_INDEX]);
                }
            }
            else if (IsDeviceSelected())
            {
                DeselectDevice();
            }

            if (onUpdateDeviceState != null)
            {
                onUpdateDeviceState(prevState, currState);
            }

            UpdateMainCamTracking();
        }
예제 #6
0
 protected void InvokeControllerRoleChangedEvent()
 {
     VRModule.InvokeControllerRoleChangedEvent();
 }
예제 #7
0
 protected void InvokeInputFocusEvent(bool value)
 {
     VRModule.InvokeInputFocusEvent(value);
 }
예제 #8
0
            protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
            {
                if (s_viveRgx.IsMatch(deviceState.modelNumber) || s_viveRgx.IsMatch(deviceState.renderModelName))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        if (s_viveCosmosRgx.IsMatch(deviceState.modelNumber))
                        {
                            if (s_leftRgx.IsMatch(deviceState.renderModelName))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.ViveCosmosControllerLeft;
                            }
                            else if (s_rightRgx.IsMatch(deviceState.renderModelName))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.ViveCosmosControllerRight;
                            }
                            deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                        }
                        else
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.ViveController;
                            deviceState.input2DType = VRModuleInput2DType.TouchpadOnly;
                        }
                        return;

                    case VRModuleDeviceClass.GenericTracker:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveTracker;
                        return;

                    case VRModuleDeviceClass.TrackingReference:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveBaseStation;
                        return;
                    }
                }
                else if (s_oculusRgx.IsMatch(deviceState.modelNumber))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.OculusHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        if (s_leftRgx.IsMatch(deviceState.modelNumber))
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.OculusTouchLeft;
                            deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                            return;
                        }
                        else if (s_rightRgx.IsMatch(deviceState.modelNumber))
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.OculusTouchRight;
                            deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                            return;
                        }
                        break;

                    case VRModuleDeviceClass.TrackingReference:
                        deviceState.deviceModel = VRModuleDeviceModel.OculusSensor;
                        return;
                    }
                }
                else if (s_wmrRgx.IsMatch(deviceState.modelNumber) || s_wmrRgx.IsMatch(deviceState.renderModelName))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.WMRHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        if (s_leftRgx.IsMatch(deviceState.modelNumber) && VRModule.GetLeftControllerDeviceIndex() == deviceState.deviceIndex)
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.WMRControllerLeft;
                            deviceState.input2DType = VRModuleInput2DType.Both;
                            return;
                        }
                        else if (s_rightRgx.IsMatch(deviceState.modelNumber) && VRModule.GetRightControllerDeviceIndex() == deviceState.deviceIndex)
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.WMRControllerRight;
                            deviceState.input2DType = VRModuleInput2DType.Both;
                            return;
                        }
                        break;
                    }
                }
                else if (deviceState.deviceClass == VRModuleDeviceClass.Controller && s_knucklesRgx.IsMatch(deviceState.modelNumber))
                {
                    if (s_leftRgx.IsMatch(deviceState.renderModelName))
                    {
                        deviceState.deviceModel = VRModuleDeviceModel.KnucklesLeft;
                        deviceState.input2DType = VRModuleInput2DType.TrackpadOnly;
                        return;
                    }
                    else if (s_rightRgx.IsMatch(deviceState.renderModelName))
                    {
                        deviceState.deviceModel = VRModuleDeviceModel.KnucklesRight;
                        deviceState.input2DType = VRModuleInput2DType.TrackpadOnly;
                        return;
                    }
                }
                else if (s_daydreamRgx.IsMatch(deviceState.modelNumber))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.DaydreamHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        deviceState.deviceModel = VRModuleDeviceModel.DaydreamController;
                        deviceState.input2DType = VRModuleInput2DType.TrackpadOnly;
                        return;
                    }
                }


                deviceState.deviceModel = VRModuleDeviceModel.Unknown;
            }
예제 #9
0
            protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
            {
                if (s_viveRgx.IsMatch(deviceState.modelNumber) || s_viveRgx.IsMatch(deviceState.renderModelName))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        if (s_viveCosmosRgx.IsMatch(deviceState.modelNumber))
                        {
                            if (s_leftRgx.IsMatch(deviceState.renderModelName))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.ViveCosmosControllerLeft;
                            }
                            else if (s_rightRgx.IsMatch(deviceState.renderModelName))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.ViveCosmosControllerRight;
                            }
                            deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                        }
                        else
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.ViveController;
                            deviceState.input2DType = VRModuleInput2DType.TouchpadOnly;
                        }
                        return;

                    case VRModuleDeviceClass.GenericTracker:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveTracker;
                        return;

                    case VRModuleDeviceClass.TrackingReference:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveBaseStation;
                        return;
                    }
                }
                else if (s_oculusRgx.IsMatch(deviceState.modelNumber))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.OculusHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        if (Application.platform == RuntimePlatform.Android)
                        {
                            if (deviceState.modelNumber.Contains("Go"))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusGoController;
                                deviceState.input2DType = VRModuleInput2DType.TouchpadOnly;
                                return;
                            }
                            else if (s_leftRgx.IsMatch(deviceState.modelNumber))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusQuestControllerLeft;
                                deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                                return;
                            }
                            else if (s_rightRgx.IsMatch(deviceState.modelNumber))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusQuestControllerRight;
                                deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                                return;
                            }
                        }
                        else
                        {
                            if (s_leftRgx.IsMatch(deviceState.modelNumber))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusTouchLeft;
                                deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                                return;
                            }
                            else if (s_rightRgx.IsMatch(deviceState.modelNumber))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusTouchRight;
                                deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                                return;
                            }
                        }
                        break;

                    case VRModuleDeviceClass.TrackingReference:
                        deviceState.deviceModel = VRModuleDeviceModel.OculusSensor;
                        return;
                    }
                }
                else if (s_wmrRgx.IsMatch(deviceState.modelNumber) || s_wmrRgx.IsMatch(deviceState.renderModelName))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.WMRHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        if (s_leftRgx.IsMatch(deviceState.modelNumber) && VRModule.GetLeftControllerDeviceIndex() == deviceState.deviceIndex)
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.WMRControllerLeft;
                            deviceState.input2DType = VRModuleInput2DType.Both;
                            return;
                        }
                        else if (s_rightRgx.IsMatch(deviceState.modelNumber) && VRModule.GetRightControllerDeviceIndex() == deviceState.deviceIndex)
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.WMRControllerRight;
                            deviceState.input2DType = VRModuleInput2DType.Both;
                            return;
                        }
                        break;
                    }
                }
                else if (s_indexRgx.IsMatch(deviceState.modelNumber) || s_indexRgx.IsMatch(deviceState.renderModelName))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.IndexHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        deviceState.input2DType = VRModuleInput2DType.TouchpadOnly;
                        if (s_leftRgx.IsMatch(deviceState.renderModelName))
                        {
                            if (s_knucklesRgx.IsMatch(deviceState.renderModelName))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.KnucklesLeft;
                            }
                            else
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.IndexControllerLeft;
#if VIU_STEAMVR_2_0_0_OR_NEWER
                                deviceState.input2DType = VRModuleInput2DType.Both;
#endif
                            }
                        }
                        else if (s_rightRgx.IsMatch(deviceState.renderModelName))
                        {
                            if (s_knucklesRgx.IsMatch(deviceState.renderModelName))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.KnucklesRight;
                            }
                            else
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.IndexControllerRight;
#if VIU_STEAMVR_2_0_0_OR_NEWER
                                deviceState.input2DType = VRModuleInput2DType.Both;
#endif
                            }
                        }
                        return;

                    case VRModuleDeviceClass.TrackingReference:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveBaseStation;
                        return;
                    }
                }
                else if (s_daydreamRgx.IsMatch(deviceState.modelNumber))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.DaydreamHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        deviceState.deviceModel = VRModuleDeviceModel.DaydreamController;
                        deviceState.input2DType = VRModuleInput2DType.TrackpadOnly;
                        return;
                    }
                }


                deviceState.deviceModel = VRModuleDeviceModel.Unknown;
            }
예제 #10
0
            protected static void SetupKnownDeviceModel(IVRModuleDeviceStateRW deviceState)
            {
                //Debug.LogError(deviceState.modelNumber + "|" + deviceState.renderModelName);
                if (s_viveRgx.IsMatch(deviceState.modelNumber) || s_viveRgx.IsMatch(deviceState.renderModelName))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        if (s_viveCosmosRgx.IsMatch(deviceState.modelNumber))
                        {
                            if (s_leftRgx.IsMatch(deviceState.renderModelName))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.ViveCosmosControllerLeft;
                            }
                            else if (s_rightRgx.IsMatch(deviceState.renderModelName))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.ViveCosmosControllerRight;
                            }
                            deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                        }
                        else
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.ViveController;
                            deviceState.input2DType = VRModuleInput2DType.TouchpadOnly;
                        }
                        return;

                    case VRModuleDeviceClass.GenericTracker:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveTracker;
                        return;

                    case VRModuleDeviceClass.TrackingReference:
                        deviceState.deviceModel = VRModuleDeviceModel.ViveBaseStation;
                        return;
                    }
                }
                else if (s_oculusRgx.IsMatch(deviceState.modelNumber))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.OculusHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        if (Application.platform == RuntimePlatform.Android)
                        {
                            if (deviceState.modelNumber.Contains("Go"))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusGoController;
                                deviceState.input2DType = VRModuleInput2DType.TouchpadOnly;
                                return;
                            }
                            else if (s_leftRgx.IsMatch(deviceState.modelNumber))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusQuestControllerLeft;
                                deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                                return;
                            }
                            else if (s_rightRgx.IsMatch(deviceState.modelNumber))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusQuestControllerRight;
                                deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                                return;
                            }
                        }
                        else
                        {
                            if (s_leftRgx.IsMatch(deviceState.modelNumber))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusTouchLeft;
                                deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                                return;
                            }
                            else if (s_rightRgx.IsMatch(deviceState.modelNumber))
                            {
                                deviceState.deviceModel = VRModuleDeviceModel.OculusTouchRight;
                                deviceState.input2DType = VRModuleInput2DType.JoystickOnly;
                                return;
                            }
                        }
                        break;

                    case VRModuleDeviceClass.TrackingReference:
                        deviceState.deviceModel = VRModuleDeviceModel.OculusSensor;
                        return;
                    }
                }
                else if (s_wmrRgx.IsMatch(deviceState.modelNumber) || s_wmrRgx.IsMatch(deviceState.renderModelName))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.WMRHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        if (s_leftRgx.IsMatch(deviceState.modelNumber) && VRModule.GetLeftControllerDeviceIndex() == deviceState.deviceIndex)
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.WMRControllerLeft;
                            deviceState.input2DType = VRModuleInput2DType.Both;
                            return;
                        }
                        else if (s_rightRgx.IsMatch(deviceState.modelNumber) && VRModule.GetRightControllerDeviceIndex() == deviceState.deviceIndex)
                        {
                            deviceState.deviceModel = VRModuleDeviceModel.WMRControllerRight;
                            deviceState.input2DType = VRModuleInput2DType.Both;
                            return;
                        }
                        break;
                    }
                }
                else if (deviceState.deviceClass == VRModuleDeviceClass.Controller && s_knucklesRgx.IsMatch(deviceState.modelNumber))
                {
                    if (s_leftRgx.IsMatch(deviceState.renderModelName))
                    {
                        deviceState.deviceModel = VRModuleDeviceModel.KnucklesLeft;
                        deviceState.input2DType = VRModuleInput2DType.TrackpadOnly;
                        return;
                    }
                    else if (s_rightRgx.IsMatch(deviceState.renderModelName))
                    {
                        deviceState.deviceModel = VRModuleDeviceModel.KnucklesRight;
                        deviceState.input2DType = VRModuleInput2DType.TrackpadOnly;
                        return;
                    }
                }
                else if (s_daydreamRgx.IsMatch(deviceState.modelNumber))
                {
                    switch (deviceState.deviceClass)
                    {
                    case VRModuleDeviceClass.HMD:
                        deviceState.deviceModel = VRModuleDeviceModel.DaydreamHMD;
                        return;

                    case VRModuleDeviceClass.Controller:
                        deviceState.deviceModel = VRModuleDeviceModel.DaydreamController;
                        deviceState.input2DType = VRModuleInput2DType.TrackpadOnly;
                        return;
                    }
                }
                else if (deviceState.modelNumber == "zSpace RightHand" && deviceState.modelNumber == "zSpace RightHand")
                {
                    deviceState.deviceModel = VRModuleDeviceModel.zSpaceStylusController;
                    return;
                }
                else if (deviceState.modelNumber == "PC RightHand" && deviceState.modelNumber == "PC RightHand")
                {
                    deviceState.deviceModel = VRModuleDeviceModel.PCStylusController;
                    return;
                }
                PlatformType currentPlatform = (PlatformType)Enum.Parse(typeof(PlatformType), PlayerPrefs.GetString("CurrentPlateform", "PC"));

                Debug.LogError("currentPlatform Test   " + currentPlatform);
                deviceState.deviceModel = VRModuleDeviceModel.Unknown;
            }
예제 #11
0
        protected override void OnUpdateDeviceConnectionAndPoses()
        {
            lock (this)
            {
                if (!isStarted && retryCount > 0 && startDetectionTask.IsDone)
                {
                    // try start engine detection
                    LiteCoroutine.StartCoroutine(ref startDetectionCoroutine, startDetectionTask.RestartTask(StartDetectionCoroutine()));
                }

                if (!isStarted)
                {
                    return;
                }
            }

            var hmdPose = VRModule.GetDeviceState(VRModule.HMD_DEVICE_INDEX).pose;

            GestureInterface.SetCameraTransform(hmdPose.pos, hmdPose.rot);

            // fetch raw data from engine
            IntPtr resultPtr;
            int    resultFrame;
            var    resultSize = GestureInterface.GetGestureResult(out resultPtr, out resultFrame);

            if (resultFrame < 0)
            {
                Debug.Log(LOG_PREFIX + "Detection stopped");
                isStarted = false;
                return;
            }
            else if (resultFrame <= lastResultFrame)
            {
                // skip frame
                return;
            }

            lastResultFrame = resultFrame;

            leftResult.isConnected  = false;
            rightResult.isConnected = false;

            for (int i = 0, imax = resultSize; i < imax; ++i)
            {
                var result = (GestureResult)Marshal.PtrToStructure(resultPtr, typeof(GestureResult));
                if (result.isLeft)
                {
                    leftResult = new HandResultData()
                    {
                        isConnected = true,
                        rawData     = result,
                    };
                }
                else
                {
                    rightResult = new HandResultData()
                    {
                        isConnected = true,
                        rawData     = result,
                    };
                }
#if NET_4_6
                resultPtr = IntPtr.Add(resultPtr, sizeofGestureResult);
#else
                resultPtr = new IntPtr(resultPtr.ToInt64() + sizeofGestureResult);
#endif
            }

            UpdateDeviceConnectionAndPoses(ref leftResult, ref leftDeviceIndex, true);
            UpdateDeviceConnectionAndPoses(ref rightResult, ref rightDeviceIndex, false);
        }
예제 #12
0
        public override void UpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState)
        {
            if (WaveVR.Instance == null)
            {
                return;
            }

            // FIXME: WVR_IsInputFocusCapturedBySystem currently not implemented yet
            //m_hasInputFocus = Interop.WVR_IsInputFocusCapturedBySystem();

            Interop.WVR_GetSyncPose(m_poseOrigin, m_poses, DEVICE_COUNT);

            for (int i = 0; i < DEVICE_COUNT; ++i)
            {
                var deviceType = m_poses[i].type;
                if (deviceType < 0 || (int)deviceType >= s_type2index.Length)
                {
                    continue;
                }

                var deviceIndex = s_type2index[(int)deviceType];
                if (!VRModule.IsValidDeviceIndex(deviceIndex))
                {
                    continue;
                }

                var cState = currState[deviceIndex];
                var pState = prevState[deviceIndex];

                cState.isConnected = Interop.WVR_IsDeviceConnected(deviceType);

                if (cState.isConnected)
                {
                    if (!pState.isConnected)
                    {
                        cState.deviceClass = s_type2class[(int)deviceType];
                        cState.deviceModel = s_type2model[(int)deviceType];
                    }

                    // fetch tracking data
                    cState.isOutOfRange    = false;
                    cState.isCalibrating   = false;
                    cState.isUninitialized = false;

                    var devicePose = m_poses[i].pose;
                    cState.velocity        = new Vector3(devicePose.Velocity.v0, devicePose.Velocity.v1, -devicePose.Velocity.v2);
                    cState.angularVelocity = new Vector3(-devicePose.AngularVelocity.v0, -devicePose.AngularVelocity.v1, devicePose.AngularVelocity.v2);

                    var rigidTransform = new WaveVR_Utils.RigidTransform(devicePose.PoseMatrix);
                    cState.position = rigidTransform.pos;
                    cState.rotation = rigidTransform.rot;

                    cState.isPoseValid = cState.pose != RigidPose.identity;

                    // fetch buttons input
                    var buttons = 0u;
                    var touches = 0u;
                    // FIXME: What does WVR_GetInputTypeCount means?
                    var analogCount = Interop.WVR_GetInputTypeCount(deviceType, WVR_InputType.WVR_InputType_Analog);
                    if (m_analogStates == null || m_analogStates.Length < analogCount)
                    {
                        m_analogStates = new WVR_AnalogState_t[analogCount];
                    }
                    const uint inputType = (uint)(WVR_InputType.WVR_InputType_Button | WVR_InputType.WVR_InputType_Touch | WVR_InputType.WVR_InputType_Analog);
#if VIU_WAVEVR_2_0_32_OR_NEWER
                    if (Interop.WVR_GetInputDeviceState(deviceType, inputType, ref buttons, ref touches, m_analogStates, (uint)analogCount))
#else
                    if (Interop.WVR_GetInputDeviceState(deviceType, inputType, ref buttons, ref touches, m_analogStates, analogCount))
#endif
                    {
                        const uint dpadMask =
                            (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Touchpad)) |
                            (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Left)) |
                            (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Up)) |
                            (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Right)) |
                            (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Down));

                        const uint triggerBumperMask =
                            (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Trigger)) |
#if VIU_WAVEVR_2_1_0_OR_NEWER
                            (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger));
#else
                            (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Bumper));
#endif

                        cState.SetButtonPress(VRModuleRawButton.System, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_System)) != 0u);
                        cState.SetButtonPress(VRModuleRawButton.ApplicationMenu, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Menu)) != 0u);
                        cState.SetButtonPress(VRModuleRawButton.Touchpad, (buttons & dpadMask) != 0u);
                        cState.SetButtonPress(VRModuleRawButton.Trigger, (buttons & triggerBumperMask) != 0u);
                        cState.SetButtonPress(VRModuleRawButton.Grip, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Grip)) != 0u);
                        cState.SetButtonPress(VRModuleRawButton.DPadLeft, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Left)) != 0u);
                        cState.SetButtonPress(VRModuleRawButton.DPadUp, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Up)) != 0u);
                        cState.SetButtonPress(VRModuleRawButton.DPadRight, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Right)) != 0u);
                        cState.SetButtonPress(VRModuleRawButton.DPadDown, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Down)) != 0u);

                        cState.SetButtonTouch(VRModuleRawButton.System, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_System)) != 0u);
                        cState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Menu)) != 0u);
                        cState.SetButtonTouch(VRModuleRawButton.Touchpad, (touches & dpadMask) != 0u);
                        cState.SetButtonTouch(VRModuleRawButton.Trigger, (touches & triggerBumperMask) != 0u);
                        cState.SetButtonTouch(VRModuleRawButton.Grip, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Grip)) != 0u);
                        cState.SetButtonTouch(VRModuleRawButton.DPadLeft, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Left)) != 0u);
                        cState.SetButtonTouch(VRModuleRawButton.DPadUp, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Up)) != 0u);
                        cState.SetButtonTouch(VRModuleRawButton.DPadRight, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Right)) != 0u);
                        cState.SetButtonTouch(VRModuleRawButton.DPadDown, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Down)) != 0u);

                        for (int j = 0, jmax = m_analogStates.Length; j < jmax; ++j)
                        {
                            switch (m_analogStates[j].id)
                            {
                            case WVR_InputId.WVR_InputId_Alias1_Trigger:
                                if (m_analogStates[j].type == WVR_AnalogType.WVR_AnalogType_Trigger)
                                {
                                    cState.SetAxisValue(VRModuleRawAxis.Trigger, m_analogStates[j].axis.x);
                                }
                                break;

                            case WVR_InputId.WVR_InputId_Alias1_Touchpad:
                                if (m_analogStates[j].type == WVR_AnalogType.WVR_AnalogType_TouchPad && cState.GetButtonTouch(VRModuleRawButton.Touchpad))
                                {
                                    cState.SetAxisValue(VRModuleRawAxis.TouchpadX, m_analogStates[j].axis.x);
                                    cState.SetAxisValue(VRModuleRawAxis.TouchpadY, m_analogStates[j].axis.y);
                                }
                                else
                                {
                                    cState.SetAxisValue(VRModuleRawAxis.TouchpadX, 0f);
                                    cState.SetAxisValue(VRModuleRawAxis.TouchpadY, 0f);
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        cState.buttonPressed = 0u;
                        cState.buttonTouched = 0u;
                        for (int j = 0, jmax = cState.axisValue.Length; j < jmax; ++j)
                        {
                            cState.axisValue[j] = 0f;
                        }
                    }
                }
                else
                {
                    if (pState.isConnected)
                    {
                        cState.Reset();
                    }
                }
            }

            var headState  = currState[s_type2index[(int)WVR_DeviceType.WVR_DeviceType_HMD]];
            var rightState = currState[s_type2index[(int)WVR_DeviceType.WVR_DeviceType_Controller_Right]];
            var leftState  = currState[s_type2index[(int)WVR_DeviceType.WVR_DeviceType_Controller_Left]];
            ApplyVirtualArmAndSimulateInput(rightState, headState, RIGHT_ARM_MULTIPLIER);
            ApplyVirtualArmAndSimulateInput(leftState, headState, LEFT_ARM_MULTIPLIER);
        }
예제 #13
0
        public override void UpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState)
        {
            if (VRSettings.isDeviceActive && VRDevice.isPresent)
            {
                InputTracking.GetNodeStates(m_nodeStateList);
            }

            var rightIndex = INVALID_DEVICE_INDEX;
            var leftIndex  = INVALID_DEVICE_INDEX;

            for (int i = 0, imax = m_nodeStateList.Count; i < imax; ++i)
            {
                uint deviceIndex;
                if (!TryGetNodeDeviceIndex(m_nodeStateList[i], out deviceIndex))
                {
                    continue;
                }

                m_prevExistNodeUids.Remove(m_nodeStateList[i].uniqueID);
                m_currExistNodeUids.Add(m_nodeStateList[i].uniqueID);

                var prevDeviceState = prevState[deviceIndex];
                var currDeviceState = currState[deviceIndex];

                currDeviceState.isConnected = true;

                switch (m_nodeStateList[i].nodeType)
                {
                case VRNode.Head:
                    currDeviceState.deviceClass = VRModuleDeviceClass.HMD;
                    break;

                case VRNode.RightHand:
                    currDeviceState.deviceClass = VRModuleDeviceClass.Controller;
                    rightIndex = deviceIndex;
                    break;

                case VRNode.LeftHand:
                    currDeviceState.deviceClass = VRModuleDeviceClass.Controller;
                    leftIndex = deviceIndex;
                    break;

                case VRNode.GameController:
                    currDeviceState.deviceClass = VRModuleDeviceClass.Controller;
                    break;

                case VRNode.HardwareTracker:
                    currDeviceState.deviceClass = VRModuleDeviceClass.GenericTracker;
                    break;

                case VRNode.TrackingReference:
                    currDeviceState.deviceClass = VRModuleDeviceClass.TrackingReference;
                    break;

                default:
                    currDeviceState.deviceClass = VRModuleDeviceClass.Invalid;
                    break;
                }

                if (!prevDeviceState.isConnected)
                {
                    // FIXME: getting wrong name in Unity 2017.1f1
                    //currDeviceState.serialNumber = InputTracking.GetNodeName(m_nodeStateList[i].uniqueID) ?? string.Empty;
                    currDeviceState.serialNumber    = VRDevice.model + " " + m_nodeStateList[i].uniqueID.ToString("X8");
                    currDeviceState.modelNumber     = VRDevice.model + " " + m_nodeStateList[i].nodeType;
                    currDeviceState.renderModelName = VRDevice.model + " " + m_nodeStateList[i].nodeType;

                    SetupKnownDeviceModel(currDeviceState);
                }

                // update device status
                currDeviceState.isPoseValid = m_nodeStateList[i].tracked;

                var velocity = default(Vector3);
                if (m_nodeStateList[i].TryGetVelocity(out velocity))
                {
                    currDeviceState.velocity = velocity;
                }

                var position = default(Vector3);
                if (m_nodeStateList[i].TryGetPosition(out position))
                {
                    currDeviceState.position = position;
                }

                var rotation = default(Quaternion);
                if (m_nodeStateList[i].TryGetRotation(out rotation))
                {
                    currDeviceState.rotation = rotation;
                }
            }

            m_nodeStateList.Clear();

            if (VRModule.IsValidDeviceIndex(rightIndex))
            {
                var rightCurrState = currState[m_rightIndex];
                var rightPrevState = prevState[m_rightIndex];

                var rightMenuPress    = Input.GetKey(ButtonKeyCode.RMenuPress);
                var rightAButtonPress = Input.GetKey(ButtonKeyCode.RAKeyPress);
                var rightPadPress     = Input.GetKey(ButtonKeyCode.RPadPress);

                var rightMenuTouch    = Input.GetKey(ButtonKeyCode.RMenuTouch);
                var rightAButtonTouch = Input.GetKey(ButtonKeyCode.RAKeyTouch);
                var rightPadTouch     = Input.GetKey(ButtonKeyCode.RPadTouch);
                var rightTriggerTouch = Input.GetKey(ButtonKeyCode.RTriggerTouch);

                var rightTrackpadX = Input.GetAxisRaw(ButtonAxisName.RPadX);
                var rightTrackpadY = Input.GetAxisRaw(ButtonAxisName.RPadY);
                var rightTrigger   = Input.GetAxisRaw(ButtonAxisName.RTrigger);
                var rightGrip      = Input.GetAxisRaw(ButtonAxisName.RGrip);

                rightCurrState.SetButtonPress(VRModuleRawButton.ApplicationMenu, rightMenuPress);
                rightCurrState.SetButtonPress(VRModuleRawButton.A, rightAButtonPress);
                rightCurrState.SetButtonPress(VRModuleRawButton.Touchpad, rightPadPress);
                rightCurrState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(rightPrevState.GetButtonPress(VRModuleRawButton.Trigger), rightTrigger, 0.55f, 0.45f));
                rightCurrState.SetButtonPress(VRModuleRawButton.Grip, AxisToPress(rightPrevState.GetButtonPress(VRModuleRawButton.Grip), rightGrip, 0.55f, 0.45f));
                rightCurrState.SetButtonPress(VRModuleRawButton.CapSenseGrip, AxisToPress(rightPrevState.GetButtonPress(VRModuleRawButton.CapSenseGrip), rightGrip, 0.55f, 0.45f));

                rightCurrState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, rightMenuTouch);
                rightCurrState.SetButtonTouch(VRModuleRawButton.A, rightAButtonTouch);
                rightCurrState.SetButtonTouch(VRModuleRawButton.Touchpad, rightPadTouch);
                rightCurrState.SetButtonTouch(VRModuleRawButton.Trigger, rightTriggerTouch);
                rightCurrState.SetButtonTouch(VRModuleRawButton.CapSenseGrip, AxisToPress(rightPrevState.GetButtonTouch(VRModuleRawButton.CapSenseGrip), rightGrip, 0.25f, 0.20f));

                rightCurrState.SetAxisValue(VRModuleRawAxis.TouchpadX, rightTrackpadX);
                rightCurrState.SetAxisValue(VRModuleRawAxis.TouchpadY, rightTrackpadY);
                rightCurrState.SetAxisValue(VRModuleRawAxis.Trigger, rightTrigger);
                rightCurrState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, rightGrip);
            }

            if (VRModule.IsValidDeviceIndex(leftIndex))
            {
                var leftCurrState = currState[m_leftIndex];
                var leftPrevState = prevState[m_leftIndex];

                var leftMenuPress    = Input.GetKey(ButtonKeyCode.LMenuPress);
                var leftAButtonPress = Input.GetKey(ButtonKeyCode.LAKeyPress);
                var leftPadPress     = Input.GetKey(ButtonKeyCode.LPadPress);

                var leftMenuTouch    = Input.GetKey(ButtonKeyCode.LMenuTouch);
                var leftAButtonTouch = Input.GetKey(ButtonKeyCode.LAKeyTouch);
                var leftPadTouch     = Input.GetKey(ButtonKeyCode.LPadTouch);
                var leftTriggerTouch = Input.GetKey(ButtonKeyCode.LTriggerTouch);

                var leftTrackpadX = Input.GetAxisRaw(ButtonAxisName.LPadX);
                var leftTrackpadY = Input.GetAxisRaw(ButtonAxisName.LPadY);
                var leftTrigger   = Input.GetAxisRaw(ButtonAxisName.LTrigger);
                var leftGrip      = Input.GetAxisRaw(ButtonAxisName.LGrip);

                leftCurrState.SetButtonPress(VRModuleRawButton.ApplicationMenu, leftMenuPress);
                leftCurrState.SetButtonPress(VRModuleRawButton.A, leftAButtonPress);
                leftCurrState.SetButtonPress(VRModuleRawButton.Touchpad, leftPadPress);
                leftCurrState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(leftPrevState.GetButtonPress(VRModuleRawButton.Trigger), leftTrigger, 0.55f, 0.45f));
                leftCurrState.SetButtonPress(VRModuleRawButton.Grip, AxisToPress(leftPrevState.GetButtonPress(VRModuleRawButton.Grip), leftGrip, 0.55f, 0.45f));
                leftCurrState.SetButtonPress(VRModuleRawButton.CapSenseGrip, AxisToPress(leftPrevState.GetButtonPress(VRModuleRawButton.CapSenseGrip), leftGrip, 0.55f, 0.45f));

                leftCurrState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, leftMenuTouch);
                leftCurrState.SetButtonTouch(VRModuleRawButton.A, leftAButtonTouch);
                leftCurrState.SetButtonTouch(VRModuleRawButton.Touchpad, leftPadTouch);
                leftCurrState.SetButtonTouch(VRModuleRawButton.Trigger, leftTriggerTouch);
                leftCurrState.SetButtonTouch(VRModuleRawButton.CapSenseGrip, AxisToPress(leftPrevState.GetButtonTouch(VRModuleRawButton.CapSenseGrip), leftGrip, 0.25f, 0.20f));

                leftCurrState.SetAxisValue(VRModuleRawAxis.TouchpadX, leftTrackpadX);
                leftCurrState.SetAxisValue(VRModuleRawAxis.TouchpadY, leftTrackpadY);
                leftCurrState.SetAxisValue(VRModuleRawAxis.Trigger, leftTrigger);
                leftCurrState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, leftGrip);
            }

            // remove disconnected nodes
            for (int i = m_prevExistNodeUids.Count - 1; i >= 0; --i)
            {
                if (currState[i].isConnected)
                {
                    currState[i].Reset();
                }
                RemoveNodeDeviceIndex(m_prevExistNodeUids[i]);
            }

            var temp = m_prevExistNodeUids;

            m_prevExistNodeUids = m_currExistNodeUids;
            m_currExistNodeUids = temp;
            m_currExistNodeUids.Clear();

            if (m_rightIndex != rightIndex || m_leftIndex != leftIndex)
            {
                m_rightIndex = rightIndex;
                m_leftIndex  = leftIndex;
                InvokeControllerRoleChangedEvent();
            }
        }
예제 #14
0
        // update connected devices
        private void UpdateConnectedDevices()
        {
            IVRModuleDeviceState   prevState;
            IVRModuleDeviceStateRW currState;

            EnsureValidDeviceState(HEAD_INDEX, out prevState, out currState);
            if (!XRDevice.isPresent)
            {
                if (prevState.isConnected)
                {
                    currState.Reset();
                }
            }
            else
            {
                if (!prevState.isConnected)
                {
                    currState.isConnected     = true;
                    currState.deviceClass     = VRModuleDeviceClass.HMD;
                    currState.serialNumber    = XRDevice.model + " HMD";
                    currState.modelNumber     = XRDevice.model + " HMD";
                    currState.deviceModel     = VRModuleDeviceModel.DaydreamHMD;
                    currState.renderModelName = string.Empty;
                }
            }

            var controllerRoleChanged = false;

            EnsureValidDeviceState(CONTROLLER_INDEX, out prevState, out currState);
            if (GvrControllerInput.State != GvrConnectionState.Connected)
            {
                if (prevState.isConnected)
                {
                    currState.Reset();
                }
            }
            else
            {
                if (!prevState.isConnected)
                {
                    currState.isConnected     = true;
                    currState.deviceClass     = VRModuleDeviceClass.Controller;
                    currState.serialNumber    = XRDevice.model + " Controller";
                    currState.modelNumber     = XRDevice.model + " Controller";
                    currState.deviceModel     = VRModuleDeviceModel.DaydreamController;
                    currState.renderModelName = string.Empty;
                }

                switch (GvrSettings.Handedness)
                {
                case GvrSettings.UserPrefsHandedness.Right:
                    controllerRoleChanged = !VRModule.IsValidDeviceIndex(m_rightIndex) && m_leftIndex == CONTROLLER_INDEX;
                    m_rightIndex          = CONTROLLER_INDEX;
                    m_leftIndex           = INVALID_DEVICE_INDEX;
                    break;

                case GvrSettings.UserPrefsHandedness.Left:
                    controllerRoleChanged = m_rightIndex == CONTROLLER_INDEX && !VRModule.IsValidDeviceIndex(m_leftIndex);
                    m_rightIndex          = INVALID_DEVICE_INDEX;
                    m_leftIndex           = CONTROLLER_INDEX;
                    break;

                case GvrSettings.UserPrefsHandedness.Error:
                default:
                    Debug.LogError("GvrSettings.Handedness error");
                    break;
                }
            }

            if (controllerRoleChanged)
            {
                InvokeControllerRoleChangedEvent();
            }
        }
예제 #15
0
        public override void UpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState)
        {
            if (VIUSettings.enableSimulatorKeyboardMouseControl)
            {
                // Reset to default state
                if (m_resetDevices)
                {
                    m_resetDevices = false;

                    foreach (var state in currState)
                    {
                        switch (state.deviceIndex)
                        {
                        case VRModule.HMD_DEVICE_INDEX:
                        case RIGHT_INDEX:
                        case LEFT_INDEX:
                            InitializeDevice(currState[VRModule.HMD_DEVICE_INDEX], state);
                            break;

                        default:
                            if (state.isConnected)
                            {
                                state.Reset();
                            }
                            break;
                        }
                    }

                    SelectDevice(currState[VRModule.HMD_DEVICE_INDEX]);
                }

                // select/deselect device
                var keySelectDevice = default(IVRModuleDeviceStateRW);
                if (GetDeviceByInputDownKeyCode(currState, out keySelectDevice))
                {
                    if (IsShiftKeyPressed())
                    {
                        if (keySelectDevice.isConnected && keySelectDevice.deviceIndex != VRModule.HMD_DEVICE_INDEX)
                        {
                            if (IsSelectedDevice(keySelectDevice))
                            {
                                DeselectDevice();
                            }

                            keySelectDevice.Reset();
                        }
                    }
                    else
                    {
                        if (!IsSelectedDevice(keySelectDevice))
                        {
                            // select
                            if (!keySelectDevice.isConnected)
                            {
                                InitializeDevice(currState[VRModule.HMD_DEVICE_INDEX], keySelectDevice);
                            }

                            SelectDevice(keySelectDevice);
                        }
                        else
                        {
                            // deselect
                            DeselectDevice();
                        }
                    }
                }

                // control selected device
                var selectedDevice = VRModule.IsValidDeviceIndex(m_selectedDeviceIndex) && currState[m_selectedDeviceIndex].isConnected ? currState[m_selectedDeviceIndex] : null;
                if (selectedDevice != null)
                {
                    ControlDevice(selectedDevice);

                    if (selectedDevice.deviceClass != VRModuleDeviceClass.HMD)
                    {
                        HandleDeviceInput(selectedDevice);
                    }
                }

                // control camera
                if (currState[VRModule.HMD_DEVICE_INDEX].isConnected)
                {
                    ControlCamera(currState[VRModule.HMD_DEVICE_INDEX]);
                }
            }
            else if (IsDeviceSelected())
            {
                DeselectDevice();
            }

            if (onUpdateDeviceState != null)
            {
                onUpdateDeviceState(prevState, currState);
            }

            UpdateMainCamTracking();
        }