/// <summary>
 /// Update the Overlay's Position and return the resulting HmdMatrix34_t
 /// </summary>
 /// <returns></returns>
 private HmdMatrix34_t GetOverlayPosition()
 {
     if (_anchor == OpenVR.k_unTrackedDeviceIndexInvalid)
     {
         var offset = new SteamVR_Utils.RigidTransform(OverlayReference.transform, transform);
         offset.pos.x /= OverlayReference.transform.localScale.x;
         offset.pos.y /= OverlayReference.transform.localScale.y;
         offset.pos.z /= OverlayReference.transform.localScale.z;
         var t = offset.ToHmdMatrix34();
         return(t);
     }
     else
     {
         if (ZeroReference == null)
         {
             ZeroReference = new GameObject("Zero Reference")
             {
                 hideFlags = HideFlags.HideInHierarchy
             }
         }
         ;
         var offset = new SteamVR_Utils.RigidTransform(ZeroReference.transform, OverlayReference.transform);
         offset.pos.x /= ZeroReference.transform.localScale.x;
         offset.pos.y /= ZeroReference.transform.localScale.y;
         offset.pos.z /= ZeroReference.transform.localScale.z;
         var t = offset.ToHmdMatrix34();
         return(t);
     }
 }
Exemple #2
0
        private static void SaveConfiguration()
        {
            Vector3    zeroPosePosition;
            Quaternion zeroPoseRotation;

            Vector2[] hardBoundsPoints;
            Vector2[] softBoundsPoints;
            GetStandingOnlyConfigurationValues(out zeroPosePosition, out zeroPoseRotation, out hardBoundsPoints,
                                               out softBoundsPoints);
            var chaperoneSetup = OpenVR.ChaperoneSetup;

            if (chaperoneSetup == null)
            {
                Debug.LogError("Failed to get chaperone setup interface.");
            }
            else
            {
                var rigidTransform = new SteamVR_Utils.RigidTransform(zeroPosePosition, zeroPoseRotation);
                var hmdMatrix34    = rigidTransform.ToHmdMatrix34();
                chaperoneSetup.SetWorkingStandingZeroPoseToRawTrackingPose(ref hmdMatrix34);
                var pQuadsBuffer = new HmdQuad_t[hardBoundsPoints.Length];
                for (var index1 = 0; index1 < pQuadsBuffer.Length; ++index1)
                {
                    var index2  = (index1 + 1) % pQuadsBuffer.Length;
                    var point   = new Vector3(hardBoundsPoints[index1].x, 0.0f, hardBoundsPoints[index1].y);
                    var vector3 = rigidTransform.InverseTransformPoint(point);
                    pQuadsBuffer[index1].vCorners0.v0 = vector3.x;
                    pQuadsBuffer[index1].vCorners0.v1 = 0.0f;
                    pQuadsBuffer[index1].vCorners0.v2 = -vector3.z;
                    pQuadsBuffer[index1].vCorners1.v0 = vector3.x;
                    pQuadsBuffer[index1].vCorners1.v1 = 2.43f;
                    pQuadsBuffer[index1].vCorners1.v2 = -vector3.z;
                    point   = new Vector3(hardBoundsPoints[index2].x, 0.0f, hardBoundsPoints[index2].y);
                    vector3 = rigidTransform.InverseTransformPoint(point);
                    pQuadsBuffer[index1].vCorners2.v0 = vector3.x;
                    pQuadsBuffer[index1].vCorners2.v1 = 2.43f;
                    pQuadsBuffer[index1].vCorners2.v2 = -vector3.z;
                    pQuadsBuffer[index1].vCorners3.v0 = vector3.x;
                    pQuadsBuffer[index1].vCorners3.v1 = 0.0f;
                    pQuadsBuffer[index1].vCorners3.v2 = -vector3.z;
                }
                chaperoneSetup.SetWorkingCollisionBoundsInfo(pQuadsBuffer);
                var a1 = 0.0f;
                var a2 = 0.0f;
                var a3 = 0.0f;
                var a4 = 0.0f;
                for (var index = 0; index < softBoundsPoints.Length; ++index)
                {
                    var point   = new Vector3(softBoundsPoints[index].x, 0.0f, softBoundsPoints[index].y);
                    var vector3 = rigidTransform.InverseTransformPoint(point);
                    a1 = Mathf.Min(a1, vector3.x);
                    a2 = Mathf.Max(a2, vector3.x);
                    a3 = Mathf.Min(a3, vector3.z);
                    a4 = Mathf.Max(a4, vector3.z);
                }
                chaperoneSetup.SetWorkingPlayAreaSize(a2 - a1, a4 - a3);
                chaperoneSetup.CommitWorkingCopy(EChaperoneConfigFile.Live);
            }
        }
Exemple #3
0
        /// <summary>
        /// ルーム情報を初期化
        /// </summary>
        public static void Reset()
        {
            OpenVR.ChaperoneSetup.ReloadFromDisk(EChaperoneConfigFile.Live);
            var rigid = new SteamVR_Utils.RigidTransform(Vector3.zero, Quaternion.identity);
            var mat   = rigid.ToHmdMatrix34();

            OpenVR.ChaperoneSetup.SetWorkingStandingZeroPoseToRawTrackingPose(ref mat);
            OpenVR.ChaperoneSetup.CommitWorkingCopy(EChaperoneConfigFile.Live);
        }
    // Helper to create (or reuse if possible) each of our different overlay types.
    private ulong GetOverlayHandle(string overlayName, Transform transform, float widthInMeters = 1.0f)
    {
        ulong handle = OpenVR.k_ulOverlayHandleInvalid;

        var overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return(handle);
        }

        var key = SteamVR_Overlay.key + "." + overlayName;

        var error = overlay.FindOverlay(key, ref handle);

        if (error != EVROverlayError.None)
        {
            error = overlay.CreateOverlay(key, overlayName, ref handle);
        }
        if (error == EVROverlayError.None)
        {
            overlay.ShowOverlay(handle);
            overlay.SetOverlayAlpha(handle, alpha);
            overlay.SetOverlayWidthInMeters(handle, widthInMeters);

            // D3D textures are upside-down in Unity to match OpenGL.
            if (SteamVR.instance.textureType == ETextureType.DirectX)
            {
                var textureBounds = new VRTextureBounds_t();
                textureBounds.uMin = 0;
                textureBounds.vMin = 1;
                textureBounds.uMax = 1;
                textureBounds.vMax = 0;
                overlay.SetOverlayTextureBounds(handle, ref textureBounds);
            }

            // Convert from world space to tracking space using the top-most camera.
            var vrcam = (loadingScreenDistance == 0.0f) ? SteamVR_Render.Top() : null;
            if (vrcam != null && vrcam.origin != null)
            {
                var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
                offset.pos.x /= vrcam.origin.localScale.x;
                offset.pos.y /= vrcam.origin.localScale.y;
                offset.pos.z /= vrcam.origin.localScale.z;

                var t = offset.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);
            }
            else
            {
                var t = new SteamVR_Utils.RigidTransform(transform).ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);
            }
        }

        return(handle);
    }
