From a02ee5b7d551006cb4b22bdb8238fcc8a2a52c94 Mon Sep 17 00:00:00 2001 From: Daniela Date: Thu, 19 Oct 2017 18:05:51 +0100 Subject: [PATCH 1/3] Grabber Tool Move up, remove billboard on grabbermoveupoverlay --- .../system/libraries/entitySelectionTool.js | 246 +++++------------- 1 file changed, 65 insertions(+), 181 deletions(-) diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index 9715cc454c..6db9564c77 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -3,7 +3,7 @@ // examples // // Created by Brad hefta-Gaub on 10/1/14. -// Modified by Daniela Fontes @DanielaFifo and Tiago Andrade @TagoWill on 4/7/2017 +// Modified by Daniela Fontes * @DanielaFifo and Tiago Andrade @TagoWill on 4/7/2017 // Copyright 2014 High Fidelity, Inc. // // This script implements a class useful for building tools for editing entities. @@ -71,44 +71,16 @@ SelectionManager = (function() { that.selections = []; var listeners = []; - that.localRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - that.localPosition = { - x: 0, - y: 0, - z: 0 - }; - that.localDimensions = { - x: 0, - y: 0, - z: 0 - }; - that.localRegistrationPoint = { - x: 0.5, - y: 0.5, - z: 0.5 - }; + that.localRotation = Quat.IDENTITY; + that.localPosition = Vec3.ZERO; + that.localDimensions = Vec3.ZERO; + that.localRegistrationPoint = Vec3.HALF; - that.worldRotation = Quat.fromPitchYawRollDegrees(0, 0, 0); - that.worldPosition = { - x: 0, - y: 0, - z: 0 - }; - that.worldDimensions = { - x: 0, - y: 0, - z: 0 - }; - that.worldRegistrationPoint = { - x: 0.5, - y: 0.5, - z: 0.5 - }; - that.centerPosition = { - x: 0, - y: 0, - z: 0 - }; + that.worldRotation = Quat.IDENTITY; + that.worldPosition = Vec3.ZERO; + that.worldDimensions = Vec3.ZERO; + that.worldRegistrationPoint = Vec3.HALF; + that.centerPosition = Vec3.ZERO; that.saveProperties = function() { that.savedProperties = {}; @@ -231,6 +203,14 @@ SelectionManager = (function() { print("ERROR: entitySelectionTool.update got exception: " + JSON.stringify(e)); } } + + //update overlay to face Avatar + if ((!activeTool) || isActiveTool(grabberMoveUp)) { + Overlays.editOverlay(grabberMoveUp, { + rotation: Quat.lookAt(grabberMoveUpPosition, Camera.position, Quat.getUp(MyAvatar.orientation)) + }); + } + }; return that; @@ -350,11 +330,7 @@ SelectionDisplay = (function() { }; var grabberLineWidth = 0.5; var grabberSolid = true; - var grabberMoveUpPosition = { - x: 0, - y: 0, - z: 0 - }; + var grabberMoveUpPosition = Vec3.ZERO; var lightOverlayColor = { red: 255, @@ -363,11 +339,7 @@ SelectionDisplay = (function() { }; var grabberPropertiesCorner = { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: grabberSizeCorner, color: grabberColorCorner, alpha: 1, @@ -380,11 +352,7 @@ SelectionDisplay = (function() { }; var grabberPropertiesEdge = { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: grabberSizeEdge, color: grabberColorEdge, alpha: 1, @@ -397,11 +365,7 @@ SelectionDisplay = (function() { }; var grabberPropertiesFace = { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: grabberSizeFace, color: grabberColorFace, alpha: 1, @@ -414,11 +378,7 @@ SelectionDisplay = (function() { }; var grabberPropertiesCloner = { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: grabberSizeCorner, color: grabberColorCloner, alpha: 1, @@ -436,11 +396,7 @@ SelectionDisplay = (function() { }; var highlightBox = Overlays.addOverlay("cube", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 90, @@ -457,11 +413,7 @@ SelectionDisplay = (function() { }); var selectionBox = Overlays.addOverlay("cube", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 255, @@ -478,11 +430,7 @@ SelectionDisplay = (function() { var selectionBoxes = []; var rotationDegreesDisplay = Overlays.addOverlay("text3d", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, text: "", color: { red: 0, @@ -513,17 +461,12 @@ SelectionDisplay = (function() { var grabberMoveUp = Overlays.addOverlay("image3d", { url: HIFI_PUBLIC_BUCKET + "images/up-arrow.svg", - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, color: handleColor, alpha: handleAlpha, visible: false, size: 0.1, scale: 0.1, - isFacingAvatar: true, drawInFront: true }); @@ -720,16 +663,8 @@ SelectionDisplay = (function() { var xRailOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 1.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 255, green: 0, @@ -740,16 +675,8 @@ SelectionDisplay = (function() { var yRailOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 1.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 0, green: 255, @@ -760,16 +687,8 @@ SelectionDisplay = (function() { var zRailOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 1.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 0, green: 0, @@ -781,16 +700,8 @@ SelectionDisplay = (function() { var rotateZeroOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 2.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 255, green: 0, @@ -802,16 +713,8 @@ SelectionDisplay = (function() { var rotateCurrentOverlay = Overlays.addOverlay("line3d", { visible: false, lineWidth: 2.0, - start: { - x: 0, - y: 0, - z: 0 - }, - end: { - x: 0, - y: 0, - z: 0 - }, + start: Vec3.ZERO, + end: Vec3.ZERO, color: { red: 0, green: 0, @@ -822,11 +725,7 @@ SelectionDisplay = (function() { var rotateOverlayInner = Overlays.addOverlay("circle3d", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 51, @@ -856,11 +755,7 @@ SelectionDisplay = (function() { }); var rotateOverlayOuter = Overlays.addOverlay("circle3d", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 51, @@ -891,11 +786,7 @@ SelectionDisplay = (function() { }); var rotateOverlayCurrent = Overlays.addOverlay("circle3d", { - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, size: 1, color: { red: 224, @@ -922,11 +813,7 @@ SelectionDisplay = (function() { var yawHandle = Overlays.addOverlay("image3d", { url: ROTATE_ARROW_WEST_NORTH_URL, - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, color: handleColor, alpha: handleAlpha, visible: false, @@ -939,11 +826,7 @@ SelectionDisplay = (function() { var pitchHandle = Overlays.addOverlay("image3d", { url: ROTATE_ARROW_WEST_NORTH_URL, - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, color: handleColor, alpha: handleAlpha, visible: false, @@ -956,11 +839,7 @@ SelectionDisplay = (function() { var rollHandle = Overlays.addOverlay("image3d", { url: ROTATE_ARROW_WEST_NORTH_URL, - position: { - x: 0, - y: 0, - z: 0 - }, + position: Vec3.ZERO, color: handleColor, alpha: handleAlpha, visible: false, @@ -1550,11 +1429,11 @@ SelectionDisplay = (function() { Overlays.editOverlay(rollHandle, { scale: handleSize }); - var pos = Vec3.sum(grabberMoveUpPosition, { - x: 0, - y: Vec3.length(diff) * GRABBER_DISTANCE_TO_SIZE_RATIO * 3, - z: 0 - }); + var upDiff = Vec3.multiply(( + Vec3.length(diff) * GRABBER_DISTANCE_TO_SIZE_RATIO * 3), + Quat.getUp(MyAvatar.orientation) + ); + var pos = Vec3.sum(grabberMoveUpPosition, upDiff); Overlays.editOverlay(grabberMoveUp, { position: pos, scale: handleSize / 1.25 @@ -1636,7 +1515,7 @@ SelectionDisplay = (function() { position = SelectionManager.localPosition; registrationPoint = SelectionManager.localRegistrationPoint; } else { - rotation = Quat.fromPitchYawRollDegrees(0, 0, 0); + rotation = Quat.IDENTITY; dimensions = SelectionManager.worldDimensions; position = SelectionManager.worldPosition; registrationPoint = SelectionManager.worldRegistrationPoint; @@ -2227,13 +2106,15 @@ SelectionDisplay = (function() { }); var grabberMoveUpOffset = 0.1; + var upVec = Quat.getUp(MyAvatar.orientation); grabberMoveUpPosition = { - x: position.x, - y: position.y + worldTop + grabberMoveUpOffset, - z: position.z + x: position.x + (grabberMoveUpOffset + worldTop) * upVec.x , + y: position.y+ (grabberMoveUpOffset + worldTop) * upVec.y, + z: position.z + (grabberMoveUpOffset + worldTop) * upVec.z }; Overlays.editOverlay(grabberMoveUp, { - visible: (!activeTool) || isActiveTool(grabberMoveUp) + visible: (!activeTool) || isActiveTool(grabberMoveUp), + rotation: Quat.lookAt(grabberMoveUpPosition, Camera.position, upVec) }); Overlays.editOverlay(baseOfEntityProjectionOverlay, { @@ -2544,9 +2425,6 @@ SelectionDisplay = (function() { mode: "TRANSLATE_UP_DOWN", onBegin: function(event, pickRay, pickResult) { upDownPickNormal = Quat.getForward(lastCameraOrientation); - // Remove y component so the y-axis lies along the plane we're picking on - this will - // give movements that follow the mouse. - upDownPickNormal.y = 0; lastXYPick = rayPlaneIntersection(pickRay, SelectionManager.worldPosition, upDownPickNormal); SelectionManager.saveProperties(); @@ -2583,11 +2461,17 @@ SelectionDisplay = (function() { var newIntersection = rayPlaneIntersection(pickRay, SelectionManager.worldPosition, upDownPickNormal); var vector = Vec3.subtract(newIntersection, lastXYPick); + + // project vector onto avatar up vector + // we want the avatar referential not the camera. + var avatarUpVector = Quat.getUp(MyAvatar.orientation); + var dotVectorUp = Vec3.dot(vector, avatarUpVector); + vector = Vec3.multiply(dotVectorUp, avatarUpVector); + + vector = grid.snapToGrid(vector); - // we only care about the Y axis - vector.x = 0; - vector.z = 0; + var wantDebug = false; if (wantDebug) { @@ -2692,7 +2576,7 @@ SelectionDisplay = (function() { var onBegin = function(event, pickRay, pickResult) { var properties = Entities.getEntityProperties(SelectionManager.selections[0]); initialProperties = properties; - rotation = (spaceMode === SPACE_LOCAL) ? properties.rotation : Quat.fromPitchYawRollDegrees(0, 0, 0); + rotation = (spaceMode === SPACE_LOCAL) ? properties.rotation : Quat.IDENTITY; if (spaceMode === SPACE_LOCAL) { rotation = SelectionManager.localRotation; From f15038c54fe58671d34d7d4a82f8f1cbb8d50528 Mon Sep 17 00:00:00 2001 From: Daniela Date: Mon, 23 Oct 2017 19:11:32 +0100 Subject: [PATCH 2/3] Re-add isFacingAvatar to true and delete rotation of the grabbermoveup tool. --- interface/src/ui/overlays/Billboardable.cpp | 10 ++++++---- scripts/system/libraries/entitySelectionTool.js | 15 ++++----------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/interface/src/ui/overlays/Billboardable.cpp b/interface/src/ui/overlays/Billboardable.cpp index 34a4ef6df5..e71e8bb951 100644 --- a/interface/src/ui/overlays/Billboardable.cpp +++ b/interface/src/ui/overlays/Billboardable.cpp @@ -13,6 +13,7 @@ #include #include +#include "avatar/AvatarManager.h" void Billboardable::setProperties(const QVariantMap& properties) { auto isFacingAvatar = properties["isFacingAvatar"]; @@ -32,10 +33,11 @@ bool Billboardable::pointTransformAtCamera(Transform& transform, glm::quat offse if (isFacingAvatar()) { glm::vec3 billboardPos = transform.getTranslation(); glm::vec3 cameraPos = qApp->getCamera().getPosition(); - glm::vec3 look = cameraPos - billboardPos; - float elevation = -asinf(look.y / glm::length(look)); - float azimuth = atan2f(look.x, look.z); - glm::quat rotation(glm::vec3(elevation, azimuth, 0)); + + glm::vec3 avatarUP = DependencyManager::get()->getMyAvatar()->getOrientation()*Vectors::UP; + + glm::quat rotation(conjugate(toQuat(glm::lookAt(billboardPos, cameraPos, avatarUP)))); + transform.setRotation(rotation); transform.postRotate(offsetRotation); return true; diff --git a/scripts/system/libraries/entitySelectionTool.js b/scripts/system/libraries/entitySelectionTool.js index 6db9564c77..3a422bcb8a 100644 --- a/scripts/system/libraries/entitySelectionTool.js +++ b/scripts/system/libraries/entitySelectionTool.js @@ -203,14 +203,7 @@ SelectionManager = (function() { print("ERROR: entitySelectionTool.update got exception: " + JSON.stringify(e)); } } - - //update overlay to face Avatar - if ((!activeTool) || isActiveTool(grabberMoveUp)) { - Overlays.editOverlay(grabberMoveUp, { - rotation: Quat.lookAt(grabberMoveUpPosition, Camera.position, Quat.getUp(MyAvatar.orientation)) - }); - } - + }; return that; @@ -467,6 +460,7 @@ SelectionDisplay = (function() { visible: false, size: 0.1, scale: 0.1, + isFacingAvatar: true, drawInFront: true }); @@ -2113,8 +2107,7 @@ SelectionDisplay = (function() { z: position.z + (grabberMoveUpOffset + worldTop) * upVec.z }; Overlays.editOverlay(grabberMoveUp, { - visible: (!activeTool) || isActiveTool(grabberMoveUp), - rotation: Quat.lookAt(grabberMoveUpPosition, Camera.position, upVec) + visible: (!activeTool) || isActiveTool(grabberMoveUp) }); Overlays.editOverlay(baseOfEntityProjectionOverlay, { @@ -2463,7 +2456,7 @@ SelectionDisplay = (function() { var vector = Vec3.subtract(newIntersection, lastXYPick); // project vector onto avatar up vector - // we want the avatar referential not the camera. + // we want the avatar referential not the camera. var avatarUpVector = Quat.getUp(MyAvatar.orientation); var dotVectorUp = Vec3.dot(vector, avatarUpVector); vector = Vec3.multiply(dotVectorUp, avatarUpVector); From 059c5c1806d287e3072b6f0a9b56d86fb0325a79 Mon Sep 17 00:00:00 2001 From: Daniela Date: Tue, 24 Oct 2017 14:49:17 +0100 Subject: [PATCH 3/3] billboard is now using a general formula to calculate the rotation, where we don't assume y is up. Added dependency on the avatar. --- interface/src/ui/overlays/Billboardable.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/ui/overlays/Billboardable.cpp b/interface/src/ui/overlays/Billboardable.cpp index e71e8bb951..892a9d998d 100644 --- a/interface/src/ui/overlays/Billboardable.cpp +++ b/interface/src/ui/overlays/Billboardable.cpp @@ -3,6 +3,7 @@ // interface/src/ui/overlays // // Created by Zander Otavka on 8/7/15. +// Modified by Daniela Fontes on 24/10/17. // Copyright 2014 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -33,7 +34,7 @@ bool Billboardable::pointTransformAtCamera(Transform& transform, glm::quat offse if (isFacingAvatar()) { glm::vec3 billboardPos = transform.getTranslation(); glm::vec3 cameraPos = qApp->getCamera().getPosition(); - + // use the referencial from the avatar, y isn't always up glm::vec3 avatarUP = DependencyManager::get()->getMyAvatar()->getOrientation()*Vectors::UP; glm::quat rotation(conjugate(toQuat(glm::lookAt(billboardPos, cameraPos, avatarUP))));