// use -1 for absolute tracking space
    public static int GetDeviceIndex(DeviceRelation relation,
		TrackedDeviceClass deviceClass = TrackedDeviceClass.Controller,
		int relativeTo = (int)OpenVR.k_unTrackedDeviceIndex_Hmd)
    {
        var invXform = ((uint)relativeTo < OpenVR.k_unTrackedDeviceIndex_Hmd) ?
            Input(relativeTo).transform.GetInverse() : SteamVR_Utils.RigidTransform.identity;

        var vr = SteamVR.instance;
        var result = -1;
        var best = -float.MaxValue;
        var dir = (relation == DeviceRelation.Leftmost) ? Vector3.left : Vector3.right;
        for (int i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
        {
            if (i == relativeTo || vr.hmd.GetTrackedDeviceClass((uint)i) != deviceClass)
                continue;

            var device = Input(i);
            if (!device.connected)
                continue;

            if (relation == DeviceRelation.First)
                return i;

            var score = Vector3.Dot(dir, invXform * device.transform.pos);
            if (score > best)
            {
                result = i;
                best = score;
            }
        }

        return result;
    }
    // use -1 for absolute tracking space
    public static int GetDeviceIndex(DeviceRelation relation,
		TrackedDeviceClass deviceClass = TrackedDeviceClass.Controller,
		int relativeTo = (int)OpenVR.k_unTrackedDeviceIndex_Hmd)
    {
        var invXform = ((uint)relativeTo < OpenVR.k_unMaxTrackedDeviceCount) ?
            Input(relativeTo).transform.GetInverse() : SteamVR_Utils.RigidTransform.identity;

        var vr = SteamVR.instance;
        var result = -1;
        var best = -float.MaxValue;
        for (int i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
        {
            if (i == relativeTo || vr.hmd.GetTrackedDeviceClass((uint)i) != deviceClass)
                continue;

            var device = Input(i);
            if (!device.connected)
                continue;

            if (relation == DeviceRelation.First)
                return i;

            float score;

            var pos = invXform * device.transform.pos;
            if (relation == DeviceRelation.FarthestRight)
            {
                score = pos.x;
            }
            else if (relation == DeviceRelation.FarthestLeft)
            {
                score = -pos.x;
            }
            else
            {
                var dir = new Vector3(pos.x, 0.0f, pos.z).normalized;
                var dot = Vector3.Dot(dir, Vector3.forward);
                var cross = Vector3.Cross(dir, Vector3.forward);
                if (relation == DeviceRelation.Leftmost)
                {
                    score = (cross.y > 0.0f) ? 2.0f - dot : dot;
                }
                else
                {
                    score = (cross.y < 0.0f) ? 2.0f - dot : dot;
                }
            }

            if (score > best)
            {
                result = i;
                best = score;
            }
        }

        return result;
    }
Esempio n. 3
0
    public static int GetDeviceIndex(DeviceRelation relation,
                                     TrackedDeviceClass deviceClass = TrackedDeviceClass.Controller,
                                     int relativeTo = (int)OpenVR.k_unTrackedDeviceIndex_Hmd) // use -1 for absolute tracking space
    {
        var invXform = ((uint)relativeTo < OpenVR.k_unTrackedDeviceIndex_Hmd) ?
                       Input(relativeTo).transform.GetInverse() : SteamVR_Utils.RigidTransform.identity;

        var vr     = SteamVR.instance;
        var result = -1;
        var best   = -float.MaxValue;
        var dir    = (relation == DeviceRelation.Leftmost) ? Vector3.left : Vector3.right;

        for (int i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
        {
            if (i == relativeTo || vr.hmd.GetTrackedDeviceClass((uint)i) != deviceClass)
            {
                continue;
            }

            var device = Input(i);
            if (!device.connected)
            {
                continue;
            }

            if (relation == DeviceRelation.First)
            {
                return(i);
            }

            var score = Vector3.Dot(dir, invXform * device.transform.pos);
            if (score > best)
            {
                result = i;
                best   = score;
            }
        }

        return(result);
    }
Esempio n. 4
0
 internal static extern uint VR_IVRSystem_GetSortedTrackedDeviceIndicesOfClass(IntPtr instancePtr, TrackedDeviceClass eTrackedDeviceClass,  [In, Out] uint[] punTrackedDeviceIndexArray, uint unTrackedDeviceIndexArrayCount, uint unRelativeToTrackedDeviceIndex);
Esempio n. 5
0
 public abstract uint GetSortedTrackedDeviceIndicesOfClass(TrackedDeviceClass eTrackedDeviceClass,uint [] punTrackedDeviceIndexArray,uint unRelativeToTrackedDeviceIndex);
Esempio n. 6
0
 public override uint GetSortedTrackedDeviceIndicesOfClass(TrackedDeviceClass eTrackedDeviceClass,uint [] punTrackedDeviceIndexArray,uint unRelativeToTrackedDeviceIndex)
 {
     CheckIfUsable();
     uint result = VRNativeEntrypoints.VR_IVRSystem_GetSortedTrackedDeviceIndicesOfClass(m_pVRSystem,eTrackedDeviceClass,punTrackedDeviceIndexArray,(uint) punTrackedDeviceIndexArray.Length,unRelativeToTrackedDeviceIndex);
     return result;
 }
Esempio n. 7
0
    public static int GetDeviceIndex(DeviceRelation relation,
                                     TrackedDeviceClass deviceClass = TrackedDeviceClass.Controller,
                                     int relativeTo = (int)OpenVR.k_unTrackedDeviceIndex_Hmd) // use -1 for absolute tracking space
    {
        var invXform = ((uint)relativeTo < OpenVR.k_unMaxTrackedDeviceCount) ?
                       Input(relativeTo).transform.GetInverse() : SteamVR_Utils.RigidTransform.identity;

        var vr     = SteamVR.instance;
        var result = -1;
        var best   = -float.MaxValue;

        for (int i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
        {
            if (i == relativeTo || vr.hmd.GetTrackedDeviceClass((uint)i) != deviceClass)
            {
                continue;
            }

            var device = Input(i);
            if (!device.connected)
            {
                continue;
            }

            if (relation == DeviceRelation.First)
            {
                return(i);
            }

            float score;

            var pos = invXform * device.transform.pos;
            if (relation == DeviceRelation.FarthestRight)
            {
                score = pos.x;
            }
            else if (relation == DeviceRelation.FarthestLeft)
            {
                score = -pos.x;
            }
            else
            {
                var dir   = new Vector3(pos.x, 0.0f, pos.z).normalized;
                var dot   = Vector3.Dot(dir, Vector3.forward);
                var cross = Vector3.Cross(dir, Vector3.forward);
                if (relation == DeviceRelation.Leftmost)
                {
                    score = (cross.y > 0.0f) ? 2.0f - dot : dot;
                }
                else
                {
                    score = (cross.y < 0.0f) ? 2.0f - dot : dot;
                }
            }

            if (score > best)
            {
                result = i;
                best   = score;
            }
        }

        return(result);
    }