Ejemplo n.º 1
0
        public static void SortDeviceIndicesByDirection(List <uint> deviceList, RigidPose sortingReference)
        {
            if (deviceList == null || deviceList.Count == 0)
            {
                return;
            }

            for (int i = 0, imax = deviceList.Count; i < imax; ++i)
            {
                var deviceIndex = deviceList[i];
                if (!VRModule.IsValidDeviceIndex(deviceIndex))
                {
                    continue;
                }

                var deviceState = VRModule.GetCurrentDeviceState(deviceIndex);
                if (deviceState.isConnected)
                {
                    var localPos = sortingReference.InverseTransformPoint(deviceState.pose.pos);
                    s_deviceDirPoint[deviceIndex] = GetDirectionPoint(new Vector2(localPos.x, localPos.z));
                }
                else
                {
                    s_deviceDirPoint[deviceIndex] = -1f;
                }
            }

            deviceList.Sort(CompareDirection);
        }
Ejemplo n.º 2
0
 private void UpdateDefaultModel()
 {
     if (ChangeProp.Set(ref m_currentDeviceIndex, GetCurrentDeviceIndex()))
     {
         if (VRModule.IsValidDeviceIndex(m_currentDeviceIndex))
         {
             if (ChangeProp.Set(ref m_currentLoadedStaticModel, VRModule.GetCurrentDeviceState(m_currentDeviceIndex).deviceModel))
             {
                 ReloadedStaticModel(m_currentLoadedStaticModel);
             }
             else
             {
                 if (m_modelObj != null)
                 {
                     m_modelObj.SetActive(true);
                 }
             }
         }
         else
         {
             if (m_modelObj != null)
             {
                 m_modelObj.SetActive(false);
             }
         }
     }
 }
Ejemplo n.º 3
0
 public void OnClick()
 {
     if (onClick != null)
     {
         onClick(VRModule.GetCurrentDeviceState(deviceIndex).serialNumber);
     }
 }
        public static bool LoadBindingConfigFromFile(string configPath)
        {
            if (string.IsNullOrEmpty(configPath) || !File.Exists(configPath))
            {
                return(false);
            }

            using (var inputFile = new StreamReader(configPath))
            {
                s_bindingConfig = JsonUtility.FromJson <BindingConfig>(inputFile.ReadToEnd());

                foreach (var roleData in s_bindingConfig.roles)
                {
                    foreach (var binding in roleData.bindings)
                    {
                        if (VRModule.IsDeviceConnected(binding.device_sn))
                        {
                            s_modelHintTable[binding.device_sn] = VRModule.GetCurrentDeviceState(VRModule.GetConnectedDeviceIndex(binding.device_sn)).deviceModel;
                        }
                        else
                        {
                            s_modelHintTable[binding.device_sn] = binding.device_model;
                        }
                    }
                }

                return(true);
            }
        }
        public static void BindAllCurrentDeviceClassMappings(VRModuleDeviceClass deviceClass)
        {
            for (int i = 0, imax = ViveRoleEnum.ValidViveRoleTable.Count; i < imax; ++i)
            {
                var roleMap  = ViveRole.GetMap(ViveRoleEnum.ValidViveRoleTable.GetValueByIndex(i));
                var roleInfo = roleMap.RoleValueInfo;
                for (int rv = roleInfo.MinValidRoleValue, rvmax = roleInfo.MaxValidRoleValue; rv <= rvmax; ++rv)
                {
                    if (!roleInfo.IsValidRoleValue(rv))
                    {
                        continue;
                    }
                    if (roleMap.IsRoleValueBound(rv))
                    {
                        continue;
                    }

                    var mappedDevice      = roleMap.GetMappedDeviceByRoleValue(rv);
                    var mappedDeviceState = VRModule.GetCurrentDeviceState(mappedDevice);
                    if (mappedDeviceState.deviceClass != deviceClass)
                    {
                        continue;
                    }

                    roleMap.BindDeviceToRoleValue(mappedDeviceState.serialNumber, rv);
                }
            }
        }
Ejemplo n.º 6
0
        public void UpdatePosition()
        {
            var deviceState = VRModule.GetCurrentDeviceState(deviceIndex);
            var devicePose  = deviceState.pose;

            transform.localPosition = new Vector3(devicePose.pos.x, devicePose.pos.z, 0f) * 100f;
            transform.localRotation = Quaternion.Euler(0f, 0f, -devicePose.rot.eulerAngles.y);
        }
