Ejemplo n.º 1
0
    private Transform ConfigureEyeAnchor(Transform root, XR.XRNode eye)
    {
        string    eyeName = (eye == XR.XRNode.CenterEye) ? "Center" : (eye == XR.XRNode.LeftEye) ? "Left" : "Right";
        string    name    = eyeName + eyeAnchorName;
        Transform anchor  = transform.Find(root.name + "/" + name);

        if (anchor == null)
        {
            anchor = transform.Find(name);
        }

        if (anchor == null)
        {
            string legacyName = legacyEyeAnchorName + eye.ToString();
            anchor = transform.Find(legacyName);
        }

        if (anchor == null)
        {
            anchor = new GameObject(name).transform;
        }

        anchor.name          = name;
        anchor.parent        = root;
        anchor.localScale    = Vector3.one;
        anchor.localPosition = Vector3.zero;
        anchor.localRotation = Quaternion.identity;

        return(anchor);
    }
Ejemplo n.º 2
0
    private static bool ValidateProperty(Node nodeType, ref NodeState requestedNodeState)
    {
        InputTracking.GetNodeStates(nodeStateList);

        if (nodeStateList.Count == 0)
        {
            return(false);
        }

        bool nodeStateFound = false;

        requestedNodeState = nodeStateList[0];

        for (int i = 0; i < nodeStateList.Count; i++)
        {
            if (nodeStateList[i].nodeType == nodeType)
            {
                requestedNodeState = nodeStateList[i];
                nodeStateFound     = true;
                break;
            }
        }

        return(nodeStateFound);
    }
Ejemplo n.º 3
0
    private static bool GetUnityXRNodeStateVector3(Node nodeType, NodeStatePropertyType propertyType, out Vector3 retVec)
    {
        retVec = Vector3.zero;

        NodeState requestedNodeState = default(NodeState);

        if (!ValidateProperty(nodeType, ref requestedNodeState))
        {
            return(false);
        }

        if (propertyType == NodeStatePropertyType.Acceleration)
        {
            if (requestedNodeState.TryGetAcceleration(out retVec))
            {
                return(true);
            }
        }
        else if (propertyType == NodeStatePropertyType.AngularAcceleration)
        {
#if UNITY_2017_2_OR_NEWER
            if (requestedNodeState.TryGetAngularAcceleration(out retVec))
            {
                return(true);
            }
#endif
        }
        else if (propertyType == NodeStatePropertyType.Velocity)
        {
            if (requestedNodeState.TryGetVelocity(out retVec))
            {
                return(true);
            }
        }
        else if (propertyType == NodeStatePropertyType.AngularVelocity)
        {
#if UNITY_2017_2_OR_NEWER
            if (requestedNodeState.TryGetAngularVelocity(out retVec))
            {
                return(true);
            }
#endif
        }
        else if (propertyType == NodeStatePropertyType.Position)
        {
            if (requestedNodeState.TryGetPosition(out retVec))
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 4
0
    private void ConfigureEyeDesc(XR.XRNode eye)
    {
        if (!OVRManager.isHmdPresent)
        {
            return;
        }

        OVRPlugin.Sizei    size  = OVRPlugin.GetEyeTextureSize((OVRPlugin.Eye)eye);
        OVRPlugin.Frustumf frust = OVRPlugin.GetEyeFrustum((OVRPlugin.Eye)eye);

        eyeDescs[(int)eye] = new EyeRenderDesc()
        {
            resolution = new Vector2(size.w, size.h),
            fov        = Mathf.Rad2Deg * new Vector2(frust.fovX, frust.fovY),
        };
    }
Ejemplo n.º 5
0
    private void ConfigureEyeDesc(Node eye)
    {
        if (!OVRManager.isHmdPresent)
        {
            return;
        }

        int eyeTextureWidth  = Settings.eyeTextureWidth;
        int eyeTextureHeight = Settings.eyeTextureHeight;

        eyeDescs[(int)eye]            = new EyeRenderDesc();
        eyeDescs[(int)eye].resolution = new Vector2(eyeTextureWidth, eyeTextureHeight);

        OVRPlugin.Frustumf2 frust;
        if (OVRPlugin.GetNodeFrustum2((OVRPlugin.Node)eye, out frust))
        {
            eyeDescs[(int)eye].fullFov.LeftFov  = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.LeftTan);
            eyeDescs[(int)eye].fullFov.RightFov = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.RightTan);
            eyeDescs[(int)eye].fullFov.UpFov    = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.UpTan);
            eyeDescs[(int)eye].fullFov.DownFov  = Mathf.Rad2Deg * Mathf.Atan(frust.Fov.DownTan);
        }
        else
        {
            OVRPlugin.Frustumf frustOld = OVRPlugin.GetEyeFrustum((OVRPlugin.Eye)eye);
            eyeDescs[(int)eye].fullFov.LeftFov  = Mathf.Rad2Deg * frustOld.fovX * 0.5f;
            eyeDescs[(int)eye].fullFov.RightFov = Mathf.Rad2Deg * frustOld.fovX * 0.5f;
            eyeDescs[(int)eye].fullFov.UpFov    = Mathf.Rad2Deg * frustOld.fovY * 0.5f;
            eyeDescs[(int)eye].fullFov.DownFov  = Mathf.Rad2Deg * frustOld.fovY * 0.5f;
        }

        // Symmetric Fov uses the maximum fov angle
        float maxFovX = Mathf.Max(eyeDescs[(int)eye].fullFov.LeftFov, eyeDescs[(int)eye].fullFov.RightFov);
        float maxFovY = Mathf.Max(eyeDescs[(int)eye].fullFov.UpFov, eyeDescs[(int)eye].fullFov.DownFov);

        eyeDescs[(int)eye].fov.x = maxFovX * 2.0f;
        eyeDescs[(int)eye].fov.y = maxFovY * 2.0f;

        if (!OVRPlugin.AsymmetricFovEnabled)
        {
            eyeDescs[(int)eye].fullFov.LeftFov  = maxFovX;
            eyeDescs[(int)eye].fullFov.RightFov = maxFovX;

            eyeDescs[(int)eye].fullFov.UpFov   = maxFovY;
            eyeDescs[(int)eye].fullFov.DownFov = maxFovY;
        }
    }