Exemple #5
0
        private void updateOverlay()
        {
            var overlay = OpenVR.Overlay;

            if (overlay == null)
            {
                return;
            }
            var error = overlay.SetOverlayCurvature(_overlay, OVERLAY_CURVATURE);

            if (error != EVROverlayError.None)
            {
                LogError("Error setting overlay curvature.");
            }
            error = overlay.ShowOverlay(_overlay);
            if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
            {
                LogDebug("Invalid Handle or UnknownOverlay");
                if (overlay.FindOverlay(OVERLAY_KEY, ref _overlay) != EVROverlayError.None)
                {
                    return;
                }
            }
            Texture_t tex = new Texture_t();

            // We need to blit the _guiTexture into a secondary texture upside down
            // and pass the second texture into the overlay instead to get the gui
            // to display right-side up. Alternative to this was using a negative scale
            // on the immediate children of the canvas, but that results in having inverted
            // mouse cursor controls.
            Graphics.Blit(_guiTexture, _overlayTexture, new Vector2(1, -1), new Vector2(0, 1));
            tex.handle      = _overlayTexture.GetNativeTexturePtr();
            tex.eType       = SteamVR.instance.textureType;
            tex.eColorSpace = EColorSpace.Auto;
            overlay.SetOverlayTexture(_overlay, ref tex);
            overlay.SetOverlayAlpha(_overlay, 1.0f);
            if (VRPlayer.instance != null)
            {
                // Passing the same transform to this RigidTransform constructor returns a RigidTransform
                // with the same position but inverse rotation. We then offset it in the Z direction, which creates
                // the result of having a screen "z" units offset in front of the player. The screen will be at a fixed
                // distance in front of the character and drawn over top of everything else regardless of distance,
                // hence "overlay". This is great for the GUI because things like minimap and health won't ever be
                // obstructed by world objects, regardless of whether or not the GUI element is behind the object with
                // regard to distance from the camera.
                var   offset = new SteamVR_Utils.RigidTransform(VRPlayer.instance.transform, VRPlayer.instance.transform);
                float width  = 4;
                overlay.SetOverlayWidthInMeters(_overlay, width);
                offset.pos.z += 2f;
                offset.pos.y += 1f;
                offset.pos.x += 0.5f;
                var t = offset.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(_overlay, SteamVR.settings.trackingSpace, ref t);
            }
        }
    public void SaveChaperone()
    {
        TweakAction     = TweakActionType.save;
        ChaperoneSaving = true;
        ChaperoneCalibrationState state = OpenVR.Chaperone.GetCalibrationState();

        if (state != ChaperoneCalibrationState.OK)
        {
            Debug.Log("GetCalibrationState() = " + state.ToString());
            return;
        }


        SteamVR_Utils.RigidTransform rt = new SteamVR_Utils.RigidTransform();
        rt.pos = PlaySpace.transform.position;
        rt.rot = PlaySpace.transform.rotation;

        HmdMatrix34_t mat = rt.ToHmdMatrix34();

        OpenVR.ChaperoneSetup.SetWorkingStandingZeroPoseToRawTrackingPose(ref mat);

        OpenVR.ChaperoneSetup.SetWorkingPlayAreaSize(PlaySpace.transform.localScale.x, PlaySpace.transform.localScale.z);

        HmdQuad_t[] pQuadsBuffer      = new HmdQuad_t[WallCount];
        ChaperonePlaneProperties wall = FirstWall;

        for (int index = 0; index < WallCount; index++)
        {
            Vector3 wallcorner = Vector3.Scale(PlaySpace.transform.InverseTransformPoint(wall.transform.TransformPoint(new Vector3(0.5f, 0f, 0f))), PlaySpace.transform.localScale);
            pQuadsBuffer[index].vCorners0.v0 = wallcorner.x;
            pQuadsBuffer[index].vCorners0.v1 = wallcorner.y;
            pQuadsBuffer[index].vCorners0.v2 = -wallcorner.z;

            wallcorner = Vector3.Scale(PlaySpace.transform.InverseTransformPoint(wall.transform.TransformPoint(new Vector3(0.5f, 1f, 0f))), PlaySpace.transform.localScale);
            pQuadsBuffer[index].vCorners1.v0 = wallcorner.x;
            pQuadsBuffer[index].vCorners1.v1 = wallcorner.y;
            pQuadsBuffer[index].vCorners1.v2 = -wallcorner.z;

            wallcorner = Vector3.Scale(PlaySpace.transform.InverseTransformPoint(wall.transform.TransformPoint(new Vector3(-0.5f, 1f, 0f))), PlaySpace.transform.localScale);
            pQuadsBuffer[index].vCorners2.v0 = wallcorner.x;
            pQuadsBuffer[index].vCorners2.v1 = wallcorner.y;
            pQuadsBuffer[index].vCorners2.v2 = -wallcorner.z;

            wallcorner = Vector3.Scale(PlaySpace.transform.InverseTransformPoint(wall.transform.TransformPoint(new Vector3(-0.5f, 0f, 0f))), PlaySpace.transform.localScale);
            pQuadsBuffer[index].vCorners3.v0 = wallcorner.x;
            pQuadsBuffer[index].vCorners3.v1 = wallcorner.y;
            pQuadsBuffer[index].vCorners3.v2 = -wallcorner.z;

            wall = wall.LeftWall;
        }
        OpenVR.ChaperoneSetup.SetWorkingCollisionBoundsInfo(pQuadsBuffer);
        OpenVR.ChaperoneSetup.CommitWorkingCopy(EChaperoneConfigFile.Live);//
        ReloadChaperone();
        ChaperoneSaving = false;
    }
Exemple #7
0
        /// <summary>
        /// Set the overlay transform in SteamVR
        /// </summary>
        /// <param name="newPos">The new position</param>
        /// <param name="newRot">The new rotation</param>
        /// <param name="setTarget">Should this be the new target position, or is this temporary?</param>
        public void SetTransform(Vector3 newPos, Vector3 newRot, bool setTarget = true)
        {
            pos = newPos;
            rot = newRot;

            if (setTarget)
            {
                targetPos = newPos;
                targetRot = newRot;
            }

            matrixConverter.pos = newPos;
            matrixConverter.rot = Quaternion.Euler(newRot);


            _overlayTransform = matrixConverter.ToHmdMatrix34();
            _overlayTransformAbsoluteTrackingOrigin = SteamVRManager.trackingSpace;

            if (!CheckValid())
            {
                return;
            }

            switch (_overlayTransformType)
            {
            default:
            case VROverlayTransformType.VROverlayTransform_Absolute:

                error = OpenVR.Overlay.SetOverlayTransformAbsolute(handle, _overlayTransformAbsoluteTrackingOrigin,
                                                                   ref _overlayTransform);

                break;

            case VROverlayTransformType.VROverlayTransform_TrackedDeviceRelative:

                error = OpenVR.Overlay.SetOverlayTransformTrackedDeviceRelative(handle,
                                                                                _overlayTransformTrackedDeviceRelativeIndex, ref _overlayTransform);


                break;
            }
        }
Exemple #8
0
        public Overlay(string key, string name)
        {
            this.key  = key;
            this.name = name;
            var offset = new SteamVR_Utils.RigidTransform
            {
                rot = Quaternion.identity
            };

            _hmdTransform = offset.ToHmdMatrix34();
        }
