From a3c474729022531a8a6269077e459dc8a8487488 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Feb 2019 11:17:31 -0800 Subject: [PATCH] Add leveled controller-relative movement option. --- interface/src/avatar/MyAvatar.cpp | 47 +++++++++++++++++++++----- interface/src/avatar/MyAvatar.h | 16 +++++---- interface/src/ui/PreferencesDialog.cpp | 11 ++++-- 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 1953f5fba8..eeab2d1ac0 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -169,7 +169,7 @@ MyAvatar::MyAvatar(QThread* thread) : _useSnapTurnSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "useSnapTurn", _useSnapTurn), _userHeightSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "userHeight", DEFAULT_AVATAR_HEIGHT), _flyingHMDSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "flyingHMD", _flyingPrefHMD), - _handRelativeMovementSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "handRelativeMovement", _handRelativeMovement), + _movementReferenceSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "movementReference", _movementReference), _avatarEntityCountSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" << "size", 0), _userRecenterModelSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "userRecenterModel", USER_RECENTER_MODEL_AUTO), _driveGear1Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear1", _driveGear1), @@ -1283,7 +1283,7 @@ void MyAvatar::saveData() { _useSnapTurnSetting.set(_useSnapTurn); _userHeightSetting.set(getUserHeight()); _flyingHMDSetting.set(getFlyingHMDPref()); - _handRelativeMovementSetting.set(getHandRelativeMovement()); + _movementReferenceSetting.set(getMovementReference()); _driveGear1Setting.set(getDriveGear1()); _driveGear2Setting.set(getDriveGear2()); _driveGear3Setting.set(getDriveGear3()); @@ -1867,7 +1867,7 @@ void MyAvatar::loadData() { // Flying preferences must be loaded before calling setFlyingEnabled() Setting::Handle firstRunVal { Settings::firstRun, true }; setFlyingHMDPref(firstRunVal.get() ? false : _flyingHMDSetting.get()); - setHandRelativeMovement(firstRunVal.get() ? false : _handRelativeMovementSetting.get()); + setMovementReference(firstRunVal.get() ? false : _movementReferenceSetting.get()); setDriveGear1(firstRunVal.get() ? DEFAULT_GEAR_1 : _driveGear1Setting.get()); setDriveGear2(firstRunVal.get() ? DEFAULT_GEAR_2 : _driveGear2Setting.get()); setDriveGear3(firstRunVal.get() ? DEFAULT_GEAR_3 : _driveGear3Setting.get()); @@ -3354,7 +3354,36 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ // compute action input // Determine if we're head or controller relative... glm::vec3 forward, right; - if (getHandRelativeMovement() && qApp->isHMDMode()) { + + if (qApp->isHMDMode()) { + auto handRotation = getDominantHandRotation(); + glm::vec3 controllerForward(0.0f, 1.0f, 0.0f); + glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? -1.0f : 1.0f)); + // Do shit here. + switch (getMovementReference()) { + case MOVEMENT_HAND_RELATIVE: + forward = (handRotation * controllerForward); + right = (handRotation * controllerRight); + break; + case MOVEMENT_HAND_RELATIVE_LEVELED: + forward = (handRotation * controllerForward); + forward.y = 0.0f; + forward /= forward.length(); + right = (handRotation * controllerRight); + right.y = 0.0f; + right /= right.length(); + break; + case MOVEMENT_HMD_RELATIVE: + default: + forward = IDENTITY_FORWARD; + right = IDENTITY_RIGHT; + } + } else { + forward = IDENTITY_FORWARD; + right = IDENTITY_RIGHT; + } + + if (getMovementReference() && qApp->isHMDMode()) { // Here we have to get the rotation of the dominant hand and apply that to the direction vector. // If we're on the right hand, we have to flip the x-axis. auto handRotation = getDominantHandRotation(); @@ -3923,16 +3952,16 @@ void MyAvatar::setFlyingHMDPref(bool enabled) { _flyingPrefHMD = enabled; } -void MyAvatar::setHandRelativeMovement(bool enabled) { +void MyAvatar::setMovementReference(int enabled) { if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "setHandRelativeMovement", Q_ARG(bool, enabled)); + QMetaObject::invokeMethod(this, "setMovementReference", Q_ARG(bool, enabled)); return; } - _handRelativeMovement = enabled; + _movementReference = enabled; } -bool MyAvatar::getHandRelativeMovement() { - return _handRelativeMovement; +int MyAvatar::getMovementReference() { + return _movementReference; } void MyAvatar::setControlSchemeIndex(int index){ diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 815c324195..d75622eefb 100755 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -43,6 +43,10 @@ const int CONTROLS_DEFAULT = 0; const int CONTROLS_ANALOG = 1; const int CONTROLS_ANALOG_PLUS = 2; +const int MOVEMENT_HMD_RELATIVE = 0; +const int MOVEMENT_HAND_RELATIVE = 1; +const int MOVEMENT_HAND_RELATIVE_LEVELED = 2; + enum eyeContactTarget { LEFT_EYE, RIGHT_EYE, @@ -1036,18 +1040,18 @@ public: /**jsdoc * Set your preference for hand-relative movement. * @function MyAvatar.setHandRelativeMovement - * @param {boolean} enabled - Set true if you want to enable hand-relative movement, otherwise set to false. + * @param {number} enabled - Set true if you want to enable hand-relative movement, otherwise set to false. * */ - Q_INVOKABLE void setHandRelativeMovement(bool enabled); + Q_INVOKABLE void setMovementReference(int enabled); /**jsdoc * Get your preference for hand-relative movement. * @function MyAvatar.getHandRelativeMovement - * @returns {boolean} true if your preference is for user locomotion to be relative to the direction your + * @returns {number} true if your preference is for user locomotion to be relative to the direction your * controller is pointing, otherwise false. */ - Q_INVOKABLE bool getHandRelativeMovement(); + Q_INVOKABLE int getMovementReference(); /**jsdoc * Set the first 'shifting point' for acceleration step function. @@ -1802,7 +1806,6 @@ private: bool _enableFlying { false }; bool _flyingPrefDesktop { true }; bool _flyingPrefHMD { false }; - bool _handRelativeMovement{ false }; bool _wasPushing { false }; bool _isPushing { false }; bool _isBeingPushed { false }; @@ -1818,6 +1821,7 @@ private: float _driveGear4 { DEFAULT_GEAR_4 }; float _driveGear5 { DEFAULT_GEAR_5 }; int _controlSchemeIndex { CONTROLS_DEFAULT }; + int _movementReference{ 0 }; glm::vec3 _thrust { 0.0f }; // impulse accumulator for outside sources @@ -2069,7 +2073,7 @@ private: Setting::Handle _useSnapTurnSetting; Setting::Handle _userHeightSetting; Setting::Handle _flyingHMDSetting; - Setting::Handle _handRelativeMovementSetting; + Setting::Handle _movementReferenceSetting; Setting::Handle _avatarEntityCountSetting; Setting::Handle _allowTeleportingSetting { "allowTeleporting", true }; Setting::Handle _driveGear1Setting; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index e08e4bfe8f..2ae04da445 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -273,9 +273,14 @@ void setupPreferences() { preferences->addPreference(preference); } { - auto getter = [myAvatar]()->bool { return myAvatar->getHandRelativeMovement(); }; - auto setter = [myAvatar](bool value) { myAvatar->setHandRelativeMovement(value); }; - auto preference = new CheckPreference(VR_MOVEMENT, "Hand-Relative Movement", getter, setter); + auto getter = [myAvatar]()->int { return myAvatar->getMovementReference(); }; + auto setter = [myAvatar](int value) { myAvatar->setMovementReference(value); }; + //auto preference = new CheckPreference(VR_MOVEMENT, "Hand-Relative Movement", getter, setter); + auto preference = new RadioButtonsPreference(VR_MOVEMENT, "Movement Direction", getter, setter); + QStringList items; + items << "HMD-Relative" << "Hand-Relative" << "Hand-Relative (Leveled)"; + preference->setHeading("Movement Direction"); + preference->setItems(items); preferences->addPreference(preference); } {