Ejemplo n.º 6
0
    bool isRightHand;                                                           //Is this sword in the right hand?

    void Start()
    {
        //Get a reference to the animator component on the sword child object
        anim = GetComponentInChildren <Animator> ();

        //Determine if this is the right hand or not by examining the parent VRObjectTracking script
        UnityEngine.XR.XRNode node = transform.parent.GetComponent <VRObjectTracking> ().node;
        if (node == UnityEngine.XR.XRNode.RightHand)
        {
            isRightHand = true;
        }

        //Invoke the enable method after a delay. This is done so that the sword speed isn't being measured
        //as soon as the scene starts. After the first frame, VR tracking becomes enabled which will make
        //the sword position jump and have a high speed
        Invoke("Enable", initialDelay);
    }
Ejemplo n.º 7
0
 public static bool GetNodeStatePropertyQuaternion(Node nodeType, NodeStatePropertyType propertyType, OVRPlugin.Node ovrpNodeType, OVRPlugin.Step stepType, out Quaternion retQuat)
 {
     retQuat = Quaternion.identity;
     switch (propertyType)
     {
     case NodeStatePropertyType.Orientation:
         if (OVRManager.loadedXRDevice == OVRManager.XRDevice.Oculus)
         {
             retQuat = OVRPlugin.GetNodePose(ovrpNodeType, stepType).ToOVRPose().orientation;
             return(true);
         }
         if (GetUnityXRNodeStateQuaternion(nodeType, NodeStatePropertyType.Orientation, out retQuat))
         {
             return(true);
         }
         break;
     }
     return(false);
 }
Ejemplo n.º 8
0
    /// <summary>
    /// Use this function to set texture and texNativePtr when app is running
    /// GetNativeTexturePtr is a slow behavior, the value should be pre-cached
    /// </summary>
    public void OverrideOverlayTextureInfo(Texture srcTexture, IntPtr nativePtr, XR.XRNode node)
    {
        int index = (node == XR.XRNode.RightEye) ? 1 : 0;

        if (textures.Length <= index)
        {
            return;
        }

        stageCount = 3;
        CreateLayerTextures(true, true, new OVRPlugin.Sizei()
        {
            w = srcTexture.width, h = srcTexture.height
        }, false);

        textures[index] = srcTexture;
        layerTextures[index].appTexture    = srcTexture;
        layerTextures[index].appTexturePtr = nativePtr;
    }
