コード例 #1
0
        private bool IsTrackingDeviceNode(VRNodeState nodeState)
        {
            switch (nodeState.nodeType)
            {
            case VRNode.Head:
            case VRNode.RightHand:
            case VRNode.LeftHand:
            case VRNode.GameController:
            case VRNode.HardwareTracker:
            case VRNode.TrackingReference:
                return(true);

            default:
                return(false);
            }
        }
コード例 #2
0
        private bool TryGetNodeDeviceIndex(VRNodeState nodeState, out uint deviceIndex)
        {
            // only tracking certain type of node (some nodes share same uniqueID)
            if (!IsTrackingDeviceNode(nodeState))
            {
                deviceIndex = 0; return(false);
            }
            //Debug.Log(Time.frameCount + " TryGetNodeDeviceIndex " + nodeState.nodeType + " tracked=" + nodeState.tracked + " id=" + nodeState.uniqueID + " name=" + (InputTracking.GetNodeName(nodeState.uniqueID) ?? string.Empty));
            if (!m_node2Index.TryGetValue(nodeState.uniqueID, out deviceIndex))
            {
                // FIXME: 0ul is invalid id?
                if (nodeState.uniqueID == 0ul)
                {
                    return(false);
                }

                var validIndexFound = false;

                if (nodeState.nodeType == VRNode.Head)
                {
                    if (m_nodeStatesValid[0])
                    {
                        //Debug.LogWarning("[" + Time.frameCount + "] Multiple Head node found! drop node id:" + nodeState.uniqueID.ToString("X8") + " type:" + nodeState.nodeType + " name:" + InputTracking.GetNodeName(nodeState.uniqueID) + " tracked=" + nodeState.tracked);
                        return(false);
                    }

                    validIndexFound      = true;
                    m_nodeStatesValid[0] = true;
                    m_node2Index.Add(nodeState.uniqueID, 0u);
                    deviceIndex = 0;
                }
                else
                {
                    for (uint i = 1; i < MAX_DEVICE_COUNT; ++i)
                    {
                        if (!m_nodeStatesValid[i])
                        {
                            validIndexFound      = true;
                            m_nodeStatesValid[i] = true;
                            m_node2Index.Add(nodeState.uniqueID, i);

                            switch (nodeState.nodeType)
                            {
                            case VRNode.RightHand: m_rightIndex = i; break;

                            case VRNode.LeftHand: m_leftIndex = i; break;
                            }

                            deviceIndex = i;

                            break;
                        }
                    }
                }

                if (!validIndexFound)
                {
                    Debug.LogWarning("[" + Time.frameCount + "] VRNode added, but device index out of range, drop the node id:" + nodeState.uniqueID.ToString("X8") + " type:" + nodeState.nodeType + " name:" + InputTracking.GetNodeName(nodeState.uniqueID) + " tracked=" + nodeState.tracked);
                    return(false);
                }

                //Debug.Log("[" + Time.frameCount + "] Add node device index [" + deviceIndex + "] id=" + nodeState.uniqueID.ToString("X8") + " type=" + nodeState.nodeType + " tracked=" + nodeState.tracked);
            }

            return(true);
        }