From a3914894cf644c939adf955b369c9a4dbd935ac8 Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Mon, 28 Dec 2020 10:12:05 -0500 Subject: [PATCH 1/4] Avatar auto scale: match avatar eye height to user eye height. This adds an 'Auto' button to the avatar scale slider. The Auto button scales the avatar so that its eye height matches the user's real-world eye height (based on the 'User real world height' setting). In this way, the world is displayed at exactly 100% scale to the user in VR. The '1x' button now sets the avatar scale to 1.0 even if the current scale is at the same 'notch' as 1.0 on the scale slider (previously it had no effect in that situation). Test done: - In VR, kneel to position your head as if you were 1m tall. - Set 'User real-world height' to 1m (in Settings > Controls). - Open the Avatar app and click on the sliders icon at the top-right. - Click the '1x' button and observe that the world is miniaturised. - Click the 'Auto' button and observe that the world is displayed at actual size. --- .../resources/qml/hifi/avatarapp/Settings.qml | 44 ++++++++++++++++++- interface/src/avatar/MyAvatar.cpp | 7 +++ interface/src/avatar/MyAvatar.h | 8 ++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/interface/resources/qml/hifi/avatarapp/Settings.qml b/interface/resources/qml/hifi/avatarapp/Settings.qml index 4d4a0ee8094..0d5e81783e3 100644 --- a/interface/resources/qml/hifi/avatarapp/Settings.qml +++ b/interface/resources/qml/hifi/avatarapp/Settings.qml @@ -178,6 +178,12 @@ Rectangle { Layout.alignment: Qt.AlignVCenter } } + } + + RowLayout { + id: avatarScaleButtonsRow + anchors.top: avatarScaleRow.bottom + anchors.topMargin: 0 ShadowRectangle { width: 37 @@ -203,7 +209,43 @@ Rectangle { MouseArea { anchors.fill: parent onClicked: { - scaleSlider.value = 10 + scaleSlider.notify = false; + scaleSlider.value = 10; + scaleSlider.notify = true; + root.scaleChanged(1.0); + } + } + } + + ShadowRectangle { + width: 50 + height: 28 + AvatarAppStyle { + id: style2 + } + + gradient: Gradient { + GradientStop { position: 0.0; color: style2.colors.blueHighlight } + GradientStop { position: 1.0; color: style2.colors.blueAccent } + } + + radius: 3 + + RalewaySemiBold { + color: 'white' + anchors.centerIn: parent + text: "Auto" + size: 18 + } + + MouseArea { + anchors.fill: parent + onClicked: { + scaleValue = MyAvatar.getAutoAvatarScale(); + scaleSlider.notify = false; + scaleSlider.value = Math.round(scaleValue * 10); + scaleSlider.notify = true; + root.scaleChanged(scaleValue); } } } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index b3231b906db..71ea5878a20 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -4566,6 +4566,13 @@ float MyAvatar::getAvatarScale() { return getTargetScale(); } +// Gets the scale for the avatar that makes the avatar's eye height match the user's real-world eye height +// (derived from the 'User real world height' setting). +float MyAvatar::getAutoAvatarScale() const +{ + return getUserEyeHeight() / getUnscaledEyeHeight(); +} + void MyAvatar::setAvatarScale(float val) { if (QThread::currentThread() != thread()) { diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 3140c68f88a..1afa7dc7190 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1598,6 +1598,14 @@ class MyAvatar : public Avatar { */ Q_INVOKABLE float getAvatarScale(); + /**jsdoc + * Gets the scale for the avatar that makes the avatar's eye height match the user's real-world eye height (derived from + * the 'User real world height' setting). + * @function MyAvatar.getAutoAvatarScale + * @returns {number} The scale for the avatar that makes the avatar's eye height match the user's real-world eye height. + */ + Q_INVOKABLE float getAutoAvatarScale() const; + /**jsdoc * Sets the target scale of the avatar. The target scale is the desired scale of the avatar without any restrictions on * permissible scale values imposed by the domain. From 597cc07f6125c257b0abc9ebc4cd7aeef705482c Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Mon, 28 Dec 2020 17:52:55 -0500 Subject: [PATCH 2/4] Remove unnecessary new line in avatarapp/Settings.qml --- interface/resources/qml/hifi/avatarapp/Settings.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/resources/qml/hifi/avatarapp/Settings.qml b/interface/resources/qml/hifi/avatarapp/Settings.qml index 0d5e81783e3..5b0b6387bca 100644 --- a/interface/resources/qml/hifi/avatarapp/Settings.qml +++ b/interface/resources/qml/hifi/avatarapp/Settings.qml @@ -183,7 +183,6 @@ Rectangle { RowLayout { id: avatarScaleButtonsRow anchors.top: avatarScaleRow.bottom - anchors.topMargin: 0 ShadowRectangle { width: 37 From 63c3121f2bdd6b9101ac74131c5345df6dc99733 Mon Sep 17 00:00:00 2001 From: Phil <35943148+Phil-Palmer@users.noreply.github.com> Date: Tue, 29 Dec 2020 05:00:33 -0500 Subject: [PATCH 3/4] Apply suggestions from code review Improve comments and fix bracing style. Co-authored-by: David Rowe --- interface/src/avatar/MyAvatar.cpp | 5 ++--- interface/src/avatar/MyAvatar.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 71ea5878a20..1030d78817d 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -4567,9 +4567,8 @@ float MyAvatar::getAvatarScale() { } // Gets the scale for the avatar that makes the avatar's eye height match the user's real-world eye height -// (derived from the 'User real world height' setting). -float MyAvatar::getAutoAvatarScale() const -{ +// (derived from the 'User real world height' Interface setting). +float MyAvatar::getAutoAvatarScale() const { return getUserEyeHeight() / getUnscaledEyeHeight(); } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 1afa7dc7190..9d4524bda27 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1600,7 +1600,7 @@ class MyAvatar : public Avatar { /**jsdoc * Gets the scale for the avatar that makes the avatar's eye height match the user's real-world eye height (derived from - * the 'User real world height' setting). + * the "User real world height" Interface setting). * @function MyAvatar.getAutoAvatarScale * @returns {number} The scale for the avatar that makes the avatar's eye height match the user's real-world eye height. */ From e89e80d6b977239482f627b1b869bc19424193bc Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Tue, 29 Dec 2020 18:04:36 -0500 Subject: [PATCH 4/4] Rename new avatar 'Auto' scale button to 'Real Height' as suggested here: https://github.com/vircadia/vircadia/pull/942#issuecomment-752065145 --- interface/resources/qml/hifi/avatarapp/Settings.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/resources/qml/hifi/avatarapp/Settings.qml b/interface/resources/qml/hifi/avatarapp/Settings.qml index 5b0b6387bca..8c8f558fa54 100644 --- a/interface/resources/qml/hifi/avatarapp/Settings.qml +++ b/interface/resources/qml/hifi/avatarapp/Settings.qml @@ -185,7 +185,7 @@ Rectangle { anchors.top: avatarScaleRow.bottom ShadowRectangle { - width: 37 + width: 31 height: 28 AvatarAppStyle { id: style @@ -217,7 +217,7 @@ Rectangle { } ShadowRectangle { - width: 50 + width: 107 height: 28 AvatarAppStyle { id: style2 @@ -233,7 +233,7 @@ Rectangle { RalewaySemiBold { color: 'white' anchors.centerIn: parent - text: "Auto" + text: "Real Height" size: 18 }