Example #1
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);
        }