From d730b7b87b52d26a053a75ba19748b4369d25272 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Fri, 15 Dec 2017 17:00:54 -0800 Subject: [PATCH 1/3] consistent goToUser behavior in PAL, and be able to go to flying user. --- interface/resources/qml/hifi/NameCard.qml | 13 +++---------- interface/src/avatar/MyAvatar.cpp | 14 ++++++++++++++ libraries/networking/src/AddressManager.cpp | 2 +- libraries/physics/src/CharacterController.cpp | 11 +++++++++++ libraries/physics/src/CharacterController.h | 2 ++ 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/interface/resources/qml/hifi/NameCard.qml b/interface/resources/qml/hifi/NameCard.qml index 1f9caf747a..308f72345d 100644 --- a/interface/resources/qml/hifi/NameCard.qml +++ b/interface/resources/qml/hifi/NameCard.qml @@ -597,18 +597,11 @@ Item { // Function body by Howard Stearns 2017-01-08 function goToUserInDomain(avatarUuid) { var avatar = AvatarList.getAvatar(avatarUuid); - if (!avatar) { + if (!avatar || !avatar.position || !avatar.orientation) { console.log("This avatar is no longer present. goToUserInDomain() failed."); return; } - // FIXME: We would like the avatar to recompute the avatar's "maybe fly" test at the new position, so that if high enough up, - // the avatar goes into fly mode rather than falling. However, that is not exposed to Javascript right now. - // FIXME: it would be nice if this used the same teleport steps and smoothing as in the teleport.js script. - // Note, however, that this script allows teleporting to a person in the air, while teleport.js is going to a grounded target. - // Position avatar 2 metres from the target in the direction that target avatar was facing. - MyAvatar.position = Vec3.sum(avatar.position, Vec3.multiplyQbyV(avatar.orientation, {x: 0, y: 0, z: -2})); - - // Rotate avatar on Y axis to face target avatar and cancel out any inherited roll and pitch. - MyAvatar.orientation = Quat.cancelOutRollAndPitch(Quat.multiply(avatar.orientation, {y: 1})); + // This is the last step of what AddressManager.goToUser does, but we don't need to resolve the username. + MyAvatar.goToLocation(avatar.position, true, Quat.cancelOutRollAndPitch(avatar.orientation), true) } } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 02a1959a95..832ec7d00e 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -424,6 +424,7 @@ void MyAvatar::update(float deltaTime) { emit positionGoneTo(); // Run safety tests as soon as we can after goToLocation, or clear if we're not colliding. _physicsSafetyPending = getCollisionsEnabled(); + _characterController.recomputeFlying(); // In case we've gone to into the sky. } if (_physicsSafetyPending && qApp->isPhysicsEnabled() && _characterController.isEnabledAndReady()) { // When needed and ready, arrange to check and fix. @@ -2315,6 +2316,19 @@ void MyAvatar::goToLocation(const glm::vec3& newPosition, bool hasOrientation, const glm::quat& newOrientation, bool shouldFaceLocation) { + // 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 + // still worked if the target is in the air. + // - Sometimes (such as the response from /api/v1/users/:username/location), the location can be stale, but there is a + // node_id supplied by which we could update the information after going to the stale location first and "looking around". + // This could be passed through AddressManager::goToAddressFromObject => AddressManager::handleViewpoint => here. + // The trick is that you have to yield enough time to resolve the node_id. + // - Instead of always doing the same thing for shouldFaceLocation -- which places users uncomfortabley on top of each other -- + // it would be nice to see how many users are already "at" a person or place, and place ourself in semicircle or other shape + // around the target. Avatars and entities (specified by the node_id) could define an adjustable "face me" method that would + // compute the position (e.g., so that if I'm on stage, going to me would compute an available seat in the audience rather than + // being in my face on-stage). Note that this could work for going to an entity as well as to a person. + qCDebug(interfaceapp).nospace() << "MyAvatar goToLocation - moving to " << newPosition.x << ", " << newPosition.y << ", " << newPosition.z; diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index b884dcba17..21815e065a 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -596,7 +596,7 @@ bool AddressManager::handleDomainID(const QString& host) { void AddressManager::handlePath(const QString& path, LookupTrigger trigger, bool wasPathOnly) { if (!handleViewpoint(path, false, trigger, wasPathOnly)) { qCDebug(networking) << "User entered path could not be handled as a viewpoint - " << path << - "- wll attempt to ask domain-server to resolve."; + "- will attempt to ask domain-server to resolve."; if (!wasPathOnly) { // if we received a path with a host then we need to remember what it was here so we can not diff --git a/libraries/physics/src/CharacterController.cpp b/libraries/physics/src/CharacterController.cpp index 32e764bd10..f4107951b8 100755 --- a/libraries/physics/src/CharacterController.cpp +++ b/libraries/physics/src/CharacterController.cpp @@ -391,6 +391,10 @@ void CharacterController::setState(State desiredState) { } } +void CharacterController::recomputeFlying() { + _pendingFlags |= PENDING_FLAG_RECOMPUTE_FLYING; +} + void CharacterController::setLocalBoundingBox(const glm::vec3& minCorner, const glm::vec3& scale) { float x = scale.x; float z = scale.z; @@ -657,6 +661,13 @@ void CharacterController::updateState() { if (!_dynamicsWorld) { return; } + if (_pendingFlags & PENDING_FLAG_RECOMPUTE_FLYING) { + setState(CharacterController::State::Hover, "recomputeFlying"); + _hasSupport = false; + _stepHeight = _minStepHeight; // clears memory of last step obstacle + _pendingFlags &= ~PENDING_FLAG_RECOMPUTE_FLYING; + } + const btScalar FLY_TO_GROUND_THRESHOLD = 0.1f * _radius; const btScalar GROUND_TO_FLY_THRESHOLD = 0.8f * _radius + _halfHeight; const quint64 TAKE_OFF_TO_IN_AIR_PERIOD = 250 * MSECS_PER_SECOND; diff --git a/libraries/physics/src/CharacterController.h b/libraries/physics/src/CharacterController.h index 0f97cc7c16..96e479dcad 100644 --- a/libraries/physics/src/CharacterController.h +++ b/libraries/physics/src/CharacterController.h @@ -31,6 +31,7 @@ const uint32_t PENDING_FLAG_REMOVE_FROM_SIMULATION = 1U << 1; const uint32_t PENDING_FLAG_UPDATE_SHAPE = 1U << 2; const uint32_t PENDING_FLAG_JUMP = 1U << 3; const uint32_t PENDING_FLAG_UPDATE_COLLISION_GROUP = 1U << 4; +const uint32_t PENDING_FLAG_RECOMPUTE_FLYING = 1U << 5; const float DEFAULT_MIN_FLOOR_NORMAL_DOT_UP = cosf(PI / 3.0f); class btRigidBody; @@ -54,6 +55,7 @@ public: void setGravity(float gravity); float getGravity(); + void recomputeFlying(); virtual void updateShapeIfNecessary() = 0; From 813a94a79ed5f803aa870f4642eee00d95187cdb Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Fri, 15 Dec 2017 17:12:44 -0800 Subject: [PATCH 2/3] function => macro to conditionally take debug arg --- libraries/physics/src/CharacterController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/physics/src/CharacterController.cpp b/libraries/physics/src/CharacterController.cpp index f4107951b8..d39930ab76 100755 --- a/libraries/physics/src/CharacterController.cpp +++ b/libraries/physics/src/CharacterController.cpp @@ -662,7 +662,7 @@ void CharacterController::updateState() { return; } if (_pendingFlags & PENDING_FLAG_RECOMPUTE_FLYING) { - setState(CharacterController::State::Hover, "recomputeFlying"); + SET_STATE(CharacterController::State::Hover, "recomputeFlying"); _hasSupport = false; _stepHeight = _minStepHeight; // clears memory of last step obstacle _pendingFlags &= ~PENDING_FLAG_RECOMPUTE_FLYING; From bb499000a6ad7f19dfe232e22f6a3f6f0dcce8ab Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Tue, 19 Dec 2017 10:51:32 -0800 Subject: [PATCH 3/3] trailing semicolon --- interface/resources/qml/hifi/NameCard.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/resources/qml/hifi/NameCard.qml b/interface/resources/qml/hifi/NameCard.qml index 308f72345d..3f5cad655d 100644 --- a/interface/resources/qml/hifi/NameCard.qml +++ b/interface/resources/qml/hifi/NameCard.qml @@ -602,6 +602,6 @@ Item { return; } // This is the last step of what AddressManager.goToUser does, but we don't need to resolve the username. - MyAvatar.goToLocation(avatar.position, true, Quat.cancelOutRollAndPitch(avatar.orientation), true) + MyAvatar.goToLocation(avatar.position, true, Quat.cancelOutRollAndPitch(avatar.orientation), true); } }