From da4f2b8c2f1810528cac4001aa9f97b3a2c30326 Mon Sep 17 00:00:00 2001 From: Gabriel Calero Date: Fri, 30 Mar 2018 15:34:00 -0300 Subject: [PATCH 1/5] Fix zoom in unresponsive in radar mode --- scripts/system/+android/radar.js | 47 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/scripts/system/+android/radar.js b/scripts/system/+android/radar.js index 455299dd5f..2b87f8955d 100644 --- a/scripts/system/+android/radar.js +++ b/scripts/system/+android/radar.js @@ -21,7 +21,7 @@ function printd(str) { } var radar = false; -var radarHeight = 10; // camera position meters above the avatar +var radarHeight = MyAvatar.position.y + 10; // camera position (absolute y) var tablet; var RADAR_CAMERA_OFFSET = -1; // 1 meter below the avatar @@ -46,11 +46,11 @@ var uniqueColor; function moveTo(position) { if (radar) { MyAvatar.position = position; - Camera.position = Vec3.sum(MyAvatar.position, { - x : 0, + Camera.position = { + x : MyAvatar.position.x, y : radarHeight, - z : 0 - }); + z : MyAvatar.position.z + }; } } @@ -386,12 +386,12 @@ function pinchUpdate(event) { radarHeight -= pinchIncrement; } } - var deltaHeight = avatarY + radarHeight - Camera.position.y; - Camera.position = Vec3.sum(Camera.position, { - x : 0, - y : deltaHeight, - z : 0 - }); + Camera.position = { + x: Camera.position.x, + y:radarHeight, + z:Camera.position.z + }; + if (!draggingCamera) { startedDraggingCamera = true; draggingCamera = true; @@ -401,7 +401,8 @@ function pinchUpdate(event) { } function isInsideSquare(coords0, coords1, halfside) { - return Math.abs(coords0.x - coords1.x) <= halfside + return coords0 != undefined && coords1!= undefined && + Math.abs(coords0.x - coords1.x) <= halfside && Math.abs(coords0.y - coords1.y) <= halfside; } @@ -412,7 +413,7 @@ function dragScrollUpdate(event) { // drag management var pickRay = Camera.computePickRay(event.x, event.y); var dragAt = Vec3.sum(pickRay.origin, Vec3.multiply(pickRay.direction, - radarHeight)); + radarHeight-MyAvatar.position.y)); if (lastDragAt === undefined || lastDragAt === null) { lastDragAt = dragAt; @@ -722,7 +723,7 @@ function Teleporter() { return { dragTeleportBegin : function(event) { printd("[newTeleport] TELEPORT began"); - var overlayDimensions = entityIconModelDimensions(); + var overlayDimensions = entityIconModelDimensions(MyAvatar.position.y); // var destination = computeDestination(event, MyAvatar.position, // Camera.position, radarHeight); // Dimension teleport and cancel overlays (not show them yet) @@ -843,7 +844,7 @@ var avatarIconDimensionsVal = { }; function avatarIconPlaneDimensions() { // given the current height, give a size - var xy = -0.003531 * radarHeight + 0.1; + var xy = -0.003531 * (radarHeight - MyAvatar.position.y) + 0.1; avatarIconDimensionsVal.x = Math.abs(xy); avatarIconDimensionsVal.y = Math.abs(xy); // reuse object @@ -1165,9 +1166,10 @@ var entityIconModelDimensionsVal = { y : 0.00001, z : 0 }; -function entityIconModelDimensions() { +function entityIconModelDimensions(y) { // given the current height, give a size - var xz = -0.002831 * radarHeight + 0.1; + // TODO: receive entity.position.y and substract to radarHeight + var xz = -0.002831 * (radarHeight - y) + 0.1; entityIconModelDimensionsVal.x = xz; entityIconModelDimensionsVal.z = xz; // reuse object @@ -1177,8 +1179,8 @@ function entityIconModelDimensions() { * entityIconPlaneDimensions: similar to entityIconModelDimensions but using xy * plane */ -function entityIconPlaneDimensions() { - var dim = entityIconModelDimensions(); +function entityIconPlaneDimensions(y) { + var dim = entityIconModelDimensions(y); var z = dim.z; dim.z = dim.y; dim.y = z; @@ -1255,15 +1257,15 @@ function hideAllEntitiesIcons() { function renderAllEntitiesIcons() { var entityPos; var entityProps; - var iconDimensions = entityIconModelDimensions(); - var planeDimensions = entityIconPlaneDimensions(); // plane overlays uses - // xy instead of xz + for ( var QUuid in entitiesData) { if (entitiesData.hasOwnProperty(QUuid)) { entityProps = Entities.getEntityProperties(QUuid, [ "position", "visible" ]); if (entityProps != null) { entityPos = entityProps.position; + var planeDimensions = entityIconPlaneDimensions(entityPos.y); // plane overlays uses + // xy instead of xz if (entitiesData[QUuid].icon != undefined && entityPos) { var iconPos = findLineToHeightIntersectionCoords( entityPos.x, @@ -1276,6 +1278,7 @@ function renderAllEntitiesIcons() { printd("entity icon pos bad for " + QUuid); continue; } + var iconDimensions = entityIconModelDimensions(entityPos.y); var dimensions = entitiesData[QUuid].planar ? planeDimensions : iconDimensions; Overlays.editOverlay(entitiesData[QUuid].icon, { From 36bc5f841627e170cb0d15c35586106d5c176eb5 Mon Sep 17 00:00:00 2001 From: Gabriel Calero Date: Thu, 5 Apr 2018 15:35:08 -0300 Subject: [PATCH 2/5] Fix the view snap when user starts zooming --- scripts/system/+android/radar.js | 37 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/scripts/system/+android/radar.js b/scripts/system/+android/radar.js index 2b87f8955d..120bec33c3 100644 --- a/scripts/system/+android/radar.js +++ b/scripts/system/+android/radar.js @@ -21,7 +21,8 @@ function printd(str) { } var radar = false; -var radarHeight = MyAvatar.position.y + 10; // camera position (absolute y) +var RADAR_HEIGHT_INIT_DELTA = 10; +var radarHeight = MyAvatar.position.y + RADAR_HEIGHT_INIT_DELTA; // camera position (absolute y) var tablet; var RADAR_CAMERA_OFFSET = -1; // 1 meter below the avatar @@ -386,6 +387,7 @@ function pinchUpdate(event) { radarHeight -= pinchIncrement; } } + Camera.position = { x: Camera.position.x, y:radarHeight, @@ -655,6 +657,7 @@ function Teleporter() { return; } + Camera.position = Vec3.sum(Camera.position, { x : xDelta, y : 0, @@ -1301,11 +1304,12 @@ function startRadar() { saveAllOthersAvatarsData(); Camera.mode = "independent"; - Camera.position = Vec3.sum(MyAvatar.position, { - x : 0, - y : radarHeight, - z : 0 - }); + Camera.position = { + x : MyAvatar.position.x, + y : radarHeight, + z : MyAvatar.position.z + }; + Camera.orientation = Quat.fromPitchYawRollDegrees(-90, 0, 0); radar = true; @@ -1394,15 +1398,25 @@ function connectRadarModeEvents() { Controller.keyPressEvent.connect(keyPressEvent); Controller.mousePressEvent.connect(mousePress); // single click/touch Controller.touchUpdateEvent.connect(touchUpdate); + Window.domainChanged.connect(domainChanged); MyAvatar.positionGoneTo.connect(positionGoneTo); } -function positionGoneTo() { - Camera.position = Vec3.sum(MyAvatar.position, { - x : 0, +function domainChanged() { + radarHeight = MyAvatar.position.y + RADAR_HEIGHT_INIT_DELTA; + Camera.position = { + x : MyAvatar.position.x, y : radarHeight, - z : 0 - }); + z : MyAvatar.position.z + }; +} + +function positionGoneTo() { + Camera.position = { + x : MyAvatar.position.x, + y : radarHeight, + z : MyAvatar.position.z + }; } function disconnectRadarModeEvents() { @@ -1411,6 +1425,7 @@ function disconnectRadarModeEvents() { Controller.mousePressEvent.disconnect(mousePress); Controller.touchUpdateEvent.disconnect(touchUpdate); MyAvatar.positionGoneTo.disconnect(positionGoneTo); + Window.domainChanged.disconnect(domainChanged); } function init() { From d5c252c9ad70cfb2e46c95b75cd3a71d7b8f5196 Mon Sep 17 00:00:00 2001 From: Cristian Duarte Date: Mon, 9 Apr 2018 16:24:03 -0300 Subject: [PATCH 3/5] Use MyAvatar.goToLocation in radar teleport. Use MyAvatar.goToLocation in radar teleport to prevent synchronization issues that make it fail occasionally when directly modifying its world position. It will work just as teleport.js does. --- scripts/system/+android/radar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/system/+android/radar.js b/scripts/system/+android/radar.js index 120bec33c3..8100cc0887 100644 --- a/scripts/system/+android/radar.js +++ b/scripts/system/+android/radar.js @@ -46,11 +46,11 @@ var uniqueColor; function moveTo(position) { if (radar) { - MyAvatar.position = position; + MyAvatar.goToLocation(position, false); Camera.position = { - x : MyAvatar.position.x, + x : position.x, y : radarHeight, - z : MyAvatar.position.z + z : position.z }; } } From 63e17e87b0fa4e00db8b871e731c34684a1f4f08 Mon Sep 17 00:00:00 2001 From: Gabriel Calero Date: Tue, 10 Apr 2018 19:21:23 -0300 Subject: [PATCH 4/5] Fix radar initial position. Clean radar.js --- scripts/system/+android/radar.js | 232 ++----------------------------- 1 file changed, 8 insertions(+), 224 deletions(-) diff --git a/scripts/system/+android/radar.js b/scripts/system/+android/radar.js index 8100cc0887..67ba896207 100644 --- a/scripts/system/+android/radar.js +++ b/scripts/system/+android/radar.js @@ -90,46 +90,6 @@ function keyPressEvent(event) { } } -function actionOnObjectFromEvent(event) { - var rayIntersection = findRayIntersection(Camera.computePickRay(event.x, - event.y)); - if (rayIntersection && rayIntersection.intersects - && rayIntersection.overlayID) { - printd("found overlayID touched " + rayIntersection.overlayID); - if (entitiesByOverlayID[rayIntersection.overlayID]) { - var entity = Entities.getEntityProperties( - entitiesByOverlayID[rayIntersection.overlayID], - [ "sourceUrl" ]); - App.openUrl(entity.sourceUrl); - return true; - } - } - if (rayIntersection && rayIntersection.intersects - && rayIntersection.entityID && rayIntersection.properties) { - printd("found " + rayIntersection.entityID + " of type " - + rayIntersection.properties.type); - if (rayIntersection.properties.type == "Web") { - printd("found web element to " - + rayIntersection.properties.sourceUrl); - App.openUrl(rayIntersection.properties.sourceUrl); - return true; - } - } - return false; -} - -function mousePress(event) { - mousePressOrTouchEnd(event); -} - -function mousePressOrTouchEnd(event) { - if (radar) { - if (actionOnObjectFromEvent(event)) { - return; - } - } -} - function toggleRadarMode() { if (radar) { endRadar(); @@ -230,9 +190,6 @@ function touchEnd(event) { if (analyzeDoubleTap(event)) return; // double tap detected, finish - if (radar) { - mousePressOrTouchEnd(event); - } } /** @@ -726,7 +683,7 @@ function Teleporter() { return { dragTeleportBegin : function(event) { printd("[newTeleport] TELEPORT began"); - var overlayDimensions = entityIconModelDimensions(MyAvatar.position.y); + var overlayDimensions = teleportIconModelDimensions(MyAvatar.position.y); // var destination = computeDestination(event, MyAvatar.position, // Camera.position, radarHeight); // Dimension teleport and cancel overlays (not show them yet) @@ -1125,39 +1082,10 @@ function renderAllOthersAvatarIcons() { } } -function entityAdded(entityID) { - printd("Entity added " + entityID); - var props = Entities.getEntityProperties(entityID, [ "type" ]); - printd("Entity added " + entityID + " PROPS " + JSON.stringify(props)); - if (props && props.type == "Web") { - printd("Entity Web added " + entityID); - saveEntityData(entityID, true); - } -} - -function entityRemoved(entityID) { - printd("Entity removed " + entityID); - var props = Entities.getEntityProperties(entityID, [ "type" ]); - if (props && props.type == "Web") { - print("Entity Web removed " + entityID); - removeEntityData(entityID); - } -} - /******************************************************************************* * Entities (to remark) cache structure for showing entities markers ******************************************************************************/ -var entitiesData = {}; // by entityID -var entitiesByOverlayID = {}; // by overlayID -var entitiesIcons = []; // a parallel list of icons (overlays) to easily run - // through - -var ICON_ENTITY_WEB_MODEL_URL = Script.resolvePath("../assets/images/web.svg"); -var ICON_ENTITY_IMG_MODEL_URL = Script - .resolvePath("../assets/models/teleport-cancel.fbx"); // FIXME - use - // correct - // model&texture var ICON_ENTITY_DEFAULT_DIMENSIONS = { x : 0.10, y : 0.00001, @@ -1169,7 +1097,7 @@ var entityIconModelDimensionsVal = { y : 0.00001, z : 0 }; -function entityIconModelDimensions(y) { +function teleportIconModelDimensions(y) { // given the current height, give a size // TODO: receive entity.position.y and substract to radarHeight var xz = -0.002831 * (radarHeight - y) + 0.1; @@ -1178,122 +1106,6 @@ function entityIconModelDimensions(y) { // reuse object return entityIconModelDimensionsVal; } -/* - * entityIconPlaneDimensions: similar to entityIconModelDimensions but using xy - * plane - */ -function entityIconPlaneDimensions(y) { - var dim = entityIconModelDimensions(y); - var z = dim.z; - dim.z = dim.y; - dim.y = z; - return dim; -} - -function currentOverlayForEntity(QUuid) { - if (entitiesData[QUuid] != undefined) { - return entitiesData[QUuid].icon; - } else { - return null; - } -} - -function saveEntityData(QUuid, planar) { - if (QUuid == null) - return; - var entity = Entities.getEntityProperties(QUuid, [ "position" ]); - printd("entity added save entity " + QUuid); - if (entitiesData[QUuid] != undefined) { - entitiesData[QUuid].position = entity.position; - } else { - var entityIcon = Overlays.addOverlay("image3d", { - subImage : { - x : 0, - y : 0, - width : 150, - height : 150 - }, - url : ICON_ENTITY_WEB_MODEL_URL, - dimensions : ICON_ENTITY_DEFAULT_DIMENSIONS, - visible : false, - ignoreRayIntersection : false, - orientation : Quat.fromPitchYawRollDegrees(-90, 0, 0) - }); - - entitiesIcons.push(entityIcon); - entitiesData[QUuid] = { - position : entity.position, - icon : entityIcon - }; - entitiesByOverlayID[entityIcon] = QUuid; - } -} - -function removeEntityData(QUuid) { - if (QUuid == null) - return; - - var itsOverlay = currentOverlayForEntity(QUuid); - if (itsOverlay != null) { - Overlays.deleteOverlay(itsOverlay); - delete entitiesByOverlayID[itsOverlay]; - } - var idx = entitiesIcons.indexOf(itsOverlay); - entitiesIcons.splice(idx, 1); - - delete entitiesData[QUuid]; -} - -/******************************************************************************* - * Entities to remark Icon/Markers rendering - ******************************************************************************/ - -function hideAllEntitiesIcons() { - var len = entitiesIcons.length; - for (var i = 0; i < len; i++) { - Overlays.editOverlay(entitiesIcons[i], { - visible : false - }); - } -} - -function renderAllEntitiesIcons() { - var entityPos; - var entityProps; - - for ( var QUuid in entitiesData) { - if (entitiesData.hasOwnProperty(QUuid)) { - entityProps = Entities.getEntityProperties(QUuid, [ "position", - "visible" ]); - if (entityProps != null) { - entityPos = entityProps.position; - var planeDimensions = entityIconPlaneDimensions(entityPos.y); // plane overlays uses - // xy instead of xz - if (entitiesData[QUuid].icon != undefined && entityPos) { - var iconPos = findLineToHeightIntersectionCoords( - entityPos.x, - entityPos.y - + RADAR_ICONS_APPARENT_DISTANCE_TO_AVATAR_BASE, - entityPos.z, Camera.position.x, Camera.position.y, - Camera.position.z, Camera.position.y - - RADAR_CAMERA_DISTANCE_TO_ICONS); - if (!iconPos) { - printd("entity icon pos bad for " + QUuid); - continue; - } - var iconDimensions = entityIconModelDimensions(entityPos.y); - var dimensions = entitiesData[QUuid].planar ? planeDimensions - : iconDimensions; - Overlays.editOverlay(entitiesData[QUuid].icon, { - visible : entityProps.visible, - dimensions : dimensions, - position : iconPos - }); - } - } - } - } -} /******************************************************************************* * @@ -1304,11 +1116,7 @@ function startRadar() { saveAllOthersAvatarsData(); Camera.mode = "independent"; - Camera.position = { - x : MyAvatar.position.x, - y : radarHeight, - z : MyAvatar.position.z - }; + initCameraOverMyAvatar(); Camera.orientation = Quat.fromPitchYawRollDegrees(-90, 0, 0); radar = true; @@ -1326,7 +1134,6 @@ function endRadar() { Controller.setVPadEnabled(true); disconnectRadarModeEvents(); - hideAllEntitiesIcons(); hideAllAvatarIcons(); } @@ -1360,12 +1167,10 @@ function updateRadar() { // Update avatar icons if (startedDraggingCamera) { hideAllAvatarIcons(); - hideAllEntitiesIcons(); startedDraggingCamera = false; } else if (!draggingCamera) { renderMyAvatarIcon(); renderAllOthersAvatarIcons(); - renderAllEntitiesIcons(); } } @@ -1373,36 +1178,15 @@ function valueIfDefined(value) { return value !== undefined ? value : ""; } -function entitiesAnalysis() { - var ids = Entities.findEntitiesInFrustum(Camera.frustum); - var entities = []; - for (var i = 0; i < ids.length; i++) { - var id = ids[i]; - var properties = Entities.getEntityProperties(id); - entities.push({ - id : id, - name : properties.name, - type : properties.type, - url : properties.type == "Model" ? properties.modelURL : "", - sourceUrl : properties.sourceUrl, - locked : properties.locked, - visible : properties.visible, - drawCalls : valueIfDefined(properties.renderInfo.drawCalls), - hasScript : properties.script !== "" - }); - } -} - function connectRadarModeEvents() { Script.update.connect(updateRadar); // 60Hz loop Controller.keyPressEvent.connect(keyPressEvent); - Controller.mousePressEvent.connect(mousePress); // single click/touch Controller.touchUpdateEvent.connect(touchUpdate); Window.domainChanged.connect(domainChanged); MyAvatar.positionGoneTo.connect(positionGoneTo); } -function domainChanged() { +function initCameraOverMyAvatar() { radarHeight = MyAvatar.position.y + RADAR_HEIGHT_INIT_DELTA; Camera.position = { x : MyAvatar.position.x, @@ -1411,6 +1195,10 @@ function domainChanged() { }; } +function domainChanged() { + initCameraOverMyAvatar(); +} + function positionGoneTo() { Camera.position = { x : MyAvatar.position.x, @@ -1422,7 +1210,6 @@ function positionGoneTo() { function disconnectRadarModeEvents() { Script.update.disconnect(updateRadar); Controller.keyPressEvent.disconnect(keyPressEvent); - Controller.mousePressEvent.disconnect(mousePress); Controller.touchUpdateEvent.disconnect(touchUpdate); MyAvatar.positionGoneTo.disconnect(positionGoneTo); Window.domainChanged.disconnect(domainChanged); @@ -1436,7 +1223,4 @@ function init() { AvatarList.avatarAddedEvent.connect(avatarAdded); AvatarList.avatarRemovedEvent.connect(avatarRemoved); - - Entities.addingEntity.connect(entityAdded); - Entities.deletingEntity.connect(entityRemoved); } From e0b57a22286207c86c31f24cfc4582c212d26139 Mon Sep 17 00:00:00 2001 From: Gabriel Calero Date: Wed, 9 May 2018 18:20:19 -0300 Subject: [PATCH 5/5] Code review in radar.js --- scripts/system/+android/radar.js | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/scripts/system/+android/radar.js b/scripts/system/+android/radar.js index 67ba896207..5d93ed4db1 100644 --- a/scripts/system/+android/radar.js +++ b/scripts/system/+android/radar.js @@ -346,9 +346,9 @@ function pinchUpdate(event) { } Camera.position = { - x: Camera.position.x, - y:radarHeight, - z:Camera.position.z + x : Camera.position.x, + y : radarHeight, + z : Camera.position.z }; if (!draggingCamera) { @@ -360,7 +360,7 @@ function pinchUpdate(event) { } function isInsideSquare(coords0, coords1, halfside) { - return coords0 != undefined && coords1!= undefined && + return coords0 != undefined && coords1 != undefined && Math.abs(coords0.x - coords1.x) <= halfside && Math.abs(coords0.y - coords1.y) <= halfside; } @@ -372,7 +372,7 @@ function dragScrollUpdate(event) { // drag management var pickRay = Camera.computePickRay(event.x, event.y); var dragAt = Vec3.sum(pickRay.origin, Vec3.multiply(pickRay.direction, - radarHeight-MyAvatar.position.y)); + radarHeight - MyAvatar.position.y)); if (lastDragAt === undefined || lastDragAt === null) { lastDragAt = dragAt; @@ -1082,29 +1082,20 @@ function renderAllOthersAvatarIcons() { } } -/******************************************************************************* - * Entities (to remark) cache structure for showing entities markers - ******************************************************************************/ - var ICON_ENTITY_DEFAULT_DIMENSIONS = { x : 0.10, y : 0.00001, z : 0.10 }; -var entityIconModelDimensionsVal = { - x : 0, - y : 0.00001, - z : 0 -}; + function teleportIconModelDimensions(y) { - // given the current height, give a size - // TODO: receive entity.position.y and substract to radarHeight + var teleportModelDimensions = ICON_ENTITY_DEFAULT_DIMENSIONS; var xz = -0.002831 * (radarHeight - y) + 0.1; - entityIconModelDimensionsVal.x = xz; - entityIconModelDimensionsVal.z = xz; + teleportModelDimensions.x = xz; + teleportModelDimensions.z = xz; // reuse object - return entityIconModelDimensionsVal; + return teleportModelDimensions; } /*******************************************************************************