Example #1
0
    void InitOVROverlay()
    {
        if (!OVRManager.isHmdPresent)
        {
            enabled = false;
            return;
        }

        constructedOverlayXRDevice = OVRManager.XRDevice.Unknown;
        if (OVRManager.loadedXRDevice == OVRManager.XRDevice.OpenVR)
        {
            OVR.OpenVR.CVROverlay overlay = OVR.OpenVR.OpenVR.Overlay;
            if (overlay != null)
            {
                OVR.OpenVR.EVROverlayError error = overlay.CreateOverlay(OpenVROverlayKey + transform.name, gameObject.name, ref OpenVROverlayHandle);
                if (error != OVR.OpenVR.EVROverlayError.None)
                {
                    enabled = false;
                    return;
                }
            }
            else
            {
                enabled = false;
                return;
            }
        }

        constructedOverlayXRDevice = OVRManager.loadedXRDevice;
        xrDeviceConstructed        = true;
    }
Example #2
0
    void OpenVROverlayUpdate(Vector3 scale, OVRPose pose)
    {
        OVR.OpenVR.CVROverlay overlayRef = OVR.OpenVR.OpenVR.Overlay;
        if (overlayRef == null)
        {
            return;
        }

        Texture overlayTex = textures[0];

        if (overlayTex != null)
        {
            OVR.OpenVR.EVROverlayError error = overlayRef.ShowOverlay(OpenVROverlayHandle);
            if (error == OVR.OpenVR.EVROverlayError.InvalidHandle || error == OVR.OpenVR.EVROverlayError.UnknownOverlay)
            {
                if (overlayRef.FindOverlay(OpenVROverlayKey + transform.name, ref OpenVROverlayHandle) != OVR.OpenVR.EVROverlayError.None)
                {
                    return;
                }
            }

            OVR.OpenVR.Texture_t tex = new OVR.OpenVR.Texture_t();
            tex.handle      = overlayTex.GetNativeTexturePtr();
            tex.eType       = SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL") ? OVR.OpenVR.ETextureType.OpenGL : OVR.OpenVR.ETextureType.DirectX;
            tex.eColorSpace = OVR.OpenVR.EColorSpace.Auto;
            overlayRef.SetOverlayTexture(OpenVROverlayHandle, ref tex);

            OVR.OpenVR.VRTextureBounds_t textureBounds = new OVR.OpenVR.VRTextureBounds_t();
            textureBounds.uMin = (0 + OpenVRUVOffsetAndScale.x) * OpenVRUVOffsetAndScale.z;
            textureBounds.vMin = (1 + OpenVRUVOffsetAndScale.y) * OpenVRUVOffsetAndScale.w;
            textureBounds.uMax = (1 + OpenVRUVOffsetAndScale.x) * OpenVRUVOffsetAndScale.z;
            textureBounds.vMax = (0 + OpenVRUVOffsetAndScale.y) * OpenVRUVOffsetAndScale.w;

            overlayRef.SetOverlayTextureBounds(OpenVROverlayHandle, ref textureBounds);

            OVR.OpenVR.HmdVector2_t vecMouseScale = new OVR.OpenVR.HmdVector2_t();
            vecMouseScale.v0 = OpenVRMouseScale.x;
            vecMouseScale.v1 = OpenVRMouseScale.y;
            overlayRef.SetOverlayMouseScale(OpenVROverlayHandle, ref vecMouseScale);

            overlayRef.SetOverlayWidthInMeters(OpenVROverlayHandle, scale.x);

            Matrix4x4 mat44 = Matrix4x4.TRS(pose.position, pose.orientation, Vector3.one);

            OVR.OpenVR.HmdMatrix34_t pose34 = mat44.ConvertToHMDMatrix34();

            overlayRef.SetOverlayTransformAbsolute(OpenVROverlayHandle, OVR.OpenVR.ETrackingUniverseOrigin.TrackingUniverseStanding, ref pose34);
        }
    }