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); }
private void updateUiPanelScaleAndPosition() { var offsetPosition = new Vector3(0f, VHVRConfig.GetUiPanelVerticalOffset(), VHVRConfig.GetUiPanelDistance()); if (useDynamicallyPositionedGui()) { var playerInstance = Player.m_localPlayer; var currentDirection = getCurrentGuiDirection(); if (isRecentering) { // We are currently recentering, so calculate a new rotation a step towards the targe rotation // and set the GUI position using that rotation. If the new rotation is close enough to // the target rotation, then stop recentering for the 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); _uiPanel.transform.rotation = stepRotation; _uiPanel.transform.position = playerInstance.transform.position + stepRotation * offsetPosition; lastVrPlayerRotation = VRPlayer.instance.transform.rotation; maybeResetIsRecentering(stepDirection, targetDirection); } else { // We are not recentering, so keep the GUI in front of the player. Need to account for // any rotation of the VRPlayer instance caused by mouse or joystick input since the last frame. float rotationDelta = VRPlayer.instance.transform.rotation.eulerAngles.y - lastVrPlayerRotation.eulerAngles.y; lastVrPlayerRotation = VRPlayer.instance.transform.rotation; var newRotation = Quaternion.LookRotation(currentDirection, VRPlayer.instance.transform.up); newRotation *= Quaternion.AngleAxis(rotationDelta, Vector3.up); _uiPanel.transform.rotation = newRotation; _uiPanel.transform.position = playerInstance.transform.position + newRotation * offsetPosition; } } else { _uiPanel.transform.rotation = VRPlayer.instance.transform.rotation; _uiPanel.transform.position = VRPlayer.instance.transform.position + VRPlayer.instance.transform.rotation * offsetPosition; } float ratio = (float)Screen.width / (float)Screen.height; _uiPanel.transform.localScale = new Vector3(VHVRConfig.GetUiPanelSize() * ratio, VHVRConfig.GetUiPanelSize(), 1f); }