Exemple #9
0
    // Token: 0x06005F2D RID: 24365 RVA: 0x00215594 File Offset: 0x00213994
    private ulong GetOverlayHandle(string overlayName, Transform transform, float widthInMeters = 1f)
    {
        ulong      num     = 0UL;
        CVROverlay overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return(num);
        }
        string          pchOverlayKey   = SteamVR_Overlay.key + "." + overlayName;
        EVROverlayError evroverlayError = overlay.FindOverlay(pchOverlayKey, ref num);

        if (evroverlayError != EVROverlayError.None)
        {
            evroverlayError = overlay.CreateOverlay(pchOverlayKey, overlayName, ref num);
        }
        if (evroverlayError == EVROverlayError.None)
        {
            overlay.ShowOverlay(num);
            overlay.SetOverlayAlpha(num, this.alpha);
            overlay.SetOverlayWidthInMeters(num, widthInMeters);
            if (SteamVR.instance.textureType == ETextureType.DirectX)
            {
                VRTextureBounds_t vrtextureBounds_t = default(VRTextureBounds_t);
                vrtextureBounds_t.uMin = 0f;
                vrtextureBounds_t.vMin = 1f;
                vrtextureBounds_t.uMax = 1f;
                vrtextureBounds_t.vMax = 0f;
                overlay.SetOverlayTextureBounds(num, ref vrtextureBounds_t);
            }
            SteamVR_Camera steamVR_Camera = (this.loadingScreenDistance != 0f) ? null : SteamVR_Render.Top();
            if (steamVR_Camera != null && steamVR_Camera.origin != null)
            {
                SteamVR_Utils.RigidTransform rigidTransform = new SteamVR_Utils.RigidTransform(steamVR_Camera.origin, transform);
                rigidTransform.pos.x = rigidTransform.pos.x / steamVR_Camera.origin.localScale.x;
                rigidTransform.pos.y = rigidTransform.pos.y / steamVR_Camera.origin.localScale.y;
                rigidTransform.pos.z = rigidTransform.pos.z / steamVR_Camera.origin.localScale.z;
                HmdMatrix34_t hmdMatrix34_t = rigidTransform.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(num, SteamVR_Render.instance.trackingSpace, ref hmdMatrix34_t);
            }
            else
            {
                SteamVR_Utils.RigidTransform rigidTransform2 = new SteamVR_Utils.RigidTransform(transform);
                HmdMatrix34_t hmdMatrix34_t2 = rigidTransform2.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(num, SteamVR_Render.instance.trackingSpace, ref hmdMatrix34_t2);
            }
        }
        return(num);
    }
    private void UpdateOverlay()
    {
        var overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return;
        }
        if (OverlayTexture != null)
        {
            var error = overlay.ShowOverlay(_handle);
            if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
            {
                if (overlay.FindOverlay(Key + gameObject.GetInstanceID(), ref _handle) != EVROverlayError.None)
                {
                    return;
                }
            }
            var tex = new Texture_t
            {
                handle      = OverlayTexture.GetNativeTexturePtr(),
                eType       = SteamVR.instance.graphicsAPI,
                eColorSpace = EColorSpace.Auto
            };
            overlay.SetOverlayColor(_handle, 1f, 1f, 1f);
            overlay.SetOverlayTexture(_handle, ref tex);
            overlay.SetOverlayAlpha(_handle, Alpha);
            var textureBounds = new VRTextureBounds_t
            {
                uMin = (0 + UvOffset.x) * UvOffset.z,
                vMin = (1 + UvOffset.y) * UvOffset.w,
                uMax = (1 + UvOffset.x) * UvOffset.z,
                vMax = (0 + UvOffset.y) * UvOffset.w
            };
            overlay.SetOverlayTextureBounds(_handle, ref textureBounds);
            var vrcam  = SteamVR_Render.Top();
            var offset = new SteamVR_Utils.RigidTransform(OverlayReference.transform, transform);
            offset.pos.x /= OverlayReference.transform.localScale.x;
            offset.pos.y /= OverlayReference.transform.localScale.y;
            offset.pos.z /= OverlayReference.transform.localScale.z;
            var t = offset.ToHmdMatrix34();
            overlay.SetOverlayTransformTrackedDeviceRelative(_handle, 0, ref t);
        }
        else
        {
            overlay.HideOverlay(_handle);
        }
    }
Exemple #11
0
        private void updateOverlayGuiSizeAndPosition()
        {
            var overlay = OpenVR.Overlay;

            if (overlay == null)
            {
                return;
            }
            var offsetPosition = new Vector3(0f, VHVRConfig.GetOverlayVerticalOffset(), VHVRConfig.GetOverlayDistance());
            var offsetRotation = Quaternion.identity;

            if (useDynamicallyPositionedGui())
            {
                var currentDirection = getCurrentGuiDirection();
                if (isRecentering)
                {
                    // We are currently recentering, so calculate a new rotation a step towards the target
                    // rotation and reposition the GUI to that rotation. If the new rotation is close
                    // enough to the target, then end recentering for next frame.
                    var targetDirection = getTargetGuiDirection();
                    var stepDirection   = Vector3.Slerp(currentDirection, targetDirection, VHVRConfig.GuiRecenterSpeed() * Mathf.Deg2Rad * Time.deltaTime);
                    var stepRotation    = Quaternion.LookRotation(stepDirection, VRPlayer.instance.transform.up);
                    offsetPosition = stepRotation * offsetPosition;
                    offsetRotation = stepRotation;
                    maybeResetIsRecentering(stepDirection, targetDirection);
                }
                else
                {
                    // Not recentering, so leave the GUI position where it is at
                    var currentRotation = Quaternion.LookRotation(currentDirection, VRPlayer.instance.transform.up);
                    offsetPosition = currentRotation * offsetPosition;
                    offsetRotation = currentRotation;
                }
            }
            var offset = new SteamVR_Utils.RigidTransform(offsetPosition, offsetRotation);

            overlay.SetOverlayWidthInMeters(_overlay, VHVRConfig.GetOverlayWidth());
            var t = offset.ToHmdMatrix34();

            overlay.SetOverlayTransformAbsolute(_overlay, SteamVR.settings.trackingSpace, ref t);
        }
 /// <summary>
 /// Update the Overlay's Position and return the resulting HmdMatrix34_t
 /// </summary>
 /// <returns></returns>
 private HmdMatrix34_t GetOverlayPosition()
 {
     if (_anchor == OpenVR.k_unTrackedDeviceIndexInvalid)
     {
         var offset = new SteamVR_Utils.RigidTransform(OverlayReference.transform, transform);
         offset.pos.x /= OverlayReference.transform.localScale.x;
         offset.pos.y /= OverlayReference.transform.localScale.y;
         offset.pos.z /= OverlayReference.transform.localScale.z;
         var t = offset.ToHmdMatrix34();
         return(t);
     }
     else
     {
         var offset = new SteamVR_Utils.RigidTransform(HOTK_Overlay.ZeroReference.transform, OverlayReference.transform);
         offset.pos.x /= HOTK_Overlay.ZeroReference.transform.localScale.x;
         offset.pos.y /= HOTK_Overlay.ZeroReference.transform.localScale.y;
         offset.pos.z /= HOTK_Overlay.ZeroReference.transform.localScale.z;
         var t = offset.ToHmdMatrix34();
         return(t);
     }
 }
