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); } }
public override void OnBindingChanged(HandRole role, string deviceSN, bool bound) { if (!bound) { if (RoleMap.IsRoleMapped(role) && !IsController(RoleMap.GetMappedDeviceByRole(role))) { UnmappingRole(role); } } if (handsAreMappedOrBound) { MappingOthers(); } else { MappingHandsAndOthers(); } }
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); } }