Ejemplo n.º 7
0
    public void SetRole(Type roleType, int roleValue, uint selectedDevice, bool isPointed)
    {
        m_roleValue = roleValue;
        m_map       = ViveRole.GetMap(roleType);
        m_isPointed = isPointed;

        m_selectedDevice   = selectedDevice;
        m_selectedDeviceSN = VRModule.GetCurrentDeviceState(selectedDevice).serialNumber;

        UpdateState();
    }
 public static Vector3 GetAngularVelocity(uint deviceIndex, Transform origin = null)
 {
     if (!VRModule.IsValidDeviceIndex(deviceIndex))
     {
         return(Vector3.zero);
     }
     else if (origin == null)
     {
         return(VRModule.GetCurrentDeviceState(deviceIndex).angularVelocity);
     }
     else
     {
         return(origin.TransformVector(VRModule.GetCurrentDeviceState(deviceIndex).angularVelocity));
     }
 }
        public static RigidPose GetPose(uint deviceIndex, Transform origin = null)
        {
            var devicePose = VRModule.GetCurrentDeviceState(deviceIndex).pose;

            if (origin == null)
            {
                return(devicePose);
            }
            else
            {
                var rawPose = new RigidPose(origin) * devicePose;
                rawPose.pos.Scale(origin.localScale);
                return(rawPose);
            }
        }
Ejemplo n.º 10
0
 public static Pose GetPose(uint deviceIndex, Transform origin = null)
 {
     if (!VRModule.IsValidDeviceIndex(deviceIndex))
     {
         return(default(Pose));
     }
     else if (origin == null)
     {
         return(VRModule.GetCurrentDeviceState(deviceIndex).pose);
     }
     else
     {
         var rawPose = new Pose(origin) * VRModule.GetCurrentDeviceState(deviceIndex).pose;
         rawPose.pos.Scale(origin.localScale);
         return(rawPose);
     }
 }
        public static VRModuleDeviceModel GetDeviceModelHint(string deviceSN)
        {
            var deviceIndex = VRModule.GetConnectedDeviceIndex(deviceSN);

            if (VRModule.IsValidDeviceIndex(deviceIndex))
            {
                return(VRModule.GetCurrentDeviceState(deviceIndex).deviceModel);
            }

            VRModuleDeviceModel deviceModel;

            if (s_modelHintTable.TryGetValue(deviceSN, out deviceModel))
            {
                return(deviceModel);
            }

            return(VRModuleDeviceModel.Unknown);
        }
    public void UpdateStatus()
    {
        if (!VivePose.IsConnected(m_deviceIndex))
        {
            m_deviceIndex = VRModule.INVALID_DEVICE_INDEX;

            textDeviceIndex.text = string.Empty;
            textDeviceClass.text = string.Empty;
            textSerialNum.text   = string.Empty;
            textModelNum.text    = string.Empty;
        }
        else
        {
            var deviceState = VRModule.GetCurrentDeviceState(m_deviceIndex);
            textDeviceIndex.text = m_deviceIndex.ToString();
            textDeviceClass.text = deviceState.deviceClass.ToString();;
            textSerialNum.text   = deviceState.serialNumber;
            textModelNum.text    = deviceState.modelNumber;
        }
    }
        public void Refresh()
        {
            var deviceIndex = 0u;

            for (var role = RoleInfo.MinValidRole; role <= RoleInfo.MaxValidRole && deviceIndex < VRModule.MAX_DEVICE_COUNT; ++role, ++deviceIndex)
            {
                if (!RoleInfo.IsValidRole(role))
                {
                    continue;
                }

                if (VRModule.GetCurrentDeviceState(deviceIndex).isConnected)
                {
                    MappingRoleIfUnbound(role, deviceIndex);
                }
                else
                {
                    UnmappingRole(role);
                }
            }
        }
 public static bool IsUninitialized(uint deviceIndex)
 {
     return(VRModule.GetCurrentDeviceState(deviceIndex).isUninitialized);
 }
Ejemplo n.º 15
0
 public static string GetModelNumber(uint deviceIndex)
 {
     return IsValidIndex(deviceIndex) ? VRModule.GetCurrentDeviceState(deviceIndex).modelNumber : string.Empty;
 }
            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();
                }
            }
Ejemplo n.º 17
0
 public void UpdateModel()
 {
     BindingInterfaceSpriteManager.SetupTrackingDeviceIcon(m_imageModel, VRModule.GetCurrentDeviceState(deviceIndex).deviceModel, isBound);
 }
 public static bool IsCalibrating(uint deviceIndex)
 {
     return(VRModule.GetCurrentDeviceState(deviceIndex).isCalibrating);
 }
Ejemplo n.º 19
0
 private bool IsTracker(uint deviceIndex)
 {
     return(IsTracker(VRModule.GetCurrentDeviceState(deviceIndex).deviceClass));
 }