Exemple #13
0
            /**
             * Set an absolute transform for the overlay, using a RigidTransform
             */
            public void SetTransformAbsolute(ETrackingUniverseOrigin trackingUniverseOrigin, SteamVR_Utils.RigidTransform rigidTransform)
            {
                var t = rigidTransform.ToHmdMatrix34();

                SetTransformAbsolute(trackingUniverseOrigin, ref t);
            }
    // Helper to create (or reuse if possible) each of our different overlay types.
    ulong GetOverlayHandle(string overlayName, Transform transform, float widthInMeters = 1.0f)
    {
        ulong handle = OpenVR.k_ulOverlayHandleInvalid;

        var overlay = OpenVR.Overlay;
        if (overlay == null)
            return handle;

        var key = SteamVR_Overlay.key + "." + overlayName;

        var error = overlay.FindOverlay(key, ref handle);
        if (error != EVROverlayError.None)
            error = overlay.CreateOverlay(key, overlayName, ref handle);
        if (error == EVROverlayError.None)
        {
            overlay.ShowOverlay(handle);
            overlay.SetOverlayAlpha(handle, alpha);
            overlay.SetOverlayWidthInMeters(handle, widthInMeters);

            // D3D textures are upside-down in Unity to match OpenGL.
            if (SteamVR.instance.graphicsAPI == EGraphicsAPIConvention.API_DirectX)
            {
                var textureBounds = new VRTextureBounds_t();
                textureBounds.uMin = 0;
                textureBounds.vMin = 1;
                textureBounds.uMax = 1;
                textureBounds.vMax = 0;
                overlay.SetOverlayTextureBounds(handle, ref textureBounds);
            }

            // Convert from world space to tracking space using the top-most camera.
            var vrcam = (loadingScreenDistance == 0.0f) ? SteamVR_Render.Top() : null;
            if (vrcam != null && vrcam.origin != null)
            {
                var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
                offset.pos.x /= vrcam.origin.localScale.x;
                offset.pos.y /= vrcam.origin.localScale.y;
                offset.pos.z /= vrcam.origin.localScale.z;

                var t = offset.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);
            }
            else
            {
                var t = new SteamVR_Utils.RigidTransform(transform).ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);
            }
        }

        return handle;
    }
    public void UpdateOverlay()
    {
        var overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return;
        }

        if (texture != null)
        {
            var error = overlay.ShowOverlay(handle);
            if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
            {
                if (overlay.FindOverlay(key, ref handle) != EVROverlayError.None)
                {
                    return;
                }
            }

            var tex = new Texture_t();
            tex.handle      = texture.GetNativeTexturePtr();
            tex.eType       = SteamVR.instance.graphicsAPI;
            tex.eColorSpace = EColorSpace.Auto;
            overlay.SetOverlayTexture(handle, ref tex);

            overlay.SetOverlayAlpha(handle, alpha);
            overlay.SetOverlayWidthInMeters(handle, scale);
            overlay.SetOverlayAutoCurveDistanceRangeInMeters(handle, curvedRange.x, curvedRange.y);

            var textureBounds = new VRTextureBounds_t();
            textureBounds.uMin = (0 + uvOffset.x) * uvOffset.z;
            textureBounds.vMin = (1 + uvOffset.y) * uvOffset.w;
            textureBounds.uMax = (1 + uvOffset.x) * uvOffset.z;
            textureBounds.vMax = (0 + uvOffset.y) * uvOffset.w;
            overlay.SetOverlayTextureBounds(handle, ref textureBounds);

            var vecMouseScale = new HmdVector2_t();
            vecMouseScale.v0 = mouseScale.x;
            vecMouseScale.v1 = mouseScale.y;
            overlay.SetOverlayMouseScale(handle, ref vecMouseScale);

            var vrcam = SteamVR_Render.Top();
            if (vrcam != null && vrcam.origin != null)
            {
                var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
                offset.pos.x /= vrcam.origin.localScale.x;
                offset.pos.y /= vrcam.origin.localScale.y;
                offset.pos.z /= vrcam.origin.localScale.z;

                offset.pos.z += distance;

                var t = offset.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);
            }

            overlay.SetOverlayInputMethod(handle, inputMethod);

            if (curved || antialias)
            {
                highquality = true;
            }

            if (highquality)
            {
                overlay.SetHighQualityOverlay(handle);
                overlay.SetOverlayFlag(handle, VROverlayFlags.Curved, curved);
                overlay.SetOverlayFlag(handle, VROverlayFlags.RGSS4X, antialias);
            }
            else if (overlay.GetHighQualityOverlay() == handle)
            {
                overlay.SetHighQualityOverlay(OpenVR.k_ulOverlayHandleInvalid);
            }
        }
        else
        {
            overlay.HideOverlay(handle);
        }
    }
    public void UpdateOverlay(SteamVR vr)
    {
        if (texture != null)
        {
            var error = vr.overlay.ShowOverlay(handle);
            if (error == VROverlayError.InvalidHandle || error == VROverlayError.UnknownOverlay)
            {
                if (vr.overlay.FindOverlay(key, ref handle) != VROverlayError.None)
                    return;
            }

            vr.overlay.SetOverlayTexture(handle, texture.GetNativeTexturePtr());
            vr.overlay.SetOverlayAlpha(handle, alpha);
            vr.overlay.SetOverlayGamma(handle, gamma);
            vr.overlay.SetOverlayWidthInMeters(handle, scale);

            var textureBounds = new VRTextureBounds_t();
            textureBounds.uMin = (0 + uvOffset.x) * uvOffset.z;
            textureBounds.vMin = (1 + uvOffset.y) * uvOffset.w;
            textureBounds.uMax = (1 + uvOffset.x) * uvOffset.z;
            textureBounds.vMax = (0 + uvOffset.y) * uvOffset.w;
            vr.overlay.SetOverlayTextureBounds(handle, ref textureBounds);

            var vecMouseScale = new HmdVector2_t();
            vecMouseScale.v = new float[] { mouseScale.x, mouseScale.y };
            vr.overlay.SetOverlayMouseScale(handle, ref vecMouseScale);

            var vrcam = SteamVR_Render.Top();
            if (vrcam != null && vrcam.origin != null)
            {
                var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
                offset.pos.x /= vrcam.origin.localScale.x;
                offset.pos.y /= vrcam.origin.localScale.y;
                offset.pos.z /= vrcam.origin.localScale.z;

                offset.pos.z += distance;

                var t = offset.ToHmdMatrix34();
                vr.overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);
            }

            vr.overlay.SetOverlayVisibility(handle, visibility);
            vr.overlay.SetOverlayInputMethod(handle, inputMethod);

            if (curved || antialias)
                highquality = true;

            if (highquality)
            {
                vr.overlay.SetHighQualityOverlay(handle);
                vr.overlay.SetOverlayFlag(handle, VROverlayFlags.Curved, curved);
                vr.overlay.SetOverlayFlag(handle, VROverlayFlags.RGSS4X, antialias);
            }
            else if (vr.overlay.GetHighQualityOverlay() == handle)
            {
                vr.overlay.SetHighQualityOverlay(OpenVR.k_ulOverlayHandleInvalid);
            }
        }
        else
        {
            vr.overlay.HideOverlay(handle);
        }
    }
