From 17c63eb722adca1d92224653351b496779083246 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 1 Sep 2016 14:56:11 -0700 Subject: [PATCH 01/14] Add the ability to ignore invisible entities in findRayIntersection --- .gitignore | 2 +- interface/src/ui/overlays/Line3DOverlay.cpp | 12 ++++++++ .../src/EntityTreeRenderer.cpp | 4 +-- .../src/EntityTreeRenderer.h | 2 +- .../entities/src/EntityScriptingInterface.cpp | 8 +++--- .../entities/src/EntityScriptingInterface.h | 4 +-- libraries/entities/src/EntityTree.cpp | 5 ++-- libraries/entities/src/EntityTree.h | 1 + libraries/entities/src/EntityTreeElement.cpp | 8 +++--- libraries/entities/src/EntityTreeElement.h | 4 +-- plugins/openvr/src/OpenVrHelpers.cpp | 2 ++ .../system/controllers/handControllerGrab.js | 28 +++++++++++++------ 12 files changed, 54 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 4a1c1c227b..cd7fb34eaf 100644 --- a/.gitignore +++ b/.gitignore @@ -45,7 +45,7 @@ gvr-interface/libs/* # ignore files for various dev environments TAGS -*.swp +*.sw[po] # ignore node files for the console node_modules diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index c3a6c5920e..1616d4c2e2 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -124,6 +124,12 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { } properties.remove("start"); // so that Base3DOverlay doesn't respond to it + auto localStart = properties["localStart"]; + if (localStart.isValid()) { + _start = vec3FromVariant(localStart); + } + properties.remove("localStart"); // so that Base3DOverlay doesn't respond to it + auto end = properties["end"]; // if "end" property was not there, check to see if they included aliases: endPoint if (!end.isValid()) { @@ -133,6 +139,12 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { setEnd(vec3FromVariant(end)); } + auto localEnd = properties["localEnd"]; + if (localEnd.isValid()) { + _end = vec3FromVariant(localEnd); + } + properties.remove("localEnd"); // so that Base3DOverlay doesn't respond to it + auto glow = properties["glow"]; if (glow.isValid()) { setGlow(glow.toFloat()); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 24d22fee96..f7b6b6b170 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -591,7 +591,7 @@ void EntityTreeRenderer::deleteReleasedModels() { RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, bool precisionPicking, const QVector& entityIdsToInclude, - const QVector& entityIdsToDiscard) { + const QVector& entityIdsToDiscard, bool visibleOnly) { RayToEntityIntersectionResult result; if (_tree) { EntityTreePointer entityTree = std::static_pointer_cast(_tree); @@ -599,7 +599,7 @@ RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(cons OctreeElementPointer element; EntityItemPointer intersectedEntity = NULL; result.intersects = entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, - result.face, result.surfaceNormal, entityIdsToInclude, entityIdsToDiscard, + result.face, result.surfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, (void**)&intersectedEntity, lockType, &result.accurate, precisionPicking); if (result.intersects && intersectedEntity) { diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index b1d875c2fb..5efa1d4a7f 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -149,7 +149,7 @@ private: QList _releasedModels; RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, bool precisionPicking, const QVector& entityIdsToInclude = QVector(), - const QVector& entityIdsToDiscard = QVector()); + const QVector& entityIdsToDiscard = QVector(), bool visibleOnly=false); EntityItemID _currentHoverOverEntityID; EntityItemID _currentClickingOnEntityID; diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index fe7fccaece..8a9ce97668 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -610,11 +610,11 @@ QVector EntityScriptingInterface::findEntitiesInFrustum(QVariantMap frust } RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, - const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard) { + const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly) { QVector entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); QVector entitiesToDiscard = qVectorEntityItemIDFromScriptValue(entityIdsToDiscard); - return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking, entitiesToInclude, entitiesToDiscard); + return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking, entitiesToInclude, entitiesToDiscard, visibleOnly); } // FIXME - we should remove this API and encourage all users to use findRayIntersection() instead. We've changed @@ -630,7 +630,7 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlock RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, - bool precisionPicking, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard) { + bool precisionPicking, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard, bool visibleOnly) { RayToEntityIntersectionResult result; @@ -638,7 +638,7 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorke OctreeElementPointer element; EntityItemPointer intersectedEntity = NULL; result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face, - result.surfaceNormal, entityIdsToInclude, entityIdsToDiscard, (void**)&intersectedEntity, lockType, &result.accurate, + result.surfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, (void**)&intersectedEntity, lockType, &result.accurate, precisionPicking); if (result.intersects && intersectedEntity) { result.entityID = intersectedEntity->getEntityItemID(); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index d5934b1a8d..34b7d6f45b 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -143,7 +143,7 @@ public slots: /// If the scripting context has visible entities, this will determine a ray intersection, the results /// may be inaccurate if the engine is unable to access the visible entities, in which case result.accurate /// will be false. - Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray, bool precisionPicking = false, const QScriptValue& entityIdsToInclude = QScriptValue(), const QScriptValue& entityIdsToDiscard = QScriptValue()); + Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray, bool precisionPicking = false, const QScriptValue& entityIdsToInclude = QScriptValue(), const QScriptValue& entityIdsToDiscard = QScriptValue(), bool visibleOnly = false); /// If the scripting context has visible entities, this will determine a ray intersection, and will block in /// order to return an accurate result @@ -257,7 +257,7 @@ private: /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, - bool precisionPicking, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard); + bool precisionPicking, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard, bool visibleOnly = false); EntityTreePointer _entityTree; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 89f469037e..df14c0bce5 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -549,6 +549,7 @@ public: glm::vec3& surfaceNormal; const QVector& entityIdsToInclude; const QVector& entityIdsToDiscard; + bool visibleOnly; void** intersectedObject; bool found; bool precisionPicking; @@ -561,7 +562,7 @@ bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) { EntityTreeElementPointer entityTreeElementPointer = std::dynamic_pointer_cast(element); if (entityTreeElementPointer ->findRayIntersection(args->origin, args->direction, keepSearching, args->element, args->distance, args->face, args->surfaceNormal, args->entityIdsToInclude, - args->entityIdsToDiscard, args->intersectedObject, args->precisionPicking)) { + args->entityIdsToDiscard, args->visibleOnly, args->intersectedObject, args->precisionPicking)) { args->found = true; } return keepSearching; @@ -569,7 +570,7 @@ bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) { bool EntityTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, OctreeElementPointer& element, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard, void** intersectedObject, + BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard, bool visibleOnly, void** intersectedObject, Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, entityIdsToDiscard, intersectedObject, false, precisionPicking }; distance = FLT_MAX; diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 917b9333a5..434f7fcfce 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -92,6 +92,7 @@ public: OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude = QVector(), const QVector& entityIdsToDiscard = QVector(), + bool visibleOnly = false, void** intersectedObject = NULL, Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL, diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 29274d2e72..110153b08c 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -534,7 +534,7 @@ bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3 bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - const QVector& entityIdsToDiscard, void** intersectedObject, bool precisionPicking) { + const QVector& entityIdsToDiscard, bool visibleOnly, void** intersectedObject, bool precisionPicking) { keepSearching = true; // assume that we will continue searching after this. @@ -559,7 +559,7 @@ bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm:: if (_cube.contains(origin) || distanceToElementCube < distance) { if (findDetailedRayIntersection(origin, direction, keepSearching, element, distanceToElementDetails, - face, localSurfaceNormal, entityIdsToInclude, entityIdsToDiscard, intersectedObject, precisionPicking, distanceToElementCube)) { + face, localSurfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, intersectedObject, precisionPicking, distanceToElementCube)) { if (distanceToElementDetails < distance) { distance = distanceToElementDetails; @@ -574,13 +574,13 @@ bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm:: bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, - const QVector& entityIdsToInclude, const QVector& entityIDsToDiscard, void** intersectedObject, bool precisionPicking, float distanceToElementCube) { + const QVector& entityIdsToInclude, const QVector& entityIDsToDiscard, bool visibleOnly, void** intersectedObject, bool precisionPicking, float distanceToElementCube) { // only called if we do intersect our bounding cube, but find if we actually intersect with entities... int entityNumber = 0; bool somethingIntersected = false; forEachEntity([&](EntityItemPointer entity) { - if ( (entityIdsToInclude.size() > 0 && !entityIdsToInclude.contains(entity->getID())) || (entityIDsToDiscard.size() > 0 && entityIDsToDiscard.contains(entity->getID())) ) { + if ( (visibleOnly && !entity->isVisible()) || (entityIdsToInclude.size() > 0 && !entityIdsToInclude.contains(entity->getID())) || (entityIDsToDiscard.size() > 0 && entityIDsToDiscard.contains(entity->getID())) ) { return; } diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index d92dfa52dc..2f92e45726 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -147,12 +147,12 @@ public: virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - const QVector& entityIdsToDiscard, + const QVector& entityIdsToDiscard, bool visibleOnly = false, void** intersectedObject = NULL, bool precisionPicking = false); virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - const QVector& entityIdsToDiscard, + const QVector& entityIdsToDiscard, bool visibleOnly, void** intersectedObject, bool precisionPicking, float distanceToElementCube); virtual bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) const override; diff --git a/plugins/openvr/src/OpenVrHelpers.cpp b/plugins/openvr/src/OpenVrHelpers.cpp index 820476191a..c06866d2f1 100644 --- a/plugins/openvr/src/OpenVrHelpers.cpp +++ b/plugins/openvr/src/OpenVrHelpers.cpp @@ -366,6 +366,8 @@ controller::Pose openVrControllerPoseToHandPose(bool isLeftHand, const mat4& mat auto translationOffset = (isLeftHand ? leftTranslationOffset : rightTranslationOffset); auto rotationOffset = (isLeftHand ? leftRotationOffset : rightRotationOffset); + //qDebug() << "TRANSLATION OFFSET: " << isLeftHand << ", " << translationOffset.x << ", " << translationOffset.y << ", " << translationOffset.z; + glm::vec3 position = extractTranslation(mat); glm::quat rotation = glm::normalize(glm::quat_cast(mat)); diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 05edcdad03..f11fb3129b 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -1605,7 +1605,6 @@ function MyController(hand) { }; this.distanceHoldingEnter = function() { - Messages.sendLocalMessage('Hifi-Teleport-Disabler', 'both'); this.clearEquipHaptics(); this.grabPointSphereOff(); @@ -1869,12 +1868,12 @@ function MyController(hand) { }; this.nearGrabbingEnter = function() { - if (this.hand === 0) { - Messages.sendLocalMessage('Hifi-Teleport-Disabler', 'left'); - } - if (this.hand === 1) { - Messages.sendLocalMessage('Hifi-Teleport-Disabler', 'right'); - } + //if (this.hand === 0) { + //Messages.sendLocalMessage('Hifi-Teleport-Disabler', 'left'); + //} + //if (this.hand === 1) { + //Messages.sendLocalMessage('Hifi-Teleport-Disabler', 'right'); + //} this.grabPointSphereOff(); this.lineOff(); this.overlayLineOff(); @@ -2340,7 +2339,6 @@ function MyController(hand) { }; this.release = function() { - Messages.sendLocalMessage('Hifi-Teleport-Disabler', 'none'); this.turnOffVisualizations(); var noVelocity = false; @@ -2711,6 +2709,20 @@ var handleHandMessages = function(channel, message, sender) { } handToDisable = message; } + } else if (channel === 'Hifi-Grab-Disable') { + data = JSON.parse(message); + if (data.holdEnabled !== undefined) { + print("holdEnabled: ", data.holdEnabled); + holdEnabled = data.holdEnabled; + } + if (data.nearGrabEnabled !== undefined) { + print("nearGrabEnabled: ", data.nearGrabEnabled); + nearGrabEnabled = data.nearGrabEnabled; + } + if (data.farGrabEnabled !== undefined) { + print("farGrabEnabled: ", data.farGrabEnabled); + farGrabEnabled = data.farGrabEnabled; + } } else if (channel === 'Hifi-Hand-Grab') { try { data = JSON.parse(message); From b0c7e91737255b5c87218f89f746577d41360a7f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 1 Sep 2016 15:33:12 -0700 Subject: [PATCH 02/14] Disable ray picking against invisible objects in far grab and teleport --- libraries/entities/src/EntityTree.cpp | 2 +- scripts/system/controllers/handControllerGrab.js | 8 ++++---- scripts/system/controllers/teleport.js | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index df14c0bce5..2e9fdf136a 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -572,7 +572,7 @@ bool EntityTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& d OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard, bool visibleOnly, void** intersectedObject, Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { - RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, entityIdsToDiscard, intersectedObject, false, precisionPicking }; + RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, intersectedObject, false, precisionPicking }; distance = FLT_MAX; bool requireLock = lockType == Octree::Lock; diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index f11fb3129b..764fd705cb 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -344,7 +344,7 @@ function entityHasActions(entityID) { } function findRayIntersection(pickRay, precise, include, exclude) { - var entities = Entities.findRayIntersection(pickRay, precise, include, exclude); + var entities = Entities.findRayIntersection(pickRay, precise, include, exclude, true); var overlays = Overlays.findRayIntersection(pickRay); if (!overlays.intersects || (entities.intersects && (entities.distance <= overlays.distance))) { return entities; @@ -1155,9 +1155,9 @@ function MyController(hand) { var intersection; if (USE_BLACKLIST === true && blacklist.length !== 0) { - intersection = findRayIntersection(pickRay, true, [], blacklist); + intersection = findRayIntersection(pickRay, true, [], blacklist, true); } else { - intersection = findRayIntersection(pickRay, true); + intersection = findRayIntersection(pickRay, true, [], [], true); } if (intersection.intersects) { @@ -2211,7 +2211,7 @@ function MyController(hand) { var now = Date.now(); if (now - this.lastPickTime > MSECS_PER_SEC / PICKS_PER_SECOND_PER_HAND) { - var intersection = findRayIntersection(pickRay, true); + var intersection = findRayIntersection(pickRay, true, [], [], true); if (intersection.accurate || intersection.overlayID) { this.lastPickTime = now; if (intersection.entityID != this.grabbedEntity) { diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index b4a8eefcd2..3cd0615d2e 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -279,7 +279,7 @@ function Teleporter() { var location = Vec3.sum(rightPickRay.origin, Vec3.multiply(rightPickRay.direction, 50)); - var rightIntersection = Entities.findRayIntersection(teleporter.rightPickRay, true, [], [this.targetEntity]); + var rightIntersection = Entities.findRayIntersection(teleporter.rightPickRay, true, [], [this.targetEntity], true); if (rightIntersection.intersects) { if (this.tooClose === true) { @@ -342,7 +342,7 @@ function Teleporter() { var location = Vec3.sum(MyAvatar.position, Vec3.multiply(leftPickRay.direction, 50)); - var leftIntersection = Entities.findRayIntersection(teleporter.leftPickRay, true, [], [this.targetEntity]); + var leftIntersection = Entities.findRayIntersection(teleporter.leftPickRay, true, [], [this.targetEntity], true); if (leftIntersection.intersects) { From da6afb605bf2cfeee45f424c50484da76ab14b47 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 2 Sep 2016 13:42:16 -0700 Subject: [PATCH 03/14] Fix default findRayIntersection surfaceNormal to be in world space --- libraries/entities/src/EntityTreeElement.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index 110153b08c..ca22038f03 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -638,7 +638,7 @@ bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, con if (localDistance < distance && entity->getType() != EntityTypes::ParticleEffect) { distance = localDistance; face = localFace; - surfaceNormal = localSurfaceNormal; + surfaceNormal = glm::vec3(rotation * glm::vec4(localSurfaceNormal, 1.0f)); *intersectedObject = (void*)entity.get(); somethingIntersected = true; } From 75265cff6e31d990cfbabb37048dac9c6c6d8915 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 2 Sep 2016 13:42:52 -0700 Subject: [PATCH 04/14] Update teleport to not let you teleport into walls --- scripts/system/controllers/teleport.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index 3cd0615d2e..e7f12720f0 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -459,7 +459,7 @@ function Teleporter() { z: intersection.intersection.z }; - this.tooClose = isTooCloseToTeleport(position); + this.tooClose = isTooCloseToTeleport(position, intersection.surfaceNormal); var towardUs = Quat.fromPitchYawRollDegrees(0, euler.y, 0); Overlays.editOverlay(this.targetOverlay, { @@ -480,7 +480,7 @@ function Teleporter() { z: intersection.intersection.z }; - this.tooClose = isTooCloseToTeleport(position); + this.tooClose = isTooCloseToTeleport(position, intersection.surfaceNormal); var towardUs = Quat.fromPitchYawRollDegrees(0, euler.y, 0); Overlays.editOverlay(this.cancelOverlay, { @@ -627,8 +627,11 @@ function isMoving() { } }; -function isTooCloseToTeleport(position) { - return Vec3.distance(MyAvatar.position, position) <= TELEPORT_CANCEL_RANGE; +function isTooCloseToTeleport(position, surfaceNormal) { + var adj = Math.sqrt(surfaceNormal.x * surfaceNormal.x + surfaceNormal.z * surfaceNormal.z); + var angleUp = Math.atan2(surfaceNormal.y, adj) * (180 / Math.PI); + //print(angleUp); + return angleUp < 80 || angleUp > 110 || Vec3.distance(MyAvatar.position, position) <= TELEPORT_CANCEL_RANGE; }; function registerMappings() { From ee5046921348683d994b9a5978dd2c8cd2958e4f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 14 Sep 2016 13:43:13 -0700 Subject: [PATCH 05/14] Add collidableOnly arg to findRayIntersection --- .../src/EntityTreeRenderer.cpp | 10 +++--- .../src/EntityTreeRenderer.h | 3 +- .../entities/src/EntityScriptingInterface.cpp | 15 ++++---- .../entities/src/EntityScriptingInterface.h | 7 ++-- libraries/entities/src/EntityTree.cpp | 33 ++++++----------- libraries/entities/src/EntityTree.h | 36 ++++++++++++++----- libraries/entities/src/EntityTreeElement.cpp | 13 ++++--- libraries/entities/src/EntityTreeElement.h | 4 +-- 8 files changed, 69 insertions(+), 52 deletions(-) diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index f7b6b6b170..2ef2beb274 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -591,17 +591,17 @@ void EntityTreeRenderer::deleteReleasedModels() { RayToEntityIntersectionResult EntityTreeRenderer::findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, bool precisionPicking, const QVector& entityIdsToInclude, - const QVector& entityIdsToDiscard, bool visibleOnly) { + const QVector& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { RayToEntityIntersectionResult result; if (_tree) { EntityTreePointer entityTree = std::static_pointer_cast(_tree); OctreeElementPointer element; EntityItemPointer intersectedEntity = NULL; - result.intersects = entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, - result.face, result.surfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, - (void**)&intersectedEntity, lockType, &result.accurate, - precisionPicking); + result.intersects = entityTree->findRayIntersection(ray.origin, ray.direction, + entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly, precisionPicking, + element, result.distance, result.face, result.surfaceNormal, + (void**)&intersectedEntity, lockType, &result.accurate); if (result.intersects && intersectedEntity) { result.entityID = intersectedEntity->getEntityItemID(); result.properties = intersectedEntity->getProperties(); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.h b/libraries/entities-renderer/src/EntityTreeRenderer.h index 5efa1d4a7f..36e52e6f46 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.h +++ b/libraries/entities-renderer/src/EntityTreeRenderer.h @@ -149,7 +149,8 @@ private: QList _releasedModels; RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, bool precisionPicking, const QVector& entityIdsToInclude = QVector(), - const QVector& entityIdsToDiscard = QVector(), bool visibleOnly=false); + const QVector& entityIdsToDiscard = QVector(), bool visibleOnly=false, + bool collidableOnly = false); EntityItemID _currentHoverOverEntityID; EntityItemID _currentClickingOnEntityID; diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 8a9ce97668..ec48a08a74 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -610,11 +610,11 @@ QVector EntityScriptingInterface::findEntitiesInFrustum(QVariantMap frust } RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersection(const PickRay& ray, bool precisionPicking, - const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly) { + const QScriptValue& entityIdsToInclude, const QScriptValue& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { QVector entitiesToInclude = qVectorEntityItemIDFromScriptValue(entityIdsToInclude); QVector entitiesToDiscard = qVectorEntityItemIDFromScriptValue(entityIdsToDiscard); - return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking, entitiesToInclude, entitiesToDiscard, visibleOnly); + return findRayIntersectionWorker(ray, Octree::Lock, precisionPicking, entitiesToInclude, entitiesToDiscard, visibleOnly, collidableOnly); } // FIXME - we should remove this API and encourage all users to use findRayIntersection() instead. We've changed @@ -629,17 +629,18 @@ RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionBlock } RayToEntityIntersectionResult EntityScriptingInterface::findRayIntersectionWorker(const PickRay& ray, - Octree::lockType lockType, - bool precisionPicking, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard, bool visibleOnly) { + Octree::lockType lockType, bool precisionPicking, const QVector& entityIdsToInclude, + const QVector& entityIdsToDiscard, bool visibleOnly, bool collidableOnly) { RayToEntityIntersectionResult result; if (_entityTree) { OctreeElementPointer element; EntityItemPointer intersectedEntity = NULL; - result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, element, result.distance, result.face, - result.surfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, (void**)&intersectedEntity, lockType, &result.accurate, - precisionPicking); + result.intersects = _entityTree->findRayIntersection(ray.origin, ray.direction, + entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly, precisionPicking, + element, result.distance, result.face, result.surfaceNormal, + (void**)&intersectedEntity, lockType, &result.accurate); if (result.intersects && intersectedEntity) { result.entityID = intersectedEntity->getEntityItemID(); result.properties = intersectedEntity->getProperties(); diff --git a/libraries/entities/src/EntityScriptingInterface.h b/libraries/entities/src/EntityScriptingInterface.h index 34b7d6f45b..3a24ff59fd 100644 --- a/libraries/entities/src/EntityScriptingInterface.h +++ b/libraries/entities/src/EntityScriptingInterface.h @@ -143,7 +143,9 @@ public slots: /// If the scripting context has visible entities, this will determine a ray intersection, the results /// may be inaccurate if the engine is unable to access the visible entities, in which case result.accurate /// will be false. - Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray, bool precisionPicking = false, const QScriptValue& entityIdsToInclude = QScriptValue(), const QScriptValue& entityIdsToDiscard = QScriptValue(), bool visibleOnly = false); + Q_INVOKABLE RayToEntityIntersectionResult findRayIntersection(const PickRay& ray, bool precisionPicking = false, + const QScriptValue& entityIdsToInclude = QScriptValue(), const QScriptValue& entityIdsToDiscard = QScriptValue(), + bool visibleOnly = false, bool collidableOnly = false); /// If the scripting context has visible entities, this will determine a ray intersection, and will block in /// order to return an accurate result @@ -257,7 +259,8 @@ private: /// actually does the work of finding the ray intersection, can be called in locking mode or tryLock mode RayToEntityIntersectionResult findRayIntersectionWorker(const PickRay& ray, Octree::lockType lockType, - bool precisionPicking, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard, bool visibleOnly = false); + bool precisionPicking, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard, + bool visibleOnly = false, bool collidableOnly = false); EntityTreePointer _entityTree; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 2e9fdf136a..4cbfb4f5dc 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -538,41 +538,28 @@ bool EntityTree::findNearPointOperation(OctreeElementPointer element, void* extr // if this element doesn't contain the point, then none of its children can contain the point, so stop searching return false; } -// combines the ray cast arguments into a single object -class RayArgs { -public: - glm::vec3 origin; - glm::vec3 direction; - OctreeElementPointer& element; - float& distance; - BoxFace& face; - glm::vec3& surfaceNormal; - const QVector& entityIdsToInclude; - const QVector& entityIdsToDiscard; - bool visibleOnly; - void** intersectedObject; - bool found; - bool precisionPicking; -}; - bool findRayIntersectionOp(OctreeElementPointer element, void* extraData) { RayArgs* args = static_cast(extraData); bool keepSearching = true; EntityTreeElementPointer entityTreeElementPointer = std::dynamic_pointer_cast(element); - if (entityTreeElementPointer ->findRayIntersection(args->origin, args->direction, keepSearching, + if (entityTreeElementPointer->findRayIntersection(args->origin, args->direction, keepSearching, args->element, args->distance, args->face, args->surfaceNormal, args->entityIdsToInclude, - args->entityIdsToDiscard, args->visibleOnly, args->intersectedObject, args->precisionPicking)) { + args->entityIdsToDiscard, args->visibleOnly, args->collidableOnly, args->intersectedObject, args->precisionPicking)) { args->found = true; } return keepSearching; } bool EntityTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElementPointer& element, float& distance, - BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, const QVector& entityIdsToDiscard, bool visibleOnly, void** intersectedObject, - Octree::lockType lockType, bool* accurateResult, bool precisionPicking) { - RayArgs args = { origin, direction, element, distance, face, surfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, intersectedObject, false, precisionPicking }; + QVector entityIdsToInclude, QVector entityIdsToDiscard, + bool visibleOnly, bool collidableOnly, bool precisionPicking, + OctreeElementPointer& element, float& distance, + BoxFace& face, glm::vec3& surfaceNormal, void** intersectedObject, + Octree::lockType lockType, bool* accurateResult) { + RayArgs args = { origin, direction, entityIdsToInclude, entityIdsToDiscard, + visibleOnly, collidableOnly, precisionPicking, + element, distance, face, surfaceNormal, intersectedObject, false }; distance = FLT_MAX; bool requireLock = lockType == Octree::Lock; diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 434f7fcfce..80169492f7 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -31,6 +31,29 @@ using ModelWeakPointer = std::weak_ptr; class EntitySimulation; + +// combines the ray cast arguments into a single object +class RayArgs { +public: + // Inputs + glm::vec3 origin; + glm::vec3 direction; + const QVector& entityIdsToInclude; + const QVector& entityIdsToDiscard; + bool visibleOnly; + bool collidableOnly; + bool precisionPicking; + + // Outputs + OctreeElementPointer& element; + float& distance; + BoxFace& face; + glm::vec3& surfaceNormal; + void** intersectedObject; + bool found; +}; + + class NewlyCreatedEntityHook { public: virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) = 0; @@ -89,14 +112,11 @@ public: const SharedNodePointer& senderNode) override; virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, - const QVector& entityIdsToInclude = QVector(), - const QVector& entityIdsToDiscard = QVector(), - bool visibleOnly = false, - void** intersectedObject = NULL, - Octree::lockType lockType = Octree::TryLock, - bool* accurateResult = NULL, - bool precisionPicking = false); + QVector entityIdsToInclude, QVector entityIdsToDiscard, + bool visibleOnly, bool collidableOnly, bool precisionPicking, + OctreeElementPointer& node, float& distance, + BoxFace& face, glm::vec3& surfaceNormal, void** intersectedObject = NULL, + Octree::lockType lockType = Octree::TryLock, bool* accurateResult = NULL); virtual bool rootElementHasData() const override { return true; } diff --git a/libraries/entities/src/EntityTreeElement.cpp b/libraries/entities/src/EntityTreeElement.cpp index ca22038f03..629a6b37e4 100644 --- a/libraries/entities/src/EntityTreeElement.cpp +++ b/libraries/entities/src/EntityTreeElement.cpp @@ -534,7 +534,8 @@ bool EntityTreeElement::bestFitBounds(const glm::vec3& minPoint, const glm::vec3 bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - const QVector& entityIdsToDiscard, bool visibleOnly, void** intersectedObject, bool precisionPicking) { + const QVector& entityIdsToDiscard, bool visibleOnly, bool collidableOnly, + void** intersectedObject, bool precisionPicking) { keepSearching = true; // assume that we will continue searching after this. @@ -559,7 +560,8 @@ bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm:: if (_cube.contains(origin) || distanceToElementCube < distance) { if (findDetailedRayIntersection(origin, direction, keepSearching, element, distanceToElementDetails, - face, localSurfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, intersectedObject, precisionPicking, distanceToElementCube)) { + face, localSurfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly, + intersectedObject, precisionPicking, distanceToElementCube)) { if (distanceToElementDetails < distance) { distance = distanceToElementDetails; @@ -574,13 +576,16 @@ bool EntityTreeElement::findRayIntersection(const glm::vec3& origin, const glm:: bool EntityTreeElement::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, - const QVector& entityIdsToInclude, const QVector& entityIDsToDiscard, bool visibleOnly, void** intersectedObject, bool precisionPicking, float distanceToElementCube) { + const QVector& entityIdsToInclude, const QVector& entityIDsToDiscard, + bool visibleOnly, bool collidableOnly, void** intersectedObject, bool precisionPicking, float distanceToElementCube) { // only called if we do intersect our bounding cube, but find if we actually intersect with entities... int entityNumber = 0; bool somethingIntersected = false; forEachEntity([&](EntityItemPointer entity) { - if ( (visibleOnly && !entity->isVisible()) || (entityIdsToInclude.size() > 0 && !entityIdsToInclude.contains(entity->getID())) || (entityIDsToDiscard.size() > 0 && entityIDsToDiscard.contains(entity->getID())) ) { + if ( (visibleOnly && !entity->isVisible()) || (collidableOnly && (entity->getCollisionless() || entity->getShapeType() == SHAPE_TYPE_NONE)) + || (entityIdsToInclude.size() > 0 && !entityIdsToInclude.contains(entity->getID())) + || (entityIDsToDiscard.size() > 0 && entityIDsToDiscard.contains(entity->getID())) ) { return; } diff --git a/libraries/entities/src/EntityTreeElement.h b/libraries/entities/src/EntityTreeElement.h index 2f92e45726..e411e8077b 100644 --- a/libraries/entities/src/EntityTreeElement.h +++ b/libraries/entities/src/EntityTreeElement.h @@ -147,12 +147,12 @@ public: virtual bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& node, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - const QVector& entityIdsToDiscard, bool visibleOnly = false, + const QVector& entityIdsToDiscard, bool visibleOnly = false, bool collidableOnly = false, void** intersectedObject = NULL, bool precisionPicking = false); virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, const QVector& entityIdsToInclude, - const QVector& entityIdsToDiscard, bool visibleOnly, + const QVector& entityIdsToDiscard, bool visibleOnly, bool collidableOnly, void** intersectedObject, bool precisionPicking, float distanceToElementCube); virtual bool findSpherePenetration(const glm::vec3& center, float radius, glm::vec3& penetration, void** penetratedObject) const override; From 813ed59f00476c48729da9b90c05719891c6d144 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 15 Sep 2016 17:48:09 -0700 Subject: [PATCH 06/14] Update teleport to not collide with non collidable entities --- scripts/system/controllers/teleport.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index e7f12720f0..af3f6b0800 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -279,7 +279,7 @@ function Teleporter() { var location = Vec3.sum(rightPickRay.origin, Vec3.multiply(rightPickRay.direction, 50)); - var rightIntersection = Entities.findRayIntersection(teleporter.rightPickRay, true, [], [this.targetEntity], true); + var rightIntersection = Entities.findRayIntersection(teleporter.rightPickRay, true, [], [this.targetEntity], true, true); if (rightIntersection.intersects) { if (this.tooClose === true) { @@ -342,7 +342,7 @@ function Teleporter() { var location = Vec3.sum(MyAvatar.position, Vec3.multiply(leftPickRay.direction, 50)); - var leftIntersection = Entities.findRayIntersection(teleporter.leftPickRay, true, [], [this.targetEntity], true); + var leftIntersection = Entities.findRayIntersection(teleporter.leftPickRay, true, [], [this.targetEntity], true, true); if (leftIntersection.intersects) { From a84f7749990b10c694d4c0f8115a42770816f1a4 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 20 Sep 2016 12:52:22 -0700 Subject: [PATCH 07/14] Remove line3doverlay local start/end changed --- interface/src/ui/overlays/Line3DOverlay.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 1616d4c2e2..c3a6c5920e 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -124,12 +124,6 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { } properties.remove("start"); // so that Base3DOverlay doesn't respond to it - auto localStart = properties["localStart"]; - if (localStart.isValid()) { - _start = vec3FromVariant(localStart); - } - properties.remove("localStart"); // so that Base3DOverlay doesn't respond to it - auto end = properties["end"]; // if "end" property was not there, check to see if they included aliases: endPoint if (!end.isValid()) { @@ -139,12 +133,6 @@ void Line3DOverlay::setProperties(const QVariantMap& originalProperties) { setEnd(vec3FromVariant(end)); } - auto localEnd = properties["localEnd"]; - if (localEnd.isValid()) { - _end = vec3FromVariant(localEnd); - } - properties.remove("localEnd"); // so that Base3DOverlay doesn't respond to it - auto glow = properties["glow"]; if (glow.isValid()) { setGlow(glow.toFloat()); From 16d535c4959f7a7cfa056f93e18c7f555cc604bd Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 21 Sep 2016 09:30:14 -0700 Subject: [PATCH 08/14] Move EntityTree RayArgs back to header --- libraries/entities/src/EntityTree.cpp | 22 ++++++++++++++++++++++ libraries/entities/src/EntityTree.h | 22 ---------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 4cbfb4f5dc..ffb6ec31e2 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -29,6 +29,28 @@ static const quint64 DELETED_ENTITIES_EXTRA_USECS_TO_CONSIDER = USECS_PER_MSEC * const float EntityTree::DEFAULT_MAX_TMP_ENTITY_LIFETIME = 60 * 60; // 1 hour +// combines the ray cast arguments into a single object +class RayArgs { +public: + // Inputs + glm::vec3 origin; + glm::vec3 direction; + const QVector& entityIdsToInclude; + const QVector& entityIdsToDiscard; + bool visibleOnly; + bool collidableOnly; + bool precisionPicking; + + // Outputs + OctreeElementPointer& element; + float& distance; + BoxFace& face; + glm::vec3& surfaceNormal; + void** intersectedObject; + bool found; +}; + + EntityTree::EntityTree(bool shouldReaverage) : Octree(shouldReaverage), _fbxService(NULL), diff --git a/libraries/entities/src/EntityTree.h b/libraries/entities/src/EntityTree.h index 80169492f7..68c8618482 100644 --- a/libraries/entities/src/EntityTree.h +++ b/libraries/entities/src/EntityTree.h @@ -32,28 +32,6 @@ using ModelWeakPointer = std::weak_ptr; class EntitySimulation; -// combines the ray cast arguments into a single object -class RayArgs { -public: - // Inputs - glm::vec3 origin; - glm::vec3 direction; - const QVector& entityIdsToInclude; - const QVector& entityIdsToDiscard; - bool visibleOnly; - bool collidableOnly; - bool precisionPicking; - - // Outputs - OctreeElementPointer& element; - float& distance; - BoxFace& face; - glm::vec3& surfaceNormal; - void** intersectedObject; - bool found; -}; - - class NewlyCreatedEntityHook { public: virtual void entityCreated(const EntityItem& newEntity, const SharedNodePointer& senderNode) = 0; From 53623f7583b1ef4365dd0e8f33b65e1c29683be2 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 28 Sep 2016 15:59:54 -0700 Subject: [PATCH 09/14] Make teleport.js normal rejection more lenient --- scripts/system/away.js | 21 ++++++++++++++++++++- scripts/system/controllers/teleport.js | 10 ++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/scripts/system/away.js b/scripts/system/away.js index 716fe1340e..c704da83f4 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -142,6 +142,7 @@ function ifAvatarMovedGoActive() { } // MAIN CONTROL +var isEnabled = true; var wasMuted, isAway; var wasOverlaysVisible = Menu.isOptionChecked("Overlays"); var eventMappingName = "io.highfidelity.away"; // goActive on hand controller button events, too. @@ -159,7 +160,7 @@ function safeGetHMDMounted() { var wasHmdMounted = safeGetHMDMounted(); function goAway() { - if (isAway) { + if (!isEnabled || isAway) { return; } @@ -274,6 +275,24 @@ function maybeGoAway() { } } +function setEnabled(value) { + print("setting away enabled: ", value); + if (!value) { + goActive(); + } + isEnabled = value; +} + +var CHANNEL_AWAY_ENABLE = "Hifi-Away-Enable"; +var handleMessage = function(channel, message, sender) { + print("Got away message"); + if (channel == CHANNEL_AWAY_ENABLE) { + setEnabled(message == 'enable'); + } +} +Messages.subscribe(CHANNEL_AWAY_ENABLE); +Messages.messageReceived.connect(handleMessage); + Script.update.connect(maybeMoveOverlay); Script.update.connect(maybeGoAway); diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index af3f6b0800..a0159e06a5 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -627,11 +627,17 @@ function isMoving() { } }; +// When determininig whether you can teleport to a location, the normal of the +// point that is being intersected with is looked at. If this normal is more +// than MAX_ANGLE_FROM_UP_TO_TELEPORT degrees from <0, 1, 0> (straight up), then +// you can't teleport there. +var MAX_ANGLE_FROM_UP_TO_TELEPORT = 70; function isTooCloseToTeleport(position, surfaceNormal) { var adj = Math.sqrt(surfaceNormal.x * surfaceNormal.x + surfaceNormal.z * surfaceNormal.z); var angleUp = Math.atan2(surfaceNormal.y, adj) * (180 / Math.PI); - //print(angleUp); - return angleUp < 80 || angleUp > 110 || Vec3.distance(MyAvatar.position, position) <= TELEPORT_CANCEL_RANGE; + return angleUp < (90 - MAX_ANGLE_FROM_UP_TO_TELEPORT) || + angleUp > (90 + MAX_ANGLE_FROM_UP_TO_TELEPORT) || + Vec3.distance(MyAvatar.position, position) <= TELEPORT_CANCEL_RANGE; }; function registerMappings() { From 2ef7c9a57a6d0f84987d5a8e521492e088396c7e Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 30 Sep 2016 10:49:45 -0700 Subject: [PATCH 10/14] Disable smooth movement in teleport.js --- scripts/system/controllers/teleport.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index a0159e06a5..2abc6fe057 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -509,7 +509,9 @@ function Teleporter() { var offset = getAvatarFootOffset(); this.intersection.intersection.y += offset; this.exitTeleportMode(); - this.smoothArrival(); + // Disable smooth arrival, possibly temporarily + //this.smoothArrival(); + MyAvatar.position = _this.intersection.intersection; } }; From 1e6aba19287fa05b58460c90f3a91c84456c5eb7 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 4 Oct 2016 11:56:36 -0700 Subject: [PATCH 11/14] Fix teleport not removing overlay on teleport --- scripts/system/controllers/teleport.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index 2abc6fe057..6d13b41d4f 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -512,6 +512,9 @@ function Teleporter() { // Disable smooth arrival, possibly temporarily //this.smoothArrival(); MyAvatar.position = _this.intersection.intersection; + _this.deleteTargetOverlay(); + _this.deleteCancelOverlay(); + HMD.centerUI(); } }; From d0ba53a06910727d828bce19100567aa719c03e6 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 4 Oct 2016 20:22:22 -0700 Subject: [PATCH 12/14] Change name of isTooCloseToTeleport to be more descriptive --- scripts/system/controllers/teleport.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/teleport.js b/scripts/system/controllers/teleport.js index 6d13b41d4f..2a7dbb000b 100644 --- a/scripts/system/controllers/teleport.js +++ b/scripts/system/controllers/teleport.js @@ -459,7 +459,7 @@ function Teleporter() { z: intersection.intersection.z }; - this.tooClose = isTooCloseToTeleport(position, intersection.surfaceNormal); + this.tooClose = isValidTeleportLocation(position, intersection.surfaceNormal); var towardUs = Quat.fromPitchYawRollDegrees(0, euler.y, 0); Overlays.editOverlay(this.targetOverlay, { @@ -480,7 +480,7 @@ function Teleporter() { z: intersection.intersection.z }; - this.tooClose = isTooCloseToTeleport(position, intersection.surfaceNormal); + this.tooClose = isValidTeleportLocation(position, intersection.surfaceNormal); var towardUs = Quat.fromPitchYawRollDegrees(0, euler.y, 0); Overlays.editOverlay(this.cancelOverlay, { @@ -637,7 +637,7 @@ function isMoving() { // than MAX_ANGLE_FROM_UP_TO_TELEPORT degrees from <0, 1, 0> (straight up), then // you can't teleport there. var MAX_ANGLE_FROM_UP_TO_TELEPORT = 70; -function isTooCloseToTeleport(position, surfaceNormal) { +function isValidTeleportLocation(position, surfaceNormal) { var adj = Math.sqrt(surfaceNormal.x * surfaceNormal.x + surfaceNormal.z * surfaceNormal.z); var angleUp = Math.atan2(surfaceNormal.y, adj) * (180 / Math.PI); return angleUp < (90 - MAX_ANGLE_FROM_UP_TO_TELEPORT) || From 6019581f3f618843e59a099d9c3cee0ceef5d0b7 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 4 Oct 2016 20:24:15 -0700 Subject: [PATCH 13/14] Remove commented log line in OpenVrHelpers --- plugins/openvr/src/OpenVrHelpers.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/openvr/src/OpenVrHelpers.cpp b/plugins/openvr/src/OpenVrHelpers.cpp index c06866d2f1..820476191a 100644 --- a/plugins/openvr/src/OpenVrHelpers.cpp +++ b/plugins/openvr/src/OpenVrHelpers.cpp @@ -366,8 +366,6 @@ controller::Pose openVrControllerPoseToHandPose(bool isLeftHand, const mat4& mat auto translationOffset = (isLeftHand ? leftTranslationOffset : rightTranslationOffset); auto rotationOffset = (isLeftHand ? leftRotationOffset : rightRotationOffset); - //qDebug() << "TRANSLATION OFFSET: " << isLeftHand << ", " << translationOffset.x << ", " << translationOffset.y << ", " << translationOffset.z; - glm::vec3 position = extractTranslation(mat); glm::quat rotation = glm::normalize(glm::quat_cast(mat)); From d50689b795b3f82b7d9c15db7ae0175ceded042d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 4 Oct 2016 20:25:46 -0700 Subject: [PATCH 14/14] Remove disabling of teleport in hand grab --- scripts/system/controllers/handControllerGrab.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 764fd705cb..98da3d539b 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -1868,12 +1868,6 @@ function MyController(hand) { }; this.nearGrabbingEnter = function() { - //if (this.hand === 0) { - //Messages.sendLocalMessage('Hifi-Teleport-Disabler', 'left'); - //} - //if (this.hand === 1) { - //Messages.sendLocalMessage('Hifi-Teleport-Disabler', 'right'); - //} this.grabPointSphereOff(); this.lineOff(); this.overlayLineOff();