protected void MappingRoleIfUnbound(TRole role, uint deviceIndex) { if (!RoleMap.IsRoleBound(role) && !RoleMap.IsDeviceConnectedAndBound(deviceIndex)) { MappingRole(role, deviceIndex); } }
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 void MappingOtherControllers() { // mapping other controllers in order of device index var deviceIndex = 0u; var firstFoundTracker = VRModule.INVALID_DEVICE_INDEX; var rightIndex = RoleMap.GetMappedDeviceByRole(HandRole.RightHand); var leftIndex = RoleMap.GetMappedDeviceByRole(HandRole.LeftHand); for (var role = RoleInfo.MinValidRole; role <= RoleInfo.MaxValidRole; ++role) { if (!RoleInfo.IsValidRole(role)) { continue; } if (role == HandRole.RightHand || role == HandRole.LeftHand) { continue; } if (RoleMap.IsRoleBound(role)) { continue; } // find next valid device if (VRModule.IsValidDeviceIndex(deviceIndex)) { while (!IsController(deviceIndex) || RoleMap.IsDeviceConnectedAndBound(deviceIndex) || deviceIndex == rightIndex || deviceIndex == leftIndex) { if (!VRModule.IsValidDeviceIndex(firstFoundTracker) && IsTracker(deviceIndex)) { firstFoundTracker = deviceIndex; } if (!VRModule.IsValidDeviceIndex(++deviceIndex)) { break; } } } if (VRModule.IsValidDeviceIndex(deviceIndex)) { MappingRole(role, deviceIndex++); } else { UnmappingRole(role); } } // if external camera is not mapped, try mapping first found tracker if (!RoleMap.IsRoleMapped(HandRole.ExternalCamera) && VRModule.IsValidDeviceIndex(firstFoundTracker) && !RoleMap.IsDeviceConnectedAndBound(firstFoundTracker)) { MappingRole(HandRole.ExternalCamera, firstFoundTracker); } }
private void MappingTrackers() { var deviceIndex = 0u; for (var role = RoleInfo.MinValidRole; role <= RoleInfo.MaxValidRole; ++role) { if (!RoleInfo.IsValidRole(role)) { continue; } if (RoleMap.IsRoleBound(role)) { continue; } // find next valid device if (VRModule.IsValidDeviceIndex(deviceIndex)) { while (!IsTracker(deviceIndex) || RoleMap.IsDeviceConnectedAndBound(deviceIndex)) { if (!VRModule.IsValidDeviceIndex(++deviceIndex)) { break; } } } if (VRModule.IsValidDeviceIndex(deviceIndex)) { MappingRole(role, deviceIndex++); } else { UnmappingRole(role); } } }
private void MappingLeftRightHands() { // assign left/right controllers according to the hint var rightIndex = VRModule.GetRightControllerDeviceIndex(); var leftIndex = VRModule.GetLeftControllerDeviceIndex(); if (VRModule.GetCurrentDeviceState(rightIndex).isConnected) { MappingRoleIfUnbound(HandRole.RightHand, rightIndex); rightIndex = RoleMap.GetMappedDeviceByRole(HandRole.RightHand); } else if (RoleMap.IsRoleBound(HandRole.RightHand)) { rightIndex = RoleMap.GetMappedDeviceByRole(HandRole.RightHand); } else { rightIndex = VRModule.INVALID_DEVICE_INDEX; } if (VRModule.GetCurrentDeviceState(leftIndex).isConnected&& leftIndex != rightIndex) { MappingRoleIfUnbound(HandRole.LeftHand, leftIndex); leftIndex = RoleMap.GetMappedDeviceByRole(HandRole.LeftHand); } else if (RoleMap.IsRoleBound(HandRole.LeftHand)) { leftIndex = RoleMap.GetMappedDeviceByRole(HandRole.LeftHand); } else { leftIndex = VRModule.INVALID_DEVICE_INDEX; } // if not both left/right controllers are assigned, find and assign them with left/right most controller if (!VRModule.IsValidDeviceIndex(rightIndex) || !VRModule.IsValidDeviceIndex(leftIndex)) { // find right to left sorted controllers // FIXME: GetSortedTrackedDeviceIndicesOfClass doesn't return correct devices count right after device connected #if __VIU_STEAMVR if (VRModule.activeModule == SupportedVRModule.SteamVR) { var count = 0; var system = Valve.VR.OpenVR.System; if (system != null) { count = (int)system.GetSortedTrackedDeviceIndicesOfClass(Valve.VR.ETrackedDeviceClass.Controller, m_sortedDevices, Valve.VR.OpenVR.k_unTrackedDeviceIndex_Hmd); } foreach (var deviceIndex in m_sortedDevices) { if (m_sortedDeviceList.Count >= count) { break; } if (IsController(deviceIndex) && deviceIndex != rightIndex && deviceIndex != leftIndex && !RoleMap.IsDeviceConnectedAndBound(deviceIndex)) { m_sortedDeviceList.Add(deviceIndex); } } } else #endif { for (uint deviceIndex = 1u, imax = VRModule.GetDeviceStateCount(); deviceIndex < imax; ++deviceIndex) { if (IsController(deviceIndex) && deviceIndex != rightIndex && deviceIndex != leftIndex && !RoleMap.IsDeviceConnectedAndBound(deviceIndex)) { m_sortedDeviceList.Add(deviceIndex); } } if (m_sortedDeviceList.Count > 1) { SortDeviceIndicesByDirection(m_sortedDeviceList, VRModule.GetCurrentDeviceState(VRModule.HMD_DEVICE_INDEX).pose); } } if (m_sortedDeviceList.Count > 0 && !VRModule.IsValidDeviceIndex(rightIndex)) { rightIndex = m_sortedDeviceList[0]; m_sortedDeviceList.RemoveAt(0); // mapping right most controller MappingRole(HandRole.RightHand, rightIndex); } if (m_sortedDeviceList.Count > 0 && !VRModule.IsValidDeviceIndex(leftIndex)) { leftIndex = m_sortedDeviceList[m_sortedDeviceList.Count - 1]; // mapping left most controller MappingRole(HandRole.LeftHand, leftIndex); } m_sortedDeviceList.Clear(); } if (!VRModule.IsValidDeviceIndex(rightIndex)) { UnmappingRole(HandRole.RightHand); } if (!VRModule.IsValidDeviceIndex(leftIndex)) { UnmappingRole(HandRole.LeftHand); } }
public void Refresh() { // find right/left controller index var rightIndex = VRModule.INVALID_DEVICE_INDEX; var leftIndex = VRModule.INVALID_DEVICE_INDEX; if (RoleMap.IsRoleValueBound((int)ControllerRole.RightHand)) { rightIndex = RoleMap.GetMappedDeviceByRoleValue((int)ControllerRole.RightHand); } else { var index = VRModule.GetRightControllerDeviceIndex(); if (VRModule.GetDeviceState(index).deviceClass == VRModuleDeviceClass.Controller) { rightIndex = index; } } if (RoleMap.IsRoleValueBound((int)ControllerRole.LeftHand)) { leftIndex = RoleMap.GetMappedDeviceByRoleValue((int)ControllerRole.LeftHand); } else { var index = VRModule.GetRightControllerDeviceIndex(); if (VRModule.GetDeviceState(index).deviceClass == VRModuleDeviceClass.Controller) { leftIndex = index; } } if (leftIndex == rightIndex) { leftIndex = VRModule.INVALID_DEVICE_INDEX; } // find all other unbound controller class devices for (uint i = 0u, imax = VRModule.GetDeviceStateCount(); i < imax; ++i) { if (i == rightIndex) { continue; } if (i == leftIndex) { continue; } var device = VRModule.GetDeviceState(i); if (!device.isConnected) { continue; } if (device.deviceClass != VRModuleDeviceClass.Controller) { continue; } if (RoleMap.IsDeviceBound(device.serialNumber)) { continue; } m_sortedDeviceList.Add(i); } // if module didn't hint left/right controllers // find left/right most device in m_sortedDeviceList and assigned to leftIndex/rightIndex if (m_sortedDeviceList.Count > 0) { HandRoleHandler.SortDeviceIndicesByDirection(m_sortedDeviceList, VRModule.GetCurrentDeviceState(VRModule.HMD_DEVICE_INDEX).pose); if (rightIndex == VRModule.INVALID_DEVICE_INDEX && !RoleMap.IsRoleBound(ControllerRole.RightHand)) { rightIndex = m_sortedDeviceList[0]; m_sortedDeviceList.RemoveAt(0); } if (m_sortedDeviceList.Count > 0 && leftIndex == VRModule.INVALID_DEVICE_INDEX && !RoleMap.IsRoleBound(ControllerRole.RightHand)) { leftIndex = m_sortedDeviceList[m_sortedDeviceList.Count - 1]; m_sortedDeviceList.RemoveAt(m_sortedDeviceList.Count - 1); } } if (rightIndex != VRModule.INVALID_DEVICE_INDEX) { MappingRoleIfUnbound(ControllerRole.RightHand, rightIndex); } if (leftIndex != VRModule.INVALID_DEVICE_INDEX) { MappingRoleIfUnbound(ControllerRole.LeftHand, leftIndex); } if (m_sortedDeviceList.Count > 0) { var otherCtrlIndex = -1; var otherRole = ControllerRole.Controller3 - 1; while (NextUnmappedSortedDevice(ref otherCtrlIndex) && NextUnmappedRole(ref otherRole)) { MappingRole(otherRole, m_sortedDeviceList[otherCtrlIndex]); } m_sortedDeviceList.Clear(); } }
public void Refresh() { // find tracked right/left hand index var deviceCount = VRModule.GetDeviceStateCount(); var rightIndex = VRModule.INVALID_DEVICE_INDEX; var leftIndex = VRModule.INVALID_DEVICE_INDEX; for (uint deviceIndex = 0u; deviceIndex < deviceCount; ++deviceIndex) { var deviceState = VRModule.GetDeviceState(deviceIndex); if (deviceState.isConnected && deviceState.deviceClass == VRModuleDeviceClass.TrackedHand) { if (deviceState.deviceModel.IsRight()) { rightIndex = deviceIndex; } else if (deviceState.deviceModel.IsLeft()) { leftIndex = deviceIndex; } } } if (!RoleMap.IsRoleMapped(TrackedHandRole.RightHand)) { if (rightIndex < deviceCount) { MappingRoleIfUnbound(TrackedHandRole.RightHand, rightIndex); } } else if (!RoleMap.IsRoleBound(TrackedHandRole.RightHand)) { if (rightIndex < deviceCount) { MappingRoleIfUnbound(TrackedHandRole.RightHand, rightIndex); } else { UnmappingRole(TrackedHandRole.RightHand); } } if (!RoleMap.IsRoleMapped(TrackedHandRole.LeftHand)) { if (leftIndex < deviceCount) { MappingRoleIfUnbound(TrackedHandRole.LeftHand, leftIndex); } } else if (!RoleMap.IsRoleBound(TrackedHandRole.LeftHand)) { if (leftIndex < deviceCount) { MappingRoleIfUnbound(TrackedHandRole.LeftHand, leftIndex); } else { UnmappingRole(TrackedHandRole.LeftHand); } } }
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; } } }
// 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(); }