Exemple #17
0
 public void UpdatePos()
 {
     SteamVR_Utils.RigidTransform rigid = new SteamVR_Utils.RigidTransform(this.transform);
     Valve.VR.HmdMatrix34_t       trans = rigid.ToHmdMatrix34();
     SteamVR.instance.overlay.SetKeyboardTransformAbsolute(Valve.VR.ETrackingUniverseOrigin.TrackingUniverseStanding, ref trans);
 }
    /// <summary>
    /// Push Updates to our Overlay to the OpenVR System
    /// </summary>
    private void UpdateOverlay()
    {
        var overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return;
        }

        if (OverlayTexture != null)
        {
            var error = overlay.ShowOverlay(_handle);
            if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
            {
                if (overlay.FindOverlay(HOTK_Overlay.Key + gameObject.GetInstanceID(), ref _handle) != EVROverlayError.None)
                {
                    return;
                }
            }
            var tex = new Texture_t
            {
                handle      = OverlayTexture.GetNativeTexturePtr(),
                eType       = SteamVR.instance.graphicsAPI,
                eColorSpace = EColorSpace.Auto
            };
            overlay.SetOverlayColor(_handle, 1f, 1f, 1f);
            //overlay.SetOverlayGamma(_handle, 2.2f); // Doesn't exist yet :(
            overlay.SetOverlayTexture(_handle, ref tex);
            overlay.SetOverlayAlpha(_handle, _alpha);
            overlay.SetOverlayWidthInMeters(_handle, _scale);

            var textureBounds = new VRTextureBounds_t
            {
                uMin = (0 + Overlay.UvOffset.x) * Overlay.UvOffset.z,
                vMin = (1 + Overlay.UvOffset.y) * Overlay.UvOffset.w,
                uMax = (1 + Overlay.UvOffset.x) * Overlay.UvOffset.z,
                vMax = (0 + Overlay.UvOffset.y) * Overlay.UvOffset.w
            };
            overlay.SetOverlayTextureBounds(_handle, ref textureBounds);

            var vecMouseScale = new HmdVector2_t
            {
                v0 = 1f,
                v1 = (float)OverlayTexture.height / (float)OverlayTexture.width
            };
            overlay.SetOverlayMouseScale(_handle, ref vecMouseScale);

            if (_anchor != OpenVR.k_unTrackedDeviceIndexInvalid) // Attached to some HOTK_TrackedDevice, used for Controllers
            {
                var t = GetOverlayPosition();
                overlay.SetOverlayTransformTrackedDeviceRelative(_handle, _anchor, ref t);
            }
            else if (_anchorDevice == HOTK_Overlay.AttachmentDevice.World) // Attached to World
            {
                var t = GetOverlayPosition();
                overlay.SetOverlayTransformAbsolute(_handle, SteamVR_Render.instance.trackingSpace, ref t);
            }
            else
            {
                var vrcam = SteamVR_Render.Top();
                if (vrcam != null && vrcam.origin != null) // Attached to Camera (We are Rendering)
                {
                    var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
                    offset.pos.x /= vrcam.origin.localScale.x;
                    offset.pos.y /= vrcam.origin.localScale.y;
                    offset.pos.z /= vrcam.origin.localScale.z;

                    var t = offset.ToHmdMatrix34();
                    overlay.SetOverlayTransformAbsolute(_handle, SteamVR_Render.instance.trackingSpace, ref t);
                }
                else // Attached to Camera (We are Not Rendering)
                {
                    var t = GetOverlayPosition();
                    overlay.SetOverlayTransformTrackedDeviceRelative(_handle, 0, ref t);
                }
            }

            overlay.SetOverlayInputMethod(_handle, InputMethod);
        }
        else
        {
            overlay.HideOverlay(_handle);
        }
    }
