From 0c20107203fed02fa0a90d7e268b5b2ebd228900 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Fri, 18 Jan 2019 12:46:19 -0800 Subject: [PATCH 01/68] Add Controller menu items for hand/head-relative movement. --- interface/src/avatar/MyAvatar.cpp | 20 ++++++++++++++++++-- interface/src/avatar/MyAvatar.h | 18 ++++++++++++++++++ interface/src/ui/PreferencesDialog.cpp | 11 +++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index cc7742c517..81d6c94c1b 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -106,7 +106,7 @@ MyAvatar::MyAvatar(QThread* thread) : _characterController(this), _eyeContactTarget(LEFT_EYE), _realWorldFieldOfView("realWorldFieldOfView", - DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES), + DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES), _useAdvancedMovementControls("advancedMovementForHandControllersIsChecked", true), _showPlayArea("showPlayArea", true), _smoothOrientationTimer(std::numeric_limits::max()), @@ -130,7 +130,7 @@ MyAvatar::MyAvatar(QThread* thread) : _yawSpeedSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "yawSpeed", _yawSpeed), _pitchSpeedSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "pitchSpeed", _pitchSpeed), _fullAvatarURLSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "fullAvatarURL", - AvatarData::defaultFullAvatarModelUrl()), + AvatarData::defaultFullAvatarModelUrl()), _fullAvatarModelNameSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "fullAvatarModelName", _fullAvatarModelName), _animGraphURLSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "animGraphURL", QUrl("")), _displayNameSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "displayName", ""), @@ -138,6 +138,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), _avatarEntityCountSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" << "size", 0) { _clientTraitsHandler.reset(new ClientTraitsHandler(this)); @@ -1300,6 +1301,7 @@ void MyAvatar::saveData() { _useSnapTurnSetting.set(_useSnapTurn); _userHeightSetting.set(getUserHeight()); _flyingHMDSetting.set(getFlyingHMDPref()); + _handRelativeMovementSetting.set(getHandRelativeMovement()); auto hmdInterface = DependencyManager::get(); saveAvatarEntityDataToSettings(); @@ -1876,6 +1878,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()); setFlyingEnabled(getFlyingEnabled()); setDisplayName(_displayNameSetting.get()); @@ -3287,6 +3290,7 @@ void MyAvatar::updateActionMotor(float deltaTime) { CharacterController::State state = _characterController.getState(); // compute action input + // Determine if we're head or controller relative... glm::vec3 forward = (getDriveKey(TRANSLATE_Z)) * IDENTITY_FORWARD; glm::vec3 right = (getDriveKey(TRANSLATE_X)) * IDENTITY_RIGHT; @@ -3816,6 +3820,18 @@ void MyAvatar::setFlyingHMDPref(bool enabled) { _flyingPrefHMD = enabled; } +void MyAvatar::setHandRelativeMovement(bool enabled) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setHandRelativeMovement", Q_ARG(bool, enabled)); + return; + } + _handRelativeMovement = enabled; +} + +bool MyAvatar::getHandRelativeMovement() { + return _handRelativeMovement; +} + bool MyAvatar::getFlyingHMDPref() { return _flyingPrefHMD; } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 58880acb08..65a3eac665 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1044,6 +1044,22 @@ public: Q_INVOKABLE bool getFlyingHMDPref(); + /**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. + * + */ + Q_INVOKABLE void setHandRelativeMovement(bool 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 + * controller is pointing, otherwise false. + */ + Q_INVOKABLE bool getHandRelativeMovement(); + /**jsdoc * @function MyAvatar.getAvatarScale * @returns {number} @@ -1705,6 +1721,7 @@ private: bool _enableFlying { false }; bool _flyingPrefDesktop { true }; bool _flyingPrefHMD { false }; + bool _handRelativeMovement{ false }; bool _wasPushing { false }; bool _isPushing { false }; bool _isBeingPushed { false }; @@ -1950,6 +1967,7 @@ private: Setting::Handle _useSnapTurnSetting; Setting::Handle _userHeightSetting; Setting::Handle _flyingHMDSetting; + Setting::Handle _handRelativeMovementSetting; Setting::Handle _avatarEntityCountSetting; Setting::Handle _allowTeleportingSetting { "allowTeleporting", true }; std::vector> _avatarEntityIDSettings; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 3d7971cf57..81db8d0ef9 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -265,6 +265,12 @@ void setupPreferences() { auto preference = new CheckPreference(VR_MOVEMENT, "Walking", getter, setter); 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); + preferences->addPreference(preference); + } { auto getter = [myAvatar]()->bool { return myAvatar->getFlyingHMDPref(); }; auto setter = [myAvatar](bool value) { myAvatar->setFlyingHMDPref(value); }; @@ -272,6 +278,11 @@ void setupPreferences() { preference->setIndented(true); preferences->addPreference(preference); } + { + auto getter = [myAvatar]()->QString { return myAvatar->getDominantHand(); }; + auto setter = [myAvatar](const QString& value) { myAvatar->setDominantHand(value); }; + preferences->addPreference(new PrimaryHandPreference(VR_MOVEMENT, "Dominant Hand", getter, setter)); + } { auto getter = [myAvatar]()->int { return myAvatar->getSnapTurn() ? 0 : 1; }; auto setter = [myAvatar](int value) { myAvatar->setSnapTurn(value == 0); }; From 79ff0a5b658ec70bde6f91d144aebe5d0a0a56d1 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Fri, 18 Jan 2019 14:35:26 -0800 Subject: [PATCH 02/68] Basic controller-relative (non-leveled) locomotion working. --- interface/src/avatar/MyAvatar.cpp | 24 ++++++++++++++++++++++-- interface/src/avatar/MyAvatar.h | 1 + 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 81d6c94c1b..05db6f436d 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2525,6 +2525,12 @@ controller::Pose MyAvatar::getControllerPoseInAvatarFrame(controller::Action act } } +quat MyAvatar::getDominantHandRotation() const { + auto hand = (getDominantHand() == DOMINANT_RIGHT_HAND) ? controller::Action::RIGHT_HAND : controller::Action::LEFT_HAND; + auto pose = getControllerPoseInAvatarFrame(hand); + return pose.rotation; +} + void MyAvatar::updateMotors() { _characterController.clearMotors(); glm::quat motorRotation; @@ -3291,10 +3297,24 @@ void MyAvatar::updateActionMotor(float deltaTime) { // compute action input // Determine if we're head or controller relative... - glm::vec3 forward = (getDriveKey(TRANSLATE_Z)) * IDENTITY_FORWARD; - glm::vec3 right = (getDriveKey(TRANSLATE_X)) * IDENTITY_RIGHT; + glm::vec3 forward, right; + if (getHandRelativeMovement()) { + // 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(); + glm::vec3 controllerForward(0.0f, 1.0f, 0.0f); + glm::vec3 controllerRight((getDominantHand() == DOMINANT_RIGHT_HAND ? -1.0f : 1.0f), 0.0f, 0.0f); + forward = (getDriveKey(TRANSLATE_Z)) * (handRotation * controllerForward); + right = (getDriveKey(TRANSLATE_X)) * (handRotation * controllerRight); + } + else { + forward = (getDriveKey(TRANSLATE_Z)) * IDENTITY_FORWARD; + right = (getDriveKey(TRANSLATE_X)) * IDENTITY_RIGHT; + } glm::vec3 direction = forward + right; + + // RKNOTE: This may need to be changed later... if (state == CharacterController::State::Hover || _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 65a3eac665..16df224aa5 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -961,6 +961,7 @@ public: controller::Pose getControllerPoseInSensorFrame(controller::Action action) const; controller::Pose getControllerPoseInWorldFrame(controller::Action action) const; controller::Pose getControllerPoseInAvatarFrame(controller::Action action) const; + quat MyAvatar::getDominantHandRotation() const; bool hasDriveInput() const; From 6bfe9bf19ef712d5cf5f40ee779b333dca3fde8a Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Fri, 18 Jan 2019 14:53:25 -0800 Subject: [PATCH 03/68] Move hand-relative entry in Controls menu. --- interface/src/ui/PreferencesDialog.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 81db8d0ef9..918fb6d830 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -265,12 +265,6 @@ void setupPreferences() { auto preference = new CheckPreference(VR_MOVEMENT, "Walking", getter, setter); 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); - preferences->addPreference(preference); - } { auto getter = [myAvatar]()->bool { return myAvatar->getFlyingHMDPref(); }; auto setter = [myAvatar](bool value) { myAvatar->setFlyingHMDPref(value); }; @@ -278,6 +272,12 @@ void setupPreferences() { preference->setIndented(true); 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); + preferences->addPreference(preference); + } { auto getter = [myAvatar]()->QString { return myAvatar->getDominantHand(); }; auto setter = [myAvatar](const QString& value) { myAvatar->setDominantHand(value); }; From 4fa84542163291f7928edce9bebe3579c5c74c1f Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 21 Jan 2019 13:25:06 -0800 Subject: [PATCH 04/68] Add condition for HMD mode to hand-relative code block. --- interface/src/avatar/MyAvatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 05db6f436d..ef0d16f9f0 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3298,7 +3298,7 @@ void MyAvatar::updateActionMotor(float deltaTime) { // compute action input // Determine if we're head or controller relative... glm::vec3 forward, right; - if (getHandRelativeMovement()) { + if (getHandRelativeMovement() && 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(); From ea025a687865475fc6189ab3e84f67d1f9792278 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 21 Jan 2019 15:38:36 -0800 Subject: [PATCH 05/68] Add hand dominance states to Controller.Hardware.Application for left and right hand dominance. --- interface/src/Application.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7ed05611ee..95c9cbcff5 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -689,6 +689,8 @@ private: * InHMDnumbernumberThe user is in HMD mode. * AdvancedMovementnumbernumberAdvanced movement controls are enabled. * + * LeftHandDominantnumbernumberDominant hand set to left. + * RightHandDominantnumbernumberDominant hand set to right. * SnapTurnnumbernumberSnap turn is enabled. * GroundednumbernumberThe user's avatar is on the ground. * NavigationFocusednumbernumberNot used. @@ -710,6 +712,8 @@ static const QString STATE_NAV_FOCUSED = "NavigationFocused"; static const QString STATE_PLATFORM_WINDOWS = "PlatformWindows"; static const QString STATE_PLATFORM_MAC = "PlatformMac"; static const QString STATE_PLATFORM_ANDROID = "PlatformAndroid"; +static const QString STATE_LEFT_HAND_DOMINANT = "LeftHandDominant"; +static const QString STATE_RIGHT_HAND_DOMINANT = "RightHandDominant"; // Statically provided display and input plugins extern DisplayPluginList getDisplayPlugins(); @@ -898,7 +902,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { controller::StateController::setStateVariables({ { STATE_IN_HMD, STATE_CAMERA_FULL_SCREEN_MIRROR, STATE_CAMERA_FIRST_PERSON, STATE_CAMERA_THIRD_PERSON, STATE_CAMERA_ENTITY, STATE_CAMERA_INDEPENDENT, STATE_SNAP_TURN, STATE_ADVANCED_MOVEMENT_CONTROLS, STATE_GROUNDED, STATE_NAV_FOCUSED, - STATE_PLATFORM_WINDOWS, STATE_PLATFORM_MAC, STATE_PLATFORM_ANDROID } }); + STATE_PLATFORM_WINDOWS, STATE_PLATFORM_MAC, STATE_PLATFORM_ANDROID, STATE_LEFT_HAND_DOMINANT, STATE_RIGHT_HAND_DOMINANT } }); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -1720,6 +1724,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _applicationStateDevice->setInputVariant(STATE_ADVANCED_MOVEMENT_CONTROLS, []() -> float { return qApp->getMyAvatar()->useAdvancedMovementControls() ? 1 : 0; }); + _applicationStateDevice->setInputVariant(STATE_LEFT_HAND_DOMINANT, []() -> float { + return qApp->getMyAvatar()->getDominantHand() == "left" ? 1 : 0; + }); + _applicationStateDevice->setInputVariant(STATE_RIGHT_HAND_DOMINANT, []() -> float { + return qApp->getMyAvatar()->getDominantHand() == "right" ? 1 : 0; + }); _applicationStateDevice->setInputVariant(STATE_GROUNDED, []() -> float { return qApp->getMyAvatar()->getCharacterController()->onGround() ? 1 : 0; From 9586f88ebc34aa772a8efa0693b556a30d8f5f3a Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 21 Jan 2019 15:39:27 -0800 Subject: [PATCH 06/68] Add hand dominance state awareness to bindings, add bindings for both cases. --- interface/resources/controllers/standard.json | 80 +++++++++++++++++-- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 28f15605e0..a1faf8e760 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -1,11 +1,14 @@ { "name": "Standard to Action", "channels": [ - { "from": "Standard.LY", "to": "Actions.TranslateZ" }, + { "from": "Standard.LY", + "when": "Application.LeftHandDominant", + "to": "Actions.TranslateZ" + }, { "from": "Standard.LX", "when": [ - "Application.InHMD", "!Application.AdvancedMovement", + "Application.InHMD", "!Application.AdvancedMovement", "Application.LeftHandDominant", "Application.SnapTurn", "!Standard.RX" ], "to": "Actions.StepYaw", @@ -18,14 +21,14 @@ ] }, { "from": "Standard.LX", "to": "Actions.TranslateX", - "when": [ "Application.AdvancedMovement" ] + "when": [ "Application.AdvancedMovement", "Application.LeftHandDominant" ] }, { "from": "Standard.LX", "to": "Actions.Yaw", - "when": [ "!Application.AdvancedMovement", "!Application.SnapTurn" ] + "when": [ "!Application.AdvancedMovement", "!Application.SnapTurn", "Application.LeftHandDominant" ] }, { "from": "Standard.RX", - "when": [ "Application.SnapTurn" ], + "when": [ "Application.SnapTurn", "Application.LeftHandDominant" ], "to": "Actions.StepYaw", "filters": [ @@ -36,11 +39,11 @@ ] }, { "from": "Standard.RX", "to": "Actions.Yaw", - "when": [ "!Application.SnapTurn" ] + "when": [ "!Application.SnapTurn", "Application.LeftHandDominant" ] }, { "from": "Standard.RY", - "when": "Application.Grounded", + "when": [ "Application.Grounded", "Application.LeftHandDominant" ], "to": "Actions.Up", "filters": [ @@ -49,7 +52,68 @@ ] }, - { "from": "Standard.RY", "to": "Actions.Up", "filters": "invert"}, + { "from": "Standard.RY", + "when": "Application.LeftHandDominant", + "to": "Actions.Up", + "filters": "invert" + }, + + { "from": "Standard.RY", + "when": "Application.RightHandDominant", + "to": "Actions.TranslateZ" + }, + + { "from": "Standard.RX", + "when": [ + "Application.InHMD", "!Application.AdvancedMovement", "Application.RightHandDominant", + "Application.SnapTurn", "!Standard.RX" + ], + "to": "Actions.StepYaw", + "filters": + [ + { "type": "deadZone", "min": 0.15 }, + "constrainToInteger", + { "type": "pulse", "interval": 0.25 }, + { "type": "scale", "scale": 22.5 } + ] + }, + { "from": "Standard.RX", "to": "Actions.TranslateX", + "when": [ "Application.AdvancedMovement", "Application.RightHandDominant" ] + }, + { "from": "Standard.RX", "to": "Actions.Yaw", + "when": [ "!Application.AdvancedMovement", "!Application.SnapTurn", "Application.RightHandDominant" ] + }, + + { "from": "Standard.LX", + "when": [ "Application.SnapTurn", "Application.RightHandDominant" ], + "to": "Actions.StepYaw", + "filters": + [ + { "type": "deadZone", "min": 0.15 }, + "constrainToInteger", + { "type": "pulse", "interval": 0.25 }, + { "type": "scale", "scale": 22.5 } + ] + }, + { "from": "Standard.LX", "to": "Actions.Yaw", + "when": [ "!Application.SnapTurn", "Application.RightHandDominant" ] + }, + + { "from": "Standard.LY", + "when": [ "Application.Grounded", "Application.RightHandDominant" ], + "to": "Actions.Up", + "filters": + [ + { "type": "deadZone", "min": 0.6 }, + "invert" + ] + }, + + { "from": "Standard.LY", + "when": "Application.RightHandDominant", + "to": "Actions.Up", + "filters": "invert" + }, { "from": "Standard.Back", "to": "Actions.CycleCamera" }, { "from": "Standard.Start", "to": "Actions.ContextMenu" }, From d3c1843d45d777a32dbc1f62f54a1f242bc63280 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 21 Jan 2019 15:40:12 -0800 Subject: [PATCH 07/68] Disable toggleAdvancedMovementForHandControllers.js until such time the Controller.Standard.RY binding can be fixed. --- scripts/system/controllers/controllerScripts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/controllers/controllerScripts.js b/scripts/system/controllers/controllerScripts.js index 2114f2c0b2..3693e3651b 100644 --- a/scripts/system/controllers/controllerScripts.js +++ b/scripts/system/controllers/controllerScripts.js @@ -15,7 +15,7 @@ var CONTOLLER_SCRIPTS = [ "squeezeHands.js", "controllerDisplayManager.js", "grab.js", - "toggleAdvancedMovementForHandControllers.js", + //"toggleAdvancedMovementForHandControllers.js", "handTouch.js", "controllerDispatcher.js", "controllerModules/nearParentGrabOverlay.js", From 1e10afe762d6d0ce8685de69a00b9d5c2ed27ac2 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 22 Jan 2019 14:14:54 -0800 Subject: [PATCH 08/68] Add function for calculating direction in MyAvatar. --- interface/src/avatar/MyAvatar.cpp | 46 ++++++++++++++++++------------- interface/src/avatar/MyAvatar.h | 1 + 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index ef0d16f9f0..5242d52431 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3278,21 +3278,7 @@ static float scaleSpeedByDirection(const glm::vec2 velocityDirection, const floa return scaledSpeed; } -void MyAvatar::updateActionMotor(float deltaTime) { - bool thrustIsPushing = (glm::length2(_thrust) > EPSILON); - bool scriptedMotorIsPushing = (_motionBehaviors & AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED) - && _scriptedMotorTimescale < MAX_CHARACTER_MOTOR_TIMESCALE; - _isBeingPushed = thrustIsPushing || scriptedMotorIsPushing; - if (_isPushing || _isBeingPushed) { - // we don't want the motor to brake if a script is pushing the avatar around - // (we assume the avatar is driving itself via script) - _isBraking = false; - } else { - float speed = glm::length(_actionMotorVelocity); - const float MIN_ACTION_BRAKE_SPEED = 0.1f; - _isBraking = _wasPushing || (_isBraking && speed > MIN_ACTION_BRAKE_SPEED); - } - +glm::vec3 MyAvatar::calculateScaledDirection(){ CharacterController::State state = _characterController.getState(); // compute action input @@ -3313,11 +3299,12 @@ void MyAvatar::updateActionMotor(float deltaTime) { } glm::vec3 direction = forward + right; - + // RKNOTE: This may need to be changed later... if (state == CharacterController::State::Hover || - _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { + _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP; + up /= glm::length(up); direction += up; } @@ -3325,13 +3312,34 @@ void MyAvatar::updateActionMotor(float deltaTime) { float directionLength = glm::length(direction); _isPushing = directionLength > EPSILON; - // normalize direction if (_isPushing) { - direction /= directionLength; + direction; } else { direction = Vectors::ZERO; } + return direction; +} + +void MyAvatar::updateActionMotor(float deltaTime) { + bool thrustIsPushing = (glm::length2(_thrust) > EPSILON); + bool scriptedMotorIsPushing = (_motionBehaviors & AVATAR_MOTION_SCRIPTED_MOTOR_ENABLED) + && _scriptedMotorTimescale < MAX_CHARACTER_MOTOR_TIMESCALE; + _isBeingPushed = thrustIsPushing || scriptedMotorIsPushing; + if (_isPushing || _isBeingPushed) { + // we don't want the motor to brake if a script is pushing the avatar around + // (we assume the avatar is driving itself via script) + _isBraking = false; + } else { + float speed = glm::length(_actionMotorVelocity); + const float MIN_ACTION_BRAKE_SPEED = 0.1f; + _isBraking = _wasPushing || (_isBraking && speed > MIN_ACTION_BRAKE_SPEED); + } + + CharacterController::State state = _characterController.getState(); + + glm::vec3 direction = calculateScaledDirection(); + if (state == CharacterController::State::Hover) { // we're flying --> complex acceleration curve that builds on top of current motor speed and caps at some max speed diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 16df224aa5..9520fb7cc4 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1772,6 +1772,7 @@ private: // private methods void updateOrientation(float deltaTime); + glm::vec3 calculateScaledDirection(); void updateActionMotor(float deltaTime); void updatePosition(float deltaTime); void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency); From 09d15c9cb058864b2fe87baa92fc1cf8aac99b30 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 24 Jan 2019 14:20:42 -0800 Subject: [PATCH 09/68] Block TranslateZ when off-hand Y axis is active. --- interface/resources/controllers/standard.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index a1faf8e760..25f75c5670 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -2,7 +2,7 @@ "name": "Standard to Action", "channels": [ { "from": "Standard.LY", - "when": "Application.LeftHandDominant", + "when": ["Application.LeftHandDominant", "!Standard.RY"], "to": "Actions.TranslateZ" }, @@ -59,7 +59,7 @@ }, { "from": "Standard.RY", - "when": "Application.RightHandDominant", + "when": ["Application.RightHandDominant", "!Standard.LY"], "to": "Actions.TranslateZ" }, From 690f67c9d99d0bf2a83588dda415e9d3c9cd8088 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 24 Jan 2019 14:21:18 -0800 Subject: [PATCH 10/68] Add variable for teleport deadzone on y-axis. --- scripts/system/libraries/controllerDispatcherUtils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/system/libraries/controllerDispatcherUtils.js b/scripts/system/libraries/controllerDispatcherUtils.js index 221af07474..27e637ab63 100644 --- a/scripts/system/libraries/controllerDispatcherUtils.js +++ b/scripts/system/libraries/controllerDispatcherUtils.js @@ -103,6 +103,8 @@ TEAR_AWAY_DISTANCE = 0.15; // ungrab an entity if its bounding-box moves this fa TEAR_AWAY_COUNT = 2; // multiply by TEAR_AWAY_CHECK_TIME to know how long the item must be away TEAR_AWAY_CHECK_TIME = 0.15; // seconds, duration between checks +TELEPORT_DEADZONE = 0.15; + NEAR_GRAB_DISTANCE = 0.14; // Grab an entity if its bounding box is within this distance. // Smaller than TEAR_AWAY_DISTANCE for hysteresis. From 80abfbab5ee60f08f4896fa773589f8bbc08f9e4 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 24 Jan 2019 14:22:01 -0800 Subject: [PATCH 11/68] Modify teleport to 'superpower' spec. --- .../controllers/controllerModules/teleport.js | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index 8770ae8dde..bbc690d663 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -129,6 +129,8 @@ Script.include("/~/system/libraries/controllers.js"); this.init = false; this.hand = hand; this.buttonValue = 0; + this.standardAxisLY = 0.0; + this.standardAxisRY = 0.0; this.disabled = false; // used by the 'Hifi-Teleport-Disabler' message handler this.active = false; this.state = TELEPORTER_STATES.IDLE; @@ -690,6 +692,43 @@ Script.include("/~/system/libraries/controllers.js"); } }; + this.getStandardLY = function (value) { + _this.standardAxisLY = value; + }; + + this.getStandardRY = function (value) { + _this.standardAxisRY = value; + }; + + // Return value for the getDominantY and getOffhandY functions has to be inverted. + this.getDominantY = function () { + return (MyAvatar.getDominantHand() === "left") ? -(_this.standardAxisLY) : -(_this.standardAxisRY); + }; + + this.getOffhandY = function () { + return (MyAvatar.getDominantHand() === "left") ? -(_this.standardAxisRY) : -(_this.standardAxisLY); + }; + + this.getDominantHand = function () { + return (MyAvatar.getDominantHand() === "left") ? LEFT_HAND : RIGHT_HAND; + } + + this.getOffHand = function () { + return (MyAvatar.getDominantHand() === "left") ? RIGHT_HAND : LEFT_HAND; + } + + this.showReticle = function () { + return (_this.getOffhandY() > TELEPORT_DEADZONE) ? true : false; + }; + + this.shouldTeleport = function () { + return (_this.getDominantY() > TELEPORT_DEADZONE && _this.getOffhandY() > TELEPORT_DEADZONE) ? true : false; + }; + + this.shouldCancel = function () { + return (_this.getDominantY() < -TELEPORT_DEADZONE || _this.getOffhandY() < -TELEPORT_DEADZONE) ? true : false; + }; + this.parameters = makeDispatcherModuleParameters( 80, this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"], @@ -706,7 +745,7 @@ Script.include("/~/system/libraries/controllers.js"); } var otherModule = this.getOtherModule(); - if (!this.disabled && this.buttonValue !== 0 && !otherModule.active) { + if (!this.disabled && this.showReticle() && !otherModule.active && this.hand === this.getOffHand()) { this.active = true; this.enterTeleport(); return makeRunningValues(true, [], []); @@ -715,6 +754,12 @@ Script.include("/~/system/libraries/controllers.js"); }; this.run = function(controllerData, deltaTime) { + // Kill condition: + if (this.shouldCancel()) { + this.disableLasers(); + this.active = false; + return makeRunningValues(false, [], []); + } // Get current hand pose information to see if the pose is valid var pose = Controller.getPoseValue(handInfo[(_this.hand === RIGHT_HAND) ? 'right' : 'left'].controllerInput); @@ -778,7 +823,7 @@ Script.include("/~/system/libraries/controllers.js"); this.teleport = function(newResult, target) { var result = newResult; this.teleportedPosition = newResult.intersection; - if (_this.buttonValue !== 0) { + if (!_this.shouldTeleport()) { return makeRunningValues(true, [], []); } @@ -982,6 +1027,10 @@ Script.include("/~/system/libraries/controllers.js"); // Teleport actions. teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftTeleporter.buttonPress); teleportMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(rightTeleporter.buttonPress); + teleportMapping.from(Controller.Standard.LY).peek().to(leftTeleporter.getStandardLY); + teleportMapping.from(Controller.Standard.RY).peek().to(leftTeleporter.getStandardRY); + teleportMapping.from(Controller.Standard.LY).peek().to(rightTeleporter.getStandardLY); + teleportMapping.from(Controller.Standard.RY).peek().to(rightTeleporter.getStandardRY); } var leftTeleporter = new Teleporter(LEFT_HAND); From a1c24516c28f4265465b4e9bcd073e6d2c2de192 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 24 Jan 2019 14:38:31 -0800 Subject: [PATCH 12/68] Fix strafing with controller-relative movement (was wrong local axis for controller). --- interface/src/avatar/MyAvatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 5242d52431..3183388214 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3289,7 +3289,7 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ // If we're on the right hand, we have to flip the x-axis. auto handRotation = getDominantHandRotation(); glm::vec3 controllerForward(0.0f, 1.0f, 0.0f); - glm::vec3 controllerRight((getDominantHand() == DOMINANT_RIGHT_HAND ? -1.0f : 1.0f), 0.0f, 0.0f); + glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? -1.0f : 1.0f)); forward = (getDriveKey(TRANSLATE_Z)) * (handRotation * controllerForward); right = (getDriveKey(TRANSLATE_X)) * (handRotation * controllerRight); } From 9ea476ea89dd956d23c96916c6fa53bc37af54e3 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Fri, 25 Jan 2019 12:53:59 -0800 Subject: [PATCH 13/68] Attempt to add acceleration curve. --- .../qml/hifi/tablet/ControllerSettings.qml | 2 +- interface/src/avatar/MyAvatar.cpp | 618 ++++++++++-------- interface/src/avatar/MyAvatar.h | 96 +++ interface/src/ui/PreferencesDialog.cpp | 47 ++ 4 files changed, 493 insertions(+), 270 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/ControllerSettings.qml b/interface/resources/qml/hifi/tablet/ControllerSettings.qml index 6727047eb0..9feb0f6f08 100644 --- a/interface/resources/qml/hifi/tablet/ControllerSettings.qml +++ b/interface/resources/qml/hifi/tablet/ControllerSettings.qml @@ -332,7 +332,7 @@ Item { anchors.fill: stackView id: controllerPrefereneces objectName: "TabletControllerPreferences" - showCategories: ["VR Movement", "Game Controller", "Sixense Controllers", "Perception Neuron", "Leap Motion"] + showCategories: ["VR Movement", "Acceleration Step Function", "Game Controller", "Sixense Controllers", "Perception Neuron", "Leap Motion"] categoryProperties: { "VR Movement" : { "User real-world height (meters)" : { "anchors.right" : "undefined" }, diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 3183388214..f37b8e1b0a 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -139,7 +139,12 @@ MyAvatar::MyAvatar(QThread* thread) : _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), - _avatarEntityCountSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" << "size", 0) + _avatarEntityCountSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" << "size", 0), + _driveGear1Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear1", _driveGear1), + _driveGear2Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear2", _driveGear2), + _driveGear3Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear3", _driveGear3), + _driveGear4Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear4", _driveGear4), + _driveGear5Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear5", _driveGear5) { _clientTraitsHandler.reset(new ClientTraitsHandler(this)); @@ -161,7 +166,7 @@ MyAvatar::MyAvatar(QThread* thread) : qApp->loadAvatarScripts(hfmModel.scripts); _shouldLoadScripts = false; } - // Load and convert old attachments to avatar entities + // Load and convert old attachments to avatar entities if (_oldAttachmentData.size() > 0) { setAttachmentData(_oldAttachmentData); _oldAttachmentData.clear(); @@ -182,7 +187,7 @@ MyAvatar::MyAvatar(QThread* thread) : // connect to AddressManager signal for location jumps connect(DependencyManager::get().data(), &AddressManager::locationChangeRequired, - this, static_cast(&MyAvatar::goToFeetLocation)); + this, static_cast(&MyAvatar::goToFeetLocation)); // handle scale constraints imposed on us by the domain-server auto& domainHandler = DependencyManager::get()->getDomainHandler(); @@ -393,7 +398,7 @@ void MyAvatar::centerBody() { // derive the desired body orientation from the current hmd orientation, before the sensor reset. auto newBodySensorMatrix = deriveBodyFromHMDSensor(); // Based on current cached HMD position/rotation.. - // transform this body into world space + // transform this body into world space auto worldBodyMatrix = _sensorToWorldMatrix * newBodySensorMatrix; auto worldBodyPos = extractTranslation(worldBodyMatrix); auto worldBodyRot = glmExtractRotation(worldBodyMatrix); @@ -446,7 +451,7 @@ void MyAvatar::reset(bool andRecenter, bool andReload, bool andHead) { // derive the desired body orientation from the *old* hmd orientation, before the sensor reset. auto newBodySensorMatrix = deriveBodyFromHMDSensor(); // Based on current cached HMD position/rotation.. - // transform this body into world space + // transform this body into world space auto worldBodyMatrix = _sensorToWorldMatrix * newBodySensorMatrix; auto worldBodyPos = extractTranslation(worldBodyMatrix); auto worldBodyRot = glmExtractRotation(worldBodyMatrix); @@ -701,16 +706,16 @@ void MyAvatar::updateEyeContactTarget(float deltaTime) { float const FIFTY_FIFTY_CHANCE = 0.5f; float const EYE_TO_MOUTH_CHANCE = 0.25f; switch (_eyeContactTarget) { - case LEFT_EYE: - _eyeContactTarget = (randFloat() < EYE_TO_MOUTH_CHANCE) ? MOUTH : RIGHT_EYE; - break; - case RIGHT_EYE: - _eyeContactTarget = (randFloat() < EYE_TO_MOUTH_CHANCE) ? MOUTH : LEFT_EYE; - break; - case MOUTH: - default: - _eyeContactTarget = (randFloat() < FIFTY_FIFTY_CHANCE) ? RIGHT_EYE : LEFT_EYE; - break; + case LEFT_EYE: + _eyeContactTarget = (randFloat() < EYE_TO_MOUTH_CHANCE) ? MOUTH : RIGHT_EYE; + break; + case RIGHT_EYE: + _eyeContactTarget = (randFloat() < EYE_TO_MOUTH_CHANCE) ? MOUTH : LEFT_EYE; + break; + case MOUTH: + default: + _eyeContactTarget = (randFloat() < FIFTY_FIFTY_CHANCE) ? RIGHT_EYE : LEFT_EYE; + break; } const float EYE_TARGET_DELAY_TIME = 0.33f; @@ -1010,17 +1015,17 @@ void MyAvatar::updateSensorToWorldMatrix() { if (_enableDebugDrawSensorToWorldMatrix) { DebugDraw::getInstance().addMarker("sensorToWorldMatrix", glmExtractRotation(_sensorToWorldMatrix), - extractTranslation(_sensorToWorldMatrix), glm::vec4(1)); + extractTranslation(_sensorToWorldMatrix), glm::vec4(1)); } _sensorToWorldMatrixCache.set(_sensorToWorldMatrix); updateJointFromController(controller::Action::LEFT_HAND, _controllerLeftHandMatrixCache); updateJointFromController(controller::Action::RIGHT_HAND, _controllerRightHandMatrixCache); - + if (hasSensorToWorldScaleChanged) { emit sensorToWorldScaleChanged(sensorToWorldScale); } - + } // Update avatar head rotation with sensor data @@ -1046,7 +1051,7 @@ void MyAvatar::updateFromTrackers(float deltaTime) { const float TRACKER_MIN_YAW_TURN = 15.0f; const float TRACKER_MAX_YAW_TURN = 50.0f; if ( (fabs(estimatedRotation.y) > TRACKER_MIN_YAW_TURN) && - (fabs(estimatedRotation.y) < TRACKER_MAX_YAW_TURN) ) { + (fabs(estimatedRotation.y) < TRACKER_MAX_YAW_TURN) ) { if (estimatedRotation.y > 0.0f) { _bodyYawDelta += (estimatedRotation.y - TRACKER_MIN_YAW_TURN) * TRACKER_YAW_TURN_SENSITIVITY; } else { @@ -1206,7 +1211,7 @@ void MyAvatar::render(RenderArgs* renderArgs) { void MyAvatar::overrideAnimation(const QString& url, float fps, bool loop, float firstFrame, float lastFrame) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "overrideAnimation", Q_ARG(const QString&, url), Q_ARG(float, fps), - Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame)); + Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame)); return; } _skeletonModel->getRig().overrideAnimation(url, fps, loop, firstFrame, lastFrame); @@ -1230,10 +1235,10 @@ QStringList MyAvatar::getAnimationRoles() { } void MyAvatar::overrideRoleAnimation(const QString& role, const QString& url, float fps, bool loop, - float firstFrame, float lastFrame) { + float firstFrame, float lastFrame) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "overrideRoleAnimation", Q_ARG(const QString&, role), Q_ARG(const QString&, url), - Q_ARG(float, fps), Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame)); + Q_ARG(float, fps), Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame)); return; } _skeletonModel->getRig().overrideRoleAnimation(role, url, fps, loop, firstFrame, lastFrame); @@ -1250,8 +1255,8 @@ void MyAvatar::restoreRoleAnimation(const QString& role) { void MyAvatar::saveAvatarUrl() { if (qApp->getSaveAvatarOverrideUrl() || !qApp->getAvatarOverrideUrl().isValid()) { _fullAvatarURLSetting.set(_fullAvatarURLFromPreferences == AvatarData::defaultFullAvatarModelUrl() ? - "" : - _fullAvatarURLFromPreferences.toString()); + "" : + _fullAvatarURLFromPreferences.toString()); } } @@ -1268,10 +1273,10 @@ void MyAvatar::resizeAvatarEntitySettingHandles(uint32_t maxIndex) { uint32_t settingsIndex = (uint32_t)_avatarEntityIDSettings.size() + 1; while (settingsIndex <= maxIndex) { Setting::Handle idHandle(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" - << QString::number(settingsIndex) << "id", QUuid()); + << QString::number(settingsIndex) << "id", QUuid()); _avatarEntityIDSettings.push_back(idHandle); Setting::Handle dataHandle(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" - << QString::number(settingsIndex) << "properties", QByteArray()); + << QString::number(settingsIndex) << "properties", QByteArray()); _avatarEntityDataSettings.push_back(dataHandle); settingsIndex++; } @@ -1289,8 +1294,8 @@ void MyAvatar::saveData() { // --replaceAvatarURL (so _saveAvatarOverrideUrl is true) if (qApp->getSaveAvatarOverrideUrl() || !qApp->getAvatarOverrideUrl().isValid() ) { _fullAvatarURLSetting.set(_fullAvatarURLFromPreferences == AvatarData::defaultFullAvatarModelUrl() ? - "" : - _fullAvatarURLFromPreferences.toString()); + "" : + _fullAvatarURLFromPreferences.toString()); } _fullAvatarModelNameSetting.set(_fullAvatarModelName); @@ -1302,6 +1307,11 @@ void MyAvatar::saveData() { _userHeightSetting.set(getUserHeight()); _flyingHMDSetting.set(getFlyingHMDPref()); _handRelativeMovementSetting.set(getHandRelativeMovement()); + _driveGear1Setting.set(getDriveGear1()); + _driveGear2Setting.set(getDriveGear2()); + _driveGear3Setting.set(getDriveGear3()); + _driveGear4Setting.set(getDriveGear4()); + _driveGear5Setting.set(getDriveGear5()); auto hmdInterface = DependencyManager::get(); saveAvatarEntityDataToSettings(); @@ -1879,6 +1889,11 @@ void MyAvatar::loadData() { Setting::Handle firstRunVal { Settings::firstRun, true }; setFlyingHMDPref(firstRunVal.get() ? false : _flyingHMDSetting.get()); setHandRelativeMovement(firstRunVal.get() ? false : _handRelativeMovementSetting.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()); + setDriveGear4(firstRunVal.get() ? DEFAULT_GEAR_4 : _driveGear4Setting.get()); + setDriveGear5(firstRunVal.get() ? DEFAULT_GEAR_5 : _driveGear5Setting.get()); setFlyingEnabled(getFlyingEnabled()); setDisplayName(_displayNameSetting.get()); @@ -2005,7 +2020,7 @@ ScriptAvatarData* MyAvatar::getTargetAvatar() const { } static float lookAtCostFunction(const glm::vec3& myForward, const glm::vec3& myPosition, const glm::vec3& otherForward, const glm::vec3& otherPosition, - bool otherIsTalking, bool lookingAtOtherAlready) { + bool otherIsTalking, bool lookingAtOtherAlready) { const float DISTANCE_FACTOR = 3.14f; const float MY_ANGLE_FACTOR = 1.0f; const float OTHER_ANGLE_FACTOR = 1.0f; @@ -2026,10 +2041,10 @@ static float lookAtCostFunction(const glm::vec3& myForward, const glm::vec3& myP return FLT_MAX; } else { return (DISTANCE_FACTOR * distance + - MY_ANGLE_FACTOR * myAngle + - OTHER_ANGLE_FACTOR * otherAngle + - OTHER_IS_TALKING_TERM + - LOOKING_AT_OTHER_ALREADY_TERM); + MY_ANGLE_FACTOR * myAngle + + OTHER_ANGLE_FACTOR * otherAngle + + OTHER_IS_TALKING_TERM + + LOOKING_AT_OTHER_ALREADY_TERM); } } @@ -2077,8 +2092,8 @@ void MyAvatar::snapOtherAvatarLookAtTargetsToMe(const AvatarHash& hash) { // Alter their gaze to look directly at my camera; this looks more natural than looking at my avatar's face. glm::vec3 lookAtPosition = avatar->getHead()->getLookAtPosition(); // A position, in world space, on my avatar. - // The camera isn't at the point midway between the avatar eyes. (Even without an HMD, the head can be offset a bit.) - // Let's get everything to world space: + // The camera isn't at the point midway between the avatar eyes. (Even without an HMD, the head can be offset a bit.) + // Let's get everything to world space: glm::vec3 avatarLeftEye = getHead()->getLeftEyePosition(); glm::vec3 avatarRightEye = getHead()->getRightEyePosition(); @@ -2086,12 +2101,12 @@ void MyAvatar::snapOtherAvatarLookAtTargetsToMe(const AvatarHash& hash) { // (We will be adding that offset to the camera position, after making some other adjustments.) glm::vec3 gazeOffset = lookAtPosition - getHead()->getEyePosition(); - ViewFrustum viewFrustum; - qApp->copyViewFrustum(viewFrustum); + ViewFrustum viewFrustum; + qApp->copyViewFrustum(viewFrustum); - glm::vec3 viewPosition = viewFrustum.getPosition(); + glm::vec3 viewPosition = viewFrustum.getPosition(); #if DEBUG_ALWAYS_LOOKAT_EYES_NOT_CAMERA - viewPosition = (avatarLeftEye + avatarRightEye) / 2.0f; + viewPosition = (avatarLeftEye + avatarRightEye) / 2.0f; #endif // scale gazeOffset by IPD, if wearing an HMD. if (qApp->isHMDMode()) { @@ -2166,121 +2181,121 @@ void MyAvatar::setJointRotations(const QVector& jointRotations) { void MyAvatar::setJointData(int index, const glm::quat& rotation, const glm::vec3& translation) { switch (index) { - case FARGRAB_RIGHTHAND_INDEX: { - _farGrabRightMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); - break; - } - case FARGRAB_LEFTHAND_INDEX: { - _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); - break; - } - case FARGRAB_MOUSE_INDEX: { - _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); - break; - } - default: { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "setJointData", Q_ARG(int, index), Q_ARG(const glm::quat&, rotation), - Q_ARG(const glm::vec3&, translation)); - return; - } - // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority - _skeletonModel->getRig().setJointState(index, true, rotation, translation, SCRIPT_PRIORITY); + case FARGRAB_RIGHTHAND_INDEX: { + _farGrabRightMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); + break; + } + case FARGRAB_LEFTHAND_INDEX: { + _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); + break; + } + case FARGRAB_MOUSE_INDEX: { + _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); + break; + } + default: { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setJointData", Q_ARG(int, index), Q_ARG(const glm::quat&, rotation), + Q_ARG(const glm::vec3&, translation)); + return; } + // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority + _skeletonModel->getRig().setJointState(index, true, rotation, translation, SCRIPT_PRIORITY); + } } } void MyAvatar::setJointRotation(int index, const glm::quat& rotation) { switch (index) { - case FARGRAB_RIGHTHAND_INDEX: { - glm::mat4 prevMat = _farGrabRightMatrixCache.get(); - glm::vec3 previousTranslation = extractTranslation(prevMat); - _farGrabRightMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); - break; - } - case FARGRAB_LEFTHAND_INDEX: { - glm::mat4 prevMat = _farGrabLeftMatrixCache.get(); - glm::vec3 previousTranslation = extractTranslation(prevMat); - _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); - break; - } - case FARGRAB_MOUSE_INDEX: { - glm::mat4 prevMat = _farGrabMouseMatrixCache.get(); - glm::vec3 previousTranslation = extractTranslation(prevMat); - _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); - break; - } - default: { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "setJointRotation", Q_ARG(int, index), Q_ARG(const glm::quat&, rotation)); - return; - } - // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority - _skeletonModel->getRig().setJointRotation(index, true, rotation, SCRIPT_PRIORITY); + case FARGRAB_RIGHTHAND_INDEX: { + glm::mat4 prevMat = _farGrabRightMatrixCache.get(); + glm::vec3 previousTranslation = extractTranslation(prevMat); + _farGrabRightMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); + break; + } + case FARGRAB_LEFTHAND_INDEX: { + glm::mat4 prevMat = _farGrabLeftMatrixCache.get(); + glm::vec3 previousTranslation = extractTranslation(prevMat); + _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); + break; + } + case FARGRAB_MOUSE_INDEX: { + glm::mat4 prevMat = _farGrabMouseMatrixCache.get(); + glm::vec3 previousTranslation = extractTranslation(prevMat); + _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); + break; + } + default: { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setJointRotation", Q_ARG(int, index), Q_ARG(const glm::quat&, rotation)); + return; } + // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority + _skeletonModel->getRig().setJointRotation(index, true, rotation, SCRIPT_PRIORITY); + } } } void MyAvatar::setJointTranslation(int index, const glm::vec3& translation) { switch (index) { - case FARGRAB_RIGHTHAND_INDEX: { - glm::mat4 prevMat = _farGrabRightMatrixCache.get(); - glm::quat previousRotation = extractRotation(prevMat); - _farGrabRightMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); - break; - } - case FARGRAB_LEFTHAND_INDEX: { - glm::mat4 prevMat = _farGrabLeftMatrixCache.get(); - glm::quat previousRotation = extractRotation(prevMat); - _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); - break; - } - case FARGRAB_MOUSE_INDEX: { - glm::mat4 prevMat = _farGrabMouseMatrixCache.get(); - glm::quat previousRotation = extractRotation(prevMat); - _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); - break; - } - default: { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "setJointTranslation", - Q_ARG(int, index), Q_ARG(const glm::vec3&, translation)); - return; - } - // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority - _skeletonModel->getRig().setJointTranslation(index, true, translation, SCRIPT_PRIORITY); + case FARGRAB_RIGHTHAND_INDEX: { + glm::mat4 prevMat = _farGrabRightMatrixCache.get(); + glm::quat previousRotation = extractRotation(prevMat); + _farGrabRightMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); + break; + } + case FARGRAB_LEFTHAND_INDEX: { + glm::mat4 prevMat = _farGrabLeftMatrixCache.get(); + glm::quat previousRotation = extractRotation(prevMat); + _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); + break; + } + case FARGRAB_MOUSE_INDEX: { + glm::mat4 prevMat = _farGrabMouseMatrixCache.get(); + glm::quat previousRotation = extractRotation(prevMat); + _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); + break; + } + default: { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setJointTranslation", + Q_ARG(int, index), Q_ARG(const glm::vec3&, translation)); + return; } + // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority + _skeletonModel->getRig().setJointTranslation(index, true, translation, SCRIPT_PRIORITY); + } } } void MyAvatar::clearJointData(int index) { switch (index) { - case FARGRAB_RIGHTHAND_INDEX: { - _farGrabRightMatrixCache.invalidate(); - break; - } - case FARGRAB_LEFTHAND_INDEX: { - _farGrabLeftMatrixCache.invalidate(); - break; - } - case FARGRAB_MOUSE_INDEX: { - _farGrabMouseMatrixCache.invalidate(); - break; - } - default: { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "clearJointData", Q_ARG(int, index)); - return; - } - _skeletonModel->getRig().clearJointAnimationPriority(index); + case FARGRAB_RIGHTHAND_INDEX: { + _farGrabRightMatrixCache.invalidate(); + break; + } + case FARGRAB_LEFTHAND_INDEX: { + _farGrabLeftMatrixCache.invalidate(); + break; + } + case FARGRAB_MOUSE_INDEX: { + _farGrabMouseMatrixCache.invalidate(); + break; + } + default: { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "clearJointData", Q_ARG(int, index)); + return; } + _skeletonModel->getRig().clearJointAnimationPriority(index); + } } } void MyAvatar::setJointData(const QString& name, const glm::quat& rotation, const glm::vec3& translation) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "setJointData", Q_ARG(QString, name), Q_ARG(const glm::quat&, rotation), - Q_ARG(const glm::vec3&, translation)); + Q_ARG(const glm::vec3&, translation)); return; } writeLockWithNamedJointIndex(name, [&](int index) { @@ -2346,25 +2361,25 @@ void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) { std::shared_ptr skeletonConnection = std::make_shared(); *skeletonConnection = QObject::connect(_skeletonModel.get(), &SkeletonModel::skeletonLoaded, [this, skeletonModelChangeCount, skeletonConnection]() { - if (skeletonModelChangeCount == _skeletonModelChangeCount) { + if (skeletonModelChangeCount == _skeletonModelChangeCount) { - if (_fullAvatarModelName.isEmpty()) { - // Store the FST file name into preferences - const auto& mapping = _skeletonModel->getGeometry()->getMapping(); - if (mapping.value("name").isValid()) { - _fullAvatarModelName = mapping.value("name").toString(); - } - } + if (_fullAvatarModelName.isEmpty()) { + // Store the FST file name into preferences + const auto& mapping = _skeletonModel->getGeometry()->getMapping(); + if (mapping.value("name").isValid()) { + _fullAvatarModelName = mapping.value("name").toString(); + } + } - initHeadBones(); - _skeletonModel->setCauterizeBoneSet(_headBoneSet); - _fstAnimGraphOverrideUrl = _skeletonModel->getGeometry()->getAnimGraphOverrideUrl(); - initAnimGraph(); - _skeletonModelLoaded = true; - } - QObject::disconnect(*skeletonConnection); + initHeadBones(); + _skeletonModel->setCauterizeBoneSet(_headBoneSet); + _fstAnimGraphOverrideUrl = _skeletonModel->getGeometry()->getAnimGraphOverrideUrl(); + initAnimGraph(); + _skeletonModelLoaded = true; + } + QObject::disconnect(*skeletonConnection); }); - + saveAvatarUrl(); emit skeletonChanged(); } @@ -2413,7 +2428,7 @@ QVariantList MyAvatar::getAvatarEntitiesVariant() { if (entityTree) { QList avatarEntityIDs; _avatarEntitiesLock.withReadLock([&] { - avatarEntityIDs = _packedAvatarEntityData.keys(); + avatarEntityIDs = _packedAvatarEntityData.keys(); }); for (const auto& entityID : avatarEntityIDs) { auto entity = entityTree->findEntityByID(entityID); @@ -2447,8 +2462,8 @@ void MyAvatar::useFullAvatarURL(const QUrl& fullAvatarURL, const QString& modelN if (QThread::currentThread() != thread()) { BLOCKING_INVOKE_METHOD(this, "useFullAvatarURL", - Q_ARG(const QUrl&, fullAvatarURL), - Q_ARG(const QString&, modelName)); + Q_ARG(const QUrl&, fullAvatarURL), + Q_ARG(const QString&, modelName)); return; } @@ -2543,7 +2558,7 @@ void MyAvatar::updateMotors() { float verticalMotorTimescale; if (_characterController.getState() == CharacterController::State::Hover || - _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { + _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { horizontalMotorTimescale = FLYING_MOTOR_TIMESCALE; verticalMotorTimescale = FLYING_MOTOR_TIMESCALE; } else { @@ -2553,7 +2568,7 @@ void MyAvatar::updateMotors() { if (_motionBehaviors & AVATAR_MOTION_ACTION_MOTOR_ENABLED) { if (_characterController.getState() == CharacterController::State::Hover || - _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { + _characterController.computeCollisionGroup() == BULLET_COLLISION_GROUP_COLLISIONLESS) { motorRotation = getMyHead()->getHeadOrientation(); } else { // non-hovering = walking: follow camera twist about vertical but not lift @@ -2694,7 +2709,7 @@ void MyAvatar::setScriptedMotorTimescale(float timescale) { // we clamp the timescale on the large side (instead of just the low side) to prevent // obnoxiously large values from introducing NaN into avatar's velocity _scriptedMotorTimescale = glm::clamp(timescale, MIN_SCRIPTED_MOTOR_TIMESCALE, - DEFAULT_SCRIPTED_MOTOR_TIMESCALE); + DEFAULT_SCRIPTED_MOTOR_TIMESCALE); } void MyAvatar::setScriptedMotorFrame(QString frame) { @@ -2736,9 +2751,9 @@ SharedSoundPointer MyAvatar::getCollisionSound() { } void MyAvatar::attach(const QString& modelURL, const QString& jointName, - const glm::vec3& translation, const glm::quat& rotation, - float scale, bool isSoft, - bool allowDuplicates, bool useSaved) { + const glm::vec3& translation, const glm::quat& rotation, + float scale, bool isSoft, + bool allowDuplicates, bool useSaved) { if (QThread::currentThread() != thread()) { BLOCKING_INVOKE_METHOD(this, "attach", Q_ARG(const QString&, modelURL), @@ -2863,7 +2878,7 @@ void MyAvatar::setAttachmentsVariant(const QVariantList& variant) { bool MyAvatar::findAvatarEntity(const QString& modelURL, const QString& jointName, QUuid& entityID) { QList avatarEntityIDs; _avatarEntitiesLock.withReadLock([&] { - avatarEntityIDs = _packedAvatarEntityData.keys(); + avatarEntityIDs = _packedAvatarEntityData.keys(); }); for (const auto& entityID : avatarEntityIDs) { auto props = DependencyManager::get()->getEntityProperties(entityID); @@ -3420,7 +3435,7 @@ void MyAvatar::updateCollisionSound(const glm::vec3 &penetration, float deltaTim } bool findAvatarAvatarPenetration(const glm::vec3 positionA, float radiusA, float heightA, - const glm::vec3 positionB, float radiusB, float heightB, glm::vec3& penetration) { + const glm::vec3 positionB, float radiusB, float heightB, glm::vec3& penetration) { glm::vec3 positionBA = positionB - positionA; float xzDistance = sqrt(positionBA.x * positionBA.x + positionBA.z * positionBA.z); if (xzDistance < (radiusA + radiusB)) { @@ -3525,7 +3540,7 @@ void MyAvatar::restrictScaleFromDomainSettings(const QJsonObject& domainSettings _targetScale = getDomainLimitedScale(); qCDebug(interfaceapp) << "This domain requires a minimum avatar scale of " << _domainMinimumHeight - << " and a maximum avatar scale of " << _domainMaximumHeight; + << " and a maximum avatar scale of " << _domainMaximumHeight; _isAnimatingScale = true; @@ -3585,15 +3600,15 @@ void MyAvatar::goToLocation(const QVariant& propertiesVar) { } void MyAvatar::goToFeetLocation(const glm::vec3& newPosition, - bool hasOrientation, const glm::quat& newOrientation, - bool shouldFaceLocation) { + bool hasOrientation, const glm::quat& newOrientation, + bool shouldFaceLocation) { _goToFeetAjustment = true; goToLocation(newPosition, hasOrientation, newOrientation, shouldFaceLocation); } void MyAvatar::goToLocation(const glm::vec3& newPosition, - bool hasOrientation, const glm::quat& newOrientation, - bool shouldFaceLocation, bool withSafeLanding) { + bool hasOrientation, const glm::quat& newOrientation, + bool shouldFaceLocation, bool withSafeLanding) { // Most cases of going to a place or user go through this now. Some possible improvements to think about in the future: // - It would be nice if this used the same teleport steps and smoothing as in the teleport.js script, as long as it @@ -3617,7 +3632,7 @@ void MyAvatar::goToLocation(const glm::vec3& newPosition, _goToOrientation = getWorldOrientation(); if (hasOrientation) { qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - new orientation is " - << newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w; + << newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w; // orient the user to face the target glm::quat quatOrientation = cancelOutRollAndPitch(newOrientation); @@ -3662,13 +3677,13 @@ bool MyAvatar::safeLanding(const glm::vec3& position) { } if (!getCollisionsEnabled()) { goToLocation(better); // recurses on next update - } else { // If you try to go while stuck, physics will keep you stuck. + } else { // If you try to go while stuck, physics will keep you stuck. setCollisionsEnabled(false); // Don't goToLocation just yet. Yield so that physics can act on the above. QMetaObject::invokeMethod(this, "goToLocationAndEnableCollisions", Qt::QueuedConnection, // The equivalent of javascript nextTick Q_ARG(glm::vec3, better)); - } - return true; + } + return true; } // If position is not reliably safe from being stuck by physics, answer true and place a candidate better position in betterPositionOut. @@ -3860,6 +3875,71 @@ bool MyAvatar::getHandRelativeMovement() { return _handRelativeMovement; } +void MyAvatar::setDriveGear1(float shiftPoint) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setDriveGear1", Q_ARG(float, shiftPoint)); + return; + } + if (shiftPoint > 1.0 || shiftPoint < 0) return; + _driveGear1 = (shiftPoint <= _driveGear2) ? shiftPoint : _driveGear1; +} + +float MyAvatar::getDriveGear1() { + return _driveGear1; +} + +void MyAvatar::setDriveGear2(float shiftPoint) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setDriveGear2", Q_ARG(float, shiftPoint)); + return; + } + if (shiftPoint > 1.0 || shiftPoint < 0) return; + _driveGear2 = (shiftPoint <= _driveGear3 && shiftPoint >= _driveGear1) ? shiftPoint : _driveGear2; +} + +float MyAvatar::getDriveGear2() { + return _driveGear2; +} + +void MyAvatar::setDriveGear3(float shiftPoint) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setDriveGear3", Q_ARG(float, shiftPoint)); + return; + } + if (shiftPoint > 1.0 || shiftPoint < 0) return; + _driveGear3 = (shiftPoint <= _driveGear4 && shiftPoint >= _driveGear2) ? shiftPoint : _driveGear3; +} + +float MyAvatar::getDriveGear3() { + return _driveGear3; +} + +void MyAvatar::setDriveGear4(float shiftPoint) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setDriveGear4", Q_ARG(float, shiftPoint)); + return; + } + if (shiftPoint > 1.0 || shiftPoint < 0) return; + _driveGear4 = (shiftPoint <= _driveGear5 && shiftPoint >= _driveGear3) ? shiftPoint : _driveGear4; +} + +float MyAvatar::getDriveGear4() { + return _driveGear4; +} + +void MyAvatar::setDriveGear5(float shiftPoint) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setDriveGear5", Q_ARG(float, shiftPoint)); + return; + } + if (shiftPoint > 1.0 || shiftPoint < 0) return; + _driveGear5 = (shiftPoint >= _driveGear4) ? shiftPoint : _driveGear5; +} + +float MyAvatar::getDriveGear5() { + return _driveGear5; +} + bool MyAvatar::getFlyingHMDPref() { return _flyingPrefHMD; } @@ -4490,27 +4570,27 @@ void MyAvatar::setUserRecenterModel(MyAvatar::SitStandModelType modelName) { _userRecenterModel.set(modelName); switch (modelName) { - case MyAvatar::SitStandModelType::ForceSit: - setHMDLeanRecenterEnabled(true); - setIsInSittingState(true); - setIsSitStandStateLocked(true); - break; - case MyAvatar::SitStandModelType::ForceStand: - setHMDLeanRecenterEnabled(true); - setIsInSittingState(false); - setIsSitStandStateLocked(true); - break; - case MyAvatar::SitStandModelType::Auto: - default: - setHMDLeanRecenterEnabled(true); - setIsInSittingState(false); - setIsSitStandStateLocked(false); - break; - case MyAvatar::SitStandModelType::DisableHMDLean: - setHMDLeanRecenterEnabled(false); - setIsInSittingState(false); - setIsSitStandStateLocked(false); - break; + case MyAvatar::SitStandModelType::ForceSit: + setHMDLeanRecenterEnabled(true); + setIsInSittingState(true); + setIsSitStandStateLocked(true); + break; + case MyAvatar::SitStandModelType::ForceStand: + setHMDLeanRecenterEnabled(true); + setIsInSittingState(false); + setIsSitStandStateLocked(true); + break; + case MyAvatar::SitStandModelType::Auto: + default: + setHMDLeanRecenterEnabled(true); + setIsInSittingState(false); + setIsSitStandStateLocked(false); + break; + case MyAvatar::SitStandModelType::DisableHMDLean: + setHMDLeanRecenterEnabled(false); + setIsInSittingState(false); + setIsSitStandStateLocked(false); + break; } } @@ -4558,15 +4638,15 @@ QVector MyAvatar::getScriptUrls() { glm::vec3 MyAvatar::getPositionForAudio() { glm::vec3 result; switch (_audioListenerMode) { - case AudioListenerMode::FROM_HEAD: - result = getHead()->getPosition(); - break; - case AudioListenerMode::FROM_CAMERA: - result = qApp->getCamera().getPosition(); - break; - case AudioListenerMode::CUSTOM: - result = _customListenPosition; - break; + case AudioListenerMode::FROM_HEAD: + result = getHead()->getPosition(); + break; + case AudioListenerMode::FROM_CAMERA: + result = qApp->getCamera().getPosition(); + break; + case AudioListenerMode::CUSTOM: + result = _customListenPosition; + break; } if (isNaN(result)) { @@ -4581,15 +4661,15 @@ glm::quat MyAvatar::getOrientationForAudio() { glm::quat result; switch (_audioListenerMode) { - case AudioListenerMode::FROM_HEAD: - result = getHead()->getFinalOrientationInWorldFrame(); - break; - case AudioListenerMode::FROM_CAMERA: - result = qApp->getCamera().getOrientation(); - break; - case AudioListenerMode::CUSTOM: - result = _customListenOrientation; - break; + case AudioListenerMode::FROM_HEAD: + result = getHead()->getFinalOrientationInWorldFrame(); + break; + case AudioListenerMode::FROM_CAMERA: + result = qApp->getCamera().getOrientation(); + break; + case AudioListenerMode::CUSTOM: + result = _customListenOrientation; + break; } if (isNaN(result)) { @@ -4794,7 +4874,7 @@ bool MyAvatar::FollowHelper::shouldActivateVertical(const MyAvatar& myAvatar, co } void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, - const glm::mat4& currentBodyMatrix, bool hasDriveInput) { + const glm::mat4& currentBodyMatrix, bool hasDriveInput) { if (myAvatar.getHMDLeanRecenterEnabled() && qApp->getCamera().getMode() != CAMERA_MODE_MIRROR) { @@ -4858,8 +4938,8 @@ void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat followWorldPose.scale() = glm::vec3(1.0f); if (isActive(Rotation)) { - //use the hmd reading for the hips follow - followWorldPose.rot() = glmExtractRotation(desiredWorldMatrix); + //use the hmd reading for the hips follow + followWorldPose.rot() = glmExtractRotation(desiredWorldMatrix); } if (isActive(Horizontal)) { glm::vec3 desiredTranslation = extractTranslation(desiredWorldMatrix); @@ -4890,7 +4970,7 @@ glm::mat4 MyAvatar::FollowHelper::postPhysicsUpdate(MyAvatar& myAvatar, const gl glm::quat sensorAngularDisplacement = glmExtractRotation(worldToSensorMatrix) * worldAngularDisplacement * glmExtractRotation(sensorToWorldMatrix); glm::mat4 newBodyMat = createMatFromQuatAndPos(sensorAngularDisplacement * glmExtractRotation(currentBodyMatrix), - sensorLinearDisplacement + extractTranslation(currentBodyMatrix)); + sensorLinearDisplacement + extractTranslation(currentBodyMatrix)); if (myAvatar.getSitStandStateChange()) { myAvatar.setSitStandStateChange(false); deactivate(Vertical); @@ -5002,34 +5082,34 @@ glm::quat MyAvatar::getAbsoluteJointRotationInObjectFrame(int index) const { } switch (index) { - case CONTROLLER_LEFTHAND_INDEX: { - return getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).getRotation(); - } - case CONTROLLER_RIGHTHAND_INDEX: { - return getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).getRotation(); - } - case CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX: { - auto pose = getControllerPoseInSensorFrame(controller::Action::LEFT_HAND); - glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); - glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); - return glmExtractRotation(result); - } - case CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX: { - auto pose = getControllerPoseInSensorFrame(controller::Action::RIGHT_HAND); - glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); - glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); - return glmExtractRotation(result); - } - case CAMERA_MATRIX_INDEX: { - bool success; - Transform avatarTransform; - Transform::mult(avatarTransform, getParentTransform(success), getLocalTransform()); - glm::mat4 invAvatarMat = avatarTransform.getInverseMatrix(); - return glmExtractRotation(invAvatarMat * qApp->getCamera().getTransform()); - } - default: { - return Avatar::getAbsoluteJointRotationInObjectFrame(index); - } + case CONTROLLER_LEFTHAND_INDEX: { + return getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).getRotation(); + } + case CONTROLLER_RIGHTHAND_INDEX: { + return getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).getRotation(); + } + case CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX: { + auto pose = getControllerPoseInSensorFrame(controller::Action::LEFT_HAND); + glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); + glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); + return glmExtractRotation(result); + } + case CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX: { + auto pose = getControllerPoseInSensorFrame(controller::Action::RIGHT_HAND); + glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); + glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); + return glmExtractRotation(result); + } + case CAMERA_MATRIX_INDEX: { + bool success; + Transform avatarTransform; + Transform::mult(avatarTransform, getParentTransform(success), getLocalTransform()); + glm::mat4 invAvatarMat = avatarTransform.getInverseMatrix(); + return glmExtractRotation(invAvatarMat * qApp->getCamera().getTransform()); + } + default: { + return Avatar::getAbsoluteJointRotationInObjectFrame(index); + } } } @@ -5039,34 +5119,34 @@ glm::vec3 MyAvatar::getAbsoluteJointTranslationInObjectFrame(int index) const { } switch (index) { - case CONTROLLER_LEFTHAND_INDEX: { - return getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).getTranslation(); - } - case CONTROLLER_RIGHTHAND_INDEX: { - return getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).getTranslation(); - } - case CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX: { - auto pose = getControllerPoseInSensorFrame(controller::Action::LEFT_HAND); - glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); - glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); - return extractTranslation(result); - } - case CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX: { - auto pose = getControllerPoseInSensorFrame(controller::Action::RIGHT_HAND); - glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); - glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); - return extractTranslation(result); - } - case CAMERA_MATRIX_INDEX: { - bool success; - Transform avatarTransform; - Transform::mult(avatarTransform, getParentTransform(success), getLocalTransform()); - glm::mat4 invAvatarMat = avatarTransform.getInverseMatrix(); - return extractTranslation(invAvatarMat * qApp->getCamera().getTransform()); - } - default: { - return Avatar::getAbsoluteJointTranslationInObjectFrame(index); - } + case CONTROLLER_LEFTHAND_INDEX: { + return getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).getTranslation(); + } + case CONTROLLER_RIGHTHAND_INDEX: { + return getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).getTranslation(); + } + case CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX: { + auto pose = getControllerPoseInSensorFrame(controller::Action::LEFT_HAND); + glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); + glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); + return extractTranslation(result); + } + case CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX: { + auto pose = getControllerPoseInSensorFrame(controller::Action::RIGHT_HAND); + glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); + glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); + return extractTranslation(result); + } + case CAMERA_MATRIX_INDEX: { + bool success; + Transform avatarTransform; + Transform::mult(avatarTransform, getParentTransform(success), getLocalTransform()); + glm::mat4 invAvatarMat = avatarTransform.getInverseMatrix(); + return extractTranslation(invAvatarMat * qApp->getCamera().getTransform()); + } + default: { + return Avatar::getAbsoluteJointTranslationInObjectFrame(index); + } } } @@ -5286,7 +5366,7 @@ SpatialParentTree* MyAvatar::getParentTree() const { } const QUuid MyAvatar::grab(const QUuid& targetID, int parentJointIndex, - glm::vec3 positionalOffset, glm::quat rotationalOffset) { + glm::vec3 positionalOffset, glm::quat rotationalOffset) { auto grabID = QUuid::createUuid(); // create a temporary grab object to get grabData @@ -5297,14 +5377,14 @@ const QUuid MyAvatar::grab(const QUuid& targetID, int parentJointIndex, parentJointIndex == getJointIndex("RightHand")) { hand = "right"; } else if (parentJointIndex == CONTROLLER_LEFTHAND_INDEX || - parentJointIndex == CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX || - parentJointIndex == FARGRAB_LEFTHAND_INDEX || - parentJointIndex == getJointIndex("LeftHand")) { + parentJointIndex == CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX || + parentJointIndex == FARGRAB_LEFTHAND_INDEX || + parentJointIndex == getJointIndex("LeftHand")) { hand = "left"; } Grab tmpGrab(DependencyManager::get()->getSessionUUID(), - targetID, parentJointIndex, hand, positionalOffset, rotationalOffset); + targetID, parentJointIndex, hand, positionalOffset, rotationalOffset); QByteArray grabData = tmpGrab.toByteArray(); bool dataChanged = updateAvatarGrabData(grabID, grabData); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 9520fb7cc4..c5c3b1b46a 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -253,6 +253,12 @@ class MyAvatar : public Avatar { const QString DOMINANT_LEFT_HAND = "left"; const QString DOMINANT_RIGHT_HAND = "right"; + const float DEFAULT_GEAR_1 = 0.2f; + const float DEFAULT_GEAR_2 = 0.4f; + const float DEFAULT_GEAR_3 = 0.8f; + const float DEFAULT_GEAR_4 = 0.9f; + const float DEFAULT_GEAR_5 = 1.0f; + public: enum DriveKeys { TRANSLATE_X = 0, @@ -1061,6 +1067,76 @@ public: */ Q_INVOKABLE bool getHandRelativeMovement(); + /**jsdoc + * Set the first 'shifting point' for acceleration step function. + * @function MyAvatar.setDriveGear1 + * @param {number} shiftPoint - Set the first shift point for analog movement acceleration step function, between [0.0, 1.0]. Must be less than or equal to Gear 2. + */ + Q_INVOKABLE void setDriveGear1(float shiftPoint); + + /**jsdoc + * Get the first 'shifting point' for acceleration step function. + * @function MyAvatar.getDriveGear1 + * @returns {number} Value between [0.0, 1.0]. + */ + Q_INVOKABLE float getDriveGear1(); + + /**jsdoc + * Set the second 'shifting point' for acceleration step function. + * @function MyAvatar.setDriveGear2 + * @param {number} shiftPoint - Defines the second shift point for analog movement acceleration step function, between [0, 1]. Must be greater than or equal to Gear 1 and less than or equal to Gear 2. + */ + Q_INVOKABLE void setDriveGear2(float shiftPoint); + + /**jsdoc + * Get the second 'shifting point' for acceleration step function. + * @function MyAvatar.getDriveGear2 + * @returns {number} Value between [0.0, 1.0]. + */ + Q_INVOKABLE float getDriveGear2(); + + /**jsdoc + * Set the third 'shifting point' for acceleration step function. + * @function MyAvatar.setDriveGear3 + * @param {number} shiftPoint - Defines the third shift point for analog movement acceleration step function, between [0, 1]. Must be greater than or equal to Gear 2 and less than or equal to Gear 4. + */ + Q_INVOKABLE void setDriveGear3(float shiftPoint); + + /**jsdoc + * Get the third 'shifting point' for acceleration step function. + * @function MyAvatar.getDriveGear3 + * @returns {number} Value between [0.0, 1.0]. + */ + Q_INVOKABLE float getDriveGear3(); + + /**jsdoc + * Set the fourth 'shifting point' for acceleration step function. + * @function MyAvatar.setDriveGear4 + * @param {number} shiftPoint - Defines the fourth shift point for analog movement acceleration step function, between [0, 1]. Must be greater than Gear 3 and less than Gear 5. + */ + Q_INVOKABLE void setDriveGear4(float shiftPoint); + + /**jsdoc + * Get the fourth 'shifting point' for acceleration step function. + * @function MyAvatar.getDriveGear4 + * @returns {number} Value between [0.0, 1.0]. + */ + Q_INVOKABLE float getDriveGear4(); + + /**jsdoc + * Set the fifth 'shifting point' for acceleration step function. + * @function MyAvatar.setDriveGear5 + * @param {number} shiftPoint - Defines the fifth shift point for analog movement acceleration step function, between [0, 1]. Must be greater than or equal to Gear 4. + */ + Q_INVOKABLE void setDriveGear5(float shiftPoint); + + /**jsdoc + * Get the fifth 'shifting point' for acceleration step function. + * @function MyAvatar.getDriveGear5 + * @returns {number} Value between [0.0, 1.0]. + */ + Q_INVOKABLE float getDriveGear5(); + /**jsdoc * @function MyAvatar.getAvatarScale * @returns {number} @@ -1732,6 +1808,20 @@ private: float _boomLength { ZOOM_DEFAULT }; float _yawSpeed; // degrees/sec float _pitchSpeed; // degrees/sec + float _driveGear1 { DEFAULT_GEAR_1 }; + float _driveGear2 { DEFAULT_GEAR_2 }; + float _driveGear3 { DEFAULT_GEAR_3 }; + float _driveGear4 { DEFAULT_GEAR_4 }; + float _driveGear5 { DEFAULT_GEAR_5 }; + + int _controlSchemeIndex; + + //Setting::Handle _driveGear1Setting; + //Setting::Handle _driveGear2Setting; + //Setting::Handle _driveGear3Setting; + //Setting::Handle _driveGear4Setting; + //Setting::Handle _driveGear5Setting; + //Setting::Handle controlSchemeIndex; glm::vec3 _thrust { 0.0f }; // impulse accumulator for outside sources @@ -1972,6 +2062,12 @@ private: Setting::Handle _handRelativeMovementSetting; Setting::Handle _avatarEntityCountSetting; Setting::Handle _allowTeleportingSetting { "allowTeleporting", true }; + Setting::Handle _driveGear1Setting; + Setting::Handle _driveGear2Setting; + Setting::Handle _driveGear3Setting; + Setting::Handle _driveGear4Setting; + Setting::Handle _driveGear5Setting; + Setting::Handle controlSchemeIndexSetting; std::vector> _avatarEntityIDSettings; std::vector> _avatarEntityDataSettings; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 918fb6d830..97561eb78d 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -348,6 +348,53 @@ void setupPreferences() { preferences->addPreference(preference); } + static const QString ACCEL_CURVE{ "Acceleration Step Function" }; + { + auto getter = [myAvatar]()->float { return myAvatar->getDriveGear1(); }; + auto setter = [myAvatar](float value) { myAvatar->setDriveGear1(value); }; + auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 1", getter, setter); + preference->setMin(1); + preference->setMax(5); + preference->setStep(1); + preferences->addPreference(preference); + } + { + auto getter = [myAvatar]()->float { return myAvatar->getDriveGear2(); }; + auto setter = [myAvatar](float value) { myAvatar->setDriveGear2(value); }; + auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 2", getter, setter); + preference->setMin(1); + preference->setMax(5); + preference->setStep(1); + preferences->addPreference(preference); + } + { + auto getter = [myAvatar]()->float { return myAvatar->getDriveGear3(); }; + auto setter = [myAvatar](float value) { myAvatar->setDriveGear3(value); }; + auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 3", getter, setter); + preference->setMin(1); + preference->setMax(5); + preference->setStep(1); + preferences->addPreference(preference); + } + { + auto getter = [myAvatar]()->float { return myAvatar->getDriveGear4(); }; + auto setter = [myAvatar](float value) { myAvatar->setDriveGear4(value); }; + auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 4", getter, setter); + preference->setMin(1); + preference->setMax(5); + preference->setStep(1); + preferences->addPreference(preference); + } + { + auto getter = [myAvatar]()->float { return myAvatar->getDriveGear5(); }; + auto setter = [myAvatar](float value) { myAvatar->setDriveGear5(value); }; + auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 5", getter, setter); + preference->setMin(1); + preference->setMax(5); + preference->setStep(1); + preferences->addPreference(preference); + } + static const QString AVATAR_CAMERA{ "Mouse Sensitivity" }; { auto getter = [myAvatar]()->float { return myAvatar->getPitchSpeed(); }; From 35818e9b9d495b883b1be7af9c5a958bb6086833 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Fri, 25 Jan 2019 14:27:02 -0800 Subject: [PATCH 14/68] Add menu items for 'gear' selection. --- interface/src/avatar/MyAvatar.h | 10 ---------- interface/src/ui/PreferencesDialog.cpp | 25 +++++++++++++++---------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index c5c3b1b46a..799fcef1ea 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1814,15 +1814,6 @@ private: float _driveGear4 { DEFAULT_GEAR_4 }; float _driveGear5 { DEFAULT_GEAR_5 }; - int _controlSchemeIndex; - - //Setting::Handle _driveGear1Setting; - //Setting::Handle _driveGear2Setting; - //Setting::Handle _driveGear3Setting; - //Setting::Handle _driveGear4Setting; - //Setting::Handle _driveGear5Setting; - //Setting::Handle controlSchemeIndex; - glm::vec3 _thrust { 0.0f }; // impulse accumulator for outside sources glm::vec3 _actionMotorVelocity; // target local-frame velocity of avatar (default controller actions) @@ -2067,7 +2058,6 @@ private: Setting::Handle _driveGear3Setting; Setting::Handle _driveGear4Setting; Setting::Handle _driveGear5Setting; - Setting::Handle controlSchemeIndexSetting; std::vector> _avatarEntityIDSettings; std::vector> _avatarEntityDataSettings; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 97561eb78d..ae5eefbe7a 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -353,45 +353,50 @@ void setupPreferences() { auto getter = [myAvatar]()->float { return myAvatar->getDriveGear1(); }; auto setter = [myAvatar](float value) { myAvatar->setDriveGear1(value); }; auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 1", getter, setter); - preference->setMin(1); - preference->setMax(5); + preference->setMin(0.0f); + preference->setMax(1.0f); preference->setStep(1); + preference->setDecimals(2); preferences->addPreference(preference); } { auto getter = [myAvatar]()->float { return myAvatar->getDriveGear2(); }; auto setter = [myAvatar](float value) { myAvatar->setDriveGear2(value); }; auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 2", getter, setter); - preference->setMin(1); - preference->setMax(5); + preference->setMin(0.0f); + preference->setMax(1.0f); preference->setStep(1); + preference->setDecimals(2); preferences->addPreference(preference); } { auto getter = [myAvatar]()->float { return myAvatar->getDriveGear3(); }; auto setter = [myAvatar](float value) { myAvatar->setDriveGear3(value); }; auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 3", getter, setter); - preference->setMin(1); - preference->setMax(5); + preference->setMin(0.0f); + preference->setMax(1.0f); preference->setStep(1); + preference->setDecimals(2); preferences->addPreference(preference); } { auto getter = [myAvatar]()->float { return myAvatar->getDriveGear4(); }; auto setter = [myAvatar](float value) { myAvatar->setDriveGear4(value); }; auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 4", getter, setter); - preference->setMin(1); - preference->setMax(5); + preference->setMin(0.0f); + preference->setMax(1.0f); preference->setStep(1); + preference->setDecimals(2); preferences->addPreference(preference); } { auto getter = [myAvatar]()->float { return myAvatar->getDriveGear5(); }; auto setter = [myAvatar](float value) { myAvatar->setDriveGear5(value); }; auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 5", getter, setter); - preference->setMin(1); - preference->setMax(5); + preference->setMin(0.0f); + preference->setMax(1.0f); preference->setStep(1); + preference->setDecimals(2); preferences->addPreference(preference); } From 338d4c3c18fdb8147994401177c69871fed58035 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Fri, 25 Jan 2019 15:14:17 -0800 Subject: [PATCH 15/68] Lay groundwork for control scheme selection. --- interface/src/avatar/MyAvatar.cpp | 18 +++++++++++++++++- interface/src/avatar/MyAvatar.h | 17 +++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index f37b8e1b0a..789e192a69 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -144,7 +144,8 @@ MyAvatar::MyAvatar(QThread* thread) : _driveGear2Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear2", _driveGear2), _driveGear3Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear3", _driveGear3), _driveGear4Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear4", _driveGear4), - _driveGear5Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear5", _driveGear5) + _driveGear5Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear5", _driveGear5), + _controlSchemeIndexSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "controlSchemeIndex", _controlSchemeIndex) { _clientTraitsHandler.reset(new ClientTraitsHandler(this)); @@ -1312,6 +1313,7 @@ void MyAvatar::saveData() { _driveGear3Setting.set(getDriveGear3()); _driveGear4Setting.set(getDriveGear4()); _driveGear5Setting.set(getDriveGear5()); + _controlSchemeIndexSetting.set(getControlSchemeIndex()); auto hmdInterface = DependencyManager::get(); saveAvatarEntityDataToSettings(); @@ -1894,6 +1896,7 @@ void MyAvatar::loadData() { setDriveGear3(firstRunVal.get() ? DEFAULT_GEAR_3 : _driveGear3Setting.get()); setDriveGear4(firstRunVal.get() ? DEFAULT_GEAR_4 : _driveGear4Setting.get()); setDriveGear5(firstRunVal.get() ? DEFAULT_GEAR_5 : _driveGear5Setting.get()); + setControlSchemeIndex(firstRunVal.get() ? DEFAULT_CONTROL_SCHEME_INDEX : _controlSchemeIndexSetting.get()); setFlyingEnabled(getFlyingEnabled()); setDisplayName(_displayNameSetting.get()); @@ -3875,6 +3878,19 @@ bool MyAvatar::getHandRelativeMovement() { return _handRelativeMovement; } +void MyAvatar::setControlSchemeIndex(int index){ + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setControlSchemeIndex", Q_ARG(int, index)); + return; + } + // Need to add checks for valid indices. + _controlSchemeIndex = index; +} + +int MyAvatar::getControlSchemeIndex() { + return _controlSchemeIndex; +} + void MyAvatar::setDriveGear1(float shiftPoint) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "setDriveGear1", Q_ARG(float, shiftPoint)); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 799fcef1ea..c0264b97dc 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -258,6 +258,7 @@ class MyAvatar : public Avatar { const float DEFAULT_GEAR_3 = 0.8f; const float DEFAULT_GEAR_4 = 0.9f; const float DEFAULT_GEAR_5 = 1.0f; + const int DEFAULT_CONTROL_SCHEME_INDEX = 0; public: enum DriveKeys { @@ -1137,6 +1138,20 @@ public: */ Q_INVOKABLE float getDriveGear5(); + /**jsdoc + * Choose the control scheme. + * @function MyAvatar.setControlSchemeIndex + * @param {number} Choose the control scheme to be used. + */ + void setControlSchemeIndex(int index); + + /**jsdoc + * Check what control scheme is in use. + * @function MyAvatar.getControlSchemeIndex + * @returns {number} Returns the index associated with a given control scheme. + */ + int getControlSchemeIndex(); + /**jsdoc * @function MyAvatar.getAvatarScale * @returns {number} @@ -1813,6 +1828,7 @@ private: float _driveGear3 { DEFAULT_GEAR_3 }; float _driveGear4 { DEFAULT_GEAR_4 }; float _driveGear5 { DEFAULT_GEAR_5 }; + int _controlSchemeIndex { DEFAULT_CONTROL_SCHEME_INDEX }; glm::vec3 _thrust { 0.0f }; // impulse accumulator for outside sources @@ -2058,6 +2074,7 @@ private: Setting::Handle _driveGear3Setting; Setting::Handle _driveGear4Setting; Setting::Handle _driveGear5Setting; + Setting::Handle _controlSchemeIndexSetting; std::vector> _avatarEntityIDSettings; std::vector> _avatarEntityDataSettings; From 6552d8d9eed25efa6c53dc58add838323a111922 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 28 Jan 2019 10:40:31 -0800 Subject: [PATCH 16/68] Add settings for control scheme. --- interface/src/avatar/MyAvatar.cpp | 2 +- interface/src/avatar/MyAvatar.h | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 789e192a69..8d7d0d2972 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1896,7 +1896,7 @@ void MyAvatar::loadData() { setDriveGear3(firstRunVal.get() ? DEFAULT_GEAR_3 : _driveGear3Setting.get()); setDriveGear4(firstRunVal.get() ? DEFAULT_GEAR_4 : _driveGear4Setting.get()); setDriveGear5(firstRunVal.get() ? DEFAULT_GEAR_5 : _driveGear5Setting.get()); - setControlSchemeIndex(firstRunVal.get() ? DEFAULT_CONTROL_SCHEME_INDEX : _controlSchemeIndexSetting.get()); + setControlSchemeIndex(firstRunVal.get() ? CONTROLS_DEFAULT : _controlSchemeIndexSetting.get()); setFlyingEnabled(getFlyingEnabled()); setDisplayName(_displayNameSetting.get()); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index c0264b97dc..98a84b3a0e 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -258,7 +258,9 @@ class MyAvatar : public Avatar { const float DEFAULT_GEAR_3 = 0.8f; const float DEFAULT_GEAR_4 = 0.9f; const float DEFAULT_GEAR_5 = 1.0f; - const int DEFAULT_CONTROL_SCHEME_INDEX = 0; + const int CONTROLS_DEFAULT = 0; + const int CONTROLS_ANALOG = 1; + const int CONTROLS_ANALOG_PLUS = 2; public: enum DriveKeys { @@ -511,7 +513,17 @@ public: */ Q_INVOKABLE void setSnapTurn(bool on) { _useSnapTurn = on; } + /** + * @function MyAvatar.getControlScheme + * @returns {number} + */ + Q_INVOKABLE int getControlScheme() const { return _controlSchemeIndex; } + /** + * @function MyAvatar.setControlScheme + * @param {number} index + */ + Q_INVOKABLE void setControlScheme(int index) { _controlSchemeIndex = index; } /**jsdoc * @function MyAvatar.setDominantHand * @param {string} hand @@ -1828,7 +1840,7 @@ private: float _driveGear3 { DEFAULT_GEAR_3 }; float _driveGear4 { DEFAULT_GEAR_4 }; float _driveGear5 { DEFAULT_GEAR_5 }; - int _controlSchemeIndex { DEFAULT_CONTROL_SCHEME_INDEX }; + int _controlSchemeIndex { CONTROLS_DEFAULT }; glm::vec3 _thrust { 0.0f }; // impulse accumulator for outside sources From f45ff3c6627ca1e537891fa244c542eb8130c41a Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 28 Jan 2019 10:40:43 -0800 Subject: [PATCH 17/68] Add menu item for selecting control scheme. --- interface/src/ui/PreferencesDialog.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index ae5eefbe7a..e08e4bfe8f 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -293,6 +293,16 @@ void setupPreferences() { preference->setItems(items); preferences->addPreference(preference); } + { + auto getter = [myAvatar]()->int { return myAvatar->getControlScheme(); }; + auto setter = [myAvatar](int index) { myAvatar->setControlScheme(index); }; + auto preference = new RadioButtonsPreference(VR_MOVEMENT, "Control Scheme", getter, setter); + QStringList items; + items << "Default" << "Analog" << "Analog++"; + preference->setHeading("Control Scheme Selection"); + preference->setItems(items); + preferences->addPreference(preference); + } { auto getter = [myAvatar]()->bool { return myAvatar->getShowPlayArea(); }; auto setter = [myAvatar](bool value) { myAvatar->setShowPlayArea(value); }; From 0429280148d6643212b30ac943c533289670205b Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 28 Jan 2019 14:06:32 -0800 Subject: [PATCH 18/68] Default vs Analog implemented. --- interface/src/avatar/MyAvatar.cpp | 76 +++++++++++++++++++++++-------- interface/src/avatar/MyAvatar.h | 11 +++-- 2 files changed, 64 insertions(+), 23 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 8d7d0d2972..b7b1c173b6 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3296,6 +3296,44 @@ static float scaleSpeedByDirection(const glm::vec2 velocityDirection, const floa return scaledSpeed; } +glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 right) { + float stickFullOn = 0.95f; + auto zSpeed = getDriveKey(TRANSLATE_Z); + auto xSpeed = getDriveKey(TRANSLATE_X); + glm::vec3 direction; + switch(_controlSchemeIndex) { + case CONTROLS_DEFAULT: + // No acceleration curve for this one, constant speed. + if (zSpeed || xSpeed) { + direction = forward + right; + return getSensorToWorldScale() * _walkSpeedScalar * direction; + } else { + return Vectors::ZERO; + } + case CONTROLS_ANALOG: + if (zSpeed || xSpeed) { + glm::vec3 scaledForward = getSensorToWorldScale() * zSpeed * ((zSpeed >= stickFullOn) ? _sprintSpeed.get() : _walkSpeed.get()) * forward; + glm::vec3 scaledRight = getSensorToWorldScale() * xSpeed * ((xSpeed > stickFullOn) ? _sprintSpeed.get() : _walkSpeed.get()) * right; + direction = scaledForward + scaledRight; + return direction; + } else { + return Vectors::ZERO; + } + case CONTROLS_ANALOG_PLUS: + if (zSpeed || xSpeed) { + glm::vec3 scaledForward = getSensorToWorldScale() * zSpeed * ((zSpeed >= stickFullOn) ? _sprintSpeed.get() : _walkSpeed.get()) * forward; + glm::vec3 scaledRight = getSensorToWorldScale() * xSpeed * ((xSpeed > stickFullOn) ? _sprintSpeed.get() : _walkSpeed.get()) * right; + direction = scaledForward + scaledRight; + return direction; + } else { + return Vectors::ZERO; + } + default: + qDebug() << "Invalid control scheme index."; + return Vectors::ZERO; + } +} + glm::vec3 MyAvatar::calculateScaledDirection(){ CharacterController::State state = _characterController.getState(); @@ -3308,15 +3346,15 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ 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)); - forward = (getDriveKey(TRANSLATE_Z)) * (handRotation * controllerForward); - right = (getDriveKey(TRANSLATE_X)) * (handRotation * controllerRight); + forward = (handRotation * controllerForward); + right = (handRotation * controllerRight); } else { - forward = (getDriveKey(TRANSLATE_Z)) * IDENTITY_FORWARD; - right = (getDriveKey(TRANSLATE_X)) * IDENTITY_RIGHT; + forward = IDENTITY_FORWARD; + right = IDENTITY_RIGHT; } - glm::vec3 direction = forward + right; + glm::vec3 direction = scaleMotorSpeed(forward, right); // RKNOTE: This may need to be changed later... if (state == CharacterController::State::Hover || @@ -3326,16 +3364,6 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ direction += up; } - _wasPushing = _isPushing; - float directionLength = glm::length(direction); - _isPushing = directionLength > EPSILON; - - if (_isPushing) { - direction; - } else { - direction = Vectors::ZERO; - } - return direction; } @@ -3358,6 +3386,16 @@ void MyAvatar::updateActionMotor(float deltaTime) { glm::vec3 direction = calculateScaledDirection(); + _wasPushing = _isPushing; + float directionLength = glm::length(direction); + _isPushing = directionLength > EPSILON; + + if (_isPushing) { + direction; + } else { + direction = Vectors::ZERO; + } + if (state == CharacterController::State::Hover) { // we're flying --> complex acceleration curve that builds on top of current motor speed and caps at some max speed @@ -3369,6 +3407,7 @@ void MyAvatar::updateActionMotor(float deltaTime) { const float maxBoostSpeed = getSensorToWorldScale() * MAX_BOOST_SPEED; if (_isPushing) { + direction /= direction; if (motorSpeed < maxBoostSpeed) { // an active action motor should never be slower than this float boostCoefficient = (maxBoostSpeed - motorSpeed) / maxBoostSpeed; @@ -3380,10 +3419,11 @@ void MyAvatar::updateActionMotor(float deltaTime) { _actionMotorVelocity = motorSpeed * direction; } else { // we're interacting with a floor --> simple horizontal speed and exponential decay - const glm::vec2 currentVel = { direction.x, direction.z }; - float scaledSpeed = scaleSpeedByDirection(currentVel, _walkSpeed.get(), _walkBackwardSpeed.get()); + //const glm::vec2 currentVel = { direction.x, direction.z }; + //float scaledSpeed = scaleSpeedByDirection(currentVel, _walkSpeed.get(), _walkBackwardSpeed.get()); // _walkSpeedScalar is a multiplier if we are in sprint mode, otherwise 1.0 - _actionMotorVelocity = getSensorToWorldScale() * (scaledSpeed * _walkSpeedScalar) * direction; + _actionMotorVelocity = direction; + //_actionMotorVelocity = getSensorToWorldScale() * (scaledSpeed * _walkSpeedScalar) * direction; } float previousBoomLength = _boomLength; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 98a84b3a0e..91dc0d47b0 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -38,6 +38,10 @@ class AvatarActionHold; class ModelItemID; class MyHead; +const int CONTROLS_DEFAULT = 0; +const int CONTROLS_ANALOG = 1; +const int CONTROLS_ANALOG_PLUS = 2; + enum eyeContactTarget { LEFT_EYE, RIGHT_EYE, @@ -258,10 +262,6 @@ class MyAvatar : public Avatar { const float DEFAULT_GEAR_3 = 0.8f; const float DEFAULT_GEAR_4 = 0.9f; const float DEFAULT_GEAR_5 = 1.0f; - const int CONTROLS_DEFAULT = 0; - const int CONTROLS_ANALOG = 1; - const int CONTROLS_ANALOG_PLUS = 2; - public: enum DriveKeys { TRANSLATE_X = 0, @@ -523,7 +523,7 @@ public: * @function MyAvatar.setControlScheme * @param {number} index */ - Q_INVOKABLE void setControlScheme(int index) { _controlSchemeIndex = index; } + Q_INVOKABLE void setControlScheme(int index) { _controlSchemeIndex = (index >= 0 && index <= 2) ? index : 0; } /**jsdoc * @function MyAvatar.setDominantHand * @param {string} hand @@ -1882,6 +1882,7 @@ private: // private methods void updateOrientation(float deltaTime); glm::vec3 calculateScaledDirection(); + glm::vec3 scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 right); void updateActionMotor(float deltaTime); void updatePosition(float deltaTime); void updateCollisionSound(const glm::vec3& penetration, float deltaTime, float frequency); From b6036e492127810709d11b4540d905d3ca7a2e2b Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 28 Jan 2019 15:04:51 -0800 Subject: [PATCH 19/68] Remove needless qualification breaking Mac builds. --- interface/src/avatar/MyAvatar.cpp | 2 +- interface/src/avatar/MyAvatar.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index b7b1c173b6..121d7bd5a5 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2543,7 +2543,7 @@ controller::Pose MyAvatar::getControllerPoseInAvatarFrame(controller::Action act } } -quat MyAvatar::getDominantHandRotation() const { +quat MyAvatar::getDominantHandRotation() { auto hand = (getDominantHand() == DOMINANT_RIGHT_HAND) ? controller::Action::RIGHT_HAND : controller::Action::LEFT_HAND; auto pose = getControllerPoseInAvatarFrame(hand); return pose.rotation; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 91dc0d47b0..cb751aac2c 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -980,7 +980,7 @@ public: controller::Pose getControllerPoseInSensorFrame(controller::Action action) const; controller::Pose getControllerPoseInWorldFrame(controller::Action action) const; controller::Pose getControllerPoseInAvatarFrame(controller::Action action) const; - quat MyAvatar::getDominantHandRotation() const; + quat MyAvatar::getDominantHandRotation(); bool hasDriveInput() const; From 0f45781779e47553a67572f0d13cf4ffd00e44f3 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 28 Jan 2019 15:52:18 -0800 Subject: [PATCH 20/68] Remove extra qualifier from function signature in MyAvatar.h --- interface/src/avatar/MyAvatar.cpp | 2 +- interface/src/avatar/MyAvatar.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index b7b1c173b6..c9c2105aba 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2543,7 +2543,7 @@ controller::Pose MyAvatar::getControllerPoseInAvatarFrame(controller::Action act } } -quat MyAvatar::getDominantHandRotation() const { +glm::quat MyAvatar::getDominantHandRotation() const { auto hand = (getDominantHand() == DOMINANT_RIGHT_HAND) ? controller::Action::RIGHT_HAND : controller::Action::LEFT_HAND; auto pose = getControllerPoseInAvatarFrame(hand); return pose.rotation; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 91dc0d47b0..e6f967e563 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -980,7 +980,7 @@ public: controller::Pose getControllerPoseInSensorFrame(controller::Action action) const; controller::Pose getControllerPoseInWorldFrame(controller::Action action) const; controller::Pose getControllerPoseInAvatarFrame(controller::Action action) const; - quat MyAvatar::getDominantHandRotation() const; + glm::quat getDominantHandRotation() const; bool hasDriveInput() const; From d4cf1de4ddf0e756a7175fd5686eb269da608649 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 29 Jan 2019 12:02:02 -0800 Subject: [PATCH 21/68] Fix default locomotion scaling. --- interface/src/avatar/MyAvatar.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index c9c2105aba..23fad72181 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3305,8 +3305,11 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig case CONTROLS_DEFAULT: // No acceleration curve for this one, constant speed. if (zSpeed || xSpeed) { - direction = forward + right; - return getSensorToWorldScale() * _walkSpeedScalar * direction; + direction = (zSpeed * forward) + (xSpeed * right); + // Normalize direction. + direction /= glm::length(direction); + float scale = scaleSpeedByDirection(direction, _walkSpeed.get(), _walkBackwardSpeed.get()); + return getSensorToWorldScale() * scale * direction; } else { return Vectors::ZERO; } From 4d2ee07512845378d6e5c4129899681f0f7f62a0 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 29 Jan 2019 12:02:23 -0800 Subject: [PATCH 22/68] Change deactivation criteria as per conversation between Joshua and Mukul. --- scripts/system/controllers/controllerModules/teleport.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index bbc690d663..124fe3d3ea 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -726,7 +726,8 @@ Script.include("/~/system/libraries/controllers.js"); }; this.shouldCancel = function () { - return (_this.getDominantY() < -TELEPORT_DEADZONE || _this.getOffhandY() < -TELEPORT_DEADZONE) ? true : false; + //return (_this.getDominantY() < -TELEPORT_DEADZONE || _this.getOffhandY() < -TELEPORT_DEADZONE) ? true : false; + return (_this.getOffhandY() <= TELEPORT_DEADZONE) ? true : false; }; this.parameters = makeDispatcherModuleParameters( From e1cbb187cd33981a25cdc0ae701485faaa1660a2 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 29 Jan 2019 16:12:49 -0800 Subject: [PATCH 23/68] Clean up comments in MyAvatar.cpp --- interface/src/avatar/MyAvatar.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 23fad72181..c1ebd10f81 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3308,8 +3308,7 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig direction = (zSpeed * forward) + (xSpeed * right); // Normalize direction. direction /= glm::length(direction); - float scale = scaleSpeedByDirection(direction, _walkSpeed.get(), _walkBackwardSpeed.get()); - return getSensorToWorldScale() * scale * direction; + return getSensorToWorldScale() * direction * _sprintSpeed.get(); } else { return Vectors::ZERO; } From 17518640425b0b23f84e1e90ed81029f8463762a Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 29 Jan 2019 16:13:11 -0800 Subject: [PATCH 24/68] Fix this references in module run function. --- scripts/system/controllers/controllerModules/teleport.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index 124fe3d3ea..386e03d616 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -756,8 +756,8 @@ Script.include("/~/system/libraries/controllers.js"); this.run = function(controllerData, deltaTime) { // Kill condition: - if (this.shouldCancel()) { - this.disableLasers(); + if (_this.shouldCancel()) { + _this.disableLasers(); this.active = false; return makeRunningValues(false, [], []); } From 7e9d35a0fb3e06fbf89622e79b4e434df1fb9508 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Wed, 30 Jan 2019 15:06:35 -0800 Subject: [PATCH 25/68] Add individual speed settings per control mode. --- interface/src/avatar/MyAvatar.cpp | 96 ++++++++++++++++++++++---- interface/src/avatar/MyAvatar.h | 13 +++- libraries/shared/src/AvatarConstants.h | 13 +++- 3 files changed, 106 insertions(+), 16 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index c1ebd10f81..dfc95a1d8a 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3308,14 +3308,14 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig direction = (zSpeed * forward) + (xSpeed * right); // Normalize direction. direction /= glm::length(direction); - return getSensorToWorldScale() * direction * _sprintSpeed.get(); + return getSensorToWorldScale() * direction * getSprintSpeed(); } else { return Vectors::ZERO; } case CONTROLS_ANALOG: if (zSpeed || xSpeed) { - glm::vec3 scaledForward = getSensorToWorldScale() * zSpeed * ((zSpeed >= stickFullOn) ? _sprintSpeed.get() : _walkSpeed.get()) * forward; - glm::vec3 scaledRight = getSensorToWorldScale() * xSpeed * ((xSpeed > stickFullOn) ? _sprintSpeed.get() : _walkSpeed.get()) * right; + glm::vec3 scaledForward = getSensorToWorldScale() * zSpeed * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; + glm::vec3 scaledRight = getSensorToWorldScale() * xSpeed * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; direction = scaledForward + scaledRight; return direction; } else { @@ -3323,8 +3323,8 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig } case CONTROLS_ANALOG_PLUS: if (zSpeed || xSpeed) { - glm::vec3 scaledForward = getSensorToWorldScale() * zSpeed * ((zSpeed >= stickFullOn) ? _sprintSpeed.get() : _walkSpeed.get()) * forward; - glm::vec3 scaledRight = getSensorToWorldScale() * xSpeed * ((xSpeed > stickFullOn) ? _sprintSpeed.get() : _walkSpeed.get()) * right; + glm::vec3 scaledForward = getSensorToWorldScale() * zSpeed * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; + glm::vec3 scaledRight = getSensorToWorldScale() * xSpeed * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; direction = scaledForward + scaledRight; return direction; } else { @@ -4590,11 +4590,27 @@ bool MyAvatar::getIsSitStandStateLocked() const { } float MyAvatar::getWalkSpeed() const { - return _walkSpeed.get() * _walkSpeedScalar; + switch(_controlSchemeIndex) { + case CONTROLS_ANALOG: + return _analogWalkSpeed.get() * _walkSpeedScalar; + case CONTROLS_ANALOG_PLUS: + return _analogPlusWalkSpeed.get() * _walkSpeedScalar; + case CONTROLS_DEFAULT: + default: + return _defaultWalkSpeed.get() * _walkSpeedScalar; + } } float MyAvatar::getWalkBackwardSpeed() const { - return _walkSpeed.get() * _walkSpeedScalar; + switch(_controlSchemeIndex) { + case CONTROLS_ANALOG: + return _analogWalkBackwardSpeed.get() * _walkSpeedScalar; + case CONTROLS_ANALOG_PLUS: + return _analogPlusWalkBackwardSpeed.get() * _walkSpeedScalar; + case CONTROLS_DEFAULT: + default: + return _defaultWalkBackwardSpeed.get() * _walkSpeedScalar; + } } bool MyAvatar::isReadyForPhysics() const { @@ -4602,7 +4618,19 @@ bool MyAvatar::isReadyForPhysics() const { } void MyAvatar::setSprintMode(bool sprint) { - _walkSpeedScalar = sprint ? _sprintSpeed.get() : AVATAR_WALK_SPEED_SCALAR; + float value = AVATAR_WALK_SPEED_SCALAR; + if (sprint) { + switch(_controlSchemeIndex) { + case CONTROLS_ANALOG: + value = _analogSprintSpeed.get() * _walkSpeedScalar; + case CONTROLS_ANALOG_PLUS: + value = _analogPlusSprintSpeed.get() * _walkSpeedScalar; + case CONTROLS_DEFAULT: + default: + value = _defaultSprintSpeed.get() * _walkSpeedScalar; + } + } + _walkSpeedScalar = value; } void MyAvatar::setIsInWalkingState(bool isWalking) { @@ -4665,19 +4693,63 @@ void MyAvatar::setIsSitStandStateLocked(bool isLocked) { } void MyAvatar::setWalkSpeed(float value) { - _walkSpeed.set(value); + switch(_controlSchemeIndex) { + case CONTROLS_DEFAULT: + _defaultWalkSpeed.set(value); + break; + case CONTROLS_ANALOG: + _analogWalkSpeed.set(value); + break; + case CONTROLS_ANALOG_PLUS: + _analogPlusWalkSpeed.set(value); + break; + default: + break; + } } void MyAvatar::setWalkBackwardSpeed(float value) { - _walkBackwardSpeed.set(value); + switch(_controlSchemeIndex) { + case CONTROLS_DEFAULT: + _defaultWalkBackwardSpeed.set(value); + break; + case CONTROLS_ANALOG: + _analogWalkBackwardSpeed.set(value); + break; + case CONTROLS_ANALOG_PLUS: + _analogPlusWalkBackwardSpeed.set(value); + break; + default: + break; + } } void MyAvatar::setSprintSpeed(float value) { - _sprintSpeed.set(value); + switch(_controlSchemeIndex) { + case CONTROLS_DEFAULT: + _defaultSprintSpeed.set(value); + break; + case CONTROLS_ANALOG: + _analogSprintSpeed.set(value); + break; + case CONTROLS_ANALOG_PLUS: + _analogPlusSprintSpeed.set(value); + break; + default: + break; + } } float MyAvatar::getSprintSpeed() const { - return _sprintSpeed.get(); + switch(_controlSchemeIndex) { + case CONTROLS_ANALOG: + return _analogSprintSpeed.get(); + case CONTROLS_ANALOG_PLUS: + return _analogPlusSprintSpeed.get(); + case CONTROLS_DEFAULT: + default: + return _defaultSprintSpeed.get(); + } } void MyAvatar::setSitStandStateChange(bool stateChanged) { diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index e6f967e563..eee8036235 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -2047,9 +2047,16 @@ private: ThreadSafeValueCache _lockSitStandState { false }; // max unscaled forward movement speed - ThreadSafeValueCache _walkSpeed { DEFAULT_AVATAR_MAX_WALKING_SPEED }; - ThreadSafeValueCache _walkBackwardSpeed { DEFAULT_AVATAR_MAX_WALKING_BACKWARD_SPEED }; - ThreadSafeValueCache _sprintSpeed { AVATAR_SPRINT_SPEED_SCALAR }; + ThreadSafeValueCache _defaultWalkSpeed { DEFAULT_AVATAR_MAX_WALKING_SPEED }; + ThreadSafeValueCache _defaultWalkBackwardSpeed { DEFAULT_AVATAR_MAX_WALKING_BACKWARD_SPEED }; + ThreadSafeValueCache _defaultSprintSpeed { DEFAULT_AVATAR_MAX_SPRINT_SPEED }; + ThreadSafeValueCache _analogWalkSpeed { ANALOG_AVATAR_MAX_WALKING_SPEED }; + ThreadSafeValueCache _analogWalkBackwardSpeed { ANALOG_AVATAR_MAX_WALKING_BACKWARD_SPEED }; + ThreadSafeValueCache _analogSprintSpeed { ANALOG_AVATAR_MAX_SPRINT_SPEED }; + ThreadSafeValueCache _analogPlusWalkSpeed { ANALOG_PLUS_AVATAR_MAX_WALKING_SPEED }; + ThreadSafeValueCache _analogPlusWalkBackwardSpeed { ANALOG_PLUS_AVATAR_MAX_WALKING_BACKWARD_SPEED }; + ThreadSafeValueCache _analogPlusSprintSpeed { ANALOG_PLUS_AVATAR_MAX_SPRINT_SPEED }; + float _walkSpeedScalar { AVATAR_WALK_SPEED_SCALAR }; bool _isInWalkingState { false }; ThreadSafeValueCache _isInSittingState { false }; diff --git a/libraries/shared/src/AvatarConstants.h b/libraries/shared/src/AvatarConstants.h index 87da47a27a..d4af94e68c 100644 --- a/libraries/shared/src/AvatarConstants.h +++ b/libraries/shared/src/AvatarConstants.h @@ -68,7 +68,18 @@ const glm::quat DEFAULT_AVATAR_RIGHTFOOT_ROT { -0.4016716778278351f, 0.915461599 const float DEFAULT_AVATAR_MAX_WALKING_SPEED = 2.6f; // meters / second const float DEFAULT_AVATAR_MAX_WALKING_BACKWARD_SPEED = 2.2f; // meters / second const float DEFAULT_AVATAR_MAX_FLYING_SPEED = 30.0f; // meters / second -const float DEFAULT_AVATAR_WALK_SPEED_THRESHOLD = 0.15f; +const float DEFAULT_AVATAR_MAX_SPRINT_SPEED = 3.0f; // meters / second +const float DEFAULT_AVATAR_WALK_SPEED_THRESHOLD = 0.15f; // meters / second + +const float ANALOG_AVATAR_MAX_WALKING_SPEED = 2.6f; // meters / second +const float ANALOG_AVATAR_MAX_WALKING_BACKWARD_SPEED = 2.2f; // meters / second +const float ANALOG_AVATAR_MAX_FLYING_SPEED = 30.0f; // meters / second +const float ANALOG_AVATAR_MAX_SPRINT_SPEED = 3.0f; // meters / second + +const float ANALOG_PLUS_AVATAR_MAX_WALKING_SPEED = 3.3f; // meters / second +const float ANALOG_PLUS_AVATAR_MAX_WALKING_BACKWARD_SPEED = 2.42f; // meters / second +const float ANALOG_PLUS_AVATAR_MAX_FLYING_SPEED = 30.0f; // meters / second +const float ANALOG_PLUS_AVATAR_MAX_SPRINT_SPEED = 4.0f; // meters / second const float DEFAULT_AVATAR_GRAVITY = -5.0f; // meters / second^2 (world) const float DEFAULT_AVATAR_JUMP_SPEED = 3.5f; // meters / second (sensor) From bdafb99402cc3d7a680ad40d060e67719bdd1723 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 11 Feb 2019 14:19:15 -0800 Subject: [PATCH 26/68] Remove unused variable and function to address warnings in Mac and Linux builds. --- interface/src/avatar/MyAvatar.cpp | 42 +++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index dfc95a1d8a..e0dff940d5 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3279,22 +3279,22 @@ void MyAvatar::updateOrientation(float deltaTime) { } } -static float scaleSpeedByDirection(const glm::vec2 velocityDirection, const float forwardSpeed, const float backwardSpeed) { - // for the elipse function --> (x^2)/(backwardSpeed*backwardSpeed) + y^2/(forwardSpeed*forwardSpeed) = 1, scale == y^2 when x is 0 - float fwdScale = forwardSpeed * forwardSpeed; - float backScale = backwardSpeed * backwardSpeed; - float scaledX = velocityDirection.x * backwardSpeed; - float scaledSpeed = forwardSpeed; - if (velocityDirection.y < 0.0f) { - if (backScale > 0.0f) { - float yValue = sqrtf(fwdScale * (1.0f - ((scaledX * scaledX) / backScale))); - scaledSpeed = sqrtf((scaledX * scaledX) + (yValue * yValue)); - } - } else { - scaledSpeed = backwardSpeed; - } - return scaledSpeed; -} +//static float scaleSpeedByDirection(const glm::vec2 velocityDirection, const float forwardSpeed, const float backwardSpeed) { +// // for the elipse function --> (x^2)/(backwardSpeed*backwardSpeed) + y^2/(forwardSpeed*forwardSpeed) = 1, scale == y^2 when x is 0 +// float fwdScale = forwardSpeed * forwardSpeed; +// float backScale = backwardSpeed * backwardSpeed; +// float scaledX = velocityDirection.x * backwardSpeed; +// float scaledSpeed = forwardSpeed; +// if (velocityDirection.y < 0.0f) { +// if (backScale > 0.0f) { +// float yValue = sqrtf(fwdScale * (1.0f - ((scaledX * scaledX) / backScale))); +// scaledSpeed = sqrtf((scaledX * scaledX) + (yValue * yValue)); +// } +// } else { +// scaledSpeed = backwardSpeed; +// } +// return scaledSpeed; +//} glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 right) { float stickFullOn = 0.95f; @@ -3392,9 +3392,13 @@ void MyAvatar::updateActionMotor(float deltaTime) { float directionLength = glm::length(direction); _isPushing = directionLength > EPSILON; - if (_isPushing) { - direction; - } else { + //if (_isPushing) { + // direction; + //} else { + // direction = Vectors::ZERO; + //} + + if (!_isPushing) { direction = Vectors::ZERO; } From f52b096bb92b1c792a52338976b28623d7d43f41 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 19 Feb 2019 11:26:42 -0800 Subject: [PATCH 27/68] Change far grab to chorded input 'superpower' --- .../controllerModules/farGrabEntity.js | 115 ++++++++++++++---- 1 file changed, 90 insertions(+), 25 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index dab1aa97af..40f7fc57d7 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -18,7 +18,7 @@ Script.include("/~/system/libraries/controllerDispatcherUtils.js"); Script.include("/~/system/libraries/controllers.js"); -(function() { +(function () { var MARGIN = 25; function TargetObject(entityID, entityProps) { @@ -27,12 +27,13 @@ Script.include("/~/system/libraries/controllers.js"); this.targetEntityID = null; this.targetEntityProps = null; - this.getTargetEntity = function() { + this.getTargetEntity = function () { var parentPropsLength = this.parentProps.length; if (parentPropsLength !== 0) { var targetEntity = { id: this.parentProps[parentPropsLength - 1].id, - props: this.parentProps[parentPropsLength - 1]}; + props: this.parentProps[parentPropsLength - 1] + }; this.targetEntityID = targetEntity.id; this.targetEntityProps = targetEntity.props; return targetEntity; @@ -41,11 +42,13 @@ Script.include("/~/system/libraries/controllers.js"); this.targetEntityProps = this.entityProps; return { id: this.entityID, - props: this.entityProps}; + props: this.entityProps + }; }; } function FarGrabEntity(hand) { + var _this = this; this.hand = hand; this.grabbing = false; this.targetEntityID = null; @@ -76,11 +79,11 @@ Script.include("/~/system/libraries/controllers.js"); makeLaserParams(this.hand, false)); - this.handToController = function() { + this.handToController = function () { return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand; }; - this.distanceGrabTimescale = function(mass, distance) { + this.distanceGrabTimescale = function (mass, distance) { var timeScale = DISTANCE_HOLDING_ACTION_TIMEFRAME * mass / DISTANCE_HOLDING_UNITY_MASS * distance / DISTANCE_HOLDING_UNITY_DISTANCE; @@ -90,7 +93,7 @@ Script.include("/~/system/libraries/controllers.js"); return timeScale; }; - this.getMass = function(dimensions, density) { + this.getMass = function (dimensions, density) { return (dimensions.x * dimensions.y * dimensions.z) * density; }; @@ -156,8 +159,8 @@ Script.include("/~/system/libraries/controllers.js"); } var farJointIndex = FAR_GRAB_JOINTS[this.hand]; this.grabID = MyAvatar.grab(targetProps.id, farJointIndex, - Entities.worldToLocalPosition(targetProps.position, MyAvatar.SELF_ID, farJointIndex), - Entities.worldToLocalRotation(targetProps.rotation, MyAvatar.SELF_ID, farJointIndex)); + Entities.worldToLocalPosition(targetProps.position, MyAvatar.SELF_ID, farJointIndex), + Entities.worldToLocalRotation(targetProps.rotation, MyAvatar.SELF_ID, farJointIndex)); Messages.sendMessage('Hifi-Object-Manipulation', JSON.stringify({ action: 'grab', @@ -169,7 +172,7 @@ Script.include("/~/system/libraries/controllers.js"); this.previousRoomControllerPosition = roomControllerPosition; }; - this.continueDistanceHolding = function(controllerData) { + this.continueDistanceHolding = function (controllerData) { var controllerLocation = controllerData.controllerLocations[this.hand]; var worldControllerPosition = controllerLocation.position; var worldControllerRotation = controllerLocation.orientation; @@ -215,7 +218,7 @@ Script.include("/~/system/libraries/controllers.js"); var RADIAL_GRAB_AMPLIFIER = 10.0; if (Math.abs(this.grabRadialVelocity) > 0.0) { this.grabRadius = this.grabRadius + (this.grabRadialVelocity * deltaObjectTime * - this.grabRadius * RADIAL_GRAB_AMPLIFIER); + this.grabRadius * RADIAL_GRAB_AMPLIFIER); } // don't let grabRadius go all the way to zero, because it can't come back from that @@ -259,13 +262,13 @@ Script.include("/~/system/libraries/controllers.js"); MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); }; - this.updateRecommendedArea = function() { + this.updateRecommendedArea = function () { var dims = Controller.getViewportDimensions(); this.reticleMaxX = dims.x - MARGIN; this.reticleMaxY = dims.y - MARGIN; }; - this.calculateNewReticlePosition = function(intersection) { + this.calculateNewReticlePosition = function (intersection) { this.updateRecommendedArea(); var point2d = HMD.overlayFromWorldPoint(intersection); point2d.x = Math.max(this.reticleMinX, Math.min(point2d.x, this.reticleMaxX)); @@ -273,7 +276,7 @@ Script.include("/~/system/libraries/controllers.js"); return point2d; }; - this.notPointingAtEntity = function(controllerData) { + this.notPointingAtEntity = function (controllerData) { var intersection = controllerData.rayPicks[this.hand]; var entityProperty = Entities.getEntityProperties(intersection.objectID, DISPATCHER_PROPERTIES); var entityType = entityProperty.type; @@ -286,7 +289,7 @@ Script.include("/~/system/libraries/controllers.js"); return false; }; - this.destroyContextOverlay = function(controllerData) { + this.destroyContextOverlay = function (controllerData) { if (this.entityWithContextOverlay) { ContextOverlay.destroyContextOverlay(this.entityWithContextOverlay); this.entityWithContextOverlay = false; @@ -294,7 +297,7 @@ Script.include("/~/system/libraries/controllers.js"); } }; - this.targetIsNull = function() { + this.targetIsNull = function () { var properties = Entities.getEntityProperties(this.targetEntityID, DISPATCHER_PROPERTIES); if (Object.keys(properties).length === 0 && this.distanceHolding) { return true; @@ -318,15 +321,70 @@ Script.include("/~/system/libraries/controllers.js"); return null; }; + var mappingName = "FarGrab-Mapping-" + Math.random(); + var grabMapping; + + this.setup = function () { + grabMapping = Controller.newMapping(mappingName); + grabMapping.from(Controller.Standard.LT).peek().to(_this.getLeftTrigger); + grabMapping.from(Controller.Standard.RT).peek().to(_this.getRightTrigger); + Controller.enableMapping(mappingName); + }; + + this.cleanup = function () { + grabMapping.disable(); + }; + + this.leftTrigger = 0.0; + this.rightTrigger = 0.0; + + this.getDominantHand = function () { + return (MyAvatar.getDominantHand() === "left") ? LEFT_HAND : RIGHT_HAND; + }; + + this.getOffHand = function () { + return (MyAvatar.getDominantHand() === "left") ? RIGHT_HAND : LEFT_HAND; + }; + + this.getLeftTrigger = function (value) { + _this.leftTrigger = value; + }; + + this.getRightTrigger = function (value) { + _this.rightTrigger = value; + }; + + this.getDominantTrigger = function () { + return (MyAvatar.getDominantHand() === "left") ? (_this.leftTrigger) : (_this.rightTrigger); + }; + + this.getOffHandTrigger = function () { + return (MyAvatar.getDominantHand() === "left") ? (_this.rightTrigger) : (_this.leftTrigger); + }; + + this.shouldShowLaser = function () { + return (_this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false; + }; + + this.shouldGrab = function () { + return (_this.getDominantTrigger() > TRIGGER_ON_VALUE && _this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false; + }; + + this.shouldCancel = function () { + // Kill condition : Off hand is <= 15% trigger pull. + return (_this.getOffHandTrigger() <= TRIGGER_OFF_VALUE) ? true : false; + }; + this.isReady = function (controllerData) { - if (HMD.active) { + if (HMD.active && this.hand === this.getOffHand()) { if (this.notPointingAtEntity(controllerData)) { return makeRunningValues(false, [], []); } this.distanceHolding = false; - if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) { + //if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) { + if (this.shouldShowLaser()) { return makeRunningValues(true, [], []); } else { this.destroyContextOverlay(); @@ -336,7 +394,9 @@ Script.include("/~/system/libraries/controllers.js"); }; this.run = function (controllerData) { - if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.targetIsNull()) { + //if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.targetIsNull()) { + if (this.shouldCancel() || this.targetIsNull()) { + print("Canceling..."); this.endFarGrabEntity(controllerData); return makeRunningValues(false, [], []); } @@ -383,7 +443,8 @@ Script.include("/~/system/libraries/controllers.js"); var rayPickInfo = controllerData.rayPicks[this.hand]; if (rayPickInfo.type === Picks.INTERSECTED_ENTITY) { - if (controllerData.triggerClicks[this.hand]) { + if (this.shouldGrab()) { + print("Grabbing..."); var entityID = rayPickInfo.objectID; var targetProps = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES); if (targetProps.href !== "") { @@ -432,12 +493,12 @@ Script.include("/~/system/libraries/controllers.js"); _this.contextOverlayTimer && _this.potentialEntityWithContextOverlay === rayPickInfo.objectID) { var cotProps = Entities.getEntityProperties(rayPickInfo.objectID, - DISPATCHER_PROPERTIES); + DISPATCHER_PROPERTIES); var pointerEvent = { type: "Move", id: _this.hand + 1, // 0 is reserved for hardware mouse pos2D: projectOntoEntityXYPlane(rayPickInfo.objectID, - rayPickInfo.intersection, cotProps), + rayPickInfo.intersection, cotProps), pos3D: rayPickInfo.intersection, normal: rayPickInfo.surfaceNormal, direction: Vec3.subtract(ZERO_VEC, rayPickInfo.surfaceNormal), @@ -456,7 +517,7 @@ Script.include("/~/system/libraries/controllers.js"); return this.exitIfDisabled(controllerData); }; - this.exitIfDisabled = function(controllerData) { + this.exitIfDisabled = function (controllerData) { var moduleName = this.hand === RIGHT_HAND ? "RightDisableModules" : "LeftDisableModules"; var disableModule = getEnabledModuleByName(moduleName); if (disableModule) { @@ -473,10 +534,10 @@ Script.include("/~/system/libraries/controllers.js"); return makeRunningValues(true, [], [], laserLockInfo); }; - this.calculateOffset = function(controllerData) { + this.calculateOffset = function (controllerData) { if (this.distanceHolding) { var targetProps = Entities.getEntityProperties(this.targetObject.entityID, - [ "position", "rotation", "registrationPoint", "dimensions" ]); + ["position", "rotation", "registrationPoint", "dimensions"]); return worldPositionToRegistrationFrameMatrix(targetProps, controllerData.rayPicks[this.hand].intersection); } return undefined; @@ -485,11 +546,15 @@ Script.include("/~/system/libraries/controllers.js"); var leftFarGrabEntity = new FarGrabEntity(LEFT_HAND); var rightFarGrabEntity = new FarGrabEntity(RIGHT_HAND); + leftFarGrabEntity.setup(); + rightFarGrabEntity.setup(); enableDispatcherModule("LeftFarGrabEntity", leftFarGrabEntity); enableDispatcherModule("RightFarGrabEntity", rightFarGrabEntity); function cleanup() { + leftFarGrabEntity.cleanup(); + rightFarGrabEntity.cleanup(); disableDispatcherModule("LeftFarGrabEntity"); disableDispatcherModule("RightFarGrabEntity"); } From 03058775f63bc9acb513d7681c5d10c3e2c6fd12 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 19 Feb 2019 11:27:13 -0800 Subject: [PATCH 28/68] Remove debug prints. --- scripts/system/controllers/controllerModules/farGrabEntity.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 40f7fc57d7..69c17229e3 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -396,7 +396,6 @@ Script.include("/~/system/libraries/controllers.js"); this.run = function (controllerData) { //if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.targetIsNull()) { if (this.shouldCancel() || this.targetIsNull()) { - print("Canceling..."); this.endFarGrabEntity(controllerData); return makeRunningValues(false, [], []); } @@ -444,7 +443,6 @@ Script.include("/~/system/libraries/controllers.js"); var rayPickInfo = controllerData.rayPicks[this.hand]; if (rayPickInfo.type === Picks.INTERSECTED_ENTITY) { if (this.shouldGrab()) { - print("Grabbing..."); var entityID = rayPickInfo.objectID; var targetProps = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES); if (targetProps.href !== "") { From d8b1a479742d8efce3f7351383cf6453e967ee7b Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 19 Feb 2019 15:05:39 -0800 Subject: [PATCH 29/68] Fix oversized Vive deadzone. --- interface/resources/controllers/vive.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/resources/controllers/vive.json b/interface/resources/controllers/vive.json index 24b1587691..b937cee511 100644 --- a/interface/resources/controllers/vive.json +++ b/interface/resources/controllers/vive.json @@ -10,8 +10,8 @@ "filters": [ { "type": "hysteresis", "min": 0.7, "max": 0.75 } ] }, - { "from": "Vive.LY", "when": "Vive.LSY", "filters": ["invert"], "to": "Standard.LY" }, - { "from": "Vive.LX", "when": "Vive.LSX", "to": "Standard.LX" }, + { "from": "Vive.LY", "when": "Vive.LS", "filters": ["invert"], "to": "Standard.LY" }, + { "from": "Vive.LX", "when": "Vive.LS", "to": "Standard.LX" }, { "from": "Vive.LT", "to": "Standard.LT", "filters": [ @@ -28,8 +28,8 @@ }, { "from": "Vive.LSTouch", "to": "Standard.LSTouch" }, - { "from": "Vive.RY", "when": "Vive.RSY", "filters": ["invert"], "to": "Standard.RY" }, - { "from": "Vive.RX", "when": "Vive.RSX", "to": "Standard.RX" }, + { "from": "Vive.RY", "when": "Vive.RS", "filters": ["invert"], "to": "Standard.RY" }, + { "from": "Vive.RX", "when": "Vive.RS", "to": "Standard.RX" }, { "from": "Vive.RT", "to": "Standard.RT", "filters": [ From 0255036e6da8fbe2aacac6ed3e4b1a03b16825a7 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 19 Feb 2019 15:23:05 -0800 Subject: [PATCH 30/68] Fix default mappings' deadzones. --- .../resources/controllers/oculus_touch.json | 8 ++++---- interface/resources/controllers/vive.json | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/interface/resources/controllers/oculus_touch.json b/interface/resources/controllers/oculus_touch.json index b818d371e3..86f559d964 100644 --- a/interface/resources/controllers/oculus_touch.json +++ b/interface/resources/controllers/oculus_touch.json @@ -13,11 +13,11 @@ { "from": "OculusTouch.LY", "to": "Standard.LY", "filters": [ - { "type": "deadZone", "min": 0.7 }, + { "type": "deadZone", "min": 0.15 }, "invert" ] }, - { "from": "OculusTouch.LX", "filters": { "type": "deadZone", "min": 0.7 }, "to": "Standard.LX" }, + { "from": "OculusTouch.LX", "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.LX" }, { "from": "OculusTouch.LT", "to": "Standard.LTClick", "peek": true, "filters": [ { "type": "hysteresis", "min": 0.85, "max": 0.9 } ] @@ -29,11 +29,11 @@ { "from": "OculusTouch.RY", "to": "Standard.RY", "filters": [ - { "type": "deadZone", "min": 0.7 }, + { "type": "deadZone", "min": 0.15 }, "invert" ] }, - { "from": "OculusTouch.RX", "filters": { "type": "deadZone", "min": 0.7 }, "to": "Standard.RX" }, + { "from": "OculusTouch.RX", "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.RX" }, { "from": "OculusTouch.RT", "to": "Standard.RTClick", "peek": true, "filters": [ { "type": "hysteresis", "min": 0.85, "max": 0.9 } ] diff --git a/interface/resources/controllers/vive.json b/interface/resources/controllers/vive.json index b937cee511..d6d8f9f929 100644 --- a/interface/resources/controllers/vive.json +++ b/interface/resources/controllers/vive.json @@ -10,8 +10,13 @@ "filters": [ { "type": "hysteresis", "min": 0.7, "max": 0.75 } ] }, - { "from": "Vive.LY", "when": "Vive.LS", "filters": ["invert"], "to": "Standard.LY" }, - { "from": "Vive.LX", "when": "Vive.LS", "to": "Standard.LX" }, + { "from": "Vive.LY", "when": "Vive.LS", + "filters": [ + { "type": "deadZone", "min": 0.15 }, + "invert" + ] + , "to": "Standard.LY" }, + { "from": "Vive.LX", "when": "Vive.LS", "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.LX" }, { "from": "Vive.LT", "to": "Standard.LT", "filters": [ @@ -28,8 +33,13 @@ }, { "from": "Vive.LSTouch", "to": "Standard.LSTouch" }, - { "from": "Vive.RY", "when": "Vive.RS", "filters": ["invert"], "to": "Standard.RY" }, - { "from": "Vive.RX", "when": "Vive.RS", "to": "Standard.RX" }, + { "from": "Vive.RY", "when": "Vive.RS", + "filters": [ + { "type": "deadZone", "min": 0.15 }, + "invert" + ] + , "to": "Standard.RY" }, + { "from": "Vive.RX", "when": "Vive.RS", "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.RX" }, { "from": "Vive.RT", "to": "Standard.RT", "filters": [ From a3c474729022531a8a6269077e459dc8a8487488 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Feb 2019 11:17:31 -0800 Subject: [PATCH 31/68] 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); } { From 58906d84eb10c85cdbcc54bd12aa8e6c3bc9a7c5 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Feb 2019 15:22:21 -0800 Subject: [PATCH 32/68] Add grip button polling. --- .../controllerModules/farGrabEntity.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index e9e7068206..9c78c576d5 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -328,6 +328,8 @@ Script.include("/~/system/libraries/controllers.js"); grabMapping = Controller.newMapping(mappingName); grabMapping.from(Controller.Standard.LT).peek().to(_this.getLeftTrigger); grabMapping.from(Controller.Standard.RT).peek().to(_this.getRightTrigger); + grabMapping.from(Controller.Standard.LeftGrip).peek().to(_this.setLeftGrip); + grabMapping.from(Controller.Standard.RightGrip).peek().to(_this.setRightGrip); Controller.enableMapping(mappingName); }; @@ -337,6 +339,8 @@ Script.include("/~/system/libraries/controllers.js"); this.leftTrigger = 0.0; this.rightTrigger = 0.0; + this.leftGrip = 0.0; + this.rightGrip = 0.0; this.getDominantHand = function () { return (MyAvatar.getDominantHand() === "left") ? LEFT_HAND : RIGHT_HAND; @@ -362,6 +366,22 @@ Script.include("/~/system/libraries/controllers.js"); return (MyAvatar.getDominantHand() === "left") ? (_this.rightTrigger) : (_this.leftTrigger); }; + this.setLeftGrip = function (value) { + this.leftGrip = value; + } + + this.setRightGrip = function (value) { + this.rightGrip = value; + } + + this.getDominantGrip = function () { + return (MyAvatar.getDominantHand() === "left" ? (_this.leftGrip) : (_this.rightGrip)); + } + + this.getOffhandGrip = function () { + return (MyAvatar.getDominantHand() === "left" ? (_this.rightGrip) : (_this.leftGrip)); + } + this.shouldShowLaser = function () { return (_this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false; }; From c6a3496b2573057381da004ea030114ffe92ecf9 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Sun, 24 Feb 2019 12:36:44 -0800 Subject: [PATCH 33/68] Add utility functions for adjusting target rotation and position. --- .../controllerModules/farGrabEntity.js | 64 ++++++++++++++++++- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 9c78c576d5..92fc4a45f1 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -146,7 +146,7 @@ Script.include("/~/system/libraries/controllers.js"); var newTargetPosLocal = MyAvatar.worldToJointPoint(targetProps.position); MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); - MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); + MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); // RKNOTE: This is where the rotation should be updated. var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; Entities.callEntityMethod(targetProps.id, "startDistanceGrab", args); @@ -235,7 +235,7 @@ Script.include("/~/system/libraries/controllers.js"); // var newTargetPosLocal = Mat4.transformPoint(MyAvatar.getSensorToWorldMatrix(), newTargetPosition); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); - MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); + MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); // RKNOTE: This is where the rotation should be updated. this.previousRoomControllerPosition = roomControllerPosition; }; @@ -259,7 +259,7 @@ Script.include("/~/system/libraries/controllers.js"); this.grabbing = false; this.targetEntityID = null; this.potentialEntityWithContextOverlay = false; - MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); + MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); // RKNOTE: Here, we should edit the entity's position and rotation data with the current joint rotation data. }; this.updateRecommendedArea = function () { @@ -395,6 +395,64 @@ Script.include("/~/system/libraries/controllers.js"); return (_this.getOffHandTrigger() <= TRIGGER_OFF_VALUE) ? true : false; }; + this.getTargetPosition = function () { + if (this.targetIsNull()) { + return null; + } else { + var props = Entities.getEntityProperties(this.targetEntityID, ["position"]); + return props.position; + } + }; + + this.getTargetRotation = function () { + if (this.targetIsNull()) { + return null; + } else { + var props = Entities.getEntityProperties(this.targetEntityID, ["rotation"]); + return props.rotation; + } + }; + + this.getTargetLocalPosition = function () { + if (this.targetIsNull()) { + return null; + } else { + var props = Entities.getEntityProperties(this.targetEntityID, ["localPosition"]); + return props.localPosition; + } + }; + + this.getTargetLocalRotation = function () { + if (this.targetIsNull()) { + return null; + } else { + var props = Entities.getEntityProperties(this.targetEntityID, ["localRotation"]); + return props.localRotation; + } + }; + + this.setTargetPosition = function (newPos) { + if (this.targetIsNull()) { + print("Fargrab Error: No target to edit position."); + return; + } else { + var props; + props.position = newPos; + Entities.editEntity(this.targetEntityID, props); + } + }; + + this.setTargetRotation = function (newRot) { + if (this.targetIsNull()) { + print("Fargrab Error: No target to edit rotation."); + return; + } else { + var props; + props.rotation = newRot; + Entitis.editEntity(this.targetEntityID, props); + } + } + this.isReady = function (controllerData) { if (HMD.active && this.hand === this.getOffHand()) { if (this.notPointingAtEntity(controllerData)) { From d79681470e8ebae6561f036b3021a8dfb006a0f2 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 25 Feb 2019 13:10:25 -0800 Subject: [PATCH 34/68] Saving changes before merging master... --- .../controllerModules/farGrabEntity.js | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 92fc4a45f1..5947633508 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -111,6 +111,7 @@ Script.include("/~/system/libraries/controllers.js"); this.currentObjectPosition = targetProps.position; this.currentObjectRotation = targetProps.rotation; this.currentObjectTime = now; + this.initialEntityRotation = targetProps.rotation; this.grabRadius = this.grabbedDistance; this.grabRadialVelocity = 0.0; @@ -145,8 +146,14 @@ Script.include("/~/system/libraries/controllers.js"); Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); var newTargetPosLocal = MyAvatar.worldToJointPoint(targetProps.position); - MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); - MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); // RKNOTE: This is where the rotation should be updated. + var newTargetRotLocal = this.targetProps.rotation; + if (this.shouldManipulateTarget()) { + var rotBetween = this.calculateEntityRotationManipulation(worldControllerRotation); + var newTargetRotLocal = Quat.multiply(rotBetween, newTargetRotLocal); + } + //MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); + this.setJointTranslation(newTargetPosLocal); + this.setJointRotation(newTargetRotLocal); var args = [this.hand === RIGHT_HAND ? "right" : "left", MyAvatar.sessionUUID]; Entities.callEntityMethod(targetProps.id, "startDistanceGrab", args); @@ -234,8 +241,14 @@ Script.include("/~/system/libraries/controllers.js"); // var newTargetPosLocal = Mat4.transformPoint(MyAvatar.getSensorToWorldMatrix(), newTargetPosition); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); - MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); - MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], { x: 0, y: 0, z: 0, w: 1 }); // RKNOTE: This is where the rotation should be updated. + var newTargetRotLocal = this.initialEntityRotation; + if (this.shouldManipulateTarget()) { + var rotBetween = this.calculateEntityRotationManipulation(worldControllerRotation); + var newTargetRotLocal = Quat.multiply(rotBetween, newTargetRotLocal); + } + //MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); + this.setJointTranslation(newTargetPosLocal); + this.setJointRotation(newTargetRotLocal); this.previousRoomControllerPosition = roomControllerPosition; }; @@ -257,9 +270,10 @@ Script.include("/~/system/libraries/controllers.js"); })); unhighlightTargetEntity(this.targetEntityID); this.grabbing = false; - this.targetEntityID = null; this.potentialEntityWithContextOverlay = false; MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); // RKNOTE: Here, we should edit the entity's position and rotation data with the current joint rotation data. + this.setTargetRotation(this.lastFarGrabJointRotation); + this.targetEntityID = null; }; this.updateRecommendedArea = function () { @@ -337,6 +351,10 @@ Script.include("/~/system/libraries/controllers.js"); grabMapping.disable(); }; + this.initialControllerRotation = Quat.IDENTITY; + this.initialEntityRotation = Quat.IDENTITY; + this.lastFarGrabJointRotation = Quat.IDENTITY; + this.leftTrigger = 0.0; this.rightTrigger = 0.0; this.leftGrip = 0.0; @@ -451,8 +469,25 @@ Script.include("/~/system/libraries/controllers.js"); props.rotation = newRot; Entitis.editEntity(this.targetEntityID, props); } + }; + + this.shouldManipulateTarget = function () { + return (this.getDominantGrip() > TRIGGER_ON_VALUE); } + this.calculateEntityRotationManipulation = function (controllerRotation) { + return Quat.multiply(controllerRotation, Quat.inverse(this.initialControllerRotation)); + } + + this.setJointTranslation(newTargetPosLocal) { + MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); + }; + + this.setJointRotation(newTargetRotLocal) { + this.lastFarGrabJointRotation = newTargetRotLocal; + MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], newTargetRotLocal); + }; + this.isReady = function (controllerData) { if (HMD.active && this.hand === this.getOffHand()) { if (this.notPointingAtEntity(controllerData)) { From a66c76bf3847e4832809f18d62b205dd3f12b436 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 25 Feb 2019 13:47:31 -0800 Subject: [PATCH 35/68] Fixing typos. --- .../controllerModules/farGrabEntity.js | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 5947633508..028fe3c804 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -146,7 +146,7 @@ Script.include("/~/system/libraries/controllers.js"); Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); var newTargetPosLocal = MyAvatar.worldToJointPoint(targetProps.position); - var newTargetRotLocal = this.targetProps.rotation; + var newTargetRotLocal = targetProps.rotation; if (this.shouldManipulateTarget()) { var rotBetween = this.calculateEntityRotationManipulation(worldControllerRotation); var newTargetRotLocal = Quat.multiply(rotBetween, newTargetRotLocal); @@ -243,6 +243,7 @@ Script.include("/~/system/libraries/controllers.js"); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); var newTargetRotLocal = this.initialEntityRotation; if (this.shouldManipulateTarget()) { + print("Test this thing."); var rotBetween = this.calculateEntityRotationManipulation(worldControllerRotation); var newTargetRotLocal = Quat.multiply(rotBetween, newTargetRotLocal); } @@ -272,7 +273,8 @@ Script.include("/~/system/libraries/controllers.js"); this.grabbing = false; this.potentialEntityWithContextOverlay = false; MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); // RKNOTE: Here, we should edit the entity's position and rotation data with the current joint rotation data. - this.setTargetRotation(this.lastFarGrabJointRotation); + this.setTargetRotation(Quat.multiply(this.lastFarGrabJointRotation, this.initialEntityRotation)); + this.initialEntityRotation = Quat.IDENTITY; this.targetEntityID = null; }; @@ -386,19 +388,19 @@ Script.include("/~/system/libraries/controllers.js"); this.setLeftGrip = function (value) { this.leftGrip = value; - } + }; this.setRightGrip = function (value) { this.rightGrip = value; - } + }; this.getDominantGrip = function () { return (MyAvatar.getDominantHand() === "left" ? (_this.leftGrip) : (_this.rightGrip)); - } + }; this.getOffhandGrip = function () { return (MyAvatar.getDominantHand() === "left" ? (_this.rightGrip) : (_this.leftGrip)); - } + }; this.shouldShowLaser = function () { return (_this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false; @@ -454,8 +456,7 @@ Script.include("/~/system/libraries/controllers.js"); print("Fargrab Error: No target to edit position."); return; } else { - var props; - props.position = newPos; + var props = { position: newPos }; Entities.editEntity(this.targetEntityID, props); } }; @@ -465,25 +466,24 @@ Script.include("/~/system/libraries/controllers.js"); print("Fargrab Error: No target to edit rotation."); return; } else { - var props; - props.rotation = newRot; - Entitis.editEntity(this.targetEntityID, props); + var props = { rotation: newRot }; + Entities.editEntity(this.targetEntityID, props); } }; this.shouldManipulateTarget = function () { return (this.getDominantGrip() > TRIGGER_ON_VALUE); - } + }; this.calculateEntityRotationManipulation = function (controllerRotation) { return Quat.multiply(controllerRotation, Quat.inverse(this.initialControllerRotation)); - } + }; - this.setJointTranslation(newTargetPosLocal) { + this.setJointTranslation = function (newTargetPosLocal) { MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); }; - this.setJointRotation(newTargetRotLocal) { + this.setJointRotation = function (newTargetRotLocal) { this.lastFarGrabJointRotation = newTargetRotLocal; MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], newTargetRotLocal); }; From 52b62784d6e440079c3c28d1122b2cfbd1ed4e22 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 25 Feb 2019 14:10:48 -0800 Subject: [PATCH 36/68] Incremental, broken progress. --- .../system/controllers/controllerModules/farGrabEntity.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 028fe3c804..0aa54bc8e5 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -243,7 +243,6 @@ Script.include("/~/system/libraries/controllers.js"); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); var newTargetRotLocal = this.initialEntityRotation; if (this.shouldManipulateTarget()) { - print("Test this thing."); var rotBetween = this.calculateEntityRotationManipulation(worldControllerRotation); var newTargetRotLocal = Quat.multiply(rotBetween, newTargetRotLocal); } @@ -272,8 +271,9 @@ Script.include("/~/system/libraries/controllers.js"); unhighlightTargetEntity(this.targetEntityID); this.grabbing = false; this.potentialEntityWithContextOverlay = false; + var rot = this.getTargetRotation(); MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); // RKNOTE: Here, we should edit the entity's position and rotation data with the current joint rotation data. - this.setTargetRotation(Quat.multiply(this.lastFarGrabJointRotation, this.initialEntityRotation)); + this.setTargetRotation(Quat.multiply(this.lastFarGrabJointRotation, rot)); this.initialEntityRotation = Quat.IDENTITY; this.targetEntityID = null; }; @@ -472,7 +472,9 @@ Script.include("/~/system/libraries/controllers.js"); }; this.shouldManipulateTarget = function () { - return (this.getDominantGrip() > TRIGGER_ON_VALUE); + //var test = this.getDominantGrip() > TRIGGER_ON_VALUE; + //return test; + return true; }; this.calculateEntityRotationManipulation = function (controllerRotation) { From 0b651a8d633bcaa834492a54132d33bf1cf83d48 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 26 Feb 2019 11:29:06 -0800 Subject: [PATCH 37/68] Fix fargrab rotation with dominant hand, need to fix activation criteria next. --- .../controllerModules/farGrabEntity.js | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 0aa54bc8e5..d5bebc549f 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -111,7 +111,7 @@ Script.include("/~/system/libraries/controllers.js"); this.currentObjectPosition = targetProps.position; this.currentObjectRotation = targetProps.rotation; this.currentObjectTime = now; - this.initialEntityRotation = targetProps.rotation; + this.initialEntityRotation = targetProps.rotation; // World frame. this.grabRadius = this.grabbedDistance; this.grabRadialVelocity = 0.0; @@ -145,13 +145,10 @@ Script.include("/~/system/libraries/controllers.js"); Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); - var newTargetPosLocal = MyAvatar.worldToJointPoint(targetProps.position); - var newTargetRotLocal = targetProps.rotation; - if (this.shouldManipulateTarget()) { - var rotBetween = this.calculateEntityRotationManipulation(worldControllerRotation); - var newTargetRotLocal = Quat.multiply(rotBetween, newTargetRotLocal); - } //MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); + + var newTargetPosLocal = MyAvatar.worldToJointPoint(targetProps.position); // World frame. + var newTargetRotLocal = targetProps.rotation; // World frame. this.setJointTranslation(newTargetPosLocal); this.setJointRotation(newTargetRotLocal); @@ -243,10 +240,14 @@ Script.include("/~/system/libraries/controllers.js"); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); var newTargetRotLocal = this.initialEntityRotation; if (this.shouldManipulateTarget()) { - var rotBetween = this.calculateEntityRotationManipulation(worldControllerRotation); + var dominantHandControllerLocation = controllerData.controllerLocations[this.getDominantHand()]; + var worldDominantHandControllerRotation = dominantHandControllerLocation.rotation; + if (Quat.equal(Quat.IDENTITY, this.initialControllerRotation)) { + this.initialControllerRotation = worldDominantHandControllerRotation; + } + var rotBetween = this.calculateEntityRotationManipulation(worldDominantHandControllerRotation); var newTargetRotLocal = Quat.multiply(rotBetween, newTargetRotLocal); } - //MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); this.setJointTranslation(newTargetPosLocal); this.setJointRotation(newTargetRotLocal); @@ -271,10 +272,9 @@ Script.include("/~/system/libraries/controllers.js"); unhighlightTargetEntity(this.targetEntityID); this.grabbing = false; this.potentialEntityWithContextOverlay = false; - var rot = this.getTargetRotation(); - MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); // RKNOTE: Here, we should edit the entity's position and rotation data with the current joint rotation data. - this.setTargetRotation(Quat.multiply(this.lastFarGrabJointRotation, rot)); + MyAvatar.clearJointData(FAR_GRAB_JOINTS[this.hand]); this.initialEntityRotation = Quat.IDENTITY; + this.initialControllerRotation = Quat.IDENTITY; this.targetEntityID = null; }; @@ -355,7 +355,6 @@ Script.include("/~/system/libraries/controllers.js"); this.initialControllerRotation = Quat.IDENTITY; this.initialEntityRotation = Quat.IDENTITY; - this.lastFarGrabJointRotation = Quat.IDENTITY; this.leftTrigger = 0.0; this.rightTrigger = 0.0; @@ -486,7 +485,6 @@ Script.include("/~/system/libraries/controllers.js"); }; this.setJointRotation = function (newTargetRotLocal) { - this.lastFarGrabJointRotation = newTargetRotLocal; MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], newTargetRotLocal); }; From 2a04d2b9c59c259ad9f492f34014f49863a8a8bd Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 26 Feb 2019 12:39:51 -0800 Subject: [PATCH 38/68] Closer... --- .../controllerModules/farGrabEntity.js | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index d5bebc549f..ee0fe5f106 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -111,7 +111,7 @@ Script.include("/~/system/libraries/controllers.js"); this.currentObjectPosition = targetProps.position; this.currentObjectRotation = targetProps.rotation; this.currentObjectTime = now; - this.initialEntityRotation = targetProps.rotation; // World frame. + //this.initialEntityRotation = targetProps.rotation; // World frame. this.grabRadius = this.grabbedDistance; this.grabRadialVelocity = 0.0; @@ -238,18 +238,27 @@ Script.include("/~/system/libraries/controllers.js"); // var newTargetPosLocal = Mat4.transformPoint(MyAvatar.getSensorToWorldMatrix(), newTargetPosition); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); - var newTargetRotLocal = this.initialEntityRotation; if (this.shouldManipulateTarget()) { - var dominantHandControllerLocation = controllerData.controllerLocations[this.getDominantHand()]; - var worldDominantHandControllerRotation = dominantHandControllerLocation.rotation; - if (Quat.equal(Quat.IDENTITY, this.initialControllerRotation)) { - this.initialControllerRotation = worldDominantHandControllerRotation; + var pose = Controller.getPoseValue((this.getDominantHand() ? Controller.Standard.RightHand : Controller.Standard.LeftHand)); + if (pose.valid) { + if (!this.manipulating) { + //this.initialEntityRotation = Quat.multiply(this.getTargetRotation(), Quat.inverse(MyAvatar.orientation)); // Avatar frame. + this.initialEntityRotation = this.getTargetRotation(); // Worldframe. + this.initialControllerRotation = Quat.multiply(MyAvatar.orientation, pose.rotation); // Worldframe. + //this.initialEntityRotation = Quat.multiply(this.getTargetRotation(), Quat.inverse(MyAvatar.orientation)); + this.manipulating = true; + } } - var rotBetween = this.calculateEntityRotationManipulation(worldDominantHandControllerRotation); - var newTargetRotLocal = Quat.multiply(rotBetween, newTargetRotLocal); + + var rot = Quat.multiply(MyAvatar.orientation, pose.rotation); + var rotBetween = this.calculateEntityRotationManipulation(rot); + this.setJointRotation(Quat.multiply(rotBetween, this.initialEntityRotation)); + } else { + this.manipulating = false; + this.initialEntityRotation = Quat.IDENTITY; + this.initialControllerRotation = Quat.IDENTITY; } this.setJointTranslation(newTargetPosLocal); - this.setJointRotation(newTargetRotLocal); this.previousRoomControllerPosition = roomControllerPosition; }; @@ -276,6 +285,7 @@ Script.include("/~/system/libraries/controllers.js"); this.initialEntityRotation = Quat.IDENTITY; this.initialControllerRotation = Quat.IDENTITY; this.targetEntityID = null; + this.manipulating = false; }; this.updateRecommendedArea = function () { @@ -355,6 +365,7 @@ Script.include("/~/system/libraries/controllers.js"); this.initialControllerRotation = Quat.IDENTITY; this.initialEntityRotation = Quat.IDENTITY; + this.manipulating = false; this.leftTrigger = 0.0; this.rightTrigger = 0.0; @@ -414,6 +425,11 @@ Script.include("/~/system/libraries/controllers.js"); return (_this.getOffHandTrigger() <= TRIGGER_OFF_VALUE) ? true : false; }; + this.shouldManipulateTarget = function () { + return (_this.getDominantTrigger() > TRIGGER_ON_VALUE) ? true : false; + }; + + this.getTargetPosition = function () { if (this.targetIsNull()) { return null; @@ -470,12 +486,6 @@ Script.include("/~/system/libraries/controllers.js"); } }; - this.shouldManipulateTarget = function () { - //var test = this.getDominantGrip() > TRIGGER_ON_VALUE; - //return test; - return true; - }; - this.calculateEntityRotationManipulation = function (controllerRotation) { return Quat.multiply(controllerRotation, Quat.inverse(this.initialControllerRotation)); }; From f3b65d06ada804155ff4d6b992189eed68bb86f6 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 26 Feb 2019 12:46:46 -0800 Subject: [PATCH 39/68] Fix frame of reference for rotations. --- .../system/controllers/controllerModules/farGrabEntity.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index ee0fe5f106..2166495567 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -242,15 +242,13 @@ Script.include("/~/system/libraries/controllers.js"); var pose = Controller.getPoseValue((this.getDominantHand() ? Controller.Standard.RightHand : Controller.Standard.LeftHand)); if (pose.valid) { if (!this.manipulating) { - //this.initialEntityRotation = Quat.multiply(this.getTargetRotation(), Quat.inverse(MyAvatar.orientation)); // Avatar frame. this.initialEntityRotation = this.getTargetRotation(); // Worldframe. - this.initialControllerRotation = Quat.multiply(MyAvatar.orientation, pose.rotation); // Worldframe. - //this.initialEntityRotation = Quat.multiply(this.getTargetRotation(), Quat.inverse(MyAvatar.orientation)); + this.initialControllerRotation = Quat.multiply(pose.rotation, MyAvatar.orientation); // Worldframe. this.manipulating = true; } } - var rot = Quat.multiply(MyAvatar.orientation, pose.rotation); + var rot = Quat.multiply(pose.rotation, MyAvatar.orientation); var rotBetween = this.calculateEntityRotationManipulation(rot); this.setJointRotation(Quat.multiply(rotBetween, this.initialEntityRotation)); } else { From 030211aea8047d94db19d3ec26c87164473f41ce Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 26 Feb 2019 14:46:04 -0800 Subject: [PATCH 40/68] Fix OSX compiler error, init list in wrong order after merge. --- interface/src/avatar/MyAvatar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 94c5e2e708..14e9f1a987 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -171,13 +171,13 @@ MyAvatar::MyAvatar(QThread* thread) : _flyingHMDSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "flyingHMD", _flyingPrefHMD), _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), _driveGear2Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear2", _driveGear2), _driveGear3Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear3", _driveGear3), _driveGear4Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear4", _driveGear4), _driveGear5Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear5", _driveGear5), - _controlSchemeIndexSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "controlSchemeIndex", _controlSchemeIndex) + _controlSchemeIndexSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "controlSchemeIndex", _controlSchemeIndex), + _userRecenterModelSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "userRecenterModel", USER_RECENTER_MODEL_AUTO) { _clientTraitsHandler.reset(new ClientTraitsHandler(this)); From 2077e012dbbfa441eb5b1b92a62b8a786f27b3ff Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 26 Feb 2019 15:00:44 -0800 Subject: [PATCH 41/68] Fix case of repeated manipulations with fargrab. --- .../controllers/controllerModules/farGrabEntity.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 2166495567..756f8cd0db 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -242,7 +242,9 @@ Script.include("/~/system/libraries/controllers.js"); var pose = Controller.getPoseValue((this.getDominantHand() ? Controller.Standard.RightHand : Controller.Standard.LeftHand)); if (pose.valid) { if (!this.manipulating) { - this.initialEntityRotation = this.getTargetRotation(); // Worldframe. + if (!this.wasManipulating) { + this.initialEntityRotation = this.getTargetRotation(); // Worldframe. + } this.initialControllerRotation = Quat.multiply(pose.rotation, MyAvatar.orientation); // Worldframe. this.manipulating = true; } @@ -250,10 +252,14 @@ Script.include("/~/system/libraries/controllers.js"); var rot = Quat.multiply(pose.rotation, MyAvatar.orientation); var rotBetween = this.calculateEntityRotationManipulation(rot); - this.setJointRotation(Quat.multiply(rotBetween, this.initialEntityRotation)); + this.lastJointRotation = Quat.multiply(rotBetween, this.initialEntityRotation); + this.setJointRotation(this.lastJointRotation); } else { + if (this.manipulating) { + this.initialEntityRotation = this.lastJointRotation; + this.wasManipulating = true; + } this.manipulating = false; - this.initialEntityRotation = Quat.IDENTITY; this.initialControllerRotation = Quat.IDENTITY; } this.setJointTranslation(newTargetPosLocal); @@ -284,6 +290,7 @@ Script.include("/~/system/libraries/controllers.js"); this.initialControllerRotation = Quat.IDENTITY; this.targetEntityID = null; this.manipulating = false; + this.wasManipulating = false; }; this.updateRecommendedArea = function () { @@ -364,6 +371,7 @@ Script.include("/~/system/libraries/controllers.js"); this.initialControllerRotation = Quat.IDENTITY; this.initialEntityRotation = Quat.IDENTITY; this.manipulating = false; + this.wasManipulating = false; this.leftTrigger = 0.0; this.rightTrigger = 0.0; From 42b62ff2d531c8eda9960d185a19f2a201ac320e Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 26 Feb 2019 19:16:34 -0800 Subject: [PATCH 42/68] Fix Ubuntu compiler warnings. --- interface/src/avatar/MyAvatar.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 64c251f1fa..b202c2f570 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3371,12 +3371,11 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ right = (handRotation * controllerRight); break; case MOVEMENT_HAND_RELATIVE_LEVELED: + handRotation = cancelOutRoll(handRotation); forward = (handRotation * controllerForward); - forward.y = 0.0f; - forward /= forward.length(); + //forward = glm::normalize(forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y)); right = (handRotation * controllerRight); - right.y = 0.0f; - right /= right.length(); + //right = glm::normalize(right - (glm::dot(right, Vectors::UNIT_Y) * Vectors::UNIT_Y)); break; case MOVEMENT_HMD_RELATIVE: default: @@ -3987,7 +3986,7 @@ void MyAvatar::setDriveGear1(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear1", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear1 = (shiftPoint <= _driveGear2) ? shiftPoint : _driveGear1; } @@ -4000,7 +3999,7 @@ void MyAvatar::setDriveGear2(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear2", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear2 = (shiftPoint <= _driveGear3 && shiftPoint >= _driveGear1) ? shiftPoint : _driveGear2; } @@ -4013,7 +4012,7 @@ void MyAvatar::setDriveGear3(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear3", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear3 = (shiftPoint <= _driveGear4 && shiftPoint >= _driveGear2) ? shiftPoint : _driveGear3; } @@ -4026,7 +4025,7 @@ void MyAvatar::setDriveGear4(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear4", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear4 = (shiftPoint <= _driveGear5 && shiftPoint >= _driveGear3) ? shiftPoint : _driveGear4; } @@ -4039,7 +4038,7 @@ void MyAvatar::setDriveGear5(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear5", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear5 = (shiftPoint >= _driveGear4) ? shiftPoint : _driveGear5; } From 7c515ccd452d3d6322916675893aaab199494664 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Tue, 26 Feb 2019 19:16:45 -0800 Subject: [PATCH 43/68] Add 2x rotation multiplier. --- .../controllerModules/farGrabEntity.js | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 756f8cd0db..ea0c3e8ad6 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -252,7 +252,8 @@ Script.include("/~/system/libraries/controllers.js"); var rot = Quat.multiply(pose.rotation, MyAvatar.orientation); var rotBetween = this.calculateEntityRotationManipulation(rot); - this.lastJointRotation = Quat.multiply(rotBetween, this.initialEntityRotation); + var doubleRot = Quat.multiply(rotBetween, rotBetween); + this.lastJointRotation = Quat.multiply(doubleRot, this.initialEntityRotation); this.setJointRotation(this.lastJointRotation); } else { if (this.manipulating) { @@ -359,8 +360,6 @@ Script.include("/~/system/libraries/controllers.js"); grabMapping = Controller.newMapping(mappingName); grabMapping.from(Controller.Standard.LT).peek().to(_this.getLeftTrigger); grabMapping.from(Controller.Standard.RT).peek().to(_this.getRightTrigger); - grabMapping.from(Controller.Standard.LeftGrip).peek().to(_this.setLeftGrip); - grabMapping.from(Controller.Standard.RightGrip).peek().to(_this.setRightGrip); Controller.enableMapping(mappingName); }; @@ -375,8 +374,6 @@ Script.include("/~/system/libraries/controllers.js"); this.leftTrigger = 0.0; this.rightTrigger = 0.0; - this.leftGrip = 0.0; - this.rightGrip = 0.0; this.getDominantHand = function () { return (MyAvatar.getDominantHand() === "left") ? LEFT_HAND : RIGHT_HAND; @@ -402,22 +399,6 @@ Script.include("/~/system/libraries/controllers.js"); return (MyAvatar.getDominantHand() === "left") ? (_this.rightTrigger) : (_this.leftTrigger); }; - this.setLeftGrip = function (value) { - this.leftGrip = value; - }; - - this.setRightGrip = function (value) { - this.rightGrip = value; - }; - - this.getDominantGrip = function () { - return (MyAvatar.getDominantHand() === "left" ? (_this.leftGrip) : (_this.rightGrip)); - }; - - this.getOffhandGrip = function () { - return (MyAvatar.getDominantHand() === "left" ? (_this.rightGrip) : (_this.leftGrip)); - }; - this.shouldShowLaser = function () { return (_this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false; }; From fcdfae5a678ed3180b1190ef823a6ebc641910ea Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Wed, 27 Feb 2019 08:39:35 -0800 Subject: [PATCH 44/68] Fix notion of hand dominance. --- interface/resources/controllers/standard.json | 128 +++++++++--------- .../controllerModules/farGrabEntity.js | 10 +- .../controllers/controllerModules/teleport.js | 6 +- 3 files changed, 72 insertions(+), 72 deletions(-) diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 25f75c5670..7e23379394 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -2,68 +2,11 @@ "name": "Standard to Action", "channels": [ { "from": "Standard.LY", - "when": ["Application.LeftHandDominant", "!Standard.RY"], + "when": ["Application.RightHandDominant", "!Standard.RY"], "to": "Actions.TranslateZ" }, { "from": "Standard.LX", - "when": [ - "Application.InHMD", "!Application.AdvancedMovement", "Application.LeftHandDominant", - "Application.SnapTurn", "!Standard.RX" - ], - "to": "Actions.StepYaw", - "filters": - [ - { "type": "deadZone", "min": 0.15 }, - "constrainToInteger", - { "type": "pulse", "interval": 0.25 }, - { "type": "scale", "scale": 22.5 } - ] - }, - { "from": "Standard.LX", "to": "Actions.TranslateX", - "when": [ "Application.AdvancedMovement", "Application.LeftHandDominant" ] - }, - { "from": "Standard.LX", "to": "Actions.Yaw", - "when": [ "!Application.AdvancedMovement", "!Application.SnapTurn", "Application.LeftHandDominant" ] - }, - - { "from": "Standard.RX", - "when": [ "Application.SnapTurn", "Application.LeftHandDominant" ], - "to": "Actions.StepYaw", - "filters": - [ - { "type": "deadZone", "min": 0.15 }, - "constrainToInteger", - { "type": "pulse", "interval": 0.25 }, - { "type": "scale", "scale": 22.5 } - ] - }, - { "from": "Standard.RX", "to": "Actions.Yaw", - "when": [ "!Application.SnapTurn", "Application.LeftHandDominant" ] - }, - - { "from": "Standard.RY", - "when": [ "Application.Grounded", "Application.LeftHandDominant" ], - "to": "Actions.Up", - "filters": - [ - { "type": "deadZone", "min": 0.6 }, - "invert" - ] - }, - - { "from": "Standard.RY", - "when": "Application.LeftHandDominant", - "to": "Actions.Up", - "filters": "invert" - }, - - { "from": "Standard.RY", - "when": ["Application.RightHandDominant", "!Standard.LY"], - "to": "Actions.TranslateZ" - }, - - { "from": "Standard.RX", "when": [ "Application.InHMD", "!Application.AdvancedMovement", "Application.RightHandDominant", "Application.SnapTurn", "!Standard.RX" @@ -77,14 +20,14 @@ { "type": "scale", "scale": 22.5 } ] }, - { "from": "Standard.RX", "to": "Actions.TranslateX", + { "from": "Standard.LX", "to": "Actions.TranslateX", "when": [ "Application.AdvancedMovement", "Application.RightHandDominant" ] }, - { "from": "Standard.RX", "to": "Actions.Yaw", + { "from": "Standard.LX", "to": "Actions.Yaw", "when": [ "!Application.AdvancedMovement", "!Application.SnapTurn", "Application.RightHandDominant" ] }, - { "from": "Standard.LX", + { "from": "Standard.RX", "when": [ "Application.SnapTurn", "Application.RightHandDominant" ], "to": "Actions.StepYaw", "filters": @@ -95,11 +38,11 @@ { "type": "scale", "scale": 22.5 } ] }, - { "from": "Standard.LX", "to": "Actions.Yaw", + { "from": "Standard.RX", "to": "Actions.Yaw", "when": [ "!Application.SnapTurn", "Application.RightHandDominant" ] }, - { "from": "Standard.LY", + { "from": "Standard.RY", "when": [ "Application.Grounded", "Application.RightHandDominant" ], "to": "Actions.Up", "filters": @@ -109,11 +52,68 @@ ] }, - { "from": "Standard.LY", + { "from": "Standard.RY", "when": "Application.RightHandDominant", "to": "Actions.Up", "filters": "invert" }, + + { "from": "Standard.RY", + "when": ["Application.LeftHandDominant", "!Standard.LY"], + "to": "Actions.TranslateZ" + }, + + { "from": "Standard.RX", + "when": [ + "Application.InHMD", "!Application.AdvancedMovement", "Application.LeftHandDominant", + "Application.SnapTurn", "!Standard.RX" + ], + "to": "Actions.StepYaw", + "filters": + [ + { "type": "deadZone", "min": 0.15 }, + "constrainToInteger", + { "type": "pulse", "interval": 0.25 }, + { "type": "scale", "scale": 22.5 } + ] + }, + { "from": "Standard.RX", "to": "Actions.TranslateX", + "when": [ "Application.AdvancedMovement", "Application.LeftHandDominant" ] + }, + { "from": "Standard.RX", "to": "Actions.Yaw", + "when": [ "!Application.AdvancedMovement", "!Application.SnapTurn", "Application.LeftHandDominant" ] + }, + + { "from": "Standard.LX", + "when": [ "Application.SnapTurn", "Application.LeftHandDominant" ], + "to": "Actions.StepYaw", + "filters": + [ + { "type": "deadZone", "min": 0.15 }, + "constrainToInteger", + { "type": "pulse", "interval": 0.25 }, + { "type": "scale", "scale": 22.5 } + ] + }, + { "from": "Standard.LX", "to": "Actions.Yaw", + "when": [ "!Application.SnapTurn", "Application.LeftHandDominant" ] + }, + + { "from": "Standard.LY", + "when": [ "Application.Grounded", "Application.LeftHandDominant" ], + "to": "Actions.Up", + "filters": + [ + { "type": "deadZone", "min": 0.6 }, + "invert" + ] + }, + + { "from": "Standard.LY", + "when": "Application.LeftHandDominant", + "to": "Actions.Up", + "filters": "invert" + }, { "from": "Standard.Back", "to": "Actions.CycleCamera" }, { "from": "Standard.Start", "to": "Actions.ContextMenu" }, diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index ea0c3e8ad6..600f9a2772 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -239,7 +239,7 @@ Script.include("/~/system/libraries/controllers.js"); // var newTargetPosLocal = Mat4.transformPoint(MyAvatar.getSensorToWorldMatrix(), newTargetPosition); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); if (this.shouldManipulateTarget()) { - var pose = Controller.getPoseValue((this.getDominantHand() ? Controller.Standard.RightHand : Controller.Standard.LeftHand)); + var pose = Controller.getPoseValue((this.getDominantHand() ? Controller.Standard.LeftHand : Controller.Standard.RightHand)); if (pose.valid) { if (!this.manipulating) { if (!this.wasManipulating) { @@ -400,7 +400,7 @@ Script.include("/~/system/libraries/controllers.js"); }; this.shouldShowLaser = function () { - return (_this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false; + return (_this.getDominantTrigger() > TRIGGER_ON_VALUE) ? true : false; }; this.shouldGrab = function () { @@ -409,11 +409,11 @@ Script.include("/~/system/libraries/controllers.js"); this.shouldCancel = function () { // Kill condition : Off hand is <= 15% trigger pull. - return (_this.getOffHandTrigger() <= TRIGGER_OFF_VALUE) ? true : false; + return (_this.getDominantTrigger() <= TRIGGER_OFF_VALUE) ? true : false; }; this.shouldManipulateTarget = function () { - return (_this.getDominantTrigger() > TRIGGER_ON_VALUE) ? true : false; + return (_this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false; }; @@ -486,7 +486,7 @@ Script.include("/~/system/libraries/controllers.js"); }; this.isReady = function (controllerData) { - if (HMD.active && this.hand === this.getOffHand()) { + if (HMD.active && this.hand === this.getDominantHand()) { if (this.notPointingAtEntity(controllerData)) { return makeRunningValues(false, [], []); } diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index 9dcb456541..cd04dc9fd7 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -718,7 +718,7 @@ Script.include("/~/system/libraries/controllers.js"); } this.showReticle = function () { - return (_this.getOffhandY() > TELEPORT_DEADZONE) ? true : false; + return (_this.getDominantY() > TELEPORT_DEADZONE) ? true : false; }; this.shouldTeleport = function () { @@ -727,7 +727,7 @@ Script.include("/~/system/libraries/controllers.js"); this.shouldCancel = function () { //return (_this.getDominantY() < -TELEPORT_DEADZONE || _this.getOffhandY() < -TELEPORT_DEADZONE) ? true : false; - return (_this.getOffhandY() <= TELEPORT_DEADZONE) ? true : false; + return (_this.getDominantY() <= TELEPORT_DEADZONE) ? true : false; }; this.parameters = makeDispatcherModuleParameters( @@ -746,7 +746,7 @@ Script.include("/~/system/libraries/controllers.js"); } var otherModule = this.getOtherModule(); - if (!this.disabled && this.showReticle() && !otherModule.active && this.hand === this.getOffHand()) { + if (!this.disabled && this.showReticle() && !otherModule.active && this.hand === this.getDominantHand()) { this.active = true; this.enterTeleport(); return makeRunningValues(true, [], []); From 1ec887ffc2b63b6584a752affdd31e667aafbcb3 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Wed, 27 Feb 2019 10:51:38 -0800 Subject: [PATCH 45/68] Fix teleportation play area indicator not hiding on cancel. --- scripts/system/controllers/controllerModules/teleport.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index cd04dc9fd7..5a51773930 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -847,8 +847,8 @@ Script.include("/~/system/libraries/controllers.js"); }; this.disableLasers = function() { - _this.setPlayAreaVisible(false, null, true); - _this.setTeleportVisible(false, null, true); + _this.setPlayAreaVisible(false, null, false); + _this.setTeleportVisible(false, null, false); Pointers.disablePointer(_this.teleportParabolaHandVisuals); Pointers.disablePointer(_this.teleportParabolaHandCollisions); Pointers.disablePointer(_this.teleportParabolaHeadVisuals); From 3a5698236b9b3f2435b541534f6d8e5f236c06d0 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Wed, 27 Feb 2019 10:57:35 -0800 Subject: [PATCH 46/68] Swap FarGrab from superpower to alternative version from PR#15043 --- .../controllerModules/farGrabEntity.js | 225 ++++++------------ 1 file changed, 71 insertions(+), 154 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 600f9a2772..55ef4dd922 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -48,7 +48,6 @@ Script.include("/~/system/libraries/controllers.js"); } function FarGrabEntity(hand) { - var _this = this; this.hand = hand; this.grabbing = false; this.targetEntityID = null; @@ -63,6 +62,14 @@ Script.include("/~/system/libraries/controllers.js"); this.reticleMaxY = 0; this.endedGrab = 0; this.MIN_HAPTIC_PULSE_INTERVAL = 500; // ms + this.disabled = false; + var _this = this; + this.leftTrigger = 0.0; + this.rightTrigger = 0.0; + this.initialControllerRotation = Quat.IDENTITY; + this.currentControllerRotation = Quat.IDENTITY; + this.manipulating = false; + this.wasManipulating = false; var FAR_GRAB_JOINTS = [65527, 65528]; // FARGRAB_LEFTHAND_INDEX, FARGRAB_RIGHTHAND_INDEX @@ -78,6 +85,46 @@ Script.include("/~/system/libraries/controllers.js"); 100, makeLaserParams(this.hand, false)); + //enableDispatcherModule("LeftFarGrabEntity", leftFarGrabEntity); + //enableDispatcherModule("RightFarGrabEntity", rightFarGrabEntity); + + this.getOtherModule = function () { + // Used to fetch other module. + return getEnabledModuleByName(this.hand === RIGHT_HAND ? ("LeftFarGrabEntity") : ("RightFarGrabEntity")); + }; + + this.getTargetRotation = function () { + if (this.targetIsNull()) { + return null; + } else { + var props = Entities.getEntityProperties(this.targetEntityID, ["rotation"]); + return props.rotation; + } + }; + + this.getOffhand = function () { + return (this.hand === RIGHT_HAND ? LEFT_HAND : RIGHT_HAND); + } + + this.getOffhandTrigger = function () { + return (_this.hand === RIGHT_HAND ? _this.leftTrigger : _this.rightTrigger); + } + + this.shouldManipulateTarget = function () { + return (_this.getOffhandTrigger() > TRIGGER_ON_VALUE) ? true : false; + }; + + this.calculateEntityRotationManipulation = function (controllerRotation) { + return Quat.multiply(controllerRotation, Quat.inverse(this.initialControllerRotation)); + }; + + this.setJointTranslation = function (newTargetPosLocal) { + MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); + }; + + this.setJointRotation = function (newTargetRotLocal) { + MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], newTargetRotLocal); + }; this.handToController = function () { return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand; @@ -111,7 +158,6 @@ Script.include("/~/system/libraries/controllers.js"); this.currentObjectPosition = targetProps.position; this.currentObjectRotation = targetProps.rotation; this.currentObjectTime = now; - //this.initialEntityRotation = targetProps.rotation; // World frame. this.grabRadius = this.grabbedDistance; this.grabRadialVelocity = 0.0; @@ -145,10 +191,8 @@ Script.include("/~/system/libraries/controllers.js"); Messages.sendLocalMessage('Hifi-unhighlight-entity', JSON.stringify(message)); - //MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); - - var newTargetPosLocal = MyAvatar.worldToJointPoint(targetProps.position); // World frame. - var newTargetRotLocal = targetProps.rotation; // World frame. + var newTargetPosLocal = MyAvatar.worldToJointPoint(targetProps.position); + var newTargetRotLocal = targetProps.rotation; this.setJointTranslation(newTargetPosLocal); this.setJointRotation(newTargetRotLocal); @@ -234,18 +278,23 @@ Script.include("/~/system/libraries/controllers.js"); newTargetPosition = Vec3.sum(newTargetPosition, worldControllerPosition); newTargetPosition = Vec3.sum(newTargetPosition, this.offsetPosition); - // MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], MyAvatar.worldToJointPoint(newTargetPosition)); - - // var newTargetPosLocal = Mat4.transformPoint(MyAvatar.getSensorToWorldMatrix(), newTargetPosition); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); + + // This block handles the user's ability to rotate the object they're FarGrabbing if (this.shouldManipulateTarget()) { - var pose = Controller.getPoseValue((this.getDominantHand() ? Controller.Standard.LeftHand : Controller.Standard.RightHand)); + // Get the pose of the controller that is not grabbing. + var pose = Controller.getPoseValue((this.getOffhand() ? Controller.Standard.RightHand : Controller.Standard.LeftHand)); if (pose.valid) { + // If we weren't manipulating the object yet, initialize the entity's original position. if (!this.manipulating) { + // This will only be triggered if we've let go of the off-hand trigger and pulled it again without ending a grab. + // Need to poll the entity's rotation again here. if (!this.wasManipulating) { - this.initialEntityRotation = this.getTargetRotation(); // Worldframe. + this.initialEntityRotation = this.getTargetRotation(); } - this.initialControllerRotation = Quat.multiply(pose.rotation, MyAvatar.orientation); // Worldframe. + // Save the original controller orientation, we only care about the delta between this rotation and wherever + // the controller rotates, so that we can apply it to the entity's rotation. + this.initialControllerRotation = Quat.multiply(pose.rotation, MyAvatar.orientation); this.manipulating = true; } } @@ -292,6 +341,8 @@ Script.include("/~/system/libraries/controllers.js"); this.targetEntityID = null; this.manipulating = false; this.wasManipulating = false; + var otherModule = this.getOtherModule(); + otherModule.disabled = false; }; this.updateRecommendedArea = function () { @@ -353,148 +404,17 @@ Script.include("/~/system/libraries/controllers.js"); return null; }; - var mappingName = "FarGrab-Mapping-" + Math.random(); - var grabMapping; - - this.setup = function () { - grabMapping = Controller.newMapping(mappingName); - grabMapping.from(Controller.Standard.LT).peek().to(_this.getLeftTrigger); - grabMapping.from(Controller.Standard.RT).peek().to(_this.getRightTrigger); - Controller.enableMapping(mappingName); - }; - - this.cleanup = function () { - grabMapping.disable(); - }; - - this.initialControllerRotation = Quat.IDENTITY; - this.initialEntityRotation = Quat.IDENTITY; - this.manipulating = false; - this.wasManipulating = false; - - this.leftTrigger = 0.0; - this.rightTrigger = 0.0; - - this.getDominantHand = function () { - return (MyAvatar.getDominantHand() === "left") ? LEFT_HAND : RIGHT_HAND; - }; - - this.getOffHand = function () { - return (MyAvatar.getDominantHand() === "left") ? RIGHT_HAND : LEFT_HAND; - }; - - this.getLeftTrigger = function (value) { - _this.leftTrigger = value; - }; - - this.getRightTrigger = function (value) { - _this.rightTrigger = value; - }; - - this.getDominantTrigger = function () { - return (MyAvatar.getDominantHand() === "left") ? (_this.leftTrigger) : (_this.rightTrigger); - }; - - this.getOffHandTrigger = function () { - return (MyAvatar.getDominantHand() === "left") ? (_this.rightTrigger) : (_this.leftTrigger); - }; - - this.shouldShowLaser = function () { - return (_this.getDominantTrigger() > TRIGGER_ON_VALUE) ? true : false; - }; - - this.shouldGrab = function () { - return (_this.getDominantTrigger() > TRIGGER_ON_VALUE && _this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false; - }; - - this.shouldCancel = function () { - // Kill condition : Off hand is <= 15% trigger pull. - return (_this.getDominantTrigger() <= TRIGGER_OFF_VALUE) ? true : false; - }; - - this.shouldManipulateTarget = function () { - return (_this.getOffHandTrigger() > TRIGGER_ON_VALUE) ? true : false; - }; - - - this.getTargetPosition = function () { - if (this.targetIsNull()) { - return null; - } else { - var props = Entities.getEntityProperties(this.targetEntityID, ["position"]); - return props.position; - } - }; - - this.getTargetRotation = function () { - if (this.targetIsNull()) { - return null; - } else { - var props = Entities.getEntityProperties(this.targetEntityID, ["rotation"]); - return props.rotation; - } - }; - - this.getTargetLocalPosition = function () { - if (this.targetIsNull()) { - return null; - } else { - var props = Entities.getEntityProperties(this.targetEntityID, ["localPosition"]); - return props.localPosition; - } - }; - - this.getTargetLocalRotation = function () { - if (this.targetIsNull()) { - return null; - } else { - var props = Entities.getEntityProperties(this.targetEntityID, ["localRotation"]); - return props.localRotation; - } - }; - - this.setTargetPosition = function (newPos) { - if (this.targetIsNull()) { - print("Fargrab Error: No target to edit position."); - return; - } else { - var props = { position: newPos }; - Entities.editEntity(this.targetEntityID, props); - } - }; - - this.setTargetRotation = function (newRot) { - if (this.targetIsNull()) { - print("Fargrab Error: No target to edit rotation."); - return; - } else { - var props = { rotation: newRot }; - Entities.editEntity(this.targetEntityID, props); - } - }; - - this.calculateEntityRotationManipulation = function (controllerRotation) { - return Quat.multiply(controllerRotation, Quat.inverse(this.initialControllerRotation)); - }; - - this.setJointTranslation = function (newTargetPosLocal) { - MyAvatar.setJointTranslation(FAR_GRAB_JOINTS[this.hand], newTargetPosLocal); - }; - - this.setJointRotation = function (newTargetRotLocal) { - MyAvatar.setJointRotation(FAR_GRAB_JOINTS[this.hand], newTargetRotLocal); - }; - this.isReady = function (controllerData) { - if (HMD.active && this.hand === this.getDominantHand()) { + if (HMD.active) { if (this.notPointingAtEntity(controllerData)) { return makeRunningValues(false, [], []); } this.distanceHolding = false; - //if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) { - if (this.shouldShowLaser()) { + if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE && !this.disabled) { + var otherModule = this.getOtherModule(); + otherModule.disabled = true; return makeRunningValues(true, [], []); } else { this.destroyContextOverlay(); @@ -504,8 +424,9 @@ Script.include("/~/system/libraries/controllers.js"); }; this.run = function (controllerData) { - //if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.targetIsNull()) { - if (this.shouldCancel() || this.targetIsNull()) { + this.leftTrigger = controllerData.triggerValues[LEFT_HAND]; + this.rightTrigger = controllerData.triggerValues[RIGHT_HAND]; + if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.targetIsNull()) { this.endFarGrabEntity(controllerData); return makeRunningValues(false, [], []); } @@ -552,7 +473,7 @@ Script.include("/~/system/libraries/controllers.js"); var rayPickInfo = controllerData.rayPicks[this.hand]; if (rayPickInfo.type === Picks.INTERSECTED_ENTITY) { - if (this.shouldGrab()) { + if (controllerData.triggerClicks[this.hand]) { var entityID = rayPickInfo.objectID; var targetProps = Entities.getEntityProperties(entityID, DISPATCHER_PROPERTIES); if (targetProps.href !== "") { @@ -654,15 +575,11 @@ Script.include("/~/system/libraries/controllers.js"); var leftFarGrabEntity = new FarGrabEntity(LEFT_HAND); var rightFarGrabEntity = new FarGrabEntity(RIGHT_HAND); - leftFarGrabEntity.setup(); - rightFarGrabEntity.setup(); enableDispatcherModule("LeftFarGrabEntity", leftFarGrabEntity); enableDispatcherModule("RightFarGrabEntity", rightFarGrabEntity); function cleanup() { - leftFarGrabEntity.cleanup(); - rightFarGrabEntity.cleanup(); disableDispatcherModule("LeftFarGrabEntity"); disableDispatcherModule("RightFarGrabEntity"); } From cbd841a14de18549d5ddabc68ef8ab28080334f5 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 11 Mar 2019 16:22:48 -0700 Subject: [PATCH 47/68] Update gearing system. --- interface/src/avatar/MyAvatar.cpp | 89 ++++++++++++++++++++++---- interface/src/avatar/MyAvatar.h | 1 + libraries/shared/src/AvatarConstants.h | 5 ++ 3 files changed, 81 insertions(+), 14 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 14e9f1a987..9c1c5b49c9 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3312,6 +3312,27 @@ void MyAvatar::updateOrientation(float deltaTime) { // return scaledSpeed; //} +float MyAvatar::calculateGearedSpeed(const float driveKey) { + if (driveKey > getDriveGear5()) { + return 1.0f; + } + else if (driveKey > getDriveGear4()) { + return 0.8f; + } + else if (driveKey > getDriveGear3()) { + return 0.6f; + } + else if (driveKey > getDriveGear2()) { + return 0.4f; + } + else if (driveKey > getDriveGear1()) { + return 0.2f; + } + else { + return 0.0f; + } +} + glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 right) { float stickFullOn = 0.95f; auto zSpeed = getDriveKey(TRANSLATE_Z); @@ -3330,8 +3351,8 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig } case CONTROLS_ANALOG: if (zSpeed || xSpeed) { - glm::vec3 scaledForward = getSensorToWorldScale() * zSpeed * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; - glm::vec3 scaledRight = getSensorToWorldScale() * xSpeed * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; + glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; + glm::vec3 scaledRight = getSensorToWorldScale() * calculateGearedSpeed(xSpeed) * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; direction = scaledForward + scaledRight; return direction; } else { @@ -3339,8 +3360,8 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig } case CONTROLS_ANALOG_PLUS: if (zSpeed || xSpeed) { - glm::vec3 scaledForward = getSensorToWorldScale() * zSpeed * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; - glm::vec3 scaledRight = getSensorToWorldScale() * xSpeed * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; + glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; + glm::vec3 scaledRight = getSensorToWorldScale() * calculateGearedSpeed(xSpeed) * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; direction = scaledForward + scaledRight; return direction; } else { @@ -3987,11 +4008,19 @@ void MyAvatar::setDriveGear1(float shiftPoint) { return; } if (shiftPoint > 1.0 || shiftPoint < 0) return; - _driveGear1 = (shiftPoint <= _driveGear2) ? shiftPoint : _driveGear1; + _driveGear1 = (shiftPoint < _driveGear2) ? shiftPoint : _driveGear1; } float MyAvatar::getDriveGear1() { - return _driveGear1; + switch (_controlSchemeIndex) { + case CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_1; + case CONTROLS_ANALOG_PLUS: + return _driveGear1; + case CONTROLS_DEFAULT: + default: + return 1.0f; + } } void MyAvatar::setDriveGear2(float shiftPoint) { @@ -4000,11 +4029,19 @@ void MyAvatar::setDriveGear2(float shiftPoint) { return; } if (shiftPoint > 1.0 || shiftPoint < 0) return; - _driveGear2 = (shiftPoint <= _driveGear3 && shiftPoint >= _driveGear1) ? shiftPoint : _driveGear2; + _driveGear2 = (shiftPoint < _driveGear3 && shiftPoint >= _driveGear1) ? shiftPoint : _driveGear2; } float MyAvatar::getDriveGear2() { - return _driveGear2; + switch (_controlSchemeIndex) { + case CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_2; + case CONTROLS_ANALOG_PLUS: + return _driveGear2; + case CONTROLS_DEFAULT: + default: + return 1.0f; + } } void MyAvatar::setDriveGear3(float shiftPoint) { @@ -4013,11 +4050,19 @@ void MyAvatar::setDriveGear3(float shiftPoint) { return; } if (shiftPoint > 1.0 || shiftPoint < 0) return; - _driveGear3 = (shiftPoint <= _driveGear4 && shiftPoint >= _driveGear2) ? shiftPoint : _driveGear3; + _driveGear3 = (shiftPoint < _driveGear4 && shiftPoint >= _driveGear2) ? shiftPoint : _driveGear3; } float MyAvatar::getDriveGear3() { - return _driveGear3; + switch (_controlSchemeIndex) { + case CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_3; + case CONTROLS_ANALOG_PLUS: + return _driveGear3; + case CONTROLS_DEFAULT: + default: + return 1.0f; + } } void MyAvatar::setDriveGear4(float shiftPoint) { @@ -4026,11 +4071,19 @@ void MyAvatar::setDriveGear4(float shiftPoint) { return; } if (shiftPoint > 1.0 || shiftPoint < 0) return; - _driveGear4 = (shiftPoint <= _driveGear5 && shiftPoint >= _driveGear3) ? shiftPoint : _driveGear4; + _driveGear4 = (shiftPoint < _driveGear5 && shiftPoint >= _driveGear3) ? shiftPoint : _driveGear4; } float MyAvatar::getDriveGear4() { - return _driveGear4; + switch (_controlSchemeIndex) { + case CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_4; + case CONTROLS_ANALOG_PLUS: + return _driveGear4; + case CONTROLS_DEFAULT: + default: + return 1.0f; + } } void MyAvatar::setDriveGear5(float shiftPoint) { @@ -4039,11 +4092,19 @@ void MyAvatar::setDriveGear5(float shiftPoint) { return; } if (shiftPoint > 1.0 || shiftPoint < 0) return; - _driveGear5 = (shiftPoint >= _driveGear4) ? shiftPoint : _driveGear5; + _driveGear5 = (shiftPoint > _driveGear4) ? shiftPoint : _driveGear5; } float MyAvatar::getDriveGear5() { - return _driveGear5; + switch (_controlSchemeIndex) { + case CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_5; + case CONTROLS_ANALOG_PLUS: + return _driveGear5; + case CONTROLS_DEFAULT: + default: + return 1.0f; + } } bool MyAvatar::getFlyingHMDPref() { diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index cee0a33fb4..0da2171ca3 100755 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1877,6 +1877,7 @@ private: // private methods void updateOrientation(float deltaTime); glm::vec3 calculateScaledDirection(); + float calculateGearedSpeed(const float driveKey); glm::vec3 scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 right); void updateActionMotor(float deltaTime); void updatePosition(float deltaTime); diff --git a/libraries/shared/src/AvatarConstants.h b/libraries/shared/src/AvatarConstants.h index 1518497961..a150eb34da 100644 --- a/libraries/shared/src/AvatarConstants.h +++ b/libraries/shared/src/AvatarConstants.h @@ -76,6 +76,11 @@ const float ANALOG_AVATAR_MAX_WALKING_SPEED = 2.6f; // meters / second const float ANALOG_AVATAR_MAX_WALKING_BACKWARD_SPEED = 2.2f; // meters / second const float ANALOG_AVATAR_MAX_FLYING_SPEED = 30.0f; // meters / second const float ANALOG_AVATAR_MAX_SPRINT_SPEED = 3.0f; // meters / second +const float ANALOG_AVATAR_GEAR_1 = 0.2f; // meters / second +const float ANALOG_AVATAR_GEAR_2 = 0.4f; // meters / second +const float ANALOG_AVATAR_GEAR_3 = 0.6f; // meters / second +const float ANALOG_AVATAR_GEAR_4 = 0.8f; // meters / second +const float ANALOG_AVATAR_GEAR_5 = 1.0f; // meters / second const float ANALOG_PLUS_AVATAR_MAX_WALKING_SPEED = 3.3f; // meters / second const float ANALOG_PLUS_AVATAR_MAX_WALKING_BACKWARD_SPEED = 2.42f; // meters / second From 6ce955d915a4fe5ba2c3215d017e1fb5716b8528 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Mon, 11 Mar 2019 18:19:43 -0700 Subject: [PATCH 48/68] Fix hand-relative movement after hand dominance notion swap. --- interface/src/avatar/MyAvatar.cpp | 52 +++++++++++-------------------- interface/src/avatar/MyAvatar.h | 2 +- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index dfeae14cca..17f90d8542 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2527,8 +2527,8 @@ controller::Pose MyAvatar::getControllerPoseInAvatarFrame(controller::Action act } } -glm::quat MyAvatar::getDominantHandRotation() const { - auto hand = (getDominantHand() == DOMINANT_RIGHT_HAND) ? controller::Action::RIGHT_HAND : controller::Action::LEFT_HAND; +glm::quat MyAvatar::getOffHandRotation() const { + auto hand = (getDominantHand() == DOMINANT_RIGHT_HAND) ? controller::Action::LEFT_HAND : controller::Action::RIGHT_HAND; auto pose = getControllerPoseInAvatarFrame(hand); return pose.rotation; } @@ -3317,23 +3317,25 @@ void MyAvatar::updateOrientation(float deltaTime) { //} float MyAvatar::calculateGearedSpeed(const float driveKey) { - if (driveKey > getDriveGear5()) { - return 1.0f; + float absDriveKey = abs(driveKey); + float sign = (driveKey < 0.0f) ? -1.0f : 1.0f; + if (absDriveKey > getDriveGear5()) { + return sign * 1.0f; } - else if (driveKey > getDriveGear4()) { - return 0.8f; + else if (absDriveKey > getDriveGear4()) { + return sign * 0.8f; } - else if (driveKey > getDriveGear3()) { - return 0.6f; + else if (absDriveKey > getDriveGear3()) { + return sign * 0.6f; } - else if (driveKey > getDriveGear2()) { - return 0.4f; + else if (absDriveKey > getDriveGear2()) { + return sign * 0.4f; } - else if (driveKey > getDriveGear1()) { - return 0.2f; + else if (absDriveKey > getDriveGear1()) { + return sign * 0.2f; } else { - return 0.0f; + return sign * 0.0f; } } @@ -3385,21 +3387,19 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ glm::vec3 forward, right; if (qApp->isHMDMode()) { - auto handRotation = getDominantHandRotation(); + auto handRotation = getOffHandRotation(); 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. + glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? 1.0f : -1.0f)); switch (getMovementReference()) { case MOVEMENT_HAND_RELATIVE: forward = (handRotation * controllerForward); right = (handRotation * controllerRight); break; case MOVEMENT_HAND_RELATIVE_LEVELED: - handRotation = cancelOutRoll(handRotation); forward = (handRotation * controllerForward); - //forward = glm::normalize(forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y)); + forward = glm::normalize(forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y)); right = (handRotation * controllerRight); - //right = glm::normalize(right - (glm::dot(right, Vectors::UNIT_Y) * Vectors::UNIT_Y)); + right = glm::normalize(right - (glm::dot(right, Vectors::UNIT_Y) * Vectors::UNIT_Y)); break; case MOVEMENT_HMD_RELATIVE: default: @@ -3411,20 +3411,6 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ 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(); - glm::vec3 controllerForward(0.0f, 1.0f, 0.0f); - glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? -1.0f : 1.0f)); - forward = (handRotation * controllerForward); - right = (handRotation * controllerRight); - } - else { - forward = IDENTITY_FORWARD; - right = IDENTITY_RIGHT; - } - glm::vec3 direction = scaleMotorSpeed(forward, right); // RKNOTE: This may need to be changed later... diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 858a7d1c0b..4a248d27ae 100755 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -953,7 +953,7 @@ public: controller::Pose getControllerPoseInSensorFrame(controller::Action action) const; controller::Pose getControllerPoseInWorldFrame(controller::Action action) const; controller::Pose getControllerPoseInAvatarFrame(controller::Action action) const; - glm::quat getDominantHandRotation() const; + glm::quat getOffHandRotation() const; bool hasDriveInput() const; From 38fe22e4f749cf2d756a3d80d0a62b267c70c3f0 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 14 Mar 2019 16:27:40 -0700 Subject: [PATCH 49/68] Fix compiler error for Linux. --- interface/src/avatar/MyAvatar.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 17f90d8542..cc13e75a0f 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3996,7 +3996,7 @@ void MyAvatar::setDriveGear1(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear1", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear1 = (shiftPoint < _driveGear2) ? shiftPoint : _driveGear1; } @@ -4017,7 +4017,7 @@ void MyAvatar::setDriveGear2(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear2", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear2 = (shiftPoint < _driveGear3 && shiftPoint >= _driveGear1) ? shiftPoint : _driveGear2; } @@ -4038,7 +4038,7 @@ void MyAvatar::setDriveGear3(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear3", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear3 = (shiftPoint < _driveGear4 && shiftPoint >= _driveGear2) ? shiftPoint : _driveGear3; } @@ -4059,7 +4059,7 @@ void MyAvatar::setDriveGear4(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear4", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear4 = (shiftPoint < _driveGear5 && shiftPoint >= _driveGear3) ? shiftPoint : _driveGear4; } @@ -4080,7 +4080,7 @@ void MyAvatar::setDriveGear5(float shiftPoint) { QMetaObject::invokeMethod(this, "setDriveGear5", Q_ARG(float, shiftPoint)); return; } - if (shiftPoint > 1.0 || shiftPoint < 0) return; + if (shiftPoint > 1.0f || shiftPoint < 0.0f) return; _driveGear5 = (shiftPoint > _driveGear4) ? shiftPoint : _driveGear5; } From c9ade7ccb8ab2ce1ce5682bc796c9843dd1716bb Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Fri, 15 Mar 2019 16:09:01 -0700 Subject: [PATCH 50/68] Add grip to fargrab. --- .../controllers/controllerModules/farGrabEntity.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index 953083302a..bde5f8a8a8 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -64,8 +64,6 @@ Script.include("/~/system/libraries/controllers.js"); this.MIN_HAPTIC_PULSE_INTERVAL = 500; // ms this.disabled = false; var _this = this; - this.leftTrigger = 0.0; - this.rightTrigger = 0.0; this.initialControllerRotation = Quat.IDENTITY; this.currentControllerRotation = Quat.IDENTITY; this.manipulating = false; @@ -103,13 +101,9 @@ Script.include("/~/system/libraries/controllers.js"); return (this.hand === RIGHT_HAND ? LEFT_HAND : RIGHT_HAND); } - this.getOffhandTrigger = function () { - return (_this.hand === RIGHT_HAND ? _this.leftTrigger : _this.rightTrigger); - } - // Activation criteria for rotating a fargrabbed entity. If we're changing the mapping, this is where to do it. - this.shouldManipulateTarget = function () { - return (_this.getOffhandTrigger() > TRIGGER_ON_VALUE) ? true : false; + this.shouldManipulateTarget = function (controllerData) { + return (controllerData.triggerValues[this.getOffhand()] > TRIGGER_ON_VALUE || controllerdata.secondaryValues[this.getOffhand()] > TRIGGER_ON_VALUE) ? true : false; }; // Get the delta between the current rotation and where the controller was when manipulation started. @@ -284,7 +278,7 @@ Script.include("/~/system/libraries/controllers.js"); var newTargetPosLocal = MyAvatar.worldToJointPoint(newTargetPosition); // This block handles the user's ability to rotate the object they're FarGrabbing - if (this.shouldManipulateTarget()) { + if (this.shouldManipulateTarget(controllerData)) { // Get the pose of the controller that is not grabbing. var pose = Controller.getPoseValue((this.getOffhand() ? Controller.Standard.RightHand : Controller.Standard.LeftHand)); if (pose.valid) { @@ -430,8 +424,6 @@ Script.include("/~/system/libraries/controllers.js"); }; this.run = function (controllerData) { - this.leftTrigger = controllerData.triggerValues[LEFT_HAND]; - this.rightTrigger = controllerData.triggerValues[RIGHT_HAND]; if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.targetIsNull()) { this.endFarGrabEntity(controllerData); return makeRunningValues(false, [], []); From 0bb10544a3f5cff03c28c05f313d5ea02e5976b9 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Mar 2019 11:43:26 -0700 Subject: [PATCH 51/68] Prevent accidental rotation when teleporting. --- interface/resources/controllers/vive.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/interface/resources/controllers/vive.json b/interface/resources/controllers/vive.json index d6d8f9f929..4e22ee1bd8 100644 --- a/interface/resources/controllers/vive.json +++ b/interface/resources/controllers/vive.json @@ -16,7 +16,8 @@ "invert" ] , "to": "Standard.LY" }, - { "from": "Vive.LX", "when": "Vive.LS", "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.LX" }, + { "from": "Vive.LX", "when": ["Vive.LS", "Application.RightHandDominant"], "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.LX" }, + { "from": "Vive.LX", "when": ["Vive.LS", "Vive.LSX", "!Vive.LSY", "Application.LeftHandDominant"], "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.LX" }, { "from": "Vive.LT", "to": "Standard.LT", "filters": [ @@ -39,7 +40,8 @@ "invert" ] , "to": "Standard.RY" }, - { "from": "Vive.RX", "when": "Vive.RS", "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.RX" }, + { "from": "Vive.RX", "when": ["Vive.RS", "Application.LeftHandDominant"], "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.RX" }, + { "from": "Vive.RX", "when": ["Vive.RS", "Vive.RSX", "!Vive.RSY", "Application.RightHandDominant"], "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.RX" }, { "from": "Vive.RT", "to": "Standard.RT", "filters": [ From 543d53ecdeea39d7a78ec1026267794e96e2f5c7 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Mar 2019 13:12:15 -0700 Subject: [PATCH 52/68] Add ability to toggle strafing. --- interface/resources/controllers/standard.json | 4 ++-- interface/src/Application.cpp | 6 +++++- interface/src/avatar/MyAvatar.cpp | 11 +++++++++++ interface/src/avatar/MyAvatar.h | 15 ++++++++++++++- interface/src/ui/PreferencesDialog.cpp | 5 +++++ 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 7e23379394..dc704a69f7 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -21,7 +21,7 @@ ] }, { "from": "Standard.LX", "to": "Actions.TranslateX", - "when": [ "Application.AdvancedMovement", "Application.RightHandDominant" ] + "when": [ "Application.AdvancedMovement", "Application.StrafeEnabled", "Application.RightHandDominant" ] }, { "from": "Standard.LX", "to": "Actions.Yaw", "when": [ "!Application.AdvancedMovement", "!Application.SnapTurn", "Application.RightHandDominant" ] @@ -78,7 +78,7 @@ ] }, { "from": "Standard.RX", "to": "Actions.TranslateX", - "when": [ "Application.AdvancedMovement", "Application.LeftHandDominant" ] + "when": [ "Application.AdvancedMovement", "Application.StrafeEnabled", "Application.LeftHandDominant" ] }, { "from": "Standard.RX", "to": "Actions.Yaw", "when": [ "!Application.AdvancedMovement", "!Application.SnapTurn", "Application.LeftHandDominant" ] diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 493c5c750b..6d18e62179 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -701,6 +701,7 @@ static const QString STATE_PLATFORM_MAC = "PlatformMac"; static const QString STATE_PLATFORM_ANDROID = "PlatformAndroid"; static const QString STATE_LEFT_HAND_DOMINANT = "LeftHandDominant"; static const QString STATE_RIGHT_HAND_DOMINANT = "RightHandDominant"; +static const QString STATE_STRAFE_ENABLED = "StrafeEnabled"; // Statically provided display and input plugins extern DisplayPluginList getDisplayPlugins(); @@ -902,7 +903,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { controller::StateController::setStateVariables({ { STATE_IN_HMD, STATE_CAMERA_FULL_SCREEN_MIRROR, STATE_CAMERA_FIRST_PERSON, STATE_CAMERA_THIRD_PERSON, STATE_CAMERA_ENTITY, STATE_CAMERA_INDEPENDENT, STATE_SNAP_TURN, STATE_ADVANCED_MOVEMENT_CONTROLS, STATE_GROUNDED, STATE_NAV_FOCUSED, - STATE_PLATFORM_WINDOWS, STATE_PLATFORM_MAC, STATE_PLATFORM_ANDROID, STATE_LEFT_HAND_DOMINANT, STATE_RIGHT_HAND_DOMINANT } }); + STATE_PLATFORM_WINDOWS, STATE_PLATFORM_MAC, STATE_PLATFORM_ANDROID, STATE_LEFT_HAND_DOMINANT, STATE_RIGHT_HAND_DOMINANT, STATE_STRAFE_ENABLED } }); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -1741,6 +1742,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _applicationStateDevice->setInputVariant(STATE_RIGHT_HAND_DOMINANT, []() -> float { return qApp->getMyAvatar()->getDominantHand() == "right" ? 1 : 0; }); + _applicationStateDevice->setInputVariant(STATE_STRAFE_ENABLED, []() -> float { + return qApp->getMyAvatar()->getStrafeEnabled() ? 1 : 0; + }); _applicationStateDevice->setInputVariant(STATE_GROUNDED, []() -> float { return qApp->getMyAvatar()->getCharacterController()->onGround() ? 1 : 0; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index cc13e75a0f..c2c1c1a977 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -155,6 +155,7 @@ MyAvatar::MyAvatar(QThread* thread) : _prevShouldDrawHead(true), _audioListenerMode(FROM_HEAD), _dominantHandSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "dominantHand", DOMINANT_RIGHT_HAND), + _strafeEnabledSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "strafeEnabled", DEFAULT_STRAFE_ENABLED), _hmdAvatarAlignmentTypeSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "hmdAvatarAlignmentType", DEFAULT_HMD_AVATAR_ALIGNMENT_TYPE), _headPitchSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "", 0.0f), _scaleSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "scale", _targetScale), @@ -329,6 +330,14 @@ QString MyAvatar::getDominantHand() const { return _dominantHand.get(); } +void MyAvatar::setStrafeEnabled(bool enabled) { + _strafeEnabled.set(enabled); +} + +bool MyAvatar::getStrafeEnabled() const { + return _strafeEnabled.get(); +} + void MyAvatar::setDominantHand(const QString& hand) { if (hand == DOMINANT_LEFT_HAND || hand == DOMINANT_RIGHT_HAND) { _dominantHand.set(hand); @@ -1262,6 +1271,7 @@ void MyAvatar::resizeAvatarEntitySettingHandles(uint32_t maxIndex) { void MyAvatar::saveData() { _dominantHandSetting.set(getDominantHand()); + _strafeEnabledSetting.set(getStrafeEnabled()); _hmdAvatarAlignmentTypeSetting.set(getHmdAvatarAlignmentType()); _headPitchSetting.set(getHead()->getBasePitch()); _scaleSetting.set(_targetScale); @@ -1882,6 +1892,7 @@ void MyAvatar::loadData() { setCollisionSoundURL(_collisionSoundURLSetting.get(QUrl(DEFAULT_AVATAR_COLLISION_SOUND_URL)).toString()); setSnapTurn(_useSnapTurnSetting.get()); setDominantHand(_dominantHandSetting.get(DOMINANT_RIGHT_HAND).toLower()); + setStrafeEnabled(_strafeEnabledSetting.get(DEFAULT_STRAFE_ENABLED)); setHmdAvatarAlignmentType(_hmdAvatarAlignmentTypeSetting.get(DEFAULT_HMD_AVATAR_ALIGNMENT_TYPE).toLower()); setUserHeight(_userHeightSetting.get(DEFAULT_AVATAR_HEIGHT)); setTargetScale(_scaleSetting.get()); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 4a248d27ae..7a7e9e2c79 100755 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -272,6 +272,8 @@ class MyAvatar : public Avatar { const float DEFAULT_GEAR_3 = 0.8f; const float DEFAULT_GEAR_4 = 0.9f; const float DEFAULT_GEAR_5 = 1.0f; + + const bool DEFAULT_STRAFE_ENABLED = true; public: enum DriveKeys { TRANSLATE_X = 0, @@ -546,7 +548,16 @@ public: * @returns {string} */ Q_INVOKABLE QString getDominantHand() const; - + /**jsdoc + * @function MyAVatar.setStrafeEnabled + * @param {bool} enabled + */ + Q_INVOKABLE void setStrafeEnabled(bool enabled); + /**jsdoc + * @function MyAvatar.getStrafeEnabled + * @returns {bool} + */ + Q_INVOKABLE bool getStrafeEnabled() const; /**jsdoc * @function MyAvatar.setHmdAvatarAlignmentType * @param {string} hand @@ -1909,6 +1920,7 @@ private: bool _useSnapTurn { true }; ThreadSafeValueCache _dominantHand { DOMINANT_RIGHT_HAND }; ThreadSafeValueCache _hmdAvatarAlignmentType { DEFAULT_HMD_AVATAR_ALIGNMENT_TYPE }; + ThreadSafeValueCache _strafeEnabled{ DEFAULT_STRAFE_ENABLED }; const float ROLL_CONTROL_DEAD_ZONE_DEFAULT = 8.0f; // degrees const float ROLL_CONTROL_RATE_DEFAULT = 114.0f; // degrees / sec @@ -2089,6 +2101,7 @@ private: TimePoint _nextTraitsSendWindow; Setting::Handle _dominantHandSetting; + Setting::Handle _strafeEnabledSetting; Setting::Handle _hmdAvatarAlignmentTypeSetting; Setting::Handle _headPitchSetting; Setting::Handle _scaleSetting; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 240d4a43d8..053b3b582a 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -266,6 +266,11 @@ void setupPreferences() { auto preference = new CheckPreference(VR_MOVEMENT, "Walking", getter, setter); preferences->addPreference(preference); } + { + auto getter = [myAvatar]()->bool { return myAvatar->getStrafeEnabled(); }; + auto setter = [myAvatar](bool value) { myAvatar->setStrafeEnabled(value); }; + preferences->addPreference(new CheckPreference(VR_MOVEMENT, "Strafing", getter, setter)); + } { auto getter = [myAvatar]()->bool { return myAvatar->getFlyingHMDPref(); }; auto setter = [myAvatar](bool value) { myAvatar->setFlyingHMDPref(value); }; From 8f5a8d0caafded548a920550516e732137fa30ba Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Mar 2019 14:38:11 -0700 Subject: [PATCH 53/68] Fix typo that broke fargrab. Grip or Trigger on off hand will now manipulate. --- scripts/system/controllers/controllerModules/farGrabEntity.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/controllers/controllerModules/farGrabEntity.js b/scripts/system/controllers/controllerModules/farGrabEntity.js index bde5f8a8a8..ecafa3cb26 100644 --- a/scripts/system/controllers/controllerModules/farGrabEntity.js +++ b/scripts/system/controllers/controllerModules/farGrabEntity.js @@ -103,7 +103,7 @@ Script.include("/~/system/libraries/controllers.js"); // Activation criteria for rotating a fargrabbed entity. If we're changing the mapping, this is where to do it. this.shouldManipulateTarget = function (controllerData) { - return (controllerData.triggerValues[this.getOffhand()] > TRIGGER_ON_VALUE || controllerdata.secondaryValues[this.getOffhand()] > TRIGGER_ON_VALUE) ? true : false; + return (controllerData.triggerValues[this.getOffhand()] > TRIGGER_ON_VALUE || controllerData.secondaryValues[this.getOffhand()] > TRIGGER_ON_VALUE) ? true : false; }; // Get the delta between the current rotation and where the controller was when manipulation started. From 08bc47d7224fd420fa502b837516ade9d723bf9a Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Mar 2019 15:06:03 -0700 Subject: [PATCH 54/68] Disable tablet button on off hand (translation hand). --- scripts/system/tablet-ui/tabletUI.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index 60848224bb..9f59c0ec6e 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -291,7 +291,7 @@ var clickMapping = Controller.newMapping('tabletToggle-click'); var wantsMenu = 0; clickMapping.from(function () { return wantsMenu; }).to(Controller.Actions.ContextMenu); - clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().to(function (clicked) { + clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().when(Controller.Hardware.Application.RightHandDominant).to(function (clicked) { if (clicked) { //activeHudPoint2d(Controller.Standard.RightHand); Messages.sendLocalMessage("toggleHand", Controller.Standard.RightHand); @@ -299,7 +299,7 @@ wantsMenu = clicked; }); - clickMapping.from(Controller.Standard.LeftSecondaryThumb).peek().to(function (clicked) { + clickMapping.from(Controller.Standard.LeftSecondaryThumb).peek().when(Controller.Hardware.Application.LeftHandDominant).to(function (clicked) { if (clicked) { //activeHudPoint2d(Controller.Standard.LeftHand); Messages.sendLocalMessage("toggleHand", Controller.Standard.LeftHand); From 7a8dfe0aafd3548d90d4272802c1feabf573cd0c Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Mar 2019 15:06:21 -0700 Subject: [PATCH 55/68] Fix run speeds. --- interface/src/avatar/MyAvatar.cpp | 44 +++++++++- interface/src/avatar/MyAvatar.h | 10 +++ interface/src/ui/PreferencesDialog.cpp | 112 ++++++++++++++----------- libraries/shared/src/AvatarConstants.h | 8 +- 4 files changed, 118 insertions(+), 56 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index c2c1c1a977..8b3a9ce819 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -177,6 +177,8 @@ MyAvatar::MyAvatar(QThread* thread) : _driveGear3Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear3", _driveGear3), _driveGear4Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear4", _driveGear4), _driveGear5Setting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "driveGear5", _driveGear5), + _analogWalkSpeedSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "analogWalkSpeed", _analogWalkSpeed.get()), + _analogPlusWalkSpeedSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "analogPlusWalkSpeed", _analogPlusWalkSpeed.get()), _controlSchemeIndexSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "controlSchemeIndex", _controlSchemeIndex), _userRecenterModelSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "userRecenterModel", USER_RECENTER_MODEL_AUTO) { @@ -1301,6 +1303,8 @@ void MyAvatar::saveData() { _driveGear3Setting.set(getDriveGear3()); _driveGear4Setting.set(getDriveGear4()); _driveGear5Setting.set(getDriveGear5()); + _analogWalkSpeedSetting.set(getAnalogWalkSpeed()); + _analogPlusWalkSpeedSetting.set(getAnalogPlusWalkSpeed()); _controlSchemeIndexSetting.set(getControlSchemeIndex()); _userRecenterModelSetting.set(userRecenterModelToString(getUserRecenterModel())); @@ -1886,6 +1890,8 @@ void MyAvatar::loadData() { setDriveGear4(firstRunVal.get() ? DEFAULT_GEAR_4 : _driveGear4Setting.get()); setDriveGear5(firstRunVal.get() ? DEFAULT_GEAR_5 : _driveGear5Setting.get()); setControlSchemeIndex(firstRunVal.get() ? CONTROLS_DEFAULT : _controlSchemeIndexSetting.get()); + setAnalogWalkSpeed(firstRunVal.get() ? ANALOG_AVATAR_MAX_WALKING_SPEED : _analogWalkSpeedSetting.get()); + setAnalogPlusWalkSpeed(firstRunVal.get() ? ANALOG_PLUS_AVATAR_MAX_WALKING_SPEED : _analogPlusWalkSpeedSetting.get()); setFlyingEnabled(getFlyingEnabled()); setDisplayName(_displayNameSetting.get()); @@ -3351,7 +3357,7 @@ float MyAvatar::calculateGearedSpeed(const float driveKey) { } glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 right) { - float stickFullOn = 0.95f; + float stickFullOn = 0.85f; auto zSpeed = getDriveKey(TRANSLATE_Z); auto xSpeed = getDriveKey(TRANSLATE_X); glm::vec3 direction; @@ -4870,6 +4876,42 @@ float MyAvatar::getSprintSpeed() const { } } +void MyAvatar::setAnalogWalkSpeed(float value) { + _analogWalkSpeed.set(value); + // Sprint speed for Analog should be double walk speed. + _analogSprintSpeed.set(value * 2.0f); +} + +float MyAvatar::getAnalogWalkSpeed() const { + return _analogWalkSpeed.get(); +} + +void MyAvatar::setAnalogSprintSpeed(float value) { + _analogSprintSpeed.set(value); +} + +float MyAvatar::getAnalogSprintSpeed() const { + return _analogSprintSpeed.get(); +} + +void MyAvatar::setAnalogPlusWalkSpeed(float value) { + _analogPlusWalkSpeed.set(value); + // Sprint speed for Analog Plus should be double walk speed. + _analogPlusSprintSpeed.set(value * 2.0f); +} + +float MyAvatar::getAnalogPlusWalkSpeed() const { + return _analogPlusWalkSpeed.get(); +} + +void MyAvatar::setAnalogPlusSprintSpeed(float value) { + _analogPlusSprintSpeed.set(value); +} + +float MyAvatar::getAnalogPlusSprintSpeed() const { + return _analogPlusSprintSpeed.get(); +} + void MyAvatar::setSitStandStateChange(bool stateChanged) { _sitStandStateChange = stateChanged; } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 7a7e9e2c79..b7b35ef637 100755 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -1274,6 +1274,14 @@ public: float getWalkBackwardSpeed() const; void setSprintSpeed(float value); float getSprintSpeed() const; + void setAnalogWalkSpeed(float value); + float getAnalogWalkSpeed() const; + void setAnalogSprintSpeed(float value); + float getAnalogSprintSpeed() const; + void setAnalogPlusWalkSpeed(float value); + float getAnalogPlusWalkSpeed() const; + void setAnalogPlusSprintSpeed(float value); + float getAnalogPlusSprintSpeed() const; void setSitStandStateChange(bool stateChanged); float getSitStandStateChange() const; void updateSitStandState(float newHeightReading, float dt); @@ -2123,6 +2131,8 @@ private: Setting::Handle _driveGear3Setting; Setting::Handle _driveGear4Setting; Setting::Handle _driveGear5Setting; + Setting::Handle _analogWalkSpeedSetting; + Setting::Handle _analogPlusWalkSpeedSetting; Setting::Handle _controlSchemeIndexSetting; std::vector> _avatarEntityIDSettings; std::vector> _avatarEntityDataSettings; diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 053b3b582a..81f018c119 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -314,6 +314,16 @@ void setupPreferences() { preference->setItems(items); preferences->addPreference(preference); } + { + auto getter = [myAvatar]()->float { return myAvatar->getAnalogPlusWalkSpeed(); }; + auto setter = [myAvatar](float value) { myAvatar->setAnalogPlusWalkSpeed(value); }; + auto preference = new SpinnerSliderPreference(VR_MOVEMENT, "Analog++ Walk Speed", getter, setter); + preference->setMin(6.0f); + preference->setMax(30.0f); + preference->setStep(1); + preference->setDecimals(2); + preferences->addPreference(preference); + } { auto getter = [myAvatar]()->bool { return myAvatar->getShowPlayArea(); }; auto setter = [myAvatar](bool value) { myAvatar->setShowPlayArea(value); }; @@ -369,57 +379,57 @@ void setupPreferences() { preferences->addPreference(preference); } - static const QString ACCEL_CURVE{ "Acceleration Step Function" }; - { - auto getter = [myAvatar]()->float { return myAvatar->getDriveGear1(); }; - auto setter = [myAvatar](float value) { myAvatar->setDriveGear1(value); }; - auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 1", getter, setter); - preference->setMin(0.0f); - preference->setMax(1.0f); - preference->setStep(1); - preference->setDecimals(2); - preferences->addPreference(preference); - } - { - auto getter = [myAvatar]()->float { return myAvatar->getDriveGear2(); }; - auto setter = [myAvatar](float value) { myAvatar->setDriveGear2(value); }; - auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 2", getter, setter); - preference->setMin(0.0f); - preference->setMax(1.0f); - preference->setStep(1); - preference->setDecimals(2); - preferences->addPreference(preference); - } - { - auto getter = [myAvatar]()->float { return myAvatar->getDriveGear3(); }; - auto setter = [myAvatar](float value) { myAvatar->setDriveGear3(value); }; - auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 3", getter, setter); - preference->setMin(0.0f); - preference->setMax(1.0f); - preference->setStep(1); - preference->setDecimals(2); - preferences->addPreference(preference); - } - { - auto getter = [myAvatar]()->float { return myAvatar->getDriveGear4(); }; - auto setter = [myAvatar](float value) { myAvatar->setDriveGear4(value); }; - auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 4", getter, setter); - preference->setMin(0.0f); - preference->setMax(1.0f); - preference->setStep(1); - preference->setDecimals(2); - preferences->addPreference(preference); - } - { - auto getter = [myAvatar]()->float { return myAvatar->getDriveGear5(); }; - auto setter = [myAvatar](float value) { myAvatar->setDriveGear5(value); }; - auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 5", getter, setter); - preference->setMin(0.0f); - preference->setMax(1.0f); - preference->setStep(1); - preference->setDecimals(2); - preferences->addPreference(preference); - } + //static const QString ACCEL_CURVE{ "Acceleration Step Function" }; + //{ + // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear1(); }; + // auto setter = [myAvatar](float value) { myAvatar->setDriveGear1(value); }; + // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 1", getter, setter); + // preference->setMin(0.0f); + // preference->setMax(1.0f); + // preference->setStep(1); + // preference->setDecimals(2); + // preferences->addPreference(preference); + //} + //{ + // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear2(); }; + // auto setter = [myAvatar](float value) { myAvatar->setDriveGear2(value); }; + // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 2", getter, setter); + // preference->setMin(0.0f); + // preference->setMax(1.0f); + // preference->setStep(1); + // preference->setDecimals(2); + // preferences->addPreference(preference); + //} + //{ + // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear3(); }; + // auto setter = [myAvatar](float value) { myAvatar->setDriveGear3(value); }; + // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 3", getter, setter); + // preference->setMin(0.0f); + // preference->setMax(1.0f); + // preference->setStep(1); + // preference->setDecimals(2); + // preferences->addPreference(preference); + //} + //{ + // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear4(); }; + // auto setter = [myAvatar](float value) { myAvatar->setDriveGear4(value); }; + // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 4", getter, setter); + // preference->setMin(0.0f); + // preference->setMax(1.0f); + // preference->setStep(1); + // preference->setDecimals(2); + // preferences->addPreference(preference); + //} + //{ + // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear5(); }; + // auto setter = [myAvatar](float value) { myAvatar->setDriveGear5(value); }; + // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 5", getter, setter); + // preference->setMin(0.0f); + // preference->setMax(1.0f); + // preference->setStep(1); + // preference->setDecimals(2); + // preferences->addPreference(preference); + //} static const QString AVATAR_CAMERA{ "Mouse Sensitivity" }; { diff --git a/libraries/shared/src/AvatarConstants.h b/libraries/shared/src/AvatarConstants.h index a150eb34da..4e3642de97 100644 --- a/libraries/shared/src/AvatarConstants.h +++ b/libraries/shared/src/AvatarConstants.h @@ -72,20 +72,20 @@ const float DEFAULT_AVATAR_MAX_FLYING_SPEED = 30.0f; // meters / second const float DEFAULT_AVATAR_MAX_SPRINT_SPEED = 3.0f; // meters / second const float DEFAULT_AVATAR_WALK_SPEED_THRESHOLD = 0.15f; // meters / second -const float ANALOG_AVATAR_MAX_WALKING_SPEED = 2.6f; // meters / second +const float ANALOG_AVATAR_MAX_WALKING_SPEED = 6.0f; // meters / second const float ANALOG_AVATAR_MAX_WALKING_BACKWARD_SPEED = 2.2f; // meters / second const float ANALOG_AVATAR_MAX_FLYING_SPEED = 30.0f; // meters / second -const float ANALOG_AVATAR_MAX_SPRINT_SPEED = 3.0f; // meters / second +const float ANALOG_AVATAR_MAX_SPRINT_SPEED = 8.0f; // meters / second const float ANALOG_AVATAR_GEAR_1 = 0.2f; // meters / second const float ANALOG_AVATAR_GEAR_2 = 0.4f; // meters / second const float ANALOG_AVATAR_GEAR_3 = 0.6f; // meters / second const float ANALOG_AVATAR_GEAR_4 = 0.8f; // meters / second const float ANALOG_AVATAR_GEAR_5 = 1.0f; // meters / second -const float ANALOG_PLUS_AVATAR_MAX_WALKING_SPEED = 3.3f; // meters / second +const float ANALOG_PLUS_AVATAR_MAX_WALKING_SPEED = 10.0f; // meters / second const float ANALOG_PLUS_AVATAR_MAX_WALKING_BACKWARD_SPEED = 2.42f; // meters / second const float ANALOG_PLUS_AVATAR_MAX_FLYING_SPEED = 30.0f; // meters / second -const float ANALOG_PLUS_AVATAR_MAX_SPRINT_SPEED = 4.0f; // meters / second +const float ANALOG_PLUS_AVATAR_MAX_SPRINT_SPEED = 20.0f; // meters / second const float DEFAULT_AVATAR_GRAVITY = -5.0f; // meters / second^2 (world) const float DEFAULT_AVATAR_JUMP_SPEED = 3.5f; // meters / second (sensor) From 006e2d09b3edb3f847aa068cdfbbc87971f3434b Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Mar 2019 15:16:50 -0700 Subject: [PATCH 56/68] Add jump binding. --- interface/resources/controllers/standard.json | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index dc704a69f7..4f9fb9d41e 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -42,20 +42,14 @@ "when": [ "!Application.SnapTurn", "Application.RightHandDominant" ] }, - { "from": "Standard.RY", + { "from": "Standard.LeftSecondaryThumb", "when": [ "Application.Grounded", "Application.RightHandDominant" ], - "to": "Actions.Up", - "filters": - [ - { "type": "deadZone", "min": 0.6 }, - "invert" - ] + "to": "Actions.Up" }, - { "from": "Standard.RY", + { "from": "Standard.LeftSecondaryThumb", "when": "Application.RightHandDominant", - "to": "Actions.Up", - "filters": "invert" + "to": "Actions.Up" }, { "from": "Standard.RY", @@ -99,20 +93,14 @@ "when": [ "!Application.SnapTurn", "Application.LeftHandDominant" ] }, - { "from": "Standard.LY", + { "from": "Standard.RightSecondaryThumb", "when": [ "Application.Grounded", "Application.LeftHandDominant" ], - "to": "Actions.Up", - "filters": - [ - { "type": "deadZone", "min": 0.6 }, - "invert" - ] + "to": "Actions.Up" }, - { "from": "Standard.LY", + { "from": "Standard.RightSecondaryThumb", "when": "Application.LeftHandDominant", - "to": "Actions.Up", - "filters": "invert" + "to": "Actions.Up" }, { "from": "Standard.Back", "to": "Actions.CycleCamera" }, From 4301d74df50bb863c89fac44dbd277c9230fe6d9 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Mar 2019 16:53:53 -0700 Subject: [PATCH 57/68] Fix flying bug. --- interface/src/avatar/MyAvatar.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index e926fb5af4..c8d5d2c57f 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3434,7 +3434,7 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ if (state == CharacterController::State::Hover || _characterController.computeCollisionMask() == BULLET_COLLISION_MASK_COLLISIONLESS) { glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP; - up /= glm::length(up); + //up /= glm::length(up); direction += up; } @@ -3464,12 +3464,6 @@ void MyAvatar::updateActionMotor(float deltaTime) { float directionLength = glm::length(direction); _isPushing = directionLength > EPSILON; - //if (_isPushing) { - // direction; - //} else { - // direction = Vectors::ZERO; - //} - if (!_isPushing) { direction = Vectors::ZERO; } @@ -3486,7 +3480,7 @@ void MyAvatar::updateActionMotor(float deltaTime) { const float maxBoostSpeed = sensorToWorldScale * MAX_BOOST_SPEED; if (_isPushing) { - direction /= direction; + direction /= directionLength; if (motorSpeed < maxBoostSpeed) { // an active action motor should never be slower than this float boostCoefficient = (maxBoostSpeed - motorSpeed) / maxBoostSpeed; From 86ffa4477180c8f58c23f79e2e25ed872ef5f292 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Thu, 21 Mar 2019 17:05:20 -0700 Subject: [PATCH 58/68] Swap flying binding to other hand. --- interface/resources/controllers/standard.json | 8 ++++---- scripts/system/tablet-ui/tabletUI.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 4f9fb9d41e..9885504447 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -43,12 +43,12 @@ }, { "from": "Standard.LeftSecondaryThumb", - "when": [ "Application.Grounded", "Application.RightHandDominant" ], + "when": [ "Application.Grounded", "Application.LeftHandDominant" ], "to": "Actions.Up" }, { "from": "Standard.LeftSecondaryThumb", - "when": "Application.RightHandDominant", + "when": "Application.LeftHandDominant", "to": "Actions.Up" }, @@ -94,12 +94,12 @@ }, { "from": "Standard.RightSecondaryThumb", - "when": [ "Application.Grounded", "Application.LeftHandDominant" ], + "when": [ "Application.Grounded", "Application.RightHandDominant" ], "to": "Actions.Up" }, { "from": "Standard.RightSecondaryThumb", - "when": "Application.LeftHandDominant", + "when": "Application.RightHandDominant", "to": "Actions.Up" }, diff --git a/scripts/system/tablet-ui/tabletUI.js b/scripts/system/tablet-ui/tabletUI.js index 9f59c0ec6e..a38febaa77 100644 --- a/scripts/system/tablet-ui/tabletUI.js +++ b/scripts/system/tablet-ui/tabletUI.js @@ -291,7 +291,7 @@ var clickMapping = Controller.newMapping('tabletToggle-click'); var wantsMenu = 0; clickMapping.from(function () { return wantsMenu; }).to(Controller.Actions.ContextMenu); - clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().when(Controller.Hardware.Application.RightHandDominant).to(function (clicked) { + clickMapping.from(Controller.Standard.RightSecondaryThumb).peek().when(Controller.Hardware.Application.LeftHandDominant).to(function (clicked) { if (clicked) { //activeHudPoint2d(Controller.Standard.RightHand); Messages.sendLocalMessage("toggleHand", Controller.Standard.RightHand); @@ -299,7 +299,7 @@ wantsMenu = clicked; }); - clickMapping.from(Controller.Standard.LeftSecondaryThumb).peek().when(Controller.Hardware.Application.LeftHandDominant).to(function (clicked) { + clickMapping.from(Controller.Standard.LeftSecondaryThumb).peek().when(Controller.Hardware.Application.RightHandDominant).to(function (clicked) { if (clicked) { //activeHudPoint2d(Controller.Standard.LeftHand); Messages.sendLocalMessage("toggleHand", Controller.Standard.LeftHand); From 0d83e622ff8d263208b2d65ac9a042787354f49a Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Mon, 1 Apr 2019 10:47:49 -0700 Subject: [PATCH 59/68] Revert "Attempt to add acceleration curve." (#23) This reverts commit 9ea476ea89dd956d23c96916c6fa53bc37af54e3. --- .../qml/hifi/tablet/ControllerSettings.qml | 2 +- interface/src/avatar/MyAvatar.cpp | 502 +++++++++--------- 2 files changed, 252 insertions(+), 252 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/ControllerSettings.qml b/interface/resources/qml/hifi/tablet/ControllerSettings.qml index 9feb0f6f08..6727047eb0 100644 --- a/interface/resources/qml/hifi/tablet/ControllerSettings.qml +++ b/interface/resources/qml/hifi/tablet/ControllerSettings.qml @@ -332,7 +332,7 @@ Item { anchors.fill: stackView id: controllerPrefereneces objectName: "TabletControllerPreferences" - showCategories: ["VR Movement", "Acceleration Step Function", "Game Controller", "Sixense Controllers", "Perception Neuron", "Leap Motion"] + showCategories: ["VR Movement", "Game Controller", "Sixense Controllers", "Perception Neuron", "Leap Motion"] categoryProperties: { "VR Movement" : { "User real-world height (meters)" : { "anchors.right" : "undefined" }, diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 0f2fbb53e7..6511851d77 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -202,7 +202,7 @@ MyAvatar::MyAvatar(QThread* thread) : qApp->loadAvatarScripts(hfmModel.scripts); _shouldLoadScripts = false; } - // Load and convert old attachments to avatar entities + // Load and convert old attachments to avatar entities if (_oldAttachmentData.size() > 0) { setAttachmentData(_oldAttachmentData); _oldAttachmentData.clear(); @@ -223,7 +223,7 @@ MyAvatar::MyAvatar(QThread* thread) : // connect to AddressManager signal for location jumps connect(DependencyManager::get().data(), &AddressManager::locationChangeRequired, - this, static_cast(&MyAvatar::goToFeetLocation)); + this, static_cast(&MyAvatar::goToFeetLocation)); // handle scale constraints imposed on us by the domain-server auto& domainHandler = DependencyManager::get()->getDomainHandler(); @@ -458,7 +458,7 @@ void MyAvatar::centerBody() { // derive the desired body orientation from the current hmd orientation, before the sensor reset. auto newBodySensorMatrix = deriveBodyFromHMDSensor(); // Based on current cached HMD position/rotation.. - // transform this body into world space + // transform this body into world space auto worldBodyMatrix = _sensorToWorldMatrix * newBodySensorMatrix; auto worldBodyPos = extractTranslation(worldBodyMatrix); auto worldBodyRot = glmExtractRotation(worldBodyMatrix); @@ -511,7 +511,7 @@ void MyAvatar::reset(bool andRecenter, bool andReload, bool andHead) { // derive the desired body orientation from the *old* hmd orientation, before the sensor reset. auto newBodySensorMatrix = deriveBodyFromHMDSensor(); // Based on current cached HMD position/rotation.. - // transform this body into world space + // transform this body into world space auto worldBodyMatrix = _sensorToWorldMatrix * newBodySensorMatrix; auto worldBodyPos = extractTranslation(worldBodyMatrix); auto worldBodyRot = glmExtractRotation(worldBodyMatrix); @@ -760,16 +760,16 @@ void MyAvatar::updateEyeContactTarget(float deltaTime) { float const FIFTY_FIFTY_CHANCE = 0.5f; float const EYE_TO_MOUTH_CHANCE = 0.25f; switch (_eyeContactTarget) { - case LEFT_EYE: - _eyeContactTarget = (randFloat() < EYE_TO_MOUTH_CHANCE) ? MOUTH : RIGHT_EYE; - break; - case RIGHT_EYE: - _eyeContactTarget = (randFloat() < EYE_TO_MOUTH_CHANCE) ? MOUTH : LEFT_EYE; - break; - case MOUTH: - default: - _eyeContactTarget = (randFloat() < FIFTY_FIFTY_CHANCE) ? RIGHT_EYE : LEFT_EYE; - break; + case LEFT_EYE: + _eyeContactTarget = (randFloat() < EYE_TO_MOUTH_CHANCE) ? MOUTH : RIGHT_EYE; + break; + case RIGHT_EYE: + _eyeContactTarget = (randFloat() < EYE_TO_MOUTH_CHANCE) ? MOUTH : LEFT_EYE; + break; + case MOUTH: + default: + _eyeContactTarget = (randFloat() < FIFTY_FIFTY_CHANCE) ? RIGHT_EYE : LEFT_EYE; + break; } const float EYE_TARGET_DELAY_TIME = 0.33f; @@ -1075,17 +1075,17 @@ void MyAvatar::updateSensorToWorldMatrix() { if (_enableDebugDrawSensorToWorldMatrix) { DebugDraw::getInstance().addMarker("sensorToWorldMatrix", glmExtractRotation(_sensorToWorldMatrix), - extractTranslation(_sensorToWorldMatrix), glm::vec4(1)); + extractTranslation(_sensorToWorldMatrix), glm::vec4(1)); } _sensorToWorldMatrixCache.set(_sensorToWorldMatrix); updateJointFromController(controller::Action::LEFT_HAND, _controllerLeftHandMatrixCache); updateJointFromController(controller::Action::RIGHT_HAND, _controllerRightHandMatrixCache); - + if (hasSensorToWorldScaleChanged) { emit sensorToWorldScaleChanged(sensorToWorldScale); } - + } // Update avatar head rotation with sensor data @@ -1111,7 +1111,7 @@ void MyAvatar::updateFromTrackers(float deltaTime) { const float TRACKER_MIN_YAW_TURN = 15.0f; const float TRACKER_MAX_YAW_TURN = 50.0f; if ( (fabs(estimatedRotation.y) > TRACKER_MIN_YAW_TURN) && - (fabs(estimatedRotation.y) < TRACKER_MAX_YAW_TURN) ) { + (fabs(estimatedRotation.y) < TRACKER_MAX_YAW_TURN) ) { if (estimatedRotation.y > 0.0f) { _bodyYawDelta += (estimatedRotation.y - TRACKER_MIN_YAW_TURN) * TRACKER_YAW_TURN_SENSITIVITY; } else { @@ -1200,7 +1200,7 @@ void MyAvatar::render(RenderArgs* renderArgs) { void MyAvatar::overrideAnimation(const QString& url, float fps, bool loop, float firstFrame, float lastFrame) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "overrideAnimation", Q_ARG(const QString&, url), Q_ARG(float, fps), - Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame)); + Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame)); return; } _skeletonModel->getRig().overrideAnimation(url, fps, loop, firstFrame, lastFrame); @@ -1224,10 +1224,10 @@ QStringList MyAvatar::getAnimationRoles() { } void MyAvatar::overrideRoleAnimation(const QString& role, const QString& url, float fps, bool loop, - float firstFrame, float lastFrame) { + float firstFrame, float lastFrame) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "overrideRoleAnimation", Q_ARG(const QString&, role), Q_ARG(const QString&, url), - Q_ARG(float, fps), Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame)); + Q_ARG(float, fps), Q_ARG(bool, loop), Q_ARG(float, firstFrame), Q_ARG(float, lastFrame)); return; } _skeletonModel->getRig().overrideRoleAnimation(role, url, fps, loop, firstFrame, lastFrame); @@ -1244,8 +1244,8 @@ void MyAvatar::restoreRoleAnimation(const QString& role) { void MyAvatar::saveAvatarUrl() { if (qApp->getSaveAvatarOverrideUrl() || !qApp->getAvatarOverrideUrl().isValid()) { _fullAvatarURLSetting.set(_fullAvatarURLFromPreferences == AvatarData::defaultFullAvatarModelUrl() ? - "" : - _fullAvatarURLFromPreferences.toString()); + "" : + _fullAvatarURLFromPreferences.toString()); } } @@ -1262,10 +1262,10 @@ void MyAvatar::resizeAvatarEntitySettingHandles(uint32_t maxIndex) { uint32_t settingsIndex = (uint32_t)_avatarEntityIDSettings.size() + 1; while (settingsIndex <= maxIndex) { Setting::Handle idHandle(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" - << QString::number(settingsIndex) << "id", QUuid()); + << QString::number(settingsIndex) << "id", QUuid()); _avatarEntityIDSettings.push_back(idHandle); Setting::Handle dataHandle(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "avatarEntityData" - << QString::number(settingsIndex) << "properties", QByteArray()); + << QString::number(settingsIndex) << "properties", QByteArray()); _avatarEntityDataSettings.push_back(dataHandle); settingsIndex++; } @@ -1285,8 +1285,8 @@ void MyAvatar::saveData() { // --replaceAvatarURL (so _saveAvatarOverrideUrl is true) if (qApp->getSaveAvatarOverrideUrl() || !qApp->getAvatarOverrideUrl().isValid() ) { _fullAvatarURLSetting.set(_fullAvatarURLFromPreferences == AvatarData::defaultFullAvatarModelUrl() ? - "" : - _fullAvatarURLFromPreferences.toString()); + "" : + _fullAvatarURLFromPreferences.toString()); } _fullAvatarModelNameSetting.set(_fullAvatarModelName); @@ -2022,7 +2022,7 @@ ScriptAvatarData* MyAvatar::getTargetAvatar() const { } static float lookAtCostFunction(const glm::vec3& myForward, const glm::vec3& myPosition, const glm::vec3& otherForward, const glm::vec3& otherPosition, - bool otherIsTalking, bool lookingAtOtherAlready) { + bool otherIsTalking, bool lookingAtOtherAlready) { const float DISTANCE_FACTOR = 3.14f; const float MY_ANGLE_FACTOR = 1.0f; const float OTHER_ANGLE_FACTOR = 1.0f; @@ -2043,10 +2043,10 @@ static float lookAtCostFunction(const glm::vec3& myForward, const glm::vec3& myP return FLT_MAX; } else { return (DISTANCE_FACTOR * distance + - MY_ANGLE_FACTOR * myAngle + - OTHER_ANGLE_FACTOR * otherAngle + - OTHER_IS_TALKING_TERM + - LOOKING_AT_OTHER_ALREADY_TERM); + MY_ANGLE_FACTOR * myAngle + + OTHER_ANGLE_FACTOR * otherAngle + + OTHER_IS_TALKING_TERM + + LOOKING_AT_OTHER_ALREADY_TERM); } } @@ -2094,8 +2094,8 @@ void MyAvatar::snapOtherAvatarLookAtTargetsToMe(const AvatarHash& hash) { // Alter their gaze to look directly at my camera; this looks more natural than looking at my avatar's face. glm::vec3 lookAtPosition = avatar->getHead()->getLookAtPosition(); // A position, in world space, on my avatar. - // The camera isn't at the point midway between the avatar eyes. (Even without an HMD, the head can be offset a bit.) - // Let's get everything to world space: + // The camera isn't at the point midway between the avatar eyes. (Even without an HMD, the head can be offset a bit.) + // Let's get everything to world space: glm::vec3 avatarLeftEye = getHead()->getLeftEyePosition(); glm::vec3 avatarRightEye = getHead()->getRightEyePosition(); @@ -2103,12 +2103,12 @@ void MyAvatar::snapOtherAvatarLookAtTargetsToMe(const AvatarHash& hash) { // (We will be adding that offset to the camera position, after making some other adjustments.) glm::vec3 gazeOffset = lookAtPosition - getHead()->getEyePosition(); - ViewFrustum viewFrustum; - qApp->copyViewFrustum(viewFrustum); + ViewFrustum viewFrustum; + qApp->copyViewFrustum(viewFrustum); - glm::vec3 viewPosition = viewFrustum.getPosition(); + glm::vec3 viewPosition = viewFrustum.getPosition(); #if DEBUG_ALWAYS_LOOKAT_EYES_NOT_CAMERA - viewPosition = (avatarLeftEye + avatarRightEye) / 2.0f; + viewPosition = (avatarLeftEye + avatarRightEye) / 2.0f; #endif // scale gazeOffset by IPD, if wearing an HMD. if (qApp->isHMDMode()) { @@ -2183,121 +2183,121 @@ void MyAvatar::setJointRotations(const QVector& jointRotations) { void MyAvatar::setJointData(int index, const glm::quat& rotation, const glm::vec3& translation) { switch (index) { - case FARGRAB_RIGHTHAND_INDEX: { - _farGrabRightMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); - break; - } - case FARGRAB_LEFTHAND_INDEX: { - _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); - break; - } - case FARGRAB_MOUSE_INDEX: { - _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); - break; - } - default: { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "setJointData", Q_ARG(int, index), Q_ARG(const glm::quat&, rotation), - Q_ARG(const glm::vec3&, translation)); - return; + case FARGRAB_RIGHTHAND_INDEX: { + _farGrabRightMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); + break; + } + case FARGRAB_LEFTHAND_INDEX: { + _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); + break; + } + case FARGRAB_MOUSE_INDEX: { + _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(rotation, translation)); + break; + } + default: { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setJointData", Q_ARG(int, index), Q_ARG(const glm::quat&, rotation), + Q_ARG(const glm::vec3&, translation)); + return; + } + // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority + _skeletonModel->getRig().setJointState(index, true, rotation, translation, SCRIPT_PRIORITY); } - // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority - _skeletonModel->getRig().setJointState(index, true, rotation, translation, SCRIPT_PRIORITY); - } } } void MyAvatar::setJointRotation(int index, const glm::quat& rotation) { switch (index) { - case FARGRAB_RIGHTHAND_INDEX: { - glm::mat4 prevMat = _farGrabRightMatrixCache.get(); - glm::vec3 previousTranslation = extractTranslation(prevMat); - _farGrabRightMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); - break; - } - case FARGRAB_LEFTHAND_INDEX: { - glm::mat4 prevMat = _farGrabLeftMatrixCache.get(); - glm::vec3 previousTranslation = extractTranslation(prevMat); - _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); - break; - } - case FARGRAB_MOUSE_INDEX: { - glm::mat4 prevMat = _farGrabMouseMatrixCache.get(); - glm::vec3 previousTranslation = extractTranslation(prevMat); - _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); - break; - } - default: { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "setJointRotation", Q_ARG(int, index), Q_ARG(const glm::quat&, rotation)); - return; + case FARGRAB_RIGHTHAND_INDEX: { + glm::mat4 prevMat = _farGrabRightMatrixCache.get(); + glm::vec3 previousTranslation = extractTranslation(prevMat); + _farGrabRightMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); + break; + } + case FARGRAB_LEFTHAND_INDEX: { + glm::mat4 prevMat = _farGrabLeftMatrixCache.get(); + glm::vec3 previousTranslation = extractTranslation(prevMat); + _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); + break; + } + case FARGRAB_MOUSE_INDEX: { + glm::mat4 prevMat = _farGrabMouseMatrixCache.get(); + glm::vec3 previousTranslation = extractTranslation(prevMat); + _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(rotation, previousTranslation)); + break; + } + default: { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setJointRotation", Q_ARG(int, index), Q_ARG(const glm::quat&, rotation)); + return; + } + // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority + _skeletonModel->getRig().setJointRotation(index, true, rotation, SCRIPT_PRIORITY); } - // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority - _skeletonModel->getRig().setJointRotation(index, true, rotation, SCRIPT_PRIORITY); - } } } void MyAvatar::setJointTranslation(int index, const glm::vec3& translation) { switch (index) { - case FARGRAB_RIGHTHAND_INDEX: { - glm::mat4 prevMat = _farGrabRightMatrixCache.get(); - glm::quat previousRotation = extractRotation(prevMat); - _farGrabRightMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); - break; - } - case FARGRAB_LEFTHAND_INDEX: { - glm::mat4 prevMat = _farGrabLeftMatrixCache.get(); - glm::quat previousRotation = extractRotation(prevMat); - _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); - break; - } - case FARGRAB_MOUSE_INDEX: { - glm::mat4 prevMat = _farGrabMouseMatrixCache.get(); - glm::quat previousRotation = extractRotation(prevMat); - _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); - break; - } - default: { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "setJointTranslation", - Q_ARG(int, index), Q_ARG(const glm::vec3&, translation)); - return; + case FARGRAB_RIGHTHAND_INDEX: { + glm::mat4 prevMat = _farGrabRightMatrixCache.get(); + glm::quat previousRotation = extractRotation(prevMat); + _farGrabRightMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); + break; + } + case FARGRAB_LEFTHAND_INDEX: { + glm::mat4 prevMat = _farGrabLeftMatrixCache.get(); + glm::quat previousRotation = extractRotation(prevMat); + _farGrabLeftMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); + break; + } + case FARGRAB_MOUSE_INDEX: { + glm::mat4 prevMat = _farGrabMouseMatrixCache.get(); + glm::quat previousRotation = extractRotation(prevMat); + _farGrabMouseMatrixCache.set(createMatFromQuatAndPos(previousRotation, translation)); + break; + } + default: { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "setJointTranslation", + Q_ARG(int, index), Q_ARG(const glm::vec3&, translation)); + return; + } + // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority + _skeletonModel->getRig().setJointTranslation(index, true, translation, SCRIPT_PRIORITY); } - // HACK: ATM only JS scripts call setJointData() on MyAvatar so we hardcode the priority - _skeletonModel->getRig().setJointTranslation(index, true, translation, SCRIPT_PRIORITY); - } } } void MyAvatar::clearJointData(int index) { switch (index) { - case FARGRAB_RIGHTHAND_INDEX: { - _farGrabRightMatrixCache.invalidate(); - break; - } - case FARGRAB_LEFTHAND_INDEX: { - _farGrabLeftMatrixCache.invalidate(); - break; - } - case FARGRAB_MOUSE_INDEX: { - _farGrabMouseMatrixCache.invalidate(); - break; - } - default: { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "clearJointData", Q_ARG(int, index)); - return; + case FARGRAB_RIGHTHAND_INDEX: { + _farGrabRightMatrixCache.invalidate(); + break; + } + case FARGRAB_LEFTHAND_INDEX: { + _farGrabLeftMatrixCache.invalidate(); + break; + } + case FARGRAB_MOUSE_INDEX: { + _farGrabMouseMatrixCache.invalidate(); + break; + } + default: { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "clearJointData", Q_ARG(int, index)); + return; + } + _skeletonModel->getRig().clearJointAnimationPriority(index); } - _skeletonModel->getRig().clearJointAnimationPriority(index); - } } } void MyAvatar::setJointData(const QString& name, const glm::quat& rotation, const glm::vec3& translation) { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "setJointData", Q_ARG(QString, name), Q_ARG(const glm::quat&, rotation), - Q_ARG(const glm::vec3&, translation)); + Q_ARG(const glm::vec3&, translation)); return; } writeLockWithNamedJointIndex(name, [&](int index) { @@ -2383,7 +2383,7 @@ void MyAvatar::setSkeletonModelURL(const QUrl& skeletonModelURL) { } QObject::disconnect(*skeletonConnection); }); - + saveAvatarUrl(); emit skeletonChanged(); } @@ -2432,7 +2432,7 @@ QVariantList MyAvatar::getAvatarEntitiesVariant() { if (entityTree) { QList avatarEntityIDs; _avatarEntitiesLock.withReadLock([&] { - avatarEntityIDs = _packedAvatarEntityData.keys(); + avatarEntityIDs = _packedAvatarEntityData.keys(); }); for (const auto& entityID : avatarEntityIDs) { auto entity = entityTree->findEntityByID(entityID); @@ -2466,8 +2466,8 @@ void MyAvatar::useFullAvatarURL(const QUrl& fullAvatarURL, const QString& modelN if (QThread::currentThread() != thread()) { BLOCKING_INVOKE_METHOD(this, "useFullAvatarURL", - Q_ARG(const QUrl&, fullAvatarURL), - Q_ARG(const QString&, modelName)); + Q_ARG(const QUrl&, fullAvatarURL), + Q_ARG(const QString&, modelName)); return; } @@ -2713,7 +2713,7 @@ void MyAvatar::setScriptedMotorTimescale(float timescale) { // we clamp the timescale on the large side (instead of just the low side) to prevent // obnoxiously large values from introducing NaN into avatar's velocity _scriptedMotorTimescale = glm::clamp(timescale, MIN_SCRIPTED_MOTOR_TIMESCALE, - DEFAULT_SCRIPTED_MOTOR_TIMESCALE); + DEFAULT_SCRIPTED_MOTOR_TIMESCALE); } void MyAvatar::setScriptedMotorFrame(QString frame) { @@ -2755,9 +2755,9 @@ SharedSoundPointer MyAvatar::getCollisionSound() { } void MyAvatar::attach(const QString& modelURL, const QString& jointName, - const glm::vec3& translation, const glm::quat& rotation, - float scale, bool isSoft, - bool allowDuplicates, bool useSaved) { + const glm::vec3& translation, const glm::quat& rotation, + float scale, bool isSoft, + bool allowDuplicates, bool useSaved) { if (QThread::currentThread() != thread()) { BLOCKING_INVOKE_METHOD(this, "attach", Q_ARG(const QString&, modelURL), @@ -2882,7 +2882,7 @@ void MyAvatar::setAttachmentsVariant(const QVariantList& variant) { bool MyAvatar::findAvatarEntity(const QString& modelURL, const QString& jointName, QUuid& entityID) { QList avatarEntityIDs; _avatarEntitiesLock.withReadLock([&] { - avatarEntityIDs = _packedAvatarEntityData.keys(); + avatarEntityIDs = _packedAvatarEntityData.keys(); }); for (const auto& entityID : avatarEntityIDs) { auto props = DependencyManager::get()->getEntityProperties(entityID); @@ -3549,7 +3549,7 @@ void MyAvatar::updateCollisionSound(const glm::vec3 &penetration, float deltaTim } bool findAvatarAvatarPenetration(const glm::vec3 positionA, float radiusA, float heightA, - const glm::vec3 positionB, float radiusB, float heightB, glm::vec3& penetration) { + const glm::vec3 positionB, float radiusB, float heightB, glm::vec3& penetration) { glm::vec3 positionBA = positionB - positionA; float xzDistance = sqrt(positionBA.x * positionBA.x + positionBA.z * positionBA.z); if (xzDistance < (radiusA + radiusB)) { @@ -3692,7 +3692,7 @@ void MyAvatar::restrictScaleFromDomainSettings(const QJsonObject& domainSettings _targetScale = getDomainLimitedScale(); qCDebug(interfaceapp) << "This domain requires a minimum avatar scale of " << _domainMinimumHeight - << " and a maximum avatar scale of " << _domainMaximumHeight; + << " and a maximum avatar scale of " << _domainMaximumHeight; _isAnimatingScale = true; @@ -3752,15 +3752,15 @@ void MyAvatar::goToLocation(const QVariant& propertiesVar) { } void MyAvatar::goToFeetLocation(const glm::vec3& newPosition, - bool hasOrientation, const glm::quat& newOrientation, - bool shouldFaceLocation) { + bool hasOrientation, const glm::quat& newOrientation, + bool shouldFaceLocation) { _goToFeetAjustment = true; goToLocation(newPosition, hasOrientation, newOrientation, shouldFaceLocation); } void MyAvatar::goToLocation(const glm::vec3& newPosition, - bool hasOrientation, const glm::quat& newOrientation, - bool shouldFaceLocation, bool withSafeLanding) { + bool hasOrientation, const glm::quat& newOrientation, + bool shouldFaceLocation, bool withSafeLanding) { // Most cases of going to a place or user go through this now. Some possible improvements to think about in the future: // - It would be nice if this used the same teleport steps and smoothing as in the teleport.js script, as long as it @@ -3784,7 +3784,7 @@ void MyAvatar::goToLocation(const glm::vec3& newPosition, _goToOrientation = getWorldOrientation(); if (hasOrientation) { qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - new orientation is " - << newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w; + << newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w; // orient the user to face the target glm::quat quatOrientation = cancelOutRollAndPitch(newOrientation); @@ -3829,13 +3829,13 @@ bool MyAvatar::safeLanding(const glm::vec3& position) { } if (!getCollisionsEnabled()) { goToLocation(better); // recurses on next update - } else { // If you try to go while stuck, physics will keep you stuck. + } else { // If you try to go while stuck, physics will keep you stuck. setCollisionsEnabled(false); // Don't goToLocation just yet. Yield so that physics can act on the above. QMetaObject::invokeMethod(this, "goToLocationAndEnableCollisions", Qt::QueuedConnection, // The equivalent of javascript nextTick Q_ARG(glm::vec3, better)); - } - return true; + } + return true; } // If position is not reliably safe from being stuck by physics, answer true and place a candidate better position in betterPositionOut. @@ -4812,27 +4812,27 @@ void MyAvatar::setUserRecenterModel(MyAvatar::SitStandModelType modelName) { _userRecenterModel.set(modelName); switch (modelName) { - case MyAvatar::SitStandModelType::ForceSit: - setHMDLeanRecenterEnabled(true); - setIsInSittingState(true); - setIsSitStandStateLocked(true); - break; - case MyAvatar::SitStandModelType::ForceStand: - setHMDLeanRecenterEnabled(true); - setIsInSittingState(false); - setIsSitStandStateLocked(true); - break; - case MyAvatar::SitStandModelType::Auto: - default: - setHMDLeanRecenterEnabled(true); - setIsInSittingState(false); - setIsSitStandStateLocked(false); - break; - case MyAvatar::SitStandModelType::DisableHMDLean: - setHMDLeanRecenterEnabled(false); - setIsInSittingState(false); - setIsSitStandStateLocked(false); - break; + case MyAvatar::SitStandModelType::ForceSit: + setHMDLeanRecenterEnabled(true); + setIsInSittingState(true); + setIsSitStandStateLocked(true); + break; + case MyAvatar::SitStandModelType::ForceStand: + setHMDLeanRecenterEnabled(true); + setIsInSittingState(false); + setIsSitStandStateLocked(true); + break; + case MyAvatar::SitStandModelType::Auto: + default: + setHMDLeanRecenterEnabled(true); + setIsInSittingState(false); + setIsSitStandStateLocked(false); + break; + case MyAvatar::SitStandModelType::DisableHMDLean: + setHMDLeanRecenterEnabled(false); + setIsInSittingState(false); + setIsSitStandStateLocked(false); + break; } } @@ -4960,15 +4960,15 @@ QVector MyAvatar::getScriptUrls() { glm::vec3 MyAvatar::getPositionForAudio() { glm::vec3 result; switch (_audioListenerMode) { - case AudioListenerMode::FROM_HEAD: - result = getHead()->getPosition(); - break; - case AudioListenerMode::FROM_CAMERA: - result = qApp->getCamera().getPosition(); - break; - case AudioListenerMode::CUSTOM: - result = _customListenPosition; - break; + case AudioListenerMode::FROM_HEAD: + result = getHead()->getPosition(); + break; + case AudioListenerMode::FROM_CAMERA: + result = qApp->getCamera().getPosition(); + break; + case AudioListenerMode::CUSTOM: + result = _customListenPosition; + break; } if (isNaN(result)) { @@ -4983,15 +4983,15 @@ glm::quat MyAvatar::getOrientationForAudio() { glm::quat result; switch (_audioListenerMode) { - case AudioListenerMode::FROM_HEAD: - result = getHead()->getFinalOrientationInWorldFrame(); - break; - case AudioListenerMode::FROM_CAMERA: - result = qApp->getCamera().getOrientation(); - break; - case AudioListenerMode::CUSTOM: - result = _customListenOrientation; - break; + case AudioListenerMode::FROM_HEAD: + result = getHead()->getFinalOrientationInWorldFrame(); + break; + case AudioListenerMode::FROM_CAMERA: + result = qApp->getCamera().getOrientation(); + break; + case AudioListenerMode::CUSTOM: + result = _customListenOrientation; + break; } if (isNaN(result)) { @@ -5196,7 +5196,7 @@ bool MyAvatar::FollowHelper::shouldActivateVertical(const MyAvatar& myAvatar, co } void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, - const glm::mat4& currentBodyMatrix, bool hasDriveInput) { + const glm::mat4& currentBodyMatrix, bool hasDriveInput) { if (myAvatar.getHMDLeanRecenterEnabled() && qApp->getCamera().getMode() != CAMERA_MODE_MIRROR) { @@ -5260,8 +5260,8 @@ void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat followWorldPose.scale() = glm::vec3(1.0f); if (isActive(Rotation)) { - //use the hmd reading for the hips follow - followWorldPose.rot() = glmExtractRotation(desiredWorldMatrix); + //use the hmd reading for the hips follow + followWorldPose.rot() = glmExtractRotation(desiredWorldMatrix); } if (isActive(Horizontal)) { glm::vec3 desiredTranslation = extractTranslation(desiredWorldMatrix); @@ -5292,7 +5292,7 @@ glm::mat4 MyAvatar::FollowHelper::postPhysicsUpdate(MyAvatar& myAvatar, const gl glm::quat sensorAngularDisplacement = glmExtractRotation(worldToSensorMatrix) * worldAngularDisplacement * glmExtractRotation(sensorToWorldMatrix); glm::mat4 newBodyMat = createMatFromQuatAndPos(sensorAngularDisplacement * glmExtractRotation(currentBodyMatrix), - sensorLinearDisplacement + extractTranslation(currentBodyMatrix)); + sensorLinearDisplacement + extractTranslation(currentBodyMatrix)); if (myAvatar.getSitStandStateChange()) { myAvatar.setSitStandStateChange(false); deactivate(Vertical); @@ -5404,34 +5404,34 @@ glm::quat MyAvatar::getAbsoluteJointRotationInObjectFrame(int index) const { } switch (index) { - case CONTROLLER_LEFTHAND_INDEX: { - return getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).getRotation(); - } - case CONTROLLER_RIGHTHAND_INDEX: { - return getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).getRotation(); - } - case CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX: { - auto pose = getControllerPoseInSensorFrame(controller::Action::LEFT_HAND); - glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); - glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); - return glmExtractRotation(result); - } - case CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX: { - auto pose = getControllerPoseInSensorFrame(controller::Action::RIGHT_HAND); - glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); - glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); - return glmExtractRotation(result); - } - case CAMERA_MATRIX_INDEX: { - bool success; - Transform avatarTransform; - Transform::mult(avatarTransform, getParentTransform(success), getLocalTransform()); - glm::mat4 invAvatarMat = avatarTransform.getInverseMatrix(); - return glmExtractRotation(invAvatarMat * qApp->getCamera().getTransform()); - } - default: { - return Avatar::getAbsoluteJointRotationInObjectFrame(index); - } + case CONTROLLER_LEFTHAND_INDEX: { + return getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).getRotation(); + } + case CONTROLLER_RIGHTHAND_INDEX: { + return getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).getRotation(); + } + case CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX: { + auto pose = getControllerPoseInSensorFrame(controller::Action::LEFT_HAND); + glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); + glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); + return glmExtractRotation(result); + } + case CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX: { + auto pose = getControllerPoseInSensorFrame(controller::Action::RIGHT_HAND); + glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); + glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); + return glmExtractRotation(result); + } + case CAMERA_MATRIX_INDEX: { + bool success; + Transform avatarTransform; + Transform::mult(avatarTransform, getParentTransform(success), getLocalTransform()); + glm::mat4 invAvatarMat = avatarTransform.getInverseMatrix(); + return glmExtractRotation(invAvatarMat * qApp->getCamera().getTransform()); + } + default: { + return Avatar::getAbsoluteJointRotationInObjectFrame(index); + } } } @@ -5441,34 +5441,34 @@ glm::vec3 MyAvatar::getAbsoluteJointTranslationInObjectFrame(int index) const { } switch (index) { - case CONTROLLER_LEFTHAND_INDEX: { - return getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).getTranslation(); - } - case CONTROLLER_RIGHTHAND_INDEX: { - return getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).getTranslation(); - } - case CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX: { - auto pose = getControllerPoseInSensorFrame(controller::Action::LEFT_HAND); - glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); - glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); - return extractTranslation(result); - } - case CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX: { - auto pose = getControllerPoseInSensorFrame(controller::Action::RIGHT_HAND); - glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); - glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); - return extractTranslation(result); - } - case CAMERA_MATRIX_INDEX: { - bool success; - Transform avatarTransform; - Transform::mult(avatarTransform, getParentTransform(success), getLocalTransform()); - glm::mat4 invAvatarMat = avatarTransform.getInverseMatrix(); - return extractTranslation(invAvatarMat * qApp->getCamera().getTransform()); - } - default: { - return Avatar::getAbsoluteJointTranslationInObjectFrame(index); - } + case CONTROLLER_LEFTHAND_INDEX: { + return getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).getTranslation(); + } + case CONTROLLER_RIGHTHAND_INDEX: { + return getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).getTranslation(); + } + case CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX: { + auto pose = getControllerPoseInSensorFrame(controller::Action::LEFT_HAND); + glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); + glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); + return extractTranslation(result); + } + case CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX: { + auto pose = getControllerPoseInSensorFrame(controller::Action::RIGHT_HAND); + glm::mat4 controllerSensorMatrix = createMatFromQuatAndPos(pose.rotation, pose.translation); + glm::mat4 result = computeCameraRelativeHandControllerMatrix(controllerSensorMatrix); + return extractTranslation(result); + } + case CAMERA_MATRIX_INDEX: { + bool success; + Transform avatarTransform; + Transform::mult(avatarTransform, getParentTransform(success), getLocalTransform()); + glm::mat4 invAvatarMat = avatarTransform.getInverseMatrix(); + return extractTranslation(invAvatarMat * qApp->getCamera().getTransform()); + } + default: { + return Avatar::getAbsoluteJointTranslationInObjectFrame(index); + } } } @@ -5688,7 +5688,7 @@ SpatialParentTree* MyAvatar::getParentTree() const { } const QUuid MyAvatar::grab(const QUuid& targetID, int parentJointIndex, - glm::vec3 positionalOffset, glm::quat rotationalOffset) { + glm::vec3 positionalOffset, glm::quat rotationalOffset) { auto grabID = QUuid::createUuid(); // create a temporary grab object to get grabData @@ -5699,14 +5699,14 @@ const QUuid MyAvatar::grab(const QUuid& targetID, int parentJointIndex, parentJointIndex == getJointIndex("RightHand")) { hand = "right"; } else if (parentJointIndex == CONTROLLER_LEFTHAND_INDEX || - parentJointIndex == CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX || - parentJointIndex == FARGRAB_LEFTHAND_INDEX || - parentJointIndex == getJointIndex("LeftHand")) { + parentJointIndex == CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX || + parentJointIndex == FARGRAB_LEFTHAND_INDEX || + parentJointIndex == getJointIndex("LeftHand")) { hand = "left"; } Grab tmpGrab(DependencyManager::get()->getSessionUUID(), - targetID, parentJointIndex, hand, positionalOffset, rotationalOffset); + targetID, parentJointIndex, hand, positionalOffset, rotationalOffset); QByteArray grabData = tmpGrab.toByteArray(); bool dataChanged = updateAvatarGrabData(grabID, grabData); From ec37ad7dc6cf8c44022be69c43cddd23ec7f8967 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Wed, 3 Apr 2019 09:38:14 -0700 Subject: [PATCH 60/68] Address Wayne and Angus' comments on github. --- interface/resources/controllers/standard.json | 6 +- interface/src/avatar/MyAvatar.cpp | 68 +++++++------------ 2 files changed, 26 insertions(+), 48 deletions(-) diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 9885504447..58641892f9 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -4,7 +4,7 @@ { "from": "Standard.LY", "when": ["Application.RightHandDominant", "!Standard.RY"], "to": "Actions.TranslateZ" - }, + }, { "from": "Standard.LX", "when": [ @@ -50,12 +50,12 @@ { "from": "Standard.LeftSecondaryThumb", "when": "Application.LeftHandDominant", "to": "Actions.Up" - }, + }, { "from": "Standard.RY", "when": ["Application.LeftHandDominant", "!Standard.LY"], "to": "Actions.TranslateZ" - }, + }, { "from": "Standard.RX", "when": [ diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 6d01e10ccf..eb82d806e1 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -162,7 +162,7 @@ MyAvatar::MyAvatar(QThread* thread) : _yawSpeedSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "yawSpeed", _yawSpeed), _pitchSpeedSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "pitchSpeed", _pitchSpeed), _fullAvatarURLSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "fullAvatarURL", - AvatarData::defaultFullAvatarModelUrl()), + AvatarData::defaultFullAvatarModelUrl()), _fullAvatarModelNameSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "fullAvatarModelName", _fullAvatarModelName), _animGraphURLSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "animGraphURL", QUrl("")), _displayNameSetting(QStringList() << AVATAR_SETTINGS_GROUP_NAME << "displayName", ""), @@ -223,7 +223,7 @@ MyAvatar::MyAvatar(QThread* thread) : // connect to AddressManager signal for location jumps connect(DependencyManager::get().data(), &AddressManager::locationChangeRequired, - this, static_cast(&MyAvatar::goToFeetLocation)); + this, static_cast(&MyAvatar::goToFeetLocation)); // handle scale constraints imposed on us by the domain-server auto& domainHandler = DependencyManager::get()->getDomainHandler(); @@ -3331,23 +3331,6 @@ void MyAvatar::updateOrientation(float deltaTime) { } } -//static float scaleSpeedByDirection(const glm::vec2 velocityDirection, const float forwardSpeed, const float backwardSpeed) { -// // for the elipse function --> (x^2)/(backwardSpeed*backwardSpeed) + y^2/(forwardSpeed*forwardSpeed) = 1, scale == y^2 when x is 0 -// float fwdScale = forwardSpeed * forwardSpeed; -// float backScale = backwardSpeed * backwardSpeed; -// float scaledX = velocityDirection.x * backwardSpeed; -// float scaledSpeed = forwardSpeed; -// if (velocityDirection.y < 0.0f) { -// if (backScale > 0.0f) { -// float yValue = sqrtf(fwdScale * (1.0f - ((scaledX * scaledX) / backScale))); -// scaledSpeed = sqrtf((scaledX * scaledX) + (yValue * yValue)); -// } -// } else { -// scaledSpeed = backwardSpeed; -// } -// return scaledSpeed; -//} - float MyAvatar::calculateGearedSpeed(const float driveKey) { float absDriveKey = abs(driveKey); float sign = (driveKey < 0.0f) ? -1.0f : 1.0f; @@ -3506,12 +3489,7 @@ void MyAvatar::updateActionMotor(float deltaTime) { } _actionMotorVelocity = motorSpeed * direction; } else { - // we're interacting with a floor --> simple horizontal speed and exponential decay - //const glm::vec2 currentVel = { direction.x, direction.z }; - //float scaledSpeed = scaleSpeedByDirection(currentVel, _walkSpeed.get(), _walkBackwardSpeed.get()); - // _walkSpeedScalar is a multiplier if we are in sprint mode, otherwise 1.0 _actionMotorVelocity = direction; - //_actionMotorVelocity = getSensorToWorldScale() * (scaledSpeed * _walkSpeedScalar) * direction; } float previousBoomLength = _boomLength; @@ -4773,25 +4751,25 @@ bool MyAvatar::getIsSitStandStateLocked() const { float MyAvatar::getWalkSpeed() const { switch(_controlSchemeIndex) { - case CONTROLS_ANALOG: - return _analogWalkSpeed.get() * _walkSpeedScalar; - case CONTROLS_ANALOG_PLUS: - return _analogPlusWalkSpeed.get() * _walkSpeedScalar; - case CONTROLS_DEFAULT: - default: - return _defaultWalkSpeed.get() * _walkSpeedScalar; + case CONTROLS_ANALOG: + return _analogWalkSpeed.get() * _walkSpeedScalar; + case CONTROLS_ANALOG_PLUS: + return _analogPlusWalkSpeed.get() * _walkSpeedScalar; + case CONTROLS_DEFAULT: + default: + return _defaultWalkSpeed.get() * _walkSpeedScalar; } } float MyAvatar::getWalkBackwardSpeed() const { switch(_controlSchemeIndex) { - case CONTROLS_ANALOG: - return _analogWalkBackwardSpeed.get() * _walkSpeedScalar; - case CONTROLS_ANALOG_PLUS: - return _analogPlusWalkBackwardSpeed.get() * _walkSpeedScalar; - case CONTROLS_DEFAULT: - default: - return _defaultWalkBackwardSpeed.get() * _walkSpeedScalar; + case CONTROLS_ANALOG: + return _analogWalkBackwardSpeed.get() * _walkSpeedScalar; + case CONTROLS_ANALOG_PLUS: + return _analogPlusWalkBackwardSpeed.get() * _walkSpeedScalar; + case CONTROLS_DEFAULT: + default: + return _defaultWalkBackwardSpeed.get() * _walkSpeedScalar; } } @@ -4803,13 +4781,13 @@ void MyAvatar::setSprintMode(bool sprint) { float value = AVATAR_WALK_SPEED_SCALAR; if (sprint) { switch(_controlSchemeIndex) { - case CONTROLS_ANALOG: - value = _analogSprintSpeed.get() * _walkSpeedScalar; - case CONTROLS_ANALOG_PLUS: - value = _analogPlusSprintSpeed.get() * _walkSpeedScalar; - case CONTROLS_DEFAULT: - default: - value = _defaultSprintSpeed.get() * _walkSpeedScalar; + case CONTROLS_ANALOG: + value = _analogSprintSpeed.get() * _walkSpeedScalar; + case CONTROLS_ANALOG_PLUS: + value = _analogPlusSprintSpeed.get() * _walkSpeedScalar; + case CONTROLS_DEFAULT: + default: + value = _defaultSprintSpeed.get() * _walkSpeedScalar; } } _walkSpeedScalar = value; From ac2971894b4704db78f0f5b3d0cdf833f9ffa8de Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Wed, 3 Apr 2019 11:42:40 -0700 Subject: [PATCH 61/68] Fix sprint mode scalar. --- interface/src/avatar/MyAvatar.cpp | 111 +++++++++++++------------ libraries/shared/src/AvatarConstants.h | 4 +- 2 files changed, 59 insertions(+), 56 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index eb82d806e1..ca0e70268b 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3359,38 +3359,47 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig auto zSpeed = getDriveKey(TRANSLATE_Z); auto xSpeed = getDriveKey(TRANSLATE_X); glm::vec3 direction; - switch(_controlSchemeIndex) { - case CONTROLS_DEFAULT: - // No acceleration curve for this one, constant speed. - if (zSpeed || xSpeed) { - direction = (zSpeed * forward) + (xSpeed * right); - // Normalize direction. - direction /= glm::length(direction); - return getSensorToWorldScale() * direction * getSprintSpeed(); - } else { - return Vectors::ZERO; + if (qApp->isHMDMode()) { + switch(_controlSchemeIndex) { + case CONTROLS_DEFAULT: + // No acceleration curve for this one, constant speed. + if (zSpeed || xSpeed) { + direction = (zSpeed * forward) + (xSpeed * right); + // Normalize direction. + auto length = glm::length(direction); + if (length > EPSILON) { + direction /= length; + } + return getSensorToWorldScale() * direction * getSprintSpeed() * _walkSpeedScalar; + } else { + return Vectors::ZERO; + } + case CONTROLS_ANALOG: + if (zSpeed || xSpeed) { + glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * _walkSpeedScalar * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; + glm::vec3 scaledRight = getSensorToWorldScale() * calculateGearedSpeed(xSpeed) * _walkSpeedScalar * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; + direction = scaledForward + scaledRight; + return direction; + } else { + return Vectors::ZERO; + } + case CONTROLS_ANALOG_PLUS: + if (zSpeed || xSpeed) { + glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * _walkSpeedScalar * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; + glm::vec3 scaledRight = getSensorToWorldScale() * calculateGearedSpeed(xSpeed) * _walkSpeedScalar * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; + direction = scaledForward + scaledRight; + return direction; + } else { + return Vectors::ZERO; + } + default: + qDebug() << "Invalid control scheme index."; + return Vectors::ZERO; } - case CONTROLS_ANALOG: - if (zSpeed || xSpeed) { - glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; - glm::vec3 scaledRight = getSensorToWorldScale() * calculateGearedSpeed(xSpeed) * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; - direction = scaledForward + scaledRight; - return direction; - } else { - return Vectors::ZERO; - } - case CONTROLS_ANALOG_PLUS: - if (zSpeed || xSpeed) { - glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; - glm::vec3 scaledRight = getSensorToWorldScale() * calculateGearedSpeed(xSpeed) * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; - direction = scaledForward + scaledRight; - return direction; - } else { - return Vectors::ZERO; - } - default: - qDebug() << "Invalid control scheme index."; - return Vectors::ZERO; + } else { + // Desktop mode. + direction = (zSpeed * forward) + (xSpeed * right); + direction *= getWalkSpeed() * _walkSpeedScalar; } } @@ -3412,9 +3421,17 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ break; case MOVEMENT_HAND_RELATIVE_LEVELED: forward = (handRotation * controllerForward); - forward = glm::normalize(forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y)); + if (glm::length(forward) > EPSILON) { + forward = glm::normalize(forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y)); + } else { + forward = Vectors::ZERO; + } right = (handRotation * controllerRight); - right = glm::normalize(right - (glm::dot(right, Vectors::UNIT_Y) * Vectors::UNIT_Y)); + if (glm::length(right) > EPSILON) { + right = glm::normalize(right - (glm::dot(right, Vectors::UNIT_Y) * Vectors::UNIT_Y)); + } else { + right = Vectors::ZERO; + } break; case MOVEMENT_HMD_RELATIVE: default: @@ -3428,11 +3445,9 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ glm::vec3 direction = scaleMotorSpeed(forward, right); - // RKNOTE: This may need to be changed later... if (state == CharacterController::State::Hover || _characterController.computeCollisionMask() == BULLET_COLLISION_MASK_COLLISIONLESS) { glm::vec3 up = (getDriveKey(TRANSLATE_Y)) * IDENTITY_UP; - //up /= glm::length(up); direction += up; } @@ -4752,24 +4767,24 @@ bool MyAvatar::getIsSitStandStateLocked() const { float MyAvatar::getWalkSpeed() const { switch(_controlSchemeIndex) { case CONTROLS_ANALOG: - return _analogWalkSpeed.get() * _walkSpeedScalar; + return _analogWalkSpeed.get(); case CONTROLS_ANALOG_PLUS: - return _analogPlusWalkSpeed.get() * _walkSpeedScalar; + return _analogPlusWalkSpeed.get(); case CONTROLS_DEFAULT: default: - return _defaultWalkSpeed.get() * _walkSpeedScalar; + return _defaultWalkSpeed.get(); } } float MyAvatar::getWalkBackwardSpeed() const { switch(_controlSchemeIndex) { case CONTROLS_ANALOG: - return _analogWalkBackwardSpeed.get() * _walkSpeedScalar; + return _analogWalkBackwardSpeed.get(); case CONTROLS_ANALOG_PLUS: - return _analogPlusWalkBackwardSpeed.get() * _walkSpeedScalar; + return _analogPlusWalkBackwardSpeed.get(); case CONTROLS_DEFAULT: default: - return _defaultWalkBackwardSpeed.get() * _walkSpeedScalar; + return _defaultWalkBackwardSpeed.get(); } } @@ -4778,19 +4793,7 @@ bool MyAvatar::isReadyForPhysics() const { } void MyAvatar::setSprintMode(bool sprint) { - float value = AVATAR_WALK_SPEED_SCALAR; - if (sprint) { - switch(_controlSchemeIndex) { - case CONTROLS_ANALOG: - value = _analogSprintSpeed.get() * _walkSpeedScalar; - case CONTROLS_ANALOG_PLUS: - value = _analogPlusSprintSpeed.get() * _walkSpeedScalar; - case CONTROLS_DEFAULT: - default: - value = _defaultSprintSpeed.get() * _walkSpeedScalar; - } - } - _walkSpeedScalar = value; + _walkSpeedScalar = sprint ? AVATAR_SPRINT_SPEED_SCALAR : AVATAR_WALK_SPEED_SCALAR; } void MyAvatar::setIsInWalkingState(bool isWalking) { diff --git a/libraries/shared/src/AvatarConstants.h b/libraries/shared/src/AvatarConstants.h index 4e3642de97..5166cb7a0b 100644 --- a/libraries/shared/src/AvatarConstants.h +++ b/libraries/shared/src/AvatarConstants.h @@ -69,7 +69,7 @@ const glm::quat DEFAULT_AVATAR_RIGHTFOOT_ROT { -0.4016716778278351f, 0.915461599 const float DEFAULT_AVATAR_MAX_WALKING_SPEED = 2.6f; // meters / second const float DEFAULT_AVATAR_MAX_WALKING_BACKWARD_SPEED = 2.2f; // meters / second const float DEFAULT_AVATAR_MAX_FLYING_SPEED = 30.0f; // meters / second -const float DEFAULT_AVATAR_MAX_SPRINT_SPEED = 3.0f; // meters / second +const float DEFAULT_AVATAR_MAX_SPRINT_SPEED = 3.4f; // meters / second const float DEFAULT_AVATAR_WALK_SPEED_THRESHOLD = 0.15f; // meters / second const float ANALOG_AVATAR_MAX_WALKING_SPEED = 6.0f; // meters / second @@ -102,6 +102,6 @@ static const float MAX_AVATAR_HEIGHT = 1000.0f * DEFAULT_AVATAR_HEIGHT; // meter static const float MIN_AVATAR_HEIGHT = 0.005f * DEFAULT_AVATAR_HEIGHT; // meters static const float MIN_AVATAR_RADIUS = 0.5f * MIN_AVATAR_HEIGHT; static const float AVATAR_WALK_SPEED_SCALAR = 1.0f; -static const float AVATAR_SPRINT_SPEED_SCALAR = 3.0f; +static const float AVATAR_SPRINT_SPEED_SCALAR = 2.0f; #endif // hifi_AvatarConstants_h From 8b670110a9f065e554c87a2095784a6b6c05d4c7 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Wed, 3 Apr 2019 13:06:22 -0700 Subject: [PATCH 62/68] Fix omitted return in MyAvatar::scaleMotorSpeed --- interface/src/avatar/MyAvatar.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index ac252e511b..0fca97be09 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3397,7 +3397,12 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig } else { // Desktop mode. direction = (zSpeed * forward) + (xSpeed * right); + auto length = glm::length(direction); + if (length > EPSILON) { + direction /= length; + } direction *= getWalkSpeed() * _walkSpeedScalar; + return direction; } } From 283ec97bb9e6137c42045406135d567ea4b33c78 Mon Sep 17 00:00:00 2001 From: r3tk0n Date: Wed, 3 Apr 2019 16:09:13 -0700 Subject: [PATCH 63/68] Fix desktop movement. --- interface/src/avatar/MyAvatar.cpp | 68 +++++++++++++++++++------------ 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 0fca97be09..32c50021d6 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3357,8 +3357,12 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig auto zSpeed = getDriveKey(TRANSLATE_Z); auto xSpeed = getDriveKey(TRANSLATE_X); glm::vec3 direction; - if (qApp->isHMDMode()) { - switch(_controlSchemeIndex) { + if (!useAdvancedMovementControls() && qApp->isHMDMode()) { + // Walking disabled in settings. + return Vectors::ZERO; + } else if (qApp->isHMDMode()) { + // HMD advanced movement controls. + switch (_controlSchemeIndex) { case CONTROLS_DEFAULT: // No acceleration curve for this one, constant speed. if (zSpeed || xSpeed) { @@ -4768,27 +4772,37 @@ bool MyAvatar::getIsSitStandStateLocked() const { } float MyAvatar::getWalkSpeed() const { - switch(_controlSchemeIndex) { - case CONTROLS_ANALOG: - return _analogWalkSpeed.get(); - case CONTROLS_ANALOG_PLUS: - return _analogPlusWalkSpeed.get(); - case CONTROLS_DEFAULT: - default: - return _defaultWalkSpeed.get(); + if (qApp->isHMDMode()) { + switch (_controlSchemeIndex) { + case CONTROLS_ANALOG: + return _analogWalkSpeed.get(); + case CONTROLS_ANALOG_PLUS: + return _analogPlusWalkSpeed.get(); + case CONTROLS_DEFAULT: + default: + return _defaultWalkSpeed.get(); + } + } else { + return _defaultWalkSpeed.get(); } + } float MyAvatar::getWalkBackwardSpeed() const { - switch(_controlSchemeIndex) { - case CONTROLS_ANALOG: - return _analogWalkBackwardSpeed.get(); - case CONTROLS_ANALOG_PLUS: - return _analogPlusWalkBackwardSpeed.get(); - case CONTROLS_DEFAULT: - default: - return _defaultWalkBackwardSpeed.get(); + if (qApp->isHMDMode()) { + switch(_controlSchemeIndex) { + case CONTROLS_ANALOG: + return _analogWalkBackwardSpeed.get(); + case CONTROLS_ANALOG_PLUS: + return _analogPlusWalkBackwardSpeed.get(); + case CONTROLS_DEFAULT: + default: + return _defaultWalkBackwardSpeed.get(); + } + } else { + return _defaultWalkBackwardSpeed.get(); } + } bool MyAvatar::isReadyForPhysics() const { @@ -4907,13 +4921,17 @@ void MyAvatar::setSprintSpeed(float value) { } float MyAvatar::getSprintSpeed() const { - switch(_controlSchemeIndex) { - case CONTROLS_ANALOG: - return _analogSprintSpeed.get(); - case CONTROLS_ANALOG_PLUS: - return _analogPlusSprintSpeed.get(); - case CONTROLS_DEFAULT: - default: + if (qApp->isHMDMode()) { + switch (_controlSchemeIndex) { + case CONTROLS_ANALOG: + return _analogSprintSpeed.get(); + case CONTROLS_ANALOG_PLUS: + return _analogPlusSprintSpeed.get(); + case CONTROLS_DEFAULT: + default: + return _defaultSprintSpeed.get(); + } + } else { return _defaultSprintSpeed.get(); } } From 4f738a5b42d745e8afe030327990b55f5a6bb035 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Thu, 4 Apr 2019 12:03:48 -0700 Subject: [PATCH 64/68] code review feedback/formatting issues --- interface/resources/controllers/standard.json | 4 +- interface/resources/controllers/vive.json | 14 +- interface/src/avatar/MyAvatar.cpp | 187 +++++++++--------- interface/src/avatar/MyAvatar.h | 16 +- interface/src/ui/PreferencesDialog.cpp | 52 ----- 5 files changed, 110 insertions(+), 163 deletions(-) diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 58641892f9..0a5bd12460 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -101,7 +101,7 @@ { "from": "Standard.RightSecondaryThumb", "when": "Application.RightHandDominant", "to": "Actions.Up" - }, + }, { "from": "Standard.Back", "to": "Actions.CycleCamera" }, { "from": "Standard.Start", "to": "Actions.ContextMenu" }, @@ -180,4 +180,4 @@ { "from": "Standard.TrackedObject14", "to" : "Actions.TrackedObject14" }, { "from": "Standard.TrackedObject15", "to" : "Actions.TrackedObject15" } ] -} \ No newline at end of file +} diff --git a/interface/resources/controllers/vive.json b/interface/resources/controllers/vive.json index 4e22ee1bd8..730e1bcb58 100644 --- a/interface/resources/controllers/vive.json +++ b/interface/resources/controllers/vive.json @@ -10,12 +10,7 @@ "filters": [ { "type": "hysteresis", "min": 0.7, "max": 0.75 } ] }, - { "from": "Vive.LY", "when": "Vive.LS", - "filters": [ - { "type": "deadZone", "min": 0.15 }, - "invert" - ] - , "to": "Standard.LY" }, + { "from": "Vive.LY", "when": "Vive.LS", "filters": [ { "type": "deadZone", "min": 0.15 }, "invert" ], "to": "Standard.LY" }, { "from": "Vive.LX", "when": ["Vive.LS", "Application.RightHandDominant"], "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.LX" }, { "from": "Vive.LX", "when": ["Vive.LS", "Vive.LSX", "!Vive.LSY", "Application.LeftHandDominant"], "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.LX" }, { @@ -34,12 +29,7 @@ }, { "from": "Vive.LSTouch", "to": "Standard.LSTouch" }, - { "from": "Vive.RY", "when": "Vive.RS", - "filters": [ - { "type": "deadZone", "min": 0.15 }, - "invert" - ] - , "to": "Standard.RY" }, + { "from": "Vive.RY", "when": "Vive.RS", "filters": [ { "type": "deadZone", "min": 0.15 }, "invert" ], "to": "Standard.RY" }, { "from": "Vive.RX", "when": ["Vive.RS", "Application.LeftHandDominant"], "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.RX" }, { "from": "Vive.RX", "when": ["Vive.RS", "Vive.RSX", "!Vive.RSY", "Application.RightHandDominant"], "filters": { "type": "deadZone", "min": 0.15 }, "to": "Standard.RX" }, { diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 32c50021d6..fd855c172d 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -136,7 +136,7 @@ MyAvatar::MyAvatar(QThread* thread) : _characterController(std::shared_ptr(this)), _eyeContactTarget(LEFT_EYE), _realWorldFieldOfView("realWorldFieldOfView", - DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES), + DEFAULT_REAL_WORLD_FIELD_OF_VIEW_DEGREES), _useAdvancedMovementControls("advancedMovementForHandControllersIsChecked", true), _showPlayArea("showPlayArea", true), _smoothOrientationTimer(std::numeric_limits::max()), @@ -223,7 +223,7 @@ MyAvatar::MyAvatar(QThread* thread) : // connect to AddressManager signal for location jumps connect(DependencyManager::get().data(), &AddressManager::locationChangeRequired, - this, static_cast(&MyAvatar::goToFeetLocation)); + this, static_cast(&MyAvatar::goToFeetLocation)); // handle scale constraints imposed on us by the domain-server auto& domainHandler = DependencyManager::get()->getDomainHandler(); @@ -1890,7 +1890,7 @@ void MyAvatar::loadData() { setDriveGear3(firstRunVal.get() ? DEFAULT_GEAR_3 : _driveGear3Setting.get()); setDriveGear4(firstRunVal.get() ? DEFAULT_GEAR_4 : _driveGear4Setting.get()); setDriveGear5(firstRunVal.get() ? DEFAULT_GEAR_5 : _driveGear5Setting.get()); - setControlSchemeIndex(firstRunVal.get() ? CONTROLS_DEFAULT : _controlSchemeIndexSetting.get()); + setControlSchemeIndex(firstRunVal.get() ? LocomotionControlsMode::CONTROLS_DEFAULT : _controlSchemeIndexSetting.get()); setAnalogWalkSpeed(firstRunVal.get() ? ANALOG_AVATAR_MAX_WALKING_SPEED : _analogWalkSpeedSetting.get()); setAnalogPlusWalkSpeed(firstRunVal.get() ? ANALOG_PLUS_AVATAR_MAX_WALKING_SPEED : _analogPlusWalkSpeedSetting.get()); setFlyingEnabled(getFlyingEnabled()); @@ -3363,7 +3363,7 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig } else if (qApp->isHMDMode()) { // HMD advanced movement controls. switch (_controlSchemeIndex) { - case CONTROLS_DEFAULT: + case LocomotionControlsMode::CONTROLS_DEFAULT: // No acceleration curve for this one, constant speed. if (zSpeed || xSpeed) { direction = (zSpeed * forward) + (xSpeed * right); @@ -3376,7 +3376,7 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig } else { return Vectors::ZERO; } - case CONTROLS_ANALOG: + case LocomotionControlsMode::CONTROLS_ANALOG: if (zSpeed || xSpeed) { glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * _walkSpeedScalar * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; glm::vec3 scaledRight = getSensorToWorldScale() * calculateGearedSpeed(xSpeed) * _walkSpeedScalar * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; @@ -3385,7 +3385,7 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig } else { return Vectors::ZERO; } - case CONTROLS_ANALOG_PLUS: + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: if (zSpeed || xSpeed) { glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * _walkSpeedScalar * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; glm::vec3 scaledRight = getSensorToWorldScale() * calculateGearedSpeed(xSpeed) * _walkSpeedScalar * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; @@ -3422,14 +3422,19 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ glm::vec3 controllerForward(0.0f, 1.0f, 0.0f); glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? 1.0f : -1.0f)); switch (getMovementReference()) { - case MOVEMENT_HAND_RELATIVE: + case LocomotionRelativeMovementMode::MOVEMENT_HAND_RELATIVE: forward = (handRotation * controllerForward); right = (handRotation * controllerRight); break; - case MOVEMENT_HAND_RELATIVE_LEVELED: + case LocomotionRelativeMovementMode::MOVEMENT_HAND_RELATIVE_LEVELED: forward = (handRotation * controllerForward); if (glm::length(forward) > EPSILON) { - forward = glm::normalize(forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y)); + auto transform = forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y); + if (glm::length(transform) > 0.0f) { + forward = glm::normalize(transform); + } else { + forward = Vectors::ZERO; + } } else { forward = Vectors::ZERO; } @@ -3440,7 +3445,7 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ right = Vectors::ZERO; } break; - case MOVEMENT_HMD_RELATIVE: + case LocomotionRelativeMovementMode::MOVEMENT_HMD_RELATIVE: default: forward = IDENTITY_FORWARD; right = IDENTITY_RIGHT; @@ -4070,13 +4075,13 @@ void MyAvatar::setDriveGear1(float shiftPoint) { float MyAvatar::getDriveGear1() { switch (_controlSchemeIndex) { - case CONTROLS_ANALOG: - return ANALOG_AVATAR_GEAR_1; - case CONTROLS_ANALOG_PLUS: - return _driveGear1; - case CONTROLS_DEFAULT: - default: - return 1.0f; + case LocomotionControlsMode::CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_1; + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: + return _driveGear1; + case LocomotionControlsMode::CONTROLS_DEFAULT: + default: + return 1.0f; } } @@ -4091,13 +4096,13 @@ void MyAvatar::setDriveGear2(float shiftPoint) { float MyAvatar::getDriveGear2() { switch (_controlSchemeIndex) { - case CONTROLS_ANALOG: - return ANALOG_AVATAR_GEAR_2; - case CONTROLS_ANALOG_PLUS: - return _driveGear2; - case CONTROLS_DEFAULT: - default: - return 1.0f; + case LocomotionControlsMode::CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_2; + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: + return _driveGear2; + case LocomotionControlsMode::CONTROLS_DEFAULT: + default: + return 1.0f; } } @@ -4112,13 +4117,13 @@ void MyAvatar::setDriveGear3(float shiftPoint) { float MyAvatar::getDriveGear3() { switch (_controlSchemeIndex) { - case CONTROLS_ANALOG: - return ANALOG_AVATAR_GEAR_3; - case CONTROLS_ANALOG_PLUS: - return _driveGear3; - case CONTROLS_DEFAULT: - default: - return 1.0f; + case LocomotionControlsMode::CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_3; + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: + return _driveGear3; + case LocomotionControlsMode::CONTROLS_DEFAULT: + default: + return 1.0f; } } @@ -4133,13 +4138,13 @@ void MyAvatar::setDriveGear4(float shiftPoint) { float MyAvatar::getDriveGear4() { switch (_controlSchemeIndex) { - case CONTROLS_ANALOG: - return ANALOG_AVATAR_GEAR_4; - case CONTROLS_ANALOG_PLUS: - return _driveGear4; - case CONTROLS_DEFAULT: - default: - return 1.0f; + case LocomotionControlsMode::CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_4; + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: + return _driveGear4; + case LocomotionControlsMode::CONTROLS_DEFAULT: + default: + return 1.0f; } } @@ -4154,13 +4159,13 @@ void MyAvatar::setDriveGear5(float shiftPoint) { float MyAvatar::getDriveGear5() { switch (_controlSchemeIndex) { - case CONTROLS_ANALOG: - return ANALOG_AVATAR_GEAR_5; - case CONTROLS_ANALOG_PLUS: - return _driveGear5; - case CONTROLS_DEFAULT: - default: - return 1.0f; + case LocomotionControlsMode::CONTROLS_ANALOG: + return ANALOG_AVATAR_GEAR_5; + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: + return _driveGear5; + case LocomotionControlsMode::CONTROLS_DEFAULT: + default: + return 1.0f; } } @@ -4774,11 +4779,11 @@ bool MyAvatar::getIsSitStandStateLocked() const { float MyAvatar::getWalkSpeed() const { if (qApp->isHMDMode()) { switch (_controlSchemeIndex) { - case CONTROLS_ANALOG: + case LocomotionControlsMode::CONTROLS_ANALOG: return _analogWalkSpeed.get(); - case CONTROLS_ANALOG_PLUS: + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: return _analogPlusWalkSpeed.get(); - case CONTROLS_DEFAULT: + case LocomotionControlsMode::CONTROLS_DEFAULT: default: return _defaultWalkSpeed.get(); } @@ -4790,12 +4795,12 @@ float MyAvatar::getWalkSpeed() const { float MyAvatar::getWalkBackwardSpeed() const { if (qApp->isHMDMode()) { - switch(_controlSchemeIndex) { - case CONTROLS_ANALOG: + switch (_controlSchemeIndex) { + case LocomotionControlsMode::CONTROLS_ANALOG: return _analogWalkBackwardSpeed.get(); - case CONTROLS_ANALOG_PLUS: + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: return _analogPlusWalkBackwardSpeed.get(); - case CONTROLS_DEFAULT: + case LocomotionControlsMode::CONTROLS_DEFAULT: default: return _defaultWalkBackwardSpeed.get(); } @@ -4873,61 +4878,61 @@ void MyAvatar::setIsSitStandStateLocked(bool isLocked) { } void MyAvatar::setWalkSpeed(float value) { - switch(_controlSchemeIndex) { - case CONTROLS_DEFAULT: - _defaultWalkSpeed.set(value); - break; - case CONTROLS_ANALOG: - _analogWalkSpeed.set(value); - break; - case CONTROLS_ANALOG_PLUS: - _analogPlusWalkSpeed.set(value); - break; - default: - break; + switch (_controlSchemeIndex) { + case LocomotionControlsMode::CONTROLS_DEFAULT: + _defaultWalkSpeed.set(value); + break; + case LocomotionControlsMode::CONTROLS_ANALOG: + _analogWalkSpeed.set(value); + break; + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: + _analogPlusWalkSpeed.set(value); + break; + default: + break; } } void MyAvatar::setWalkBackwardSpeed(float value) { - switch(_controlSchemeIndex) { - case CONTROLS_DEFAULT: - _defaultWalkBackwardSpeed.set(value); - break; - case CONTROLS_ANALOG: - _analogWalkBackwardSpeed.set(value); - break; - case CONTROLS_ANALOG_PLUS: - _analogPlusWalkBackwardSpeed.set(value); - break; - default: - break; + switch (_controlSchemeIndex) { + case LocomotionControlsMode::CONTROLS_DEFAULT: + _defaultWalkBackwardSpeed.set(value); + break; + case LocomotionControlsMode::CONTROLS_ANALOG: + _analogWalkBackwardSpeed.set(value); + break; + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: + _analogPlusWalkBackwardSpeed.set(value); + break; + default: + break; } } void MyAvatar::setSprintSpeed(float value) { - switch(_controlSchemeIndex) { - case CONTROLS_DEFAULT: - _defaultSprintSpeed.set(value); - break; - case CONTROLS_ANALOG: - _analogSprintSpeed.set(value); - break; - case CONTROLS_ANALOG_PLUS: - _analogPlusSprintSpeed.set(value); - break; - default: - break; + switch (_controlSchemeIndex) { + case LocomotionControlsMode::CONTROLS_DEFAULT: + _defaultSprintSpeed.set(value); + break; + case LocomotionControlsMode::CONTROLS_ANALOG: + _analogSprintSpeed.set(value); + break; + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: + _analogPlusSprintSpeed.set(value); + break; + default: + break; } } float MyAvatar::getSprintSpeed() const { if (qApp->isHMDMode()) { switch (_controlSchemeIndex) { - case CONTROLS_ANALOG: + case LocomotionControlsMode::CONTROLS_ANALOG: return _analogSprintSpeed.get(); - case CONTROLS_ANALOG_PLUS: + case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: return _analogPlusSprintSpeed.get(); - case CONTROLS_DEFAULT: + case LocomotionControlsMode::CONTROLS_DEFAULT: default: return _defaultSprintSpeed.get(); } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index c7aa0c0aa1..004c34032a 100755 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -39,13 +39,17 @@ class ModelItemID; class MyHead; class DetailedMotionState; -const int CONTROLS_DEFAULT = 0; -const int CONTROLS_ANALOG = 1; -const int CONTROLS_ANALOG_PLUS = 2; +enum LocomotionControlsMode { + CONTROLS_DEFAULT = 0, + CONTROLS_ANALOG, + CONTROLS_ANALOG_PLUS +}; -const int MOVEMENT_HMD_RELATIVE = 0; -const int MOVEMENT_HAND_RELATIVE = 1; -const int MOVEMENT_HAND_RELATIVE_LEVELED = 2; +enum LocomotionRelativeMovementMode { + MOVEMENT_HMD_RELATIVE = 0, + MOVEMENT_HAND_RELATIVE, + MOVEMENT_HAND_RELATIVE_LEVELED +} enum eyeContactTarget { LEFT_EYE, diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 81f018c119..75279ef889 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -379,58 +379,6 @@ void setupPreferences() { preferences->addPreference(preference); } - //static const QString ACCEL_CURVE{ "Acceleration Step Function" }; - //{ - // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear1(); }; - // auto setter = [myAvatar](float value) { myAvatar->setDriveGear1(value); }; - // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 1", getter, setter); - // preference->setMin(0.0f); - // preference->setMax(1.0f); - // preference->setStep(1); - // preference->setDecimals(2); - // preferences->addPreference(preference); - //} - //{ - // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear2(); }; - // auto setter = [myAvatar](float value) { myAvatar->setDriveGear2(value); }; - // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 2", getter, setter); - // preference->setMin(0.0f); - // preference->setMax(1.0f); - // preference->setStep(1); - // preference->setDecimals(2); - // preferences->addPreference(preference); - //} - //{ - // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear3(); }; - // auto setter = [myAvatar](float value) { myAvatar->setDriveGear3(value); }; - // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 3", getter, setter); - // preference->setMin(0.0f); - // preference->setMax(1.0f); - // preference->setStep(1); - // preference->setDecimals(2); - // preferences->addPreference(preference); - //} - //{ - // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear4(); }; - // auto setter = [myAvatar](float value) { myAvatar->setDriveGear4(value); }; - // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 4", getter, setter); - // preference->setMin(0.0f); - // preference->setMax(1.0f); - // preference->setStep(1); - // preference->setDecimals(2); - // preferences->addPreference(preference); - //} - //{ - // auto getter = [myAvatar]()->float { return myAvatar->getDriveGear5(); }; - // auto setter = [myAvatar](float value) { myAvatar->setDriveGear5(value); }; - // auto preference = new SpinnerPreference(ACCEL_CURVE, "Gear 5", getter, setter); - // preference->setMin(0.0f); - // preference->setMax(1.0f); - // preference->setStep(1); - // preference->setDecimals(2); - // preferences->addPreference(preference); - //} - static const QString AVATAR_CAMERA{ "Mouse Sensitivity" }; { auto getter = [myAvatar]()->float { return myAvatar->getPitchSpeed(); }; From ec4ad021922b3d71b3cc2daa991601645dca6f38 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Thu, 4 Apr 2019 13:26:34 -0700 Subject: [PATCH 65/68] more code feedback --- interface/src/avatar/MyAvatar.cpp | 17 +++-------------- interface/src/avatar/MyAvatar.h | 2 +- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index fd855c172d..49064435c8 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3377,14 +3377,6 @@ glm::vec3 MyAvatar::scaleMotorSpeed(const glm::vec3 forward, const glm::vec3 rig return Vectors::ZERO; } case LocomotionControlsMode::CONTROLS_ANALOG: - if (zSpeed || xSpeed) { - glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * _walkSpeedScalar * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; - glm::vec3 scaledRight = getSensorToWorldScale() * calculateGearedSpeed(xSpeed) * _walkSpeedScalar * ((xSpeed > stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * right; - direction = scaledForward + scaledRight; - return direction; - } else { - return Vectors::ZERO; - } case LocomotionControlsMode::CONTROLS_ANALOG_PLUS: if (zSpeed || xSpeed) { glm::vec3 scaledForward = getSensorToWorldScale() * calculateGearedSpeed(zSpeed) * _walkSpeedScalar * ((zSpeed >= stickFullOn) ? getSprintSpeed() : getWalkSpeed()) * forward; @@ -3429,12 +3421,9 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ case LocomotionRelativeMovementMode::MOVEMENT_HAND_RELATIVE_LEVELED: forward = (handRotation * controllerForward); if (glm::length(forward) > EPSILON) { - auto transform = forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y); - if (glm::length(transform) > 0.0f) { - forward = glm::normalize(transform); - } else { - forward = Vectors::ZERO; - } + auto transform = forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y); + if (glm::length(transform) > EPSILON) { + forward = glm::normalize(transform); } else { forward = Vectors::ZERO; } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 004c34032a..804e2687e7 100755 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -49,7 +49,7 @@ enum LocomotionRelativeMovementMode { MOVEMENT_HMD_RELATIVE = 0, MOVEMENT_HAND_RELATIVE, MOVEMENT_HAND_RELATIVE_LEVELED -} +}; enum eyeContactTarget { LEFT_EYE, From 819bf9212cf06723123bc79ba49cbeb5d3604948 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Thu, 4 Apr 2019 13:47:13 -0700 Subject: [PATCH 66/68] fixing typo --- interface/src/avatar/MyAvatar.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 49064435c8..fc6e939941 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3420,7 +3420,6 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ break; case LocomotionRelativeMovementMode::MOVEMENT_HAND_RELATIVE_LEVELED: forward = (handRotation * controllerForward); - if (glm::length(forward) > EPSILON) { auto transform = forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y); if (glm::length(transform) > EPSILON) { forward = glm::normalize(transform); From c18b00ebec58c231edb8cf4739dbddbc6b71b40d Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Thu, 4 Apr 2019 13:55:35 -0700 Subject: [PATCH 67/68] adding precheck procedure --- interface/src/avatar/MyAvatar.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index fc6e939941..85b04f2764 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3427,8 +3427,9 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ forward = Vectors::ZERO; } right = (handRotation * controllerRight); - if (glm::length(right) > EPSILON) { - right = glm::normalize(right - (glm::dot(right, Vectors::UNIT_Y) * Vectors::UNIT_Y)); + transform = right - (glm::dot(right, Vectors::UNIT_Y) * Vectors::UNIT_Y); + if (glm::length(transform) > EPSILON) { + right = glm::normalize(transform); } else { right = Vectors::ZERO; } From 3f85e064b859e12042d01daedec9568ba51cb43a Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Thu, 4 Apr 2019 14:46:06 -0700 Subject: [PATCH 68/68] initialize transform outside of switch statement --- interface/src/avatar/MyAvatar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 85b04f2764..568b492b46 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -3413,6 +3413,7 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ auto handRotation = getOffHandRotation(); glm::vec3 controllerForward(0.0f, 1.0f, 0.0f); glm::vec3 controllerRight(0.0f, 0.0f, (getDominantHand() == DOMINANT_RIGHT_HAND ? 1.0f : -1.0f)); + glm::vec3 transform; switch (getMovementReference()) { case LocomotionRelativeMovementMode::MOVEMENT_HAND_RELATIVE: forward = (handRotation * controllerForward); @@ -3420,7 +3421,7 @@ glm::vec3 MyAvatar::calculateScaledDirection(){ break; case LocomotionRelativeMovementMode::MOVEMENT_HAND_RELATIVE_LEVELED: forward = (handRotation * controllerForward); - auto transform = forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y); + transform = forward - (glm::dot(forward, Vectors::UNIT_Y) * Vectors::UNIT_Y); if (glm::length(transform) > EPSILON) { forward = glm::normalize(transform); } else {