Ejemplo n.º 9
0
    private static bool GetUnityXRNodeStateQuaternion(Node nodeType, NodeStatePropertyType propertyType, out Quaternion retQuat)
    {
        retQuat = Quaternion.identity;

        NodeState requestedNodeState = default(NodeState);

        if (!ValidateProperty(nodeType, ref requestedNodeState))
        {
            return(false);
        }

        if (propertyType == NodeStatePropertyType.Orientation)
        {
            if (requestedNodeState.TryGetRotation(out retQuat))
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 10
0
 /// <summary>
 /// Gets the resolution and field of view for the given eye.
 /// </summary>
 public EyeRenderDesc GetEyeRenderDesc(UnityEngine.XR.XRNode eye)
 {
     return(eyeDescs[(int)eye]);
 }
Ejemplo n.º 11
0
    public static bool GetNodeStatePropertyVector3(Node nodeType, NodeStatePropertyType propertyType, OVRPlugin.Node ovrpNodeType, OVRPlugin.Step stepType, out Vector3 retVec)
    {
        retVec = Vector3.zero;
        switch (propertyType)
        {
        case NodeStatePropertyType.Acceleration:
            if (OVRManager.loadedXRDevice == OVRManager.XRDevice.Oculus)
            {
                retVec = OVRPlugin.GetNodeAcceleration(ovrpNodeType, stepType).FromFlippedZVector3f();
                return(true);
            }
#if UNITY_2017_1_OR_NEWER
            if (GetUnityXRNodeStateVector3(nodeType, NodeStatePropertyType.Acceleration, out retVec))
            {
                return(true);
            }
#endif
            break;

        case NodeStatePropertyType.AngularAcceleration:
            if (OVRManager.loadedXRDevice == OVRManager.XRDevice.Oculus)
            {
                retVec = OVRPlugin.GetNodeAngularAcceleration(ovrpNodeType, stepType).FromFlippedZVector3f();
                return(true);
            }
#if UNITY_2017_2_OR_NEWER
            if (GetUnityXRNodeStateVector3(nodeType, NodeStatePropertyType.AngularAcceleration, out retVec))
            {
                return(true);
            }
#endif
            break;

        case NodeStatePropertyType.Velocity:
            if (OVRManager.loadedXRDevice == OVRManager.XRDevice.Oculus)
            {
                retVec = OVRPlugin.GetNodeVelocity(ovrpNodeType, stepType).FromFlippedZVector3f();
                return(true);
            }
#if UNITY_2017_1_OR_NEWER
            if (GetUnityXRNodeStateVector3(nodeType, NodeStatePropertyType.Velocity, out retVec))
            {
                return(true);
            }
#endif
            break;

        case NodeStatePropertyType.AngularVelocity:
            if (OVRManager.loadedXRDevice == OVRManager.XRDevice.Oculus)
            {
                retVec = OVRPlugin.GetNodeAngularVelocity(ovrpNodeType, stepType).FromFlippedZVector3f();
                return(true);
            }
#if UNITY_2017_2_OR_NEWER
            if (GetUnityXRNodeStateVector3(nodeType, NodeStatePropertyType.AngularVelocity, out retVec))
            {
                return(true);
            }
#endif
            break;

        case NodeStatePropertyType.Position:
            if (OVRManager.loadedXRDevice == OVRManager.XRDevice.Oculus)
            {
                retVec = OVRPlugin.GetNodePose(ovrpNodeType, stepType).ToOVRPose().position;
                return(true);
            }
#if UNITY_2017_1_OR_NEWER
            if (GetUnityXRNodeStateVector3(nodeType, NodeStatePropertyType.Position, out retVec))
            {
                return(true);
            }
#endif
            break;
        }

        return(false);
    }
Ejemplo n.º 12
0
 /// <summary>
 /// Gets the resolution and field of view for the given eye.
 /// </summary>
 public EyeRenderDesc GetEyeRenderDesc(XR.XRNode eye)
 {
     return(eyeDescs[(int)eye]);
 }
 private static UXR.XRNode GetUNode(UXR.XRNode node)
 {
     return((UXR.XRNode)Enum.Parse(typeof(UXR.XRNode), node.ToString()));
 }
 public static Quaternion GetLocalRotation(UXR.XRNode node)
 {
     return(UXR.InputTracking.GetLocalRotation(GetUNode(node)));
 }
 public static Vector3 GetLocalPosition(UXR.XRNode node)
 {
     return(UXR.InputTracking.GetLocalPosition(GetUNode(node)));
 }