Exemple #19
0
 public void UpdatePos()
 {
     SteamVR_Utils.RigidTransform rigid = new SteamVR_Utils.RigidTransform(this.transform);
     Valve.VR.HmdMatrix34_t trans = rigid.ToHmdMatrix34();
     SteamVR.instance.overlay.SetKeyboardTransformAbsolute(Valve.VR.ETrackingUniverseOrigin.TrackingUniverseStanding, ref trans);
 }
        public void UpdateCursorOverlay()
        {
            var overlay = OpenVR.Overlay;

            if (overlay == null || guiOverlay == null)
            {
                return;
            }

            if (CursorTexture != null && guiOverlay.showCursor && guiOverlay.cursorTargetTransform != null)
            {
                var error = overlay.ShowOverlay(handle);
                if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
                {
                    if (overlay.FindOverlay(overlayKey, ref handle) != EVROverlayError.None)
                    {
                        return;
                    }
                }

                var tex = new Texture_t();
                tex.handle      = CursorTexture.GetNativeTexturePtr();
                tex.eType       = SteamVR.instance.textureType;
                tex.eColorSpace = EColorSpace.Auto;
                overlay.SetOverlayTexture(handle, ref tex);

                overlay.SetOverlayAlpha(handle, 1.0f);
                overlay.SetOverlayWidthInMeters(handle, WidthInMeters);
                var curvedRange = new Vector2(1, 2);
                overlay.SetOverlayAutoCurveDistanceRangeInMeters(handle, curvedRange.x, curvedRange.y);

                var uvOffset      = new Vector4(0, 0, 1, 1);
                var textureBounds = new VRTextureBounds_t();
                textureBounds.uMin = (0 + uvOffset.x) * uvOffset.z;
                textureBounds.vMin = (1 + uvOffset.y) * uvOffset.w;
                textureBounds.uMax = (1 + uvOffset.x) * uvOffset.z;
                textureBounds.vMax = (0 + uvOffset.y) * uvOffset.w;
                overlay.SetOverlayTextureBounds(handle, ref textureBounds);

                var vecMouseScale = new HmdVector2_t();
                var mouseScale    = new Vector2(1, 1);
                vecMouseScale.v0 = mouseScale.x;
                vecMouseScale.v1 = mouseScale.y;
                overlay.SetOverlayMouseScale(handle, ref vecMouseScale);

                if (cursorPosition == null)
                {
                    cursorPosition = (new GameObject()).transform;
                    cursorPosition.SetParent(guiOverlay.cursorTargetTransform);
                    cursorPosition.localEulerAngles = Vector3.zero;
                }
                var offset = new SteamVR_Utils.RigidTransform();

                var texWidth    = guiOverlay.cursorTargetTransform.localScale.x;
                var texHeight   = guiOverlay.cursorTargetTransform.localScale.y;
                var curWidth    = WidthInMeters;
                var curHeight   = (WidthInMeters / CursorTexture.width) * CursorTexture.height;
                var scaleWidth  = curWidth / texWidth;
                var scaleHeight = curHeight / texHeight;

                cursorPosition.localPosition = new Vector3(guiOverlay.cursorPosition.x - 0.5f + (scaleWidth / 2), 0.5f - guiOverlay.cursorPosition.y - (scaleHeight / 2), -0.0f);
                offset.pos = cursorPosition.position;
                offset.rot = cursorPosition.rotation;

                var t = offset.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);

                overlay.SetOverlaySortOrder(handle, 1); //SortOrderは数字が大きいほうが後からレンダリングされる

                overlay.SetOverlayInputMethod(handle, VROverlayInputMethod.Mouse);
            }
            else
            {
                overlay.HideOverlay(handle);
            }
        }
    public void UpdateOverlay(SteamVR vr)
    {
        if (texture != null)
        {
            var error = vr.overlay.ShowOverlay(handle);
            if (error == VROverlayError.InvalidHandle || error == VROverlayError.UnknownOverlay)
            {
                if (vr.overlay.FindOverlay(key, ref handle) != VROverlayError.None)
                {
                    return;
                }
            }

            vr.overlay.SetOverlayTexture(handle, texture.GetNativeTexturePtr());
            vr.overlay.SetOverlayAlpha(handle, alpha);
            vr.overlay.SetOverlayGamma(handle, gamma);
            vr.overlay.SetOverlayWidthInMeters(handle, scale);

            var textureBounds = new VRTextureBounds_t();
            textureBounds.uMin = (0 + uvOffset.x) * uvOffset.z;
            textureBounds.vMin = (1 + uvOffset.y) * uvOffset.w;
            textureBounds.uMax = (1 + uvOffset.x) * uvOffset.z;
            textureBounds.vMax = (0 + uvOffset.y) * uvOffset.w;
            vr.overlay.SetOverlayTextureBounds(handle, ref textureBounds);

            var vecMouseScale = new HmdVector2_t();
            vecMouseScale.v = new float[] { mouseScale.x, mouseScale.y };
            vr.overlay.SetOverlayMouseScale(handle, ref vecMouseScale);

            var vrcam = SteamVR_Render.Top();
            if (vrcam != null && vrcam.origin != null)
            {
                var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
                offset.pos.x /= vrcam.origin.localScale.x;
                offset.pos.y /= vrcam.origin.localScale.y;
                offset.pos.z /= vrcam.origin.localScale.z;

                offset.pos.z += distance;

                var t = offset.ToHmdMatrix34();
                vr.overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);
            }

            vr.overlay.SetOverlayVisibility(handle, visibility);
            vr.overlay.SetOverlayInputMethod(handle, inputMethod);

            if (curved || antialias)
            {
                highquality = true;
            }

            if (highquality)
            {
                vr.overlay.SetHighQualityOverlay(handle);
                vr.overlay.SetOverlayFlag(handle, VROverlayFlags.Curved, curved);
                vr.overlay.SetOverlayFlag(handle, VROverlayFlags.RGSS4X, antialias);
            }
            else if (vr.overlay.GetHighQualityOverlay() == handle)
            {
                vr.overlay.SetHighQualityOverlay(OpenVR.k_ulOverlayHandleInvalid);
            }
        }
        else
        {
            vr.overlay.HideOverlay(handle);
        }
    }
    void Update()
    {
        //初期化失敗するなどoverlayが無効な場合は実行しない
        if (overlay == null)
        {
            return;
        }

        //オーバーレイを表示する
        overlay.ShowOverlay(overlayHandle);

        //オーバーレイを非表示にする
        //overlay.HideOverlay(overlayHandle);

        //オーバーレイが表示されている時
        if (overlay.IsOverlayVisible(overlayHandle))
        {
            var offset = new SteamVR_Utils.RigidTransform();
            if (RenderTarget != null)
            {
                offset.pos = new Vector3(RenderTarget.position.x, RenderTarget.position.y, RenderTarget.position.z);
                offset.rot = RenderTarget.rotation;
            }
            else
            {
                offset.pos = new Vector3(0, 0, 0);
                offset.rot = Quaternion.Euler(0, 0, 0);
            }
            var t = offset.ToHmdMatrix34();
            t.m5 = -1;
            overlay.SetOverlayTransformAbsolute(overlayHandle, SteamVR_Render.instance.trackingSpace, ref t);

            //RenderTextureが生成されているかチェック
            if (!renderTexture.IsCreated())
            {
                Debug.Log(Tag + "RenderTextureがまだ生成されていない");
                return;
            }

            //RenderTextureからネイティブテクスチャのハンドルを取得
            try
            {
                overlayTexture.handle = renderTexture.GetNativeTexturePtr();
            }
            catch (UnassignedReferenceException e)
            {
                Debug.LogError(Tag + "RenderTextureがセットされていません");
                ApplicationQuit();
                return;
            }

            //オーバーレイにテクスチャを設定
            var overlayError = EVROverlayError.None;
            overlayError = overlay.SetOverlayTexture(overlayHandle, ref overlayTexture);
            if (overlayError != EVROverlayError.None)
            {
                Debug.LogError(Tag + "Overlayにテクスチャをセットできませんでした. " + overlayError.ToString());
                ApplicationQuit();
                return;
            }
        }
    }
Exemple #23
0
	public void UpdateOverlay()
	{
		var overlay = OpenVR.Overlay;
		if (overlay == null)
			return;

		if (texture != null)
		{
			var error = overlay.ShowOverlay(handle);
			if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
			{
				if (overlay.FindOverlay(key, ref handle) != EVROverlayError.None)
					return;
			}

			var tex = new Texture_t();
			tex.handle = texture.GetNativeTexturePtr();
			tex.eType = SteamVR.instance.graphicsAPI;
			tex.eColorSpace = EColorSpace.Auto;
            overlay.SetOverlayTexture(handle, ref tex);

			overlay.SetOverlayAlpha(handle, alpha);
			overlay.SetOverlayWidthInMeters(handle, scale);
			overlay.SetOverlayAutoCurveDistanceRangeInMeters(handle, curvedRange.x, curvedRange.y);

			var textureBounds = new VRTextureBounds_t();
			textureBounds.uMin = (0 + uvOffset.x) * uvOffset.z;
			textureBounds.vMin = (1 + uvOffset.y) * uvOffset.w;
			textureBounds.uMax = (1 + uvOffset.x) * uvOffset.z;
			textureBounds.vMax = (0 + uvOffset.y) * uvOffset.w;
			overlay.SetOverlayTextureBounds(handle, ref textureBounds);

			var vecMouseScale = new HmdVector2_t();
			vecMouseScale.v0 = mouseScale.x;
			vecMouseScale.v1 = mouseScale.y;
			overlay.SetOverlayMouseScale(handle, ref vecMouseScale);

			var vrcam = SteamVR_Render.Top();
			if (vrcam != null && vrcam.origin != null)
			{
				var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
				offset.pos.x /= vrcam.origin.localScale.x;
				offset.pos.y /= vrcam.origin.localScale.y;
				offset.pos.z /= vrcam.origin.localScale.z;

				offset.pos.z += distance;

				var t = offset.ToHmdMatrix34();
				overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);
			}

			overlay.SetOverlayInputMethod(handle, inputMethod);

			if (curved || antialias)
				highquality = true;

			if (highquality)
			{
				overlay.SetHighQualityOverlay(handle);
				overlay.SetOverlayFlag(handle, VROverlayFlags.Curved, curved);
				overlay.SetOverlayFlag(handle, VROverlayFlags.RGSS4X, antialias);
			}
			else if (overlay.GetHighQualityOverlay() == handle)
			{
				overlay.SetHighQualityOverlay(OpenVR.k_ulOverlayHandleInvalid);
			}
		}
		else
		{
			overlay.HideOverlay(handle);
		}
	}
    /// <summary>
    /// Push Updates to our Overlay to the OpenVR System
    /// </summary>
    private void UpdateOverlay()
    {
        var overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return;
        }

        if (OverlayTexture != null)
        {
            var error = overlay.ShowOverlay(_handle);
            if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
            {
                if (overlay.FindOverlay(Key, ref _handle) != EVROverlayError.None)
                {
                    return;
                }
            }

            var tex = new Texture_t
            {
                handle      = OverlayTexture.GetNativeTexturePtr(),
                eType       = SteamVR.instance.textureType,
                eColorSpace = EColorSpace.Auto
            };
            overlay.SetOverlayColor(_handle, 1f, 1f, 1f);
            //overlay.SetOverlayGamma(_handle, 2.2f); // Doesn't exist yet :(
            overlay.SetOverlayTexture(_handle, ref tex);
            overlay.SetOverlayAlpha(_handle, AnimateOnGaze == AnimationType.Alpha || AnimateOnGaze == AnimationType.AlphaAndScale ? _alpha : Alpha);
            overlay.SetOverlayWidthInMeters(_handle, AnimateOnGaze == AnimationType.Scale || AnimateOnGaze == AnimationType.AlphaAndScale ? _scale : Scale);
            overlay.SetOverlayAutoCurveDistanceRangeInMeters(_handle, CurvedRange.x, CurvedRange.y);

            var textureBounds = new VRTextureBounds_t
            {
                uMin = (0 + UvOffset.x) * UvOffset.z,
                vMin = (1 + UvOffset.y) * UvOffset.w,
                uMax = (1 + UvOffset.x) * UvOffset.z,
                vMax = (0 + UvOffset.y) * UvOffset.w
            };
            overlay.SetOverlayTextureBounds(_handle, ref textureBounds);

            var vecMouseScale = new HmdVector2_t
            {
                v0 = MouseScale.x,
                v1 = MouseScale.y
            };
            overlay.SetOverlayMouseScale(_handle, ref vecMouseScale);

            if (_anchor != OpenVR.k_unTrackedDeviceIndexInvalid) // Attached to some HOTK_TrackedDevice, used for Controllers
            {
                var t = GetOverlayPosition();
                overlay.SetOverlayTransformTrackedDeviceRelative(_handle, _anchor, ref t);
            }
            else if (AnchorDevice == MountDevice.World) // Attached to World
            {
                var t = GetOverlayPosition();
                overlay.SetOverlayTransformAbsolute(_handle, SteamVR_Render.instance.trackingSpace, ref t);
            }
            else
            {
                var vrcam = SteamVR_Render.Top();
                if (vrcam != null && vrcam.origin != null) // Attached to Camera (We are Rendering)
                {
                    var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform);
                    offset.pos.x /= vrcam.origin.localScale.x;
                    offset.pos.y /= vrcam.origin.localScale.y;
                    offset.pos.z /= vrcam.origin.localScale.z;

                    var t = offset.ToHmdMatrix34();
                    overlay.SetOverlayTransformAbsolute(_handle, SteamVR_Render.instance.trackingSpace, ref t);
                }
                else // Attached to Camera (We are Not Rendering)
                {
                    var t = GetOverlayPosition();
                    overlay.SetOverlayTransformTrackedDeviceRelative(_handle, 0, ref t);
                }
            }

            overlay.SetOverlayInputMethod(_handle, InputMethod);

            if (Highquality)
            {
                if (HighQualityOverlay != this && HighQualityOverlay != null)
                {
                    if (HighQualityOverlay.Highquality)
                    {
                        Debug.LogWarning("Only one Overlay can be in HighQuality mode as per the OpenVR API.");
                        HighQualityOverlay.Highquality = false;
                    }
                    HighQualityOverlay = this;
                }
                else if (HighQualityOverlay == null)
                {
                    HighQualityOverlay = this;
                }

                overlay.SetHighQualityOverlay(_handle);
                overlay.SetOverlayFlag(_handle, VROverlayFlags.Curved, Curved);
                overlay.SetOverlayFlag(_handle, VROverlayFlags.RGSS4X, Antialias);
            }
            else if (overlay.GetHighQualityOverlay() == _handle)
            {
                overlay.SetHighQualityOverlay(OpenVR.k_ulOverlayHandleInvalid);
            }
        }
        else
        {
            overlay.HideOverlay(_handle);
        }
    }
 public void UpdateOverlay()
 {
     CVROverlay overlay = OpenVR.Overlay;
     if (overlay == null)
     {
         return;
     }
     if (this.texture != null)
     {
         EVROverlayError eVROverlayError = overlay.ShowOverlay(this.handle);
         if ((eVROverlayError == EVROverlayError.InvalidHandle || eVROverlayError == EVROverlayError.UnknownOverlay) && overlay.FindOverlay(SteamVR_Overlay.key, ref this.handle) != EVROverlayError.None)
         {
             return;
         }
         Texture_t texture_t = default(Texture_t);
         texture_t.handle = this.texture.GetNativeTexturePtr();
         texture_t.eType = SteamVR.instance.graphicsAPI;
         texture_t.eColorSpace = EColorSpace.Auto;
         overlay.SetOverlayTexture(this.handle, ref texture_t);
         overlay.SetOverlayAlpha(this.handle, this.alpha);
         overlay.SetOverlayWidthInMeters(this.handle, this.scale);
         overlay.SetOverlayAutoCurveDistanceRangeInMeters(this.handle, this.curvedRange.x, this.curvedRange.y);
         VRTextureBounds_t vRTextureBounds_t = default(VRTextureBounds_t);
         vRTextureBounds_t.uMin = (0f + this.uvOffset.x) * this.uvOffset.z;
         vRTextureBounds_t.vMin = (1f + this.uvOffset.y) * this.uvOffset.w;
         vRTextureBounds_t.uMax = (1f + this.uvOffset.x) * this.uvOffset.z;
         vRTextureBounds_t.vMax = (0f + this.uvOffset.y) * this.uvOffset.w;
         overlay.SetOverlayTextureBounds(this.handle, ref vRTextureBounds_t);
         HmdVector2_t hmdVector2_t = default(HmdVector2_t);
         hmdVector2_t.v0 = this.mouseScale.x;
         hmdVector2_t.v1 = this.mouseScale.y;
         overlay.SetOverlayMouseScale(this.handle, ref hmdVector2_t);
         SteamVR_Camera steamVR_Camera = SteamVR_Render.Top();
         if (steamVR_Camera != null && steamVR_Camera.origin != null)
         {
             SteamVR_Utils.RigidTransform rigidTransform = new SteamVR_Utils.RigidTransform(steamVR_Camera.origin, base.transform);
             rigidTransform.pos.x = rigidTransform.pos.x / steamVR_Camera.origin.localScale.x;
             rigidTransform.pos.y = rigidTransform.pos.y / steamVR_Camera.origin.localScale.y;
             rigidTransform.pos.z = rigidTransform.pos.z / steamVR_Camera.origin.localScale.z;
             rigidTransform.pos.z = rigidTransform.pos.z + this.distance;
             HmdMatrix34_t hmdMatrix34_t = rigidTransform.ToHmdMatrix34();
             overlay.SetOverlayTransformAbsolute(this.handle, SteamVR_Render.instance.trackingSpace, ref hmdMatrix34_t);
         }
         overlay.SetOverlayInputMethod(this.handle, this.inputMethod);
         if (this.curved || this.antialias)
         {
             this.highquality = true;
         }
         if (this.highquality)
         {
             overlay.SetHighQualityOverlay(this.handle);
             overlay.SetOverlayFlag(this.handle, VROverlayFlags.Curved, this.curved);
             overlay.SetOverlayFlag(this.handle, VROverlayFlags.RGSS4X, this.antialias);
         }
         else if (overlay.GetHighQualityOverlay() == this.handle)
         {
             overlay.SetHighQualityOverlay(0uL);
         }
     }
     else
     {
         overlay.HideOverlay(this.handle);
     }
 }
        public void UpdateOverlay()
        {
            var overlay = OpenVR.Overlay;

            if (overlay == null)
            {
                return;
            }

            if (texture != null)
            {
                var error = overlay.ShowOverlay(handle);
                if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay)
                {
                    if (overlay.FindOverlay(overlayKey, ref handle) != EVROverlayError.None)
                    {
                        return;
                    }
                }

                var tex = new Texture_t();
                tex.handle = texture.GetNativeTexturePtr();
                switch (SystemInfo.graphicsDeviceType)
                {
                case UnityEngine.Rendering.GraphicsDeviceType.OpenGLCore:
                case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES2:
                case UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3:
                    tex.eType = ETextureType.OpenGL;
                    break;

                case UnityEngine.Rendering.GraphicsDeviceType.Vulkan:
                    tex.eType = ETextureType.Vulkan;
                    break;

                default:
                    tex.eType = ETextureType.DirectX;
                    break;
                }
                tex.eColorSpace = EColorSpace.Auto;
                overlay.SetOverlayTexture(handle, ref tex);

                overlay.SetOverlayAlpha(handle, alpha);
                overlay.SetOverlayWidthInMeters(handle, WidthInMeters);
                var curvedRange = new Vector2(1, 2);
                overlay.SetOverlayAutoCurveDistanceRangeInMeters(handle, curvedRange.x, curvedRange.y);

                var textureBounds = new VRTextureBounds_t();
                textureBounds.uMin = (0 + uvOffset.x) * uvOffset.z;
                textureBounds.vMin = (1 + uvOffset.y) * uvOffset.w;
                textureBounds.uMax = (1 + uvOffset.x) * uvOffset.z;
                textureBounds.vMax = (0 + uvOffset.y) * uvOffset.w;
                overlay.SetOverlayTextureBounds(handle, ref textureBounds);

                var vecMouseScale = new HmdVector2_t();
                var mouseScale    = new Vector2(1, 1);
                vecMouseScale.v0 = mouseScale.x;
                vecMouseScale.v1 = mouseScale.y;
                overlay.SetOverlayMouseScale(handle, ref vecMouseScale);

                if ((lastRenderPosition != RenderPosition || lastWidthInMeters != WidthInMeters || lastPositionOffset != PositionOffset))
                {
                    if (RayTargetQuad != null)
                    {
                        Destroy(RayTargetQuad);
                    }
                    //Ray飛ばし座標取得用のQuadを配置
                    RayTargetQuad = GameObject.CreatePrimitive(PrimitiveType.Quad);
                    RayTargetQuad.GetComponent <MeshRenderer>().enabled = false; // 非表示にする
                    RayTargetQuad.transform.SetParent(RenderPosition);
                    RayTargetQuad.transform.localPosition    = PositionOffset;
                    RayTargetQuad.transform.localEulerAngles = Vector3.zero;
                    RayTargetQuad.transform.localScale       = new Vector3(WidthInMeters, (WidthInMeters / texture.width) * texture.height, 1.0f);
                    lastRenderPosition = RenderPosition;
                    lastWidthInMeters  = WidthInMeters;
                    lastPositionOffset = PositionOffset;
                }

                var offset = new SteamVR_Utils.RigidTransform();
                if (RayTargetQuad != null)
                {
                    offset.pos = RayTargetQuad.transform.position;
                    offset.rot = RayTargetQuad.transform.rotation;
                }
                else
                {
                    offset.pos = new Vector3(0, 0, 0);
                    offset.rot = Quaternion.Euler(0, 0, 0);
                }
                var t = offset.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(handle, SteamVR_Render.instance.trackingSpace, ref t);


                overlay.SetOverlayInputMethod(handle, VROverlayInputMethod.Mouse);
            }
            else
            {
                overlay.HideOverlay(handle);
            }
        }
Exemple #27
0
    public void UpdateOverlay()
    {
        CVROverlay overlay = OpenVR.Overlay;

        if (overlay == null)
        {
            return;
        }
        if (this.texture != null)
        {
            EVROverlayError evroverlayError = overlay.ShowOverlay(this.handle);
            if ((evroverlayError == EVROverlayError.InvalidHandle || evroverlayError == EVROverlayError.UnknownOverlay) && overlay.FindOverlay(SteamVR_Overlay.key, ref this.handle) != EVROverlayError.None)
            {
                return;
            }
            Texture_t texture_t = default(Texture_t);
            texture_t.handle      = this.texture.GetNativeTexturePtr();
            texture_t.eType       = SteamVR.instance.textureType;
            texture_t.eColorSpace = EColorSpace.Auto;
            overlay.SetOverlayTexture(this.handle, ref texture_t);
            overlay.SetOverlayAlpha(this.handle, this.alpha);
            overlay.SetOverlayWidthInMeters(this.handle, this.scale);
            overlay.SetOverlayAutoCurveDistanceRangeInMeters(this.handle, this.curvedRange.x, this.curvedRange.y);
            VRTextureBounds_t vrtextureBounds_t = default(VRTextureBounds_t);
            vrtextureBounds_t.uMin = this.uvOffset.x * this.uvOffset.z;
            vrtextureBounds_t.vMin = (1f + this.uvOffset.y) * this.uvOffset.w;
            vrtextureBounds_t.uMax = (1f + this.uvOffset.x) * this.uvOffset.z;
            vrtextureBounds_t.vMax = this.uvOffset.y * this.uvOffset.w;
            overlay.SetOverlayTextureBounds(this.handle, ref vrtextureBounds_t);
            HmdVector2_t hmdVector2_t = default(HmdVector2_t);
            hmdVector2_t.v0 = this.mouseScale.x;
            hmdVector2_t.v1 = this.mouseScale.y;
            overlay.SetOverlayMouseScale(this.handle, ref hmdVector2_t);
            SteamVR_Camera steamVR_Camera = SteamVR_Render.Top();
            if (steamVR_Camera != null && steamVR_Camera.origin != null)
            {
                SteamVR_Utils.RigidTransform rigidTransform = new SteamVR_Utils.RigidTransform(steamVR_Camera.origin, base.transform);
                rigidTransform.pos.x = rigidTransform.pos.x / steamVR_Camera.origin.localScale.x;
                rigidTransform.pos.y = rigidTransform.pos.y / steamVR_Camera.origin.localScale.y;
                rigidTransform.pos.z = rigidTransform.pos.z / steamVR_Camera.origin.localScale.z;
                rigidTransform.pos.z = rigidTransform.pos.z + this.distance;
                HmdMatrix34_t hmdMatrix34_t = rigidTransform.ToHmdMatrix34();
                overlay.SetOverlayTransformAbsolute(this.handle, SteamVR_Render.instance.trackingSpace, ref hmdMatrix34_t);
            }
            overlay.SetOverlayInputMethod(this.handle, this.inputMethod);
            if (this.curved || this.antialias)
            {
                this.highquality = true;
            }
            if (this.highquality)
            {
                overlay.SetHighQualityOverlay(this.handle);
                overlay.SetOverlayFlag(this.handle, VROverlayFlags.Curved, this.curved);
                overlay.SetOverlayFlag(this.handle, VROverlayFlags.RGSS4X, this.antialias);
            }
            else if (overlay.GetHighQualityOverlay() == this.handle)
            {
                overlay.SetHighQualityOverlay(0UL);
            }
        }
        else
        {
            overlay.HideOverlay(this.handle);
        }
    }