Beispiel #1
0
        private void MappingOthers()
        {
            // try mapping the rest of the devices
            var role        = HandRole.Controller3;
            var deviceIndex = 0u;

            while (role <= HandRole.Controller12 && deviceIndex < ViveRole.MAX_DEVICE_COUNT)
            {
                while (RoleMap.IsRoleMapped(role) || RoleMap.IsRoleBound(role))
                {
                    if (++role > HandRole.Controller12)
                    {
                        return;
                    }
                }

                while (!IsController(deviceIndex) || RoleMap.IsDeviceMapped(deviceIndex))
                {
                    if (++deviceIndex >= ViveRole.MAX_DEVICE_COUNT)
                    {
                        return;
                    }
                }

                MappingRole(role++, deviceIndex++);
            }
        }
 private bool NextUnmappedSortedDevice(ref int i)
 {
     while (++i < m_sortedDeviceList.Count)
     {
         if (!RoleMap.IsDeviceMapped(m_sortedDeviceList[i]))
         {
             return(true);
         }
     }
     return(false);
 }
        private void MappingTrackers()
        {
            var role  = RoleMap.RoleInfo.MinValidRole;
            var index = (uint)1;

            while (true)
            {
                while (!RoleMap.RoleInfo.IsValidRole(role) || RoleMap.IsRoleMapped(role) || RoleMap.IsRoleBound(role))
                {
                    if (++role > RoleMap.RoleInfo.MaxValidRole)
                    {
                        return;
                    }
                }

                while (ViveRole.GetDeviceClass(index) != ETrackedDeviceClass.GenericTracker || RoleMap.IsDeviceMapped(index) || RoleMap.IsDeviceConnectedAndBound(index))
                {
                    if (++index >= ViveRole.MAX_DEVICE_COUNT)
                    {
                        return;
                    }
                }

                MappingRole(role++, index++);

                if (role > RoleMap.RoleInfo.MaxValidRole || index >= ViveRole.MAX_DEVICE_COUNT)
                {
                    return;
                }
            }
        }
Beispiel #4
0
        // unmapping all and mapping only right/left hands
        private void MappingHandsAndOthers()
        {
            UnmappingAll();

            var system     = OpenVR.System;
            var rightIndex = ViveRole.INVALID_DEVICE_INDEX;
            var leftIndex  = ViveRole.INVALID_DEVICE_INDEX;

            var trackedControllerCount = 0;

            if (system != null)
            {
                leftIndex  = system.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand);
                rightIndex = system.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand);

                if (RoleMap.IsDeviceMapped(leftIndex))
                {
                    leftIndex = ViveRole.INVALID_DEVICE_INDEX;
                }
                if (RoleMap.IsDeviceMapped(rightIndex))
                {
                    rightIndex = ViveRole.INVALID_DEVICE_INDEX;
                }

                trackedControllerCount = (int)system.GetSortedTrackedDeviceIndicesOfClass(ETrackedDeviceClass.Controller, m_sortedDevices, 0);
            }

            if (ViveRole.IsValidIndex(rightIndex))
            {
                MappingRoleIfUnbound(HandRole.RightHand, rightIndex);
            }

            if (ViveRole.IsValidIndex(leftIndex) && leftIndex != rightIndex)
            {
                MappingRoleIfUnbound(HandRole.LeftHand, leftIndex);
            }

            if (!RoleMap.IsRoleMapped(HandRole.RightHand) && !RoleMap.IsRoleBound(HandRole.RightHand))
            {
                // find most right side controller
                for (var i = 0; i < trackedControllerCount; ++i)
                {
                    if (RoleMap.IsDeviceMapped(m_sortedDevices[i]))
                    {
                        continue;
                    }
                    MappingRole(HandRole.RightHand, m_sortedDevices[i]);
                    break;
                }
            }

            if (!RoleMap.IsRoleMapped(HandRole.LeftHand) && !RoleMap.IsRoleBound(HandRole.LeftHand))
            {
                // find most left side controller
                for (var i = trackedControllerCount - 1; i >= 0; --i)
                {
                    if (RoleMap.IsDeviceMapped(m_sortedDevices[i]))
                    {
                        continue;
                    }
                    MappingRole(HandRole.LeftHand, m_sortedDevices[i]);
                    break;
                }
            }

            MappingOthers();
        }