From e690d4f7efd3b00d199da090cb0ed4263c166dfa Mon Sep 17 00:00:00 2001 From: RebeccaStankus Date: Mon, 19 Aug 2019 13:40:50 -0700 Subject: [PATCH] Limited distance to rez a point reticle --- .../simplifiedEmote/simplifiedEmote.js | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js b/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js index 0f1f8704d9..f840d298a4 100644 --- a/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js +++ b/scripts/simplifiedUI/simplifiedEmote/simplifiedEmote.js @@ -188,44 +188,38 @@ function beginReactionWrapper(reaction) { } } -var intersectedEntityOrAvatarID = null; + +var MAX_INTERSECTION_DISTANCE_M = 50; function mouseMoveEvent(event) { var pickRay = Camera.computePickRay(event.x, event.y); var avatarIntersectionData = AvatarManager.findRayIntersection(pickRay); var entityIntersectionData = Entities.findRayIntersection(pickRay, true); - var avatarIntersectionDistanceM = avatarIntersectionData.intersects ? avatarIntersectionData.distance : null; - var entityIntersectionDistanceM = entityIntersectionData.intersects ? entityIntersectionData.distance : null; + var avatarIntersectionDistanceM = avatarIntersectionData.intersects && avatarIntersectionData.distance < MAX_INTERSECTION_DISTANCE_M ? avatarIntersectionData.distance : null; + var entityIntersectionDistanceM = entityIntersectionData.intersects && entityIntersectionData.distance < MAX_INTERSECTION_DISTANCE_M ? entityIntersectionData.distance : null; var reticlePosition; if (avatarIntersectionDistanceM && entityIntersectionDistanceM) { if (avatarIntersectionDistanceM < entityIntersectionDistanceM) { - intersectedEntityOrAvatarID = avatarIntersectionData.avatarID; reticlePosition = avatarIntersectionData.intersection; } else { - intersectedEntityOrAvatarID = entityIntersectionData.entityID; reticlePosition = entityIntersectionData.intersection; } } else if (avatarIntersectionDistanceM) { - intersectedEntityOrAvatarID = avatarIntersectionData.avatarID; reticlePosition = avatarIntersectionData.intersection; } else if (entityIntersectionDistanceM) { - intersectedEntityOrAvatarID = entityIntersectionData.entityID; reticlePosition = entityIntersectionData.intersection; } else { - print("ERROR: No intersected avatar or entity found."); + print("ERROR: No intersected avatar or entity found or the distance is too far."); + if (pointReticle) { + Entities.deleteEntity(pointReticle); + pointReticle = null; + } return; } - //if (intersectedEntityOrAvatarID === avatarIntersectionData.intersects) { - // print("PICKRAY INTERSECTS AVATAR: ", intersectedEntityOrAvatarID); - //} else { - // print("PICKRAY INTERSECTS ENTITY: ", intersectedEntityOrAvatarID); - //} - if (pointReticle) { Entities.editEntity(pointReticle, { position: reticlePosition }); } else { - // make dimensions scale to distance pointReticle = Entities.addEntity({ type: "Sphere", name: "Point Reticle", @@ -236,13 +230,6 @@ function mouseMoveEvent(event) { ignorePickIntersection: true }, true); } - - // cast ray from camera to 3d cursor position - // get intersection of ray - // if intersects with entity, move back along normal 1/2 depth of the entity to get reticle position or maybe just SubmeshIntersection.worldIntersectionPoint - // if intersects avatar, move backward 0.5m or maybe just SubmeshIntersection.worldIntersectionPoint - // create reticle at the position - // make avatar point at the reticle }