From 9f3b82a417051c221b2cd533585f7a827959935e Mon Sep 17 00:00:00 2001 From: amantley Date: Tue, 27 Mar 2018 18:21:14 -0700 Subject: [PATCH 1/4] added the functions triggerVerticalRecenter,triggerHorizontalRecenter,and triggerRotationRecenter to MyAvatar.h, these allow java script calls to recenter the avatar on the fly --- interface/src/avatar/MyAvatar.cpp | 46 ++++++++++++++++++++++++++++++- interface/src/avatar/MyAvatar.h | 28 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 9620a2dcec..b98620cbcb 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2760,6 +2760,27 @@ bool MyAvatar::isDriveKeyDisabled(DriveKeys key) const { } } +void MyAvatar::triggerVerticalRecenter() { + //do something here + _follow._forceActivateVertical = true; + + +} + +void MyAvatar::triggerHorizontalRecenter() { + //do something here + _follow._forceActivateHorizontal = true; + + +} + +void MyAvatar::triggerRotationRecenter() { + //do something here + _follow._forceActivateRotation = true; + + +} + // old school meat hook style glm::mat4 MyAvatar::deriveBodyFromHMDSensor() const { glm::vec3 headPosition; @@ -2953,7 +2974,9 @@ void MyAvatar::FollowHelper::decrementTimeRemaining(float dt) { bool MyAvatar::FollowHelper::shouldActivateRotation(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const { const float FOLLOW_ROTATION_THRESHOLD = cosf(PI / 6.0f); // 30 degrees glm::vec2 bodyFacing = getFacingDir2D(currentBodyMatrix); + return glm::dot(-myAvatar.getHeadControllerFacingMovingAverage(), bodyFacing) < FOLLOW_ROTATION_THRESHOLD; + } bool MyAvatar::FollowHelper::shouldActivateHorizontal(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const { @@ -2970,13 +2993,16 @@ bool MyAvatar::FollowHelper::shouldActivateHorizontal(const MyAvatar& myAvatar, const float MAX_FORWARD_LEAN = 0.15f; const float MAX_BACKWARD_LEAN = 0.1f; + if (forwardLeanAmount > 0 && forwardLeanAmount > MAX_FORWARD_LEAN) { return true; - } else if (forwardLeanAmount < 0 && forwardLeanAmount < -MAX_BACKWARD_LEAN) { + } + else if (forwardLeanAmount < 0 && forwardLeanAmount < -MAX_BACKWARD_LEAN) { return true; } return fabs(lateralLeanAmount) > MAX_LATERAL_LEAN; + } bool MyAvatar::FollowHelper::shouldActivateVertical(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const { @@ -2984,6 +3010,7 @@ bool MyAvatar::FollowHelper::shouldActivateVertical(const MyAvatar& myAvatar, co const float CYLINDER_BOTTOM = -1.5f; glm::vec3 offset = extractTranslation(desiredBodyMatrix) - extractTranslation(currentBodyMatrix); + return (offset.y > CYLINDER_TOP) || (offset.y < CYLINDER_BOTTOM); } @@ -3002,6 +3029,23 @@ void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat activate(Vertical); } } + else { + if (!isActive(Rotation) && _forceActivateRotation) { + activate(Rotation); + _forceActivateRotation = false; + qCDebug(interfaceapp) << "the rotation property is activated+++++++++++++++++++++++" << endl; + } + if (!isActive(Horizontal) && _forceActivateHorizontal) { + activate(Horizontal); + _forceActivateHorizontal = false; + qCDebug(interfaceapp) << "the horizontal property is activated+++++++++++++++++++++++" << endl; + } + if (!isActive(Vertical) && _forceActivateVertical) { + activate(Vertical); + _forceActivateVertical = false; + qCDebug(interfaceapp) << "the vertical property is activated+++++++++++++++++++++++" << endl; + } + } glm::mat4 desiredWorldMatrix = myAvatar.getSensorToWorldMatrix() * desiredBodyMatrix; glm::mat4 currentWorldMatrix = myAvatar.getSensorToWorldMatrix() * currentBodyMatrix; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 5ca010d128..c3136b14c2 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -104,6 +104,9 @@ class MyAvatar : public Avatar { * @property rightHandTipPose {Pose} READ-ONLY. Returns a pose offset 30 cm from MyAvatar.rightHandPose * @property hmdLeanRecenterEnabled {bool} This can be used disable the hmd lean recenter behavior. This behavior is what causes your avatar * to follow your HMD as you walk around the room, in room scale VR. Disabling this is useful if you desire to pin the avatar to a fixed location. + * @property hmdVerticalRecenterEnabled {bool} This can be used to turn vertical recenter off and on. + * @property hmdHorizontalRecenterEnabled {bool} This can be used to turn horizontal recenter off and on. + * @property hmdRotationRecenterEnabled {bool} This can be used to turn rotational recenter off and on. * @property collisionsEnabled {bool} This can be used to disable collisions between the avatar and the world. * @property useAdvancedMovementControls {bool} Stores the user preference only, does not change user mappings, this is done in the defaultScript * "scripts/system/controllers/toggleAdvancedMovementForHandControllers.js". @@ -149,6 +152,9 @@ class MyAvatar : public Avatar { Q_PROPERTY(bool isAway READ getIsAway WRITE setAway) Q_PROPERTY(bool hmdLeanRecenterEnabled READ getHMDLeanRecenterEnabled WRITE setHMDLeanRecenterEnabled) + Q_PROPERTY(bool hmdVerticalRecenterEnabled READ getHMDVerticalRecenterEnabled WRITE setHMDVerticalRecenterEnabled) + Q_PROPERTY(bool hmdHorizontalRecenterEnabled READ getHMDHorizontalRecenterEnabled WRITE setHMDHorizontalRecenterEnabled) + Q_PROPERTY(bool hmdRotationRecenterEnabled READ getHMDRotationRecenterEnabled WRITE setHMDRotationRecenterEnabled) Q_PROPERTY(bool collisionsEnabled READ getCollisionsEnabled WRITE setCollisionsEnabled) Q_PROPERTY(bool characterControllerEnabled READ getCharacterControllerEnabled WRITE setCharacterControllerEnabled) Q_PROPERTY(bool useAdvancedMovementControls READ useAdvancedMovementControls WRITE setUseAdvancedMovementControls) @@ -374,6 +380,15 @@ public: Q_INVOKABLE void setHMDLeanRecenterEnabled(bool value) { _hmdLeanRecenterEnabled = value; } Q_INVOKABLE bool getHMDLeanRecenterEnabled() const { return _hmdLeanRecenterEnabled; } + Q_INVOKABLE void setHMDVerticalRecenterEnabled(bool value) { _hmdVerticalRecenterEnabled = value; } + Q_INVOKABLE bool getHMDVerticalRecenterEnabled() const { return _hmdVerticalRecenterEnabled; } + + Q_INVOKABLE void setHMDHorizontalRecenterEnabled(bool value) { _hmdHorizontalRecenterEnabled = value; } + Q_INVOKABLE bool getHMDHorizontalRecenterEnabled() const { return _hmdHorizontalRecenterEnabled; } + + Q_INVOKABLE void setHMDRotationRecenterEnabled(bool value) { _hmdRotationRecenterEnabled = value; } + Q_INVOKABLE bool getHMDRotationRecenterEnabled() const { return _hmdRotationRecenterEnabled; } + bool useAdvancedMovementControls() const { return _useAdvancedMovementControls.get(); } void setUseAdvancedMovementControls(bool useAdvancedMovementControls) { _useAdvancedMovementControls.set(useAdvancedMovementControls); } @@ -403,6 +418,10 @@ public: Q_INVOKABLE void enableDriveKey(DriveKeys key); Q_INVOKABLE bool isDriveKeyDisabled(DriveKeys key) const; + Q_INVOKABLE void triggerVerticalRecenter(); + Q_INVOKABLE void triggerHorizontalRecenter(); + Q_INVOKABLE void triggerRotationRecenter(); + eyeContactTarget getEyeContactTarget(); const MyHead* getMyHead() const; @@ -802,6 +821,12 @@ private: bool shouldActivateHorizontal(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const; void prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& bodySensorMatrix, const glm::mat4& currentBodyMatrix, bool hasDriveInput); glm::mat4 postPhysicsUpdate(const MyAvatar& myAvatar, const glm::mat4& currentBodyMatrix); + bool getForceActivateRotation(); + bool getForceActivateVertical(); + bool getForceActivateHorizontal(); + bool _forceActivateRotation{ false }; + bool _forceActivateVertical{ false }; + bool _forceActivateHorizontal{ false }; }; FollowHelper _follow; @@ -837,6 +862,9 @@ private: mutable std::mutex _controllerPoseMapMutex; bool _hmdLeanRecenterEnabled = true; + bool _hmdVerticalRecenterEnabled = true; + bool _hmdHorizontalRecenterEnabled = true; + bool _hmdRotationRecenterEnabled = true; AnimPose _prePhysicsRoomPose; std::mutex _holdActionsMutex; std::vector _holdActions; From 95f1d0e4fab16d91b65042090f7981d3527fbba0 Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 28 Mar 2018 10:33:00 -0700 Subject: [PATCH 2/4] added get and set functions for the activate recenter variables --- interface/src/avatar/MyAvatar.cpp | 58 +++++++++++++++++++------------ interface/src/avatar/MyAvatar.h | 22 +++--------- 2 files changed, 39 insertions(+), 41 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index b98620cbcb..2a523e9b9e 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2761,24 +2761,15 @@ bool MyAvatar::isDriveKeyDisabled(DriveKeys key) const { } void MyAvatar::triggerVerticalRecenter() { - //do something here - _follow._forceActivateVertical = true; - - + _follow.setForceActivateVertical(true); } void MyAvatar::triggerHorizontalRecenter() { - //do something here - _follow._forceActivateHorizontal = true; - - + _follow.setForceActivateHorizontal(true); } void MyAvatar::triggerRotationRecenter() { - //do something here - _follow._forceActivateRotation = true; - - + _follow.setForceActivateRotation(true); } // old school meat hook style @@ -3028,22 +3019,19 @@ void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat if (!isActive(Vertical) && (shouldActivateVertical(myAvatar, desiredBodyMatrix, currentBodyMatrix) || hasDriveInput)) { activate(Vertical); } - } - else { - if (!isActive(Rotation) && _forceActivateRotation) { + } else { + //qCDebug(interfaceapp) << "turned off the recenter" << endl; + if (!isActive(Rotation) && getForceActivateRotation()) { activate(Rotation); - _forceActivateRotation = false; - qCDebug(interfaceapp) << "the rotation property is activated+++++++++++++++++++++++" << endl; + setForceActivateRotation(false); } - if (!isActive(Horizontal) && _forceActivateHorizontal) { + if (!isActive(Horizontal) && getForceActivateHorizontal()) { activate(Horizontal); - _forceActivateHorizontal = false; - qCDebug(interfaceapp) << "the horizontal property is activated+++++++++++++++++++++++" << endl; + setForceActivateHorizontal(false); } - if (!isActive(Vertical) && _forceActivateVertical) { + if (!isActive(Vertical) && getForceActivateVertical()) { activate(Vertical); - _forceActivateVertical = false; - qCDebug(interfaceapp) << "the vertical property is activated+++++++++++++++++++++++" << endl; + setForceActivateVertical(false); } } @@ -3094,6 +3082,30 @@ glm::mat4 MyAvatar::FollowHelper::postPhysicsUpdate(const MyAvatar& myAvatar, co } } +bool MyAvatar::FollowHelper::getForceActivateRotation() { + return _forceActivateRotation; +} + +void MyAvatar::FollowHelper::setForceActivateRotation(bool val) { + _forceActivateRotation = val; +} + +bool MyAvatar::FollowHelper::getForceActivateVertical() { + return _forceActivateVertical; +} + +void MyAvatar::FollowHelper::setForceActivateVertical(bool val) { + _forceActivateVertical = val; +} + +bool MyAvatar::FollowHelper::getForceActivateHorizontal() { + return _forceActivateHorizontal; +} + +void MyAvatar::FollowHelper::setForceActivateHorizontal(bool val) { + _forceActivateHorizontal = val; +} + float MyAvatar::getAccelerationEnergy() { glm::vec3 velocity = getWorldVelocity(); int changeInVelocity = abs(velocity.length() - priorVelocity.length()); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index c3136b14c2..6f7caa5c7d 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -104,9 +104,6 @@ class MyAvatar : public Avatar { * @property rightHandTipPose {Pose} READ-ONLY. Returns a pose offset 30 cm from MyAvatar.rightHandPose * @property hmdLeanRecenterEnabled {bool} This can be used disable the hmd lean recenter behavior. This behavior is what causes your avatar * to follow your HMD as you walk around the room, in room scale VR. Disabling this is useful if you desire to pin the avatar to a fixed location. - * @property hmdVerticalRecenterEnabled {bool} This can be used to turn vertical recenter off and on. - * @property hmdHorizontalRecenterEnabled {bool} This can be used to turn horizontal recenter off and on. - * @property hmdRotationRecenterEnabled {bool} This can be used to turn rotational recenter off and on. * @property collisionsEnabled {bool} This can be used to disable collisions between the avatar and the world. * @property useAdvancedMovementControls {bool} Stores the user preference only, does not change user mappings, this is done in the defaultScript * "scripts/system/controllers/toggleAdvancedMovementForHandControllers.js". @@ -152,9 +149,6 @@ class MyAvatar : public Avatar { Q_PROPERTY(bool isAway READ getIsAway WRITE setAway) Q_PROPERTY(bool hmdLeanRecenterEnabled READ getHMDLeanRecenterEnabled WRITE setHMDLeanRecenterEnabled) - Q_PROPERTY(bool hmdVerticalRecenterEnabled READ getHMDVerticalRecenterEnabled WRITE setHMDVerticalRecenterEnabled) - Q_PROPERTY(bool hmdHorizontalRecenterEnabled READ getHMDHorizontalRecenterEnabled WRITE setHMDHorizontalRecenterEnabled) - Q_PROPERTY(bool hmdRotationRecenterEnabled READ getHMDRotationRecenterEnabled WRITE setHMDRotationRecenterEnabled) Q_PROPERTY(bool collisionsEnabled READ getCollisionsEnabled WRITE setCollisionsEnabled) Q_PROPERTY(bool characterControllerEnabled READ getCharacterControllerEnabled WRITE setCharacterControllerEnabled) Q_PROPERTY(bool useAdvancedMovementControls READ useAdvancedMovementControls WRITE setUseAdvancedMovementControls) @@ -380,15 +374,6 @@ public: Q_INVOKABLE void setHMDLeanRecenterEnabled(bool value) { _hmdLeanRecenterEnabled = value; } Q_INVOKABLE bool getHMDLeanRecenterEnabled() const { return _hmdLeanRecenterEnabled; } - Q_INVOKABLE void setHMDVerticalRecenterEnabled(bool value) { _hmdVerticalRecenterEnabled = value; } - Q_INVOKABLE bool getHMDVerticalRecenterEnabled() const { return _hmdVerticalRecenterEnabled; } - - Q_INVOKABLE void setHMDHorizontalRecenterEnabled(bool value) { _hmdHorizontalRecenterEnabled = value; } - Q_INVOKABLE bool getHMDHorizontalRecenterEnabled() const { return _hmdHorizontalRecenterEnabled; } - - Q_INVOKABLE void setHMDRotationRecenterEnabled(bool value) { _hmdRotationRecenterEnabled = value; } - Q_INVOKABLE bool getHMDRotationRecenterEnabled() const { return _hmdRotationRecenterEnabled; } - bool useAdvancedMovementControls() const { return _useAdvancedMovementControls.get(); } void setUseAdvancedMovementControls(bool useAdvancedMovementControls) { _useAdvancedMovementControls.set(useAdvancedMovementControls); } @@ -822,8 +807,11 @@ private: void prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& bodySensorMatrix, const glm::mat4& currentBodyMatrix, bool hasDriveInput); glm::mat4 postPhysicsUpdate(const MyAvatar& myAvatar, const glm::mat4& currentBodyMatrix); bool getForceActivateRotation(); + void setForceActivateRotation(bool val); bool getForceActivateVertical(); + void setForceActivateVertical(bool val); bool getForceActivateHorizontal(); + void setForceActivateHorizontal(bool val); bool _forceActivateRotation{ false }; bool _forceActivateVertical{ false }; bool _forceActivateHorizontal{ false }; @@ -862,9 +850,7 @@ private: mutable std::mutex _controllerPoseMapMutex; bool _hmdLeanRecenterEnabled = true; - bool _hmdVerticalRecenterEnabled = true; - bool _hmdHorizontalRecenterEnabled = true; - bool _hmdRotationRecenterEnabled = true; + AnimPose _prePhysicsRoomPose; std::mutex _holdActionsMutex; std::vector _holdActions; From 90d87c5b5d6dacf6a106e5a24aab44ecc393c5cc Mon Sep 17 00:00:00 2001 From: amantley Date: Wed, 28 Mar 2018 14:00:36 -0700 Subject: [PATCH 3/4] changed get functions to const in MyAvatar.cpp changed bool variables to atomic for thread safety --- interface/src/avatar/MyAvatar.cpp | 10 ++++------ interface/src/avatar/MyAvatar.h | 12 ++++++------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 46dad99bb5..a9cab9582d 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -2991,8 +2991,7 @@ bool MyAvatar::FollowHelper::shouldActivateHorizontal(const MyAvatar& myAvatar, if (forwardLeanAmount > 0 && forwardLeanAmount > MAX_FORWARD_LEAN) { return true; - } - else if (forwardLeanAmount < 0 && forwardLeanAmount < -MAX_BACKWARD_LEAN) { + } else if (forwardLeanAmount < 0 && forwardLeanAmount < -MAX_BACKWARD_LEAN) { return true; } @@ -3024,7 +3023,6 @@ void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat activate(Vertical); } } else { - //qCDebug(interfaceapp) << "turned off the recenter" << endl; if (!isActive(Rotation) && getForceActivateRotation()) { activate(Rotation); setForceActivateRotation(false); @@ -3086,7 +3084,7 @@ glm::mat4 MyAvatar::FollowHelper::postPhysicsUpdate(const MyAvatar& myAvatar, co } } -bool MyAvatar::FollowHelper::getForceActivateRotation() { +bool MyAvatar::FollowHelper::getForceActivateRotation() const { return _forceActivateRotation; } @@ -3094,7 +3092,7 @@ void MyAvatar::FollowHelper::setForceActivateRotation(bool val) { _forceActivateRotation = val; } -bool MyAvatar::FollowHelper::getForceActivateVertical() { +bool MyAvatar::FollowHelper::getForceActivateVertical() const { return _forceActivateVertical; } @@ -3102,7 +3100,7 @@ void MyAvatar::FollowHelper::setForceActivateVertical(bool val) { _forceActivateVertical = val; } -bool MyAvatar::FollowHelper::getForceActivateHorizontal() { +bool MyAvatar::FollowHelper::getForceActivateHorizontal() const { return _forceActivateHorizontal; } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 8644a277c0..6a9d53e6f4 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -807,15 +807,15 @@ private: bool shouldActivateHorizontal(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const; void prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& bodySensorMatrix, const glm::mat4& currentBodyMatrix, bool hasDriveInput); glm::mat4 postPhysicsUpdate(const MyAvatar& myAvatar, const glm::mat4& currentBodyMatrix); - bool getForceActivateRotation(); + bool getForceActivateRotation() const; void setForceActivateRotation(bool val); - bool getForceActivateVertical(); + bool getForceActivateVertical() const; void setForceActivateVertical(bool val); - bool getForceActivateHorizontal(); + bool getForceActivateHorizontal() const; void setForceActivateHorizontal(bool val); - bool _forceActivateRotation{ false }; - bool _forceActivateVertical{ false }; - bool _forceActivateHorizontal{ false }; + std::atomic _forceActivateRotation{ false }; + std::atomic _forceActivateVertical{ false }; + std::atomic _forceActivateHorizontal{ false }; }; FollowHelper _follow; From 3f44b88d2d5d512d4dedcfa988b1951e76dca4a1 Mon Sep 17 00:00:00 2001 From: amantley Date: Thu, 29 Mar 2018 10:09:51 -0700 Subject: [PATCH 4/4] added js documentation for the three trigger recenter functionsthat have been added to MyAvatar class --- interface/src/avatar/MyAvatar.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 6a9d53e6f4..118f14e71b 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -404,6 +404,28 @@ public: Q_INVOKABLE void enableDriveKey(DriveKeys key); Q_INVOKABLE bool isDriveKeyDisabled(DriveKeys key) const; + /**jsdoc + *The triggerVerticalRecenter function activates one time the recentering + *behaviour in the vertical direction. This call is only takes effect when the property + *MyAvatar.hmdLeanRecenterEnabled is set to false. + *@function MyAvatar.triggerVerticalRecenter + * + */ + + /**jsdoc + *The triggerHorizontalRecenter function activates one time the recentering behaviour + *in the horizontal direction. This call is only takes effect when the property + *MyAvatar.hmdLeanRecenterEnabled is set to false. + *@function MyAvatar.triggerHorizontalRecenter + */ + + /**jsdoc + *The triggerRotationRecenter function activates one time the recentering behaviour + *in the rotation of the root of the avatar. This call is only takes effect when the property + *MyAvatar.hmdLeanRecenterEnabled is set to false. + *@function MyAvatar.triggerRotationRecenter + */ + Q_INVOKABLE void triggerVerticalRecenter(); Q_INVOKABLE void triggerHorizontalRecenter(); Q_INVOKABLE void triggerRotationRecenter();