From f3cb25065f518b9569404aef7373a36c24072ef3 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Tue, 14 Jul 2015 17:36:22 -0700 Subject: [PATCH 01/28] can't move when hydras at base, hands can deactivate individually --- interface/src/avatar/SkeletonModel.cpp | 16 ++++++++++++---- interface/src/devices/SixenseManager.cpp | 17 +++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 20d458195d..0eb54b7c07 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -120,8 +120,8 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { Hand* hand = _owningAvatar->getHand(); hand->getLeftRightPalmIndices(leftPalmIndex, rightPalmIndex); - const float HAND_RESTORATION_RATE = 0.25f; - if (leftPalmIndex == -1 || rightPalmIndex == -1) { + const float HAND_RESTORATION_RATE = 0.25f; + if (leftPalmIndex == -1 && rightPalmIndex == -1) { // palms are not yet set, use mouse if (_owningAvatar->getHandState() == HAND_STATE_NULL) { restoreRightHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY); @@ -138,8 +138,16 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) { restoreLeftHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY); } else { - applyPalmData(geometry.leftHandJointIndex, hand->getPalms()[leftPalmIndex]); - applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]); + if (leftPalmIndex != -1) { + applyPalmData(geometry.leftHandJointIndex, hand->getPalms()[leftPalmIndex]); + } else { + restoreLeftHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY); + } + if (rightPalmIndex != -1) { + applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]); + } else { + restoreRightHandPosition(HAND_RESTORATION_RATE, PALM_PRIORITY); + } } if (_isFirstPerson) { diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 12b6f4263b..c82027cb38 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -244,14 +244,6 @@ void SixenseManager::update(float deltaTime) { palm->setTrigger(data->trigger); palm->setJoystick(data->joystick_x, data->joystick_y); - handleButtonEvent(data->buttons, numActiveControllers - 1); - handleAxisEvent(data->joystick_x, data->joystick_y, data->trigger, numActiveControllers - 1); - - // Emulate the mouse so we can use scripts - if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput) && !_controllersAtBase) { - emulateMouse(palm, numActiveControllers - 1); - } - // NOTE: Sixense API returns pos data in millimeters but we IMMEDIATELY convert to meters. glm::vec3 position(data->pos[0], data->pos[1], data->pos[2]); position *= METERS_PER_MILLIMETER; @@ -260,6 +252,15 @@ void SixenseManager::update(float deltaTime) { const float CONTROLLER_AT_BASE_DISTANCE = 0.075f; if (glm::length(position) < CONTROLLER_AT_BASE_DISTANCE) { numControllersAtBase++; + palm->setActive(false); + } else { + handleButtonEvent(data->buttons, numActiveControllers - 1); + handleAxisEvent(data->joystick_x, data->joystick_y, data->trigger, numActiveControllers - 1); + + // Emulate the mouse so we can use scripts + if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput) && !_controllersAtBase) { + emulateMouse(palm, numActiveControllers - 1); + } } // Transform the measured position into body frame. From 6a0df442f98658cd9728f3a0a5ece4e2d5b772c7 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Tue, 14 Jul 2015 17:59:59 -0700 Subject: [PATCH 02/28] emulated mouse events don't get sent back to the keyboard (can't right click and drag with sixense, etc) --- interface/src/Application.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index eabeb27d5e..79bdcea634 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1568,7 +1568,9 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { return; } - _keyboardMouseDevice.mouseMoveEvent(event, deviceID); + if (deviceID == 0) { + _keyboardMouseDevice.mouseMoveEvent(event, deviceID); + } } @@ -1589,7 +1591,9 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { if (activeWindow() == _window) { - _keyboardMouseDevice.mousePressEvent(event); + if (deviceID == 0) { + _keyboardMouseDevice.mousePressEvent(event); + } if (event->button() == Qt::LeftButton) { _mouseDragStarted = getTrueMouse(); @@ -1629,7 +1633,9 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { } if (activeWindow() == _window) { - _keyboardMouseDevice.mouseReleaseEvent(event); + if (deviceID == 0) { + _keyboardMouseDevice.mouseReleaseEvent(event); + } if (event->button() == Qt::LeftButton) { _mousePressed = false; From 316c322118ac3be6aaadfb2ed4465d52f5935e85 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 15 Jul 2015 09:36:51 -0700 Subject: [PATCH 03/28] build separate debug and release versions of polyvox library --- cmake/externals/polyvox/CMakeLists.txt | 9 ++++++--- cmake/modules/FindPolyVox.cmake | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index cfaf7ed293..85387856a8 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -48,12 +48,15 @@ endif () if (WIN32) - set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/PolyVoxCore/lib/PolyVoxCore.lib CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_DEBUG ${INSTALL_DIR}/PolyVoxCore/lib/Debug/PolyVoxCore.lib CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_RELEASE ${INSTALL_DIR}/PolyVoxCore/lib/Release/PolyVoxCore.lib CACHE FILEPATH "polyvox core library") # set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/PolyVoxUtil/lib/PolyVoxUtil.lib CACHE FILEPATH "polyvox util library") elseif (APPLE) -set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxCore.dylib CACHE FILEPATH "polyvox core library") +set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_DEBUG ${INSTALL_DIR}/lib/libPolyVoxCore.dylib CACHE FILEPATH "polyvox core library") +set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_RELEASE ${INSTALL_DIR}/lib/libPolyVoxCore.dylib CACHE FILEPATH "polyvox core library") # set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxUtil.dylib CACHE FILEPATH "polyvox util library") else () - set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_DEBUG ${INSTALL_DIR}/lib/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_RELEASE ${INSTALL_DIR}/lib/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") # set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxUtil.so CACHE FILEPATH "polyvox util library") endif () diff --git a/cmake/modules/FindPolyVox.cmake b/cmake/modules/FindPolyVox.cmake index 60a639e87c..18ba9b6671 100644 --- a/cmake/modules/FindPolyVox.cmake +++ b/cmake/modules/FindPolyVox.cmake @@ -24,7 +24,8 @@ hifi_library_search_hints("polyvox") find_path(POLYVOX_CORE_INCLUDE_DIRS PolyVoxCore/SimpleVolume.h PATH_SUFFIXES include include/PolyVoxCore HINTS ${POLYVOX_SEARCH_DIRS}) # find_path(POLYVOX_UTIL_INCLUDE_DIRS PolyVoxUtil/Serialization.h PATH_SUFFIXES include include/PolyVoxUtil HINTS ${POLYVOX_SEARCH_DIRS}) -find_library(POLYVOX_CORE_LIBRARY NAMES PolyVoxCore PATH_SUFFIXES lib HINTS ${POLYVOX_SEARCH_DIRS}) +find_library(POLYVOX_CORE_LIBRARY_DEBUG NAMES PolyVoxCore PATH_SUFFIXES lib/Debug HINTS ${POLYVOX_SEARCH_DIRS}) +find_library(POLYVOX_CORE_LIBRARY_RELEASE NAMES PolyVoxCore PATH_SUFFIXES lib/Release lib HINTS ${POLYVOX_SEARCH_DIRS}) # find_library(POLYVOX_UTIL_LIBRARY NAMES PolyVoxUtil PATH_SUFFIXES lib HINTS ${POLYVOX_SEARCH_DIRS}) From fd84893c612de9496d0f4a9c5ae1984359bbd3b6 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 15 Jul 2015 09:42:26 -0700 Subject: [PATCH 04/28] build separate debug and release versions of polyvox library --- cmake/modules/FindPolyVox.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/modules/FindPolyVox.cmake b/cmake/modules/FindPolyVox.cmake index 18ba9b6671..08e9f1c6a2 100644 --- a/cmake/modules/FindPolyVox.cmake +++ b/cmake/modules/FindPolyVox.cmake @@ -28,6 +28,8 @@ find_library(POLYVOX_CORE_LIBRARY_DEBUG NAMES PolyVoxCore PATH_SUFFIXES lib/Debu find_library(POLYVOX_CORE_LIBRARY_RELEASE NAMES PolyVoxCore PATH_SUFFIXES lib/Release lib HINTS ${POLYVOX_SEARCH_DIRS}) # find_library(POLYVOX_UTIL_LIBRARY NAMES PolyVoxUtil PATH_SUFFIXES lib HINTS ${POLYVOX_SEARCH_DIRS}) +include(SelectLibraryConfigurations) +select_library_configurations(POLYVOX_CORE) # if (WIN32) # find_path(POLYVOX_DLL_PATH polyvox.dll PATH_SUFFIXES bin HINTS ${POLYVOX_SEARCH_DIRS}) From 443cfc8970e642bcfd969b37bec148f23697c75f Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 15 Jul 2015 10:31:21 -0700 Subject: [PATCH 05/28] build separate debug and release versions of polyvox library --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 85387856a8..fcb8e8cf04 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -3,7 +3,7 @@ set(EXTERNAL_NAME polyvox) include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} - URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox.zip + URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-7-15.zip URL_MD5 904b840328278c9b36fa7a14be730c34 CMAKE_ARGS -DENABLE_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build From a71c5cae5fd54d5df39748f72519140639a1a133 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 15 Jul 2015 10:33:22 -0700 Subject: [PATCH 06/28] build separate debug and release versions of polyvox library --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index fcb8e8cf04..9e08a1018e 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-7-15.zip - URL_MD5 904b840328278c9b36fa7a14be730c34 + URL_MD5 d7965dc206e6f9bbdb210a9612f56382 CMAKE_ARGS -DENABLE_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 3bc182730a77487ef567ef25e188049cb8003e34 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 15 Jul 2015 10:52:38 -0700 Subject: [PATCH 07/28] build separate debug and release versions of polyvox library --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 9e08a1018e..3cc26f72bc 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-7-15.zip - URL_MD5 d7965dc206e6f9bbdb210a9612f56382 + URL_MD5 9268bc5dc4141b303521dd67c133f1df CMAKE_ARGS -DENABLE_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From c24c6ad39f2e80f52d3312c26b590be60ae1ea27 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 15 Jul 2015 19:56:01 +0200 Subject: [PATCH 08/28] Fixes chess game (pieces were dieing as soon as you dropped them) --- examples/entityScripts/chessPiece.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/entityScripts/chessPiece.js b/examples/entityScripts/chessPiece.js index b6dfca9efd..24ba7b33e8 100644 --- a/examples/entityScripts/chessPiece.js +++ b/examples/entityScripts/chessPiece.js @@ -130,10 +130,10 @@ var others = Entities.findEntities(this.properties.position, this.properties.dimensions.y); for (var i = 0; i < others.length; i++) { - var piece = others[i]; + var pieceID = others[i]; - if (piece.id != this.entityID) { - var properties = Entities.getEntityProperties(piece); + if (pieceID != this.entityID) { + var properties = Entities.getEntityProperties(pieceID); var isWhite = properties.modelURL.search("White") !== -1; var type = (properties.modelURL.search("King") !== -1) ? 4 : @@ -147,7 +147,7 @@ if (myPos.i === piecePos.i && myPos.j === piecePos.j && type !== -2) { var position = this.getAbsolutePosition((isWhite) ? { i: type, j: -1 } : { i: 7 - type, j: 8 }, properties.dimensions.y / 2.0); - Entities.editEntity(piece, { + Entities.editEntity(pieceID, { position: position }); break; From a444d6a2a26abef25959b2f392ee3e280f03028f Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 15 Jul 2015 13:19:59 -0700 Subject: [PATCH 09/28] remove hungarian notation --- examples/grab.js | 424 ++++++++++++++++++++++++++--------------------- 1 file changed, 235 insertions(+), 189 deletions(-) diff --git a/examples/grab.js b/examples/grab.js index 13c91bebb8..05bcf128e2 100644 --- a/examples/grab.js +++ b/examples/grab.js @@ -10,97 +10,13 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -var MOVE_TIMESCALE = 0.1; -var INV_MOVE_TIMESCALE = 1.0 / MOVE_TIMESCALE; var MAX_SOLID_ANGLE = 0.01; // objects that appear smaller than this can't be grabbed -var CLOSE_ENOUGH = 0.001; -var ZERO_VEC3 = { x: 0, y: 0, z: 0 }; -var ANGULAR_DAMPING_RATE = 0.40; - -// NOTE: to improve readability global variable names start with 'g' -var gIsGrabbing = false; -var gGrabbedEntity = null; -var gActionID = null; -var gEntityProperties; -var gStartPosition; -var gStartRotation; -var gCurrentPosition; -var gOriginalGravity = ZERO_VEC3; -var gPlaneNormal = ZERO_VEC3; - -// gMaxGrabDistance is a function of the size of the object. -var gMaxGrabDistance; - -// gGrabMode defines the degrees of freedom of the grab target positions -// relative to gGrabStartPosition options include: -// xzPlane (default) -// verticalCylinder (SHIFT) -// rotate (CONTROL) -// Modes to eventually support?: -// xyPlane -// yzPlane -// polar -// elevationAzimuth -var gGrabMode = "xzplane"; - -// gGrabOffset allows the user to grab an object off-center. It points from the object's center -// to the point where the ray intersects the grab plane (at the moment the grab is initiated). -// Future target positions of the ray intersection are on the same plane, and the offset is subtracted -// to compute the target position of the object's center. -var gGrabOffset = { x: 0, y: 0, z: 0 }; - -var gTargetPosition; -var gTargetRotation; -var gLiftKey = false; // SHIFT -var gRotateKey = false; // CONTROL - -var gInitialMouse = { x: 0, y: 0 }; -var gPreviousMouse = { x: 0, y: 0 }; -var gMouseCursorLocation = { x: 0, y: 0 }; -var gMouseAtRotateStart = { x: 0, y: 0 }; - -var gBeaconHeight = 0.10; - -// var gAngularVelocity = ZERO_VEC3; - -// TODO: play sounds again when we aren't leaking AudioInjector threads -// var grabSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/CloseClamp.wav"); -// var releaseSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/ReleaseClamp.wav"); -// var VOLUME = 0.0; - -var gBeaconHeight = 0.10; -var BEACON_COLOR = { - red: 200, - green: 200, - blue: 200 -}; -var BEACON_WIDTH = 2; +var ZERO_VEC3 = {x: 0, y: 0, z: 0}; +var IDENTITY_QUAT = {x: 0, y: 0, z: 0, w: 0}; -var gBeacon = Overlays.addOverlay("line3d", { - color: BEACON_COLOR, - alpha: 1, - visible: false, - lineWidth: BEACON_WIDTH -}); - -function updateDropLine(position) { - Overlays.editOverlay(gBeacon, { - visible: true, - start: { - x: position.x, - y: position.y + gBeaconHeight, - z: position.z - }, - end: { - x: position.x, - y: position.y - gBeaconHeight, - z: position.z - } - }); -} - -function mouseIntersectionWithPlane(pointOnPlane, planeNormal, event) { +// helper function +function mouseIntersectionWithPlane(pointOnPlane, planeNormal, event, maxDistance) { var cameraPosition = Camera.getPosition(); var localPointOnPlane = Vec3.subtract(pointOnPlane, cameraPosition); var distanceFromPlane = Vec3.dot(localPointOnPlane, planeNormal); @@ -117,7 +33,7 @@ function mouseIntersectionWithPlane(pointOnPlane, planeNormal, event) { var useMaxForwardGrab = false; if (Math.abs(dirDotNorm) > MIN_RAY_PLANE_DOT) { var distanceToIntersection = distanceFromPlane / dirDotNorm; - if (distanceToIntersection > 0 && distanceToIntersection < gMaxGrabDistance) { + if (distanceToIntersection > 0 && distanceToIntersection < maxDistance) { // ray points into the plane localIntersection = Vec3.multiply(pickRay.direction, distanceFromPlane / dirDotNorm); } else { @@ -134,52 +50,160 @@ function mouseIntersectionWithPlane(pointOnPlane, planeNormal, event) { // we re-route the intersection to be in front at max distance. var rayDirection = Vec3.subtract(pickRay.direction, Vec3.multiply(planeNormal, dirDotNorm)); rayDirection = Vec3.normalize(rayDirection); - localIntersection = Vec3.multiply(rayDirection, gMaxGrabDistance); + localIntersection = Vec3.multiply(rayDirection, maxDistance); localIntersection = Vec3.sum(localIntersection, Vec3.multiply(planeNormal, distanceFromPlane)); } var worldIntersection = Vec3.sum(cameraPosition, localIntersection); return worldIntersection; } -function computeNewGrabPlane() { - if (!gIsGrabbing) { +// Mouse class stores mouse click and drag info +Mouse = function() { + this.current = {x: 0, y: 0 }; + this.previous = {x: 0, y: 0 }; + this.rotateStart = {x: 0, y: 0 }; + this.cursorRestore = {x: 0, y: 0}; +} + +Mouse.prototype.startDrag = function(position) { + this.current = {x: position.x, y: position.y}; + this.startRotateDrag(); +} + +Mouse.prototype.updateDrag = function(position) { + this.current = {x: position.x, y: position.y }; +} + +Mouse.prototype.startRotateDrag = function() { + this.previous = {x: this.current.x, y: this.current.y}; + this.rotateStart = {x: this.current.x, y: this.current.y}; + this.cursorRestore = { x: Window.getCursorPositionX(), y: Window.getCursorPositionY() }; +} + +Mouse.prototype.getDrag = function() { + var delta = {x: this.current.x - this.previous.x, y: this.current.y - this.previous.y}; + this.previous = {x: this.current.x, y: this.current.y}; + return delta; +} + +Mouse.prototype.restoreRotateCursor = function() { + Window.setCursorPosition(this.cursorRestore.x, this.cursorRestore.y); + this.current = {x: this.rotateStart.x, y: this.rotateStart.y}; +} + +var mouse = new Mouse(); + + +// Beacon class stores info for drawing a line at object's target position +Beacon = function() { + this.height = 0.10; + this.overlayID = Overlays.addOverlay("line3d", { + color: {red: 200, green: 200, blue: 200}, + alpha: 1, + visible: false, + lineWidth: 2 + }); +} + +Beacon.prototype.enable = function() { + Overlays.editOverlay(this.overlayID, { visible: true }); +} + +Beacon.prototype.disable = function() { + Overlays.editOverlay(this.overlayID, { visible: false }); +} + +Beacon.prototype.updatePosition = function(position) { + Overlays.editOverlay(this.overlayID, { + visible: true, + start: { + x: position.x, + y: position.y + this.height, + z: position.z + }, + end: { + x: position.x, + y: position.y - this.height, + z: position.z + } + }); +} + +var beacon = new Beacon(); + + +// TODO: play sounds again when we aren't leaking AudioInjector threads +// var grabSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/CloseClamp.wav"); +// var releaseSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/ReleaseClamp.wav"); +// var VOLUME = 0.0; + + +// Grabber class stores and computes info for grab behavior +Grabber = function() { + this.isGrabbing = false; + this.entityID = null; + this.actionID = null; + this.startPosition = ZERO_VEC3; + this.lastRotation = IDENTITY_QUAT; + this.currentPosition = ZERO_VEC3; + this.planeNormal = ZERO_VEC3; + + this.originalGravity = ZERO_VEC3; + // maxDistance is a function of the size of the object. + this.maxDistance; + + // mode defines the degrees of freedom of the grab target positions + // relative to startPosition options include: + // xzPlane (default) + // verticalCylinder (SHIFT) + // rotate (CONTROL) + this.mode = "xzplane"; + + // offset allows the user to grab an object off-center. It points from the object's center + // to the point where the ray intersects the grab plane (at the moment the grab is initiated). + // Future target positions of the ray intersection are on the same plane, and the offset is subtracted + // to compute the target position of the object's center. + this.offset = {x: 0, y: 0, z: 0 }; + + this.targetPosition; + this.targetRotation; + + this.liftKey = false; // SHIFT + this.rotateKey = false; // CONTROL +} + +Grabber.prototype.computeNewGrabPlane = function() { + if (!this.isGrabbing) { return; } - var maybeResetMousePosition = false; - if (gGrabMode !== "rotate") { - gMouseAtRotateStart = gMouseCursorLocation; + var modeWasRotate = (this.mode == "rotate"); + this.mode = "xzPlane"; + this.planeNormal = {x: 0, y: 1, z: 0 }; + if (this.rotateKey) { + this.mode = "rotate"; + mouse.startRotateDrag(); } else { - maybeResetMousePosition = true; - } - gGrabMode = "xzPlane"; - gPlaneNormal = { x: 0, y: 1, z: 0 }; - if (gLiftKey) { - if (!gRotateKey) { - gGrabMode = "verticalCylinder"; - // a new planeNormal will be computed each move + if (modeWasRotate) { + // we reset the mouse screen position whenever we stop rotating + mouse.restoreRotateCursor(); } - } else if (gRotateKey) { - gGrabMode = "rotate"; - } + if (this.liftKey) { + this.mode = "verticalCylinder"; + // NOTE: during verticalCylinder mode a new planeNormal will be computed each move + } + } - gPointOnPlane = Vec3.sum(gCurrentPosition, gGrabOffset); - var xzOffset = Vec3.subtract(gPointOnPlane, Camera.getPosition()); + this.pointOnPlane = Vec3.sum(this.currentPosition, this.offset); + var xzOffset = Vec3.subtract(this.pointOnPlane, Camera.getPosition()); xzOffset.y = 0; - gXzDistanceToGrab = Vec3.length(xzOffset); - - if (gGrabMode !== "rotate" && maybeResetMousePosition) { - // we reset the mouse position whenever we stop rotating - Window.setCursorPosition(gMouseAtRotateStart.x, gMouseAtRotateStart.y); - } + this.xzDistanceToGrab = Vec3.length(xzOffset); } -function mousePressEvent(event) { +Grabber.prototype.pressEvent = function(event) { if (!event.isLeftButton) { return; } - gInitialMouse = {x: event.x, y: event.y }; - gPreviousMouse = {x: event.x, y: event.y }; var pickRay = Camera.computePickRay(event.x, event.y); var pickResults = Entities.findRayIntersection(pickRay, true); // accurate picking @@ -193,150 +217,172 @@ function mousePressEvent(event) { return; } + mouse.startDrag(event); + var clickedEntity = pickResults.entityID; var entityProperties = Entities.getEntityProperties(clickedEntity) - gStartPosition = entityProperties.position; - gStartRotation = entityProperties.rotation; + this.startPosition = entityProperties.position; + this.lastRotation = entityProperties.rotation; var cameraPosition = Camera.getPosition(); - gBeaconHeight = Vec3.length(entityProperties.dimensions); - gMaxGrabDistance = gBeaconHeight / MAX_SOLID_ANGLE; - if (Vec3.distance(gStartPosition, cameraPosition) > gMaxGrabDistance) { + var objectBoundingDiameter = Vec3.length(entityProperties.dimensions); + beacon.height = objectBoundingDiameter; + this.maxDistance = objectBoundingDiameter / MAX_SOLID_ANGLE; + if (Vec3.distance(this.startPosition, cameraPosition) > this.maxDistance) { // don't allow grabs of things far away return; } Entities.editEntity(clickedEntity, { gravity: ZERO_VEC3 }); - gIsGrabbing = true; + this.isGrabbing = true; - gGrabbedEntity = clickedEntity; - gCurrentPosition = entityProperties.position; - gOriginalGravity = entityProperties.gravity; - gTargetPosition = gStartPosition; + this.entityID = clickedEntity; + this.currentPosition = entityProperties.position; + this.originalGravity = entityProperties.gravity; + this.targetPosition = {x: this.startPosition.x, y: this.startPosition.y, z: this.startPosition.z}; // compute the grab point - var nearestPoint = Vec3.subtract(gStartPosition, cameraPosition); + var nearestPoint = Vec3.subtract(this.startPosition, cameraPosition); var distanceToGrab = Vec3.dot(nearestPoint, pickRay.direction); nearestPoint = Vec3.multiply(distanceToGrab, pickRay.direction); - gPointOnPlane = Vec3.sum(cameraPosition, nearestPoint); + this.pointOnPlane = Vec3.sum(cameraPosition, nearestPoint); // compute the grab offset (points from object center to point of grab) - gGrabOffset = Vec3.subtract(gPointOnPlane, gStartPosition); + this.offset = Vec3.subtract(this.pointOnPlane, this.startPosition); - computeNewGrabPlane(); + this.computeNewGrabPlane(); - updateDropLine(gStartPosition); + beacon.updatePosition(this.startPosition); // TODO: play sounds again when we aren't leaking AudioInjector threads //Audio.playSound(grabSound, { position: entityProperties.position, volume: VOLUME }); } -function mouseReleaseEvent() { - if (gIsGrabbing) { - if (Vec3.length(gOriginalGravity) != 0) { - Entities.editEntity(gGrabbedEntity, { gravity: gOriginalGravity }); +Grabber.prototype.releaseEvent = function() { + if (this.isGrabbing) { + if (Vec3.length(this.originalGravity) != 0) { + Entities.editEntity(this.entityID, { gravity: this.originalGravity}); } - gIsGrabbing = false - Entities.deleteAction(gGrabbedEntity, gActionID); - gActionID = null; + this.isGrabbing = false + Entities.deleteAction(this.entityID, this.actionID); + this.actionID = null; - Overlays.editOverlay(gBeacon, { visible: false }); + beacon.disable(); // TODO: play sounds again when we aren't leaking AudioInjector threads //Audio.playSound(releaseSound, { position: entityProperties.position, volume: VOLUME }); } } -function mouseMoveEvent(event) { - if (!gIsGrabbing) { +Grabber.prototype.moveEvent = function(event) { + if (!this.isGrabbing) { return; } + mouse.updateDrag(event); // see if something added/restored gravity - var entityProperties = Entities.getEntityProperties(gGrabbedEntity); + var entityProperties = Entities.getEntityProperties(this.entityID); if (Vec3.length(entityProperties.gravity) != 0) { - gOriginalGravity = entityProperties.gravity; + this.originalGravity = entityProperties.gravity; } - gCurrentPosition = entityProperties.position; + this.currentPosition = entityProperties.position; var actionArgs = {}; - if (gGrabMode === "rotate") { - var deltaMouse = { x: 0, y: 0 }; - var dx = event.x - gInitialMouse.x; - var dy = event.y - gInitialMouse.y; + if (this.mode === "rotate") { + var drag = mouse.getDrag(); var orientation = Camera.getOrientation(); - var dragOffset = Vec3.multiply(dx, Quat.getRight(orientation)); - dragOffset = Vec3.sum(dragOffset, Vec3.multiply(-dy, Quat.getUp(orientation))); + var dragOffset = Vec3.multiply(drag.x, Quat.getRight(orientation)); + dragOffset = Vec3.sum(dragOffset, Vec3.multiply(-drag.y, Quat.getUp(orientation))); var axis = Vec3.cross(dragOffset, Quat.getFront(orientation)); axis = Vec3.normalize(axis); var ROTATE_STRENGTH = 0.4; // magic number tuned by hand - var angle = ROTATE_STRENGTH * Math.sqrt((dx * dx) + (dy * dy)); + var angle = ROTATE_STRENGTH * Math.sqrt((drag.x * drag.x) + (drag.y * drag.y)); var deltaQ = Quat.angleAxis(angle, axis); // var qZero = entityProperties.rotation; - var qZero = gStartRotation; - var qOne = Quat.multiply(deltaQ, qZero); - actionArgs = {targetRotation: qOne, angularTimeScale: 0.1}; + //var qZero = this.lastRotation; + this.lastRotation = Quat.multiply(deltaQ, this.lastRotation); + actionArgs = {targetRotation: this.lastRotation, angularTimeScale: 0.1}; } else { - var newTargetPosition; - if (gGrabMode === "verticalCylinder") { + var newPointOnPlane; + if (this.mode === "verticalCylinder") { // for this mode we recompute the plane based on current Camera var planeNormal = Quat.getFront(Camera.getOrientation()); planeNormal.y = 0; planeNormal = Vec3.normalize(planeNormal); - var pointOnCylinder = Vec3.multiply(planeNormal, gXzDistanceToGrab); + var pointOnCylinder = Vec3.multiply(planeNormal, this.xzDistanceToGrab); pointOnCylinder = Vec3.sum(Camera.getPosition(), pointOnCylinder); - newTargetPosition = mouseIntersectionWithPlane(pointOnCylinder, planeNormal, event); - gPointOnPlane = Vec3.sum(newTargetPosition, gGrabOffset); + this.pointOnPlane = mouseIntersectionWithPlane(pointOnCylinder, planeNormal, mouse.current, this.maxDistance); + newPointOnPlane = {x: this.pointOnPlane.x, y: this.pointOnPlane.y, z: this.pointOnPlane.z}; } else { var cameraPosition = Camera.getPosition(); - newTargetPosition = mouseIntersectionWithPlane(gPointOnPlane, gPlaneNormal, event); - var relativePosition = Vec3.subtract(newTargetPosition, cameraPosition); + newPointOnPlane = mouseIntersectionWithPlane(this.pointOnPlane, this.planeNormal, mouse.current, this.maxDistance); + var relativePosition = Vec3.subtract(newPointOnPlane, cameraPosition); var distance = Vec3.length(relativePosition); - if (distance > gMaxGrabDistance) { + if (distance > this.maxDistance) { // clamp distance - relativePosition = Vec3.multiply(relativePosition, gMaxGrabDistance / distance); - newTargetPosition = Vec3.sum(relativePosition, cameraPosition); + relativePosition = Vec3.multiply(relativePosition, this.maxDistance / distance); + newPointOnPlane = Vec3.sum(relativePosition, cameraPosition); } } - gTargetPosition = Vec3.subtract(newTargetPosition, gGrabOffset); - actionArgs = {targetPosition: gTargetPosition, linearTimeScale: 0.1}; - } - gPreviousMouse = { x: event.x, y: event.y }; - gMouseCursorLocation = { x: Window.getCursorPositionX(), y: Window.getCursorPositionY() }; + this.targetPosition = Vec3.subtract(newPointOnPlane, this.offset); + actionArgs = {targetPosition: this.targetPosition, linearTimeScale: 0.1}; - if (!gActionID) { - gActionID = Entities.addAction("spring", gGrabbedEntity, actionArgs); + beacon.updatePosition(this.targetPosition); + } + + if (!this.actionID) { + this.actionID = Entities.addAction("spring", this.entityID, actionArgs); } else { - Entities.updateAction(gGrabbedEntity, gActionID, actionArgs); + Entities.updateAction(this.entityID, this.actionID, actionArgs); } - - updateDropLine(gTargetPosition); } -function keyReleaseEvent(event) { +Grabber.prototype.keyReleaseEvent = function(event) { if (event.text === "SHIFT") { - gLiftKey = false; + this.liftKey = false; } if (event.text === "CONTROL") { - gRotateKey = false; + this.rotateKey = false; } - computeNewGrabPlane(); + this.computeNewGrabPlane(); +} + +Grabber.prototype.keyPressEvent = function(event) { + if (event.text === "SHIFT") { + this.liftKey = true; + } + if (event.text === "CONTROL") { + this.rotateKey = true; + } + this.computeNewGrabPlane(); +} + +var grabber = new Grabber(); + +function pressEvent(event) { + grabber.pressEvent(event); +} + +function moveEvent(event) { + grabber.moveEvent(event); +} + +function releaseEvent(event) { + grabber.releaseEvent(event); } function keyPressEvent(event) { - if (event.text === "SHIFT") { - gLiftKey = true; - } - if (event.text === "CONTROL") { - gRotateKey = true; - } - computeNewGrabPlane(); + grabber.keyPressEvent(event); } -Controller.mouseMoveEvent.connect(mouseMoveEvent); -Controller.mousePressEvent.connect(mousePressEvent); -Controller.mouseReleaseEvent.connect(mouseReleaseEvent); +function keyReleaseEvent(event) { + grabber.keyReleaseEvent(event); +} + +Controller.mousePressEvent.connect(pressEvent); +Controller.mouseMoveEvent.connect(moveEvent); +Controller.mouseReleaseEvent.connect(releaseEvent); Controller.keyPressEvent.connect(keyPressEvent); Controller.keyReleaseEvent.connect(keyReleaseEvent); From f1c10f511915a0c45c52d703f2d27509f014fd67 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 15 Jul 2015 13:38:12 -0700 Subject: [PATCH 10/28] build separate debug and release versions of polyvox library --- cmake/externals/polyvox/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 3cc26f72bc..7b67bb93b5 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -4,7 +4,7 @@ include(ExternalProject) ExternalProject_Add( ${EXTERNAL_NAME} URL http://hifi-public.s3.amazonaws.com/dependencies/polyvox-master-2015-7-15.zip - URL_MD5 9268bc5dc4141b303521dd67c133f1df + URL_MD5 9ec6323b87e849ae36e562ae1c7494a9 CMAKE_ARGS -DENABLE_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH= BINARY_DIR ${EXTERNAL_PROJECT_PREFIX}/build LOG_DOWNLOAD 1 From 930e570b48f55a04d7c450b6783d9250f50a1d8a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 15 Jul 2015 13:54:57 -0700 Subject: [PATCH 11/28] build separate debug and release versions of polyvox library --- cmake/externals/polyvox/CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 7b67bb93b5..5840eaf624 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -52,11 +52,11 @@ if (WIN32) set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_RELEASE ${INSTALL_DIR}/PolyVoxCore/lib/Release/PolyVoxCore.lib CACHE FILEPATH "polyvox core library") # set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/PolyVoxUtil/lib/PolyVoxUtil.lib CACHE FILEPATH "polyvox util library") elseif (APPLE) -set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_DEBUG ${INSTALL_DIR}/lib/libPolyVoxCore.dylib CACHE FILEPATH "polyvox core library") -set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_RELEASE ${INSTALL_DIR}/lib/libPolyVoxCore.dylib CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_DEBUG ${INSTALL_DIR}/lib/Debug/libPolyVoxCore.dylib CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_RELEASE ${INSTALL_DIR}/lib/Release/libPolyVoxCore.dylib CACHE FILEPATH "polyvox core library") # set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxUtil.dylib CACHE FILEPATH "polyvox util library") else () - set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_DEBUG ${INSTALL_DIR}/lib/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") - set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_RELEASE ${INSTALL_DIR}/lib/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_DEBUG ${INSTALL_DIR}/lib/Debug/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") + set(${EXTERNAL_NAME_UPPER}_CORE_LIBRARY_RELEASE ${INSTALL_DIR}/lib/Release/libPolyVoxCore.so CACHE FILEPATH "polyvox core library") # set(${EXTERNAL_NAME_UPPER}_UTIL_LIBRARY ${INSTALL_DIR}/lib/libPolyVoxUtil.so CACHE FILEPATH "polyvox util library") endif () From 4db66e7894532b242439ce46af950a41e46e2a35 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 15 Jul 2015 14:38:44 -0700 Subject: [PATCH 12/28] build separate debug and release versions of polyvox library --- cmake/externals/polyvox/CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmake/externals/polyvox/CMakeLists.txt b/cmake/externals/polyvox/CMakeLists.txt index 5840eaf624..4563bf5918 100644 --- a/cmake/externals/polyvox/CMakeLists.txt +++ b/cmake/externals/polyvox/CMakeLists.txt @@ -24,7 +24,16 @@ if (APPLE) ${EXTERNAL_NAME} change-install-name COMMENT "Calling install_name_tool on libraries to fix install name for dylib linking" - COMMAND ${CMAKE_COMMAND} -DINSTALL_NAME_LIBRARY_DIR=${INSTALL_NAME_LIBRARY_DIR} -P ${EXTERNAL_PROJECT_DIR}/OSXInstallNameChange.cmake + COMMAND ${CMAKE_COMMAND} -DINSTALL_NAME_LIBRARY_DIR=${INSTALL_NAME_LIBRARY_DIR}/Debug -P ${EXTERNAL_PROJECT_DIR}/OSXInstallNameChange.cmake + DEPENDEES install + WORKING_DIRECTORY + LOG 1 + ) + ExternalProject_Add_Step( + ${EXTERNAL_NAME} + change-install-name + COMMENT "Calling install_name_tool on libraries to fix install name for dylib linking" + COMMAND ${CMAKE_COMMAND} -DINSTALL_NAME_LIBRARY_DIR=${INSTALL_NAME_LIBRARY_DIR}/Release -P ${EXTERNAL_PROJECT_DIR}/OSXInstallNameChange.cmake DEPENDEES install WORKING_DIRECTORY LOG 1 From 2ad2c4d55441ae0cce701bf669de634c7fbb0a00 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 15:32:02 -0700 Subject: [PATCH 13/28] remove some dead code --- interface/src/ui/ApplicationCompositor.cpp | 1 - libraries/render-utils/src/GeometryCache.cpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/interface/src/ui/ApplicationCompositor.cpp b/interface/src/ui/ApplicationCompositor.cpp index 8565371a9b..4623109cdd 100644 --- a/interface/src/ui/ApplicationCompositor.cpp +++ b/interface/src/ui/ApplicationCompositor.cpp @@ -197,7 +197,6 @@ void ApplicationCompositor::displayOverlayTexture(RenderArgs* renderArgs) { updateTooltips(); auto deviceSize = qApp->getDeviceSize(); - glViewport(0, 0, deviceSize.width(), deviceSize.height()); //Handle fading and deactivation/activation of UI gpu::Batch batch; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 7cb882acc1..2bf41bc9b3 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -433,8 +433,6 @@ void GeometryCache::renderGrid(gpu::Batch& batch, int x, int y, int width, int h } // Draw vertical grid lines for (int i = cols + 1; --i >= 0; ) { - //glVertex2i(tx, y); - //glVertex2i(tx, y + height); *(vertex++) = tx; *(vertex++) = y; From d1e511efcb073fe6d72759b4ac928d06b2bb1847 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 15:52:12 -0700 Subject: [PATCH 14/28] more naked gl cleanup, deleting dead code, tweaking comments so they don't give false positives in searching for more naked gl --- interface/src/ui/overlays/Cube3DOverlay.cpp | 2 -- libraries/gpu/src/gpu/Batch.h | 4 ++-- libraries/gpu/src/gpu/Shader.h | 2 +- libraries/render-utils/src/TextRenderer.cpp | 3 --- libraries/render-utils/src/TextureCache.cpp | 10 ---------- libraries/shared/src/Transform.h | 8 ++++---- 6 files changed, 7 insertions(+), 22 deletions(-) diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 3455ce2e51..7f6fd5f971 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -33,8 +33,6 @@ void Cube3DOverlay::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; glm::vec4 cubeColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); - //glDisable(GL_LIGHTING); - // TODO: handle registration point?? glm::vec3 position = getPosition(); glm::vec3 center = getCenter(); diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index bf6883e3a9..244ede7151 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -86,7 +86,7 @@ public: // Then by the inverse of the ViewTransform from world space to eye space // finaly projected into the clip space by the projection transform // WARNING: ViewTransform transform from eye space to world space, its inverse is composed - // with the ModelTransformu to create the equivalent of the glModelViewMatrix + // with the ModelTransform to create the equivalent of the gl ModelViewMatrix void setModelTransform(const Transform& model); void setViewTransform(const Transform& view); void setProjectionTransform(const Mat4& proj); @@ -114,7 +114,7 @@ public: // TODO: As long as we have gl calls explicitely issued from interface // code, we need to be able to record and batch these calls. THe long // term strategy is to get rid of any GL calls in favor of the HIFI GPU API - // For now, instead of calling the raw glCall, use the equivalent call on the batch so the call is beeing recorded + // For now, instead of calling the raw gl Call, use the equivalent call on the batch so the call is beeing recorded // THe implementation of these functions is in GLBackend.cpp void _glEnable(GLenum cap); diff --git a/libraries/gpu/src/gpu/Shader.h b/libraries/gpu/src/gpu/Shader.h index 9193ddb778..9c3953bff5 100755 --- a/libraries/gpu/src/gpu/Shader.h +++ b/libraries/gpu/src/gpu/Shader.h @@ -148,7 +148,7 @@ public: // // As of now (03/2015), the call to makeProgram is in fact calling gpu::Context::makeProgram and does rely // on the underneath gpu::Context::Backend available. Since we only support glsl, this means that it relies - // on a glContext and the driver to compile the glsl shader. + // on a gl Context and the driver to compile the glsl shader. // Hoppefully in a few years the shader compilation will be completely abstracted in a separate shader compiler library // independant of the graphics api in use underneath (looking at you opengl & vulkan). static bool makeProgram(Shader& shader, const Shader::BindingSet& bindings = Shader::BindingSet()); diff --git a/libraries/render-utils/src/TextRenderer.cpp b/libraries/render-utils/src/TextRenderer.cpp index fcd7bf2f2a..61a7ce78cf 100644 --- a/libraries/render-utils/src/TextRenderer.cpp +++ b/libraries/render-utils/src/TextRenderer.cpp @@ -504,9 +504,6 @@ glm::vec2 Font::drawString(float x, float y, const QString & str, _vao->release(); _texture->release(); // TODO: Brad & Sam, let's discuss this. Without this non-textured quads get their colors borked. _program->release(); - // FIXME, needed? - // glDisable(GL_TEXTURE_2D); - return advance; } diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 4df9718e24..953cfda910 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -110,9 +110,6 @@ const gpu::TexturePointer& TextureCache::getPermutationNormalTexture() { _permutationNormalTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC3, gpu::UINT8, gpu::RGB), 256, 2)); _permutationNormalTexture->assignStoredMip(0, _blueTexture->getTexelFormat(), sizeof(data), data); - - // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } return _permutationNormalTexture; } @@ -122,13 +119,6 @@ const unsigned char OPAQUE_GRAY[] = { 0x80, 0x80, 0x80, 0xFF }; const unsigned char OPAQUE_BLUE[] = { 0x80, 0x80, 0xFF, 0xFF }; const unsigned char OPAQUE_BLACK[] = { 0x00, 0x00, 0x00, 0xFF }; -/* -static void loadSingleColorTexture(const unsigned char* color) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, color); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); -} -*/ - const gpu::TexturePointer& TextureCache::getWhiteTexture() { if (!_whiteTexture) { _whiteTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA), 1, 1)); diff --git a/libraries/shared/src/Transform.h b/libraries/shared/src/Transform.h index 6f841151c4..09cb3ba65b 100644 --- a/libraries/shared/src/Transform.h +++ b/libraries/shared/src/Transform.h @@ -87,20 +87,20 @@ public: const Vec3& getTranslation() const; void setTranslation(const Vec3& translation); // [new this] = [translation] * [this.rotation] * [this.scale] void preTranslate(const Vec3& translation); // [new this] = [translation] * [this] - void postTranslate(const Vec3& translation); // [new this] = [this] * [translation] equivalent to glTranslate + void postTranslate(const Vec3& translation); // [new this] = [this] * [translation] equivalent to gl Translate const Quat& getRotation() const; void setRotation(const Quat& rotation); // [new this] = [this.translation] * [rotation] * [this.scale] void preRotate(const Quat& rotation); // [new this] = [rotation] * [this] - void postRotate(const Quat& rotation); // [new this] = [this] * [rotation] equivalent to glRotate + void postRotate(const Quat& rotation); // [new this] = [this] * [rotation] equivalent to gl Rotate const Vec3& getScale() const; void setScale(float scale); void setScale(const Vec3& scale); // [new this] = [this.translation] * [this.rotation] * [scale] void preScale(float scale); void preScale(const Vec3& scale); - void postScale(float scale); // [new this] = [this] * [scale] equivalent to glScale - void postScale(const Vec3& scale); // [new this] = [this] * [scale] equivalent to glScale + void postScale(float scale); // [new this] = [this] * [scale] equivalent to gl Scale + void postScale(const Vec3& scale); // [new this] = [this] * [scale] equivalent to gl Scale bool isIdentity() const { return (_flags & ~Flags(FLAG_CACHE_INVALID_BITSET)).none(); } bool isTranslating() const { return _flags[FLAG_TRANSLATION]; } From 7795eaace630d4e1de99092c57ef0bfc207469ab Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 15:56:27 -0700 Subject: [PATCH 15/28] remove more naked gl --- interface/src/avatar/SkeletonModel.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 2d4baaf237..05b1500b8b 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -791,19 +791,24 @@ void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha transform.setTranslation(endPoint); batch.setModelTransform(transform); auto geometryCache = DependencyManager::get(); - geometryCache->renderSphere(batch, _boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.6f, 0.6f, 0.8f, alpha)); + geometryCache->renderSphere(batch, _boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, + glm::vec4(0.6f, 0.6f, 0.8f, alpha)); // draw a yellow sphere at the capsule startpoint glm::vec3 startPoint; _boundingShape.getStartPoint(startPoint); startPoint = startPoint - _translation; glm::vec3 axis = endPoint - startPoint; - glTranslatef(-axis.x, -axis.y, -axis.z); - geometryCache->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.8f, 0.8f, 0.6f, alpha)); + Transform axisTransform = Transform(); + axisTransform.setTranslation(-axis); + batch.setModelTransform(axisTransform); + geometryCache->renderSphere(batch, _boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, + glm::vec4(0.8f, 0.8f, 0.6f, alpha)); // draw a green cylinder between the two points glm::vec3 origin(0.0f); - Avatar::renderJointConnectingCone(batch, origin, axis, _boundingShape.getRadius(), _boundingShape.getRadius(), glm::vec4(0.6f, 0.8f, 0.6f, alpha)); + Avatar::renderJointConnectingCone(batch, origin, axis, _boundingShape.getRadius(), _boundingShape.getRadius(), + glm::vec4(0.6f, 0.8f, 0.6f, alpha)); } bool SkeletonModel::hasSkeleton() { From 9657d146f7b04c9f7ccd35564d5ecd1455e0f836 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 15 Jul 2015 16:09:53 -0700 Subject: [PATCH 16/28] Clearing Model.cpp from naked gl call references --- libraries/render-utils/src/Model.cpp | 32 ++++++---------------------- libraries/render-utils/src/Model.h | 1 - 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 6385041959..07df7fbda4 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -55,10 +55,6 @@ #include "model_lightmap_specular_map_frag.h" #include "model_translucent_frag.h" - -#define GLBATCH( call ) batch._##call -//#define GLBATCH( call ) call - using namespace std; static int modelPointerTypeId = qRegisterMetaType >(); @@ -1850,22 +1846,6 @@ void Model::deleteGeometry() { _blendedBlendshapeCoefficients.clear(); } -void Model::setupBatchTransform(gpu::Batch& batch, RenderArgs* args) { - - // Capture the view matrix once for the rendering of this model - if (_transforms.empty()) { - _transforms.push_back(Transform()); - } - - // We should be able to use the Frustum viewpoint onstead of the "viewTransform" - // but it s still buggy in some cases, so let's s wait and fix it... - _transforms[0] = _viewState->getViewTransform(); - - _transforms[0].preTranslate(-_translation); - - batch.setViewTransform(_transforms[0]); -} - AABox Model::getPartBounds(int meshIndex, int partIndex) { if (meshIndex < _meshStates.size()) { @@ -2000,7 +1980,7 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran } if (isSkinned) { - GLBATCH(glUniformMatrix4fv)(locations->clusterMatrices, state.clusterMatrices.size(), false, + batch._glUniformMatrix4fv(locations->clusterMatrices, state.clusterMatrices.size(), false, (const float*)state.clusterMatrices.constData()); _transforms[0] = Transform(); _transforms[0].preTranslate(_translation); @@ -2021,7 +2001,7 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran } if (mesh.colors.isEmpty()) { - GLBATCH(glColor4f)(1.0f, 1.0f, 1.0f, 1.0f); + batch._glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } // guard against partially loaded meshes @@ -2077,7 +2057,7 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran if (!part.emissiveTexture.transform.isIdentity()) { part.emissiveTexture.transform.getMatrix(texcoordTransform[1]); } - GLBATCH(glUniformMatrix4fv)(locations->texcoordMatrices, 2, false, (const float*) &texcoordTransform); + batch._glUniformMatrix4fv(locations->texcoordMatrices, 2, false, (const float*) &texcoordTransform); } if (!mesh.tangents.isEmpty()) { @@ -2102,7 +2082,7 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran // assert(locations->emissiveParams >= 0); // we should have the emissiveParams defined in the shader float emissiveOffset = part.emissiveParams.x; float emissiveScale = part.emissiveParams.y; - GLBATCH(glUniform2f)(locations->emissiveParams, emissiveOffset, emissiveScale); + batch._glUniform2f(locations->emissiveParams, emissiveOffset, emissiveScale); NetworkTexture* emissiveMap = networkPart.emissiveTexture.data(); batch.setResourceTexture(locations->emissiveTextureUnit, (!emissiveMap || !emissiveMap->isLoaded()) ? @@ -2210,12 +2190,12 @@ void Model::pickPrograms(gpu::Batch& batch, RenderMode mode, bool translucent, f batch.setPipeline((*pipeline).second._pipeline); if ((locations->alphaThreshold > -1) && (mode != RenderArgs::SHADOW_RENDER_MODE)) { - GLBATCH(glUniform1f)(locations->alphaThreshold, alphaThreshold); + batch._glUniform1f(locations->alphaThreshold, alphaThreshold); } if ((locations->glowIntensity > -1) && (mode != RenderArgs::SHADOW_RENDER_MODE)) { const float DEFAULT_GLOW_INTENSITY = 1.0f; // FIXME - glow is removed - GLBATCH(glUniform1f)(locations->glowIntensity, DEFAULT_GLOW_INTENSITY); + batch._glUniform1f(locations->glowIntensity, DEFAULT_GLOW_INTENSITY); } } diff --git a/libraries/render-utils/src/Model.h b/libraries/render-utils/src/Model.h index b2d5ba7e4a..b3a62b8da7 100644 --- a/libraries/render-utils/src/Model.h +++ b/libraries/render-utils/src/Model.h @@ -407,7 +407,6 @@ private: // helper functions used by render() or renderInScene() - void setupBatchTransform(gpu::Batch& batch, RenderArgs* args); static void pickPrograms(gpu::Batch& batch, RenderArgs::RenderMode mode, bool translucent, float alphaThreshold, bool hasLightmap, bool hasTangents, bool hasSpecular, bool isSkinned, bool isWireframe, RenderArgs* args, Locations*& locations); From d5a6e87a029c2ce9c2d621b0b9e0e96b89a4a86f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 16:34:23 -0700 Subject: [PATCH 17/28] remove naked gl from Avatar::calculateDisplayNameTransform() --- interface/src/avatar/Avatar.cpp | 15 +++++---------- interface/src/avatar/Avatar.h | 4 ++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index d0268fd936..6374b6b10b 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -523,7 +523,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo auto cameraMode = Application::getInstance()->getCamera()->getMode(); if (!isMyAvatar() || cameraMode != CAMERA_MODE_FIRST_PERSON) { - renderDisplayName(batch, *renderArgs->_viewFrustum); + renderDisplayName(batch, *renderArgs->_viewFrustum, renderArgs->_viewport); } } @@ -674,7 +674,7 @@ glm::vec3 Avatar::getDisplayNamePosition() const { return namePosition; } -Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, float fontSize) const { +Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, float fontSize, const glm::ivec4& viewport) const { Transform result; // We assume textPosition is whithin the frustum glm::vec3 textPosition = getDisplayNamePosition(); @@ -693,12 +693,7 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa glm::vec4 p0 = viewProj * glm::vec4(testPoint0, 1.0); glm::vec4 p1 = viewProj * glm::vec4(testPoint1, 1.0); - // TODO REMOVE vvv - GLint viewportMatrix[4]; - glGetIntegerv(GL_VIEWPORT, viewportMatrix); - glm::dmat4 modelViewMatrix; - float windowSizeY = viewportMatrix[3] - viewportMatrix[1]; - // TODO REMOVE ^^^ + float windowSizeY = viewport.w; const float DESIRED_HIGHT_ON_SCREEN = 20; // In pixels (this is double on retinas) @@ -731,7 +726,7 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa } -void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum) const { +void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum, const glm::ivec4& viewport) const { bool shouldShowReceiveStats = DependencyManager::get()->shouldShowReceiveStats() && !isMyAvatar(); // If we have nothing to draw, or it's tottaly transparent, return @@ -773,7 +768,7 @@ void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum) co (_displayNameAlpha / DISPLAYNAME_ALPHA) * DISPLAYNAME_BACKGROUND_ALPHA); // Compute display name transform - auto textTransform = calculateDisplayNameTransform(frustum, renderer->getFontSize()); + auto textTransform = calculateDisplayNameTransform(frustum, renderer->getFontSize(), viewport); batch.setModelTransform(textTransform); DependencyManager::get()->bindSimpleProgram(batch, false, true, true, true); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index b23059acb0..b67caa1641 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -234,8 +234,8 @@ protected: float getPelvisFloatingHeight() const; glm::vec3 getDisplayNamePosition() const; - Transform calculateDisplayNameTransform(const ViewFrustum& frustum, float fontSize) const; - void renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum) const; + Transform calculateDisplayNameTransform(const ViewFrustum& frustum, float fontSize, const glm::ivec4& viewport) const; + void renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum, const glm::ivec4& viewport) const; virtual void renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, bool postLighting, float glowLevel = 0.0f); virtual bool shouldRenderHead(const RenderArgs* renderArgs) const; virtual void fixupModelsInScene(); From 5165210e11237f101191a0864f543b56e9857c3a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 16:35:20 -0700 Subject: [PATCH 18/28] fix Sams comment about comments --- libraries/shared/src/Transform.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/shared/src/Transform.h b/libraries/shared/src/Transform.h index 09cb3ba65b..3b66bcd814 100644 --- a/libraries/shared/src/Transform.h +++ b/libraries/shared/src/Transform.h @@ -87,20 +87,20 @@ public: const Vec3& getTranslation() const; void setTranslation(const Vec3& translation); // [new this] = [translation] * [this.rotation] * [this.scale] void preTranslate(const Vec3& translation); // [new this] = [translation] * [this] - void postTranslate(const Vec3& translation); // [new this] = [this] * [translation] equivalent to gl Translate + void postTranslate(const Vec3& translation); // [new this] = [this] * [translation] equivalent to:glTranslate const Quat& getRotation() const; void setRotation(const Quat& rotation); // [new this] = [this.translation] * [rotation] * [this.scale] void preRotate(const Quat& rotation); // [new this] = [rotation] * [this] - void postRotate(const Quat& rotation); // [new this] = [this] * [rotation] equivalent to gl Rotate + void postRotate(const Quat& rotation); // [new this] = [this] * [rotation] equivalent to:glRotate const Vec3& getScale() const; void setScale(float scale); void setScale(const Vec3& scale); // [new this] = [this.translation] * [this.rotation] * [scale] void preScale(float scale); void preScale(const Vec3& scale); - void postScale(float scale); // [new this] = [this] * [scale] equivalent to gl Scale - void postScale(const Vec3& scale); // [new this] = [this] * [scale] equivalent to gl Scale + void postScale(float scale); // [new this] = [this] * [scale] equivalent to:glScale + void postScale(const Vec3& scale); // [new this] = [this] * [scale] equivalent to:glScale bool isIdentity() const { return (_flags & ~Flags(FLAG_CACHE_INVALID_BITSET)).none(); } bool isTranslating() const { return _flags[FLAG_TRANSLATION]; } From cf0940a65d992f4cb3d2bee703e2cacc8223ba11 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 16 Jul 2015 11:07:01 -0700 Subject: [PATCH 19/28] Fix edit.js highlighting an object after being turned off --- examples/edit.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/edit.js b/examples/edit.js index 23cc942192..dfbace7be6 100644 --- a/examples/edit.js +++ b/examples/edit.js @@ -656,7 +656,9 @@ function mouseMove(event) { function handleIdleMouse() { idleMouseTimerId = null; - highlightEntityUnderCursor(lastMousePosition, true); + if (isActive) { + highlightEntityUnderCursor(lastMousePosition, true); + } } function highlightEntityUnderCursor(position, accurateRay) { From 8921f59e23fc9c5c7e42b78d66cbef301180a656 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 16 Jul 2015 12:09:35 -0700 Subject: [PATCH 20/28] fix entity packet send from interface client --- .../src/octree/OctreeInboundPacketProcessor.cpp | 4 ++-- libraries/entities/src/EntityItemProperties.cpp | 12 ++++-------- libraries/entities/src/EntityItemProperties.h | 2 +- libraries/entities/src/EntityTree.cpp | 3 ++- libraries/octree/src/OctreeEditPacketSender.cpp | 2 +- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp index 3542c7c40d..d70afa4e04 100644 --- a/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp +++ b/assignment-client/src/octree/OctreeInboundPacketProcessor.cpp @@ -128,7 +128,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer packet } if (debugProcessPacket) { - qDebug() << " numBytesPacketHeader=" << packet->localHeaderSize(); + qDebug() << " numBytesPacketHeader=" << packet->totalHeadersSize(); qDebug() << " sizeof(sequence)=" << sizeof(sequence); qDebug() << " sizeof(sentAt)=" << sizeof(sentAt); } @@ -143,7 +143,7 @@ void OctreeInboundPacketProcessor::processPacket(QSharedPointer packet } const unsigned char* editData = nullptr; - + while (packet->bytesLeftToRead() > 0) { editData = reinterpret_cast(packet->getPayload() + packet->pos()); diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 6e6a9eb0a8..61253ba6ba 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -900,14 +900,11 @@ bool EntityItemProperties::encodeEntityEditPacket(PacketType::Value command, Ent // // TODO: Implement support for script and visible properties. // -bool EntityItemProperties::decodeEntityEditPacket(NLPacket& packet, int& processedBytes, +bool EntityItemProperties::decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes, EntityItemID& entityID, EntityItemProperties& properties) { bool valid = false; - const unsigned char* data = reinterpret_cast(packet.getPayload()); const unsigned char* dataAt = data; - - int bytesToRead = packet.getPayloadSize(); processedBytes = 0; // the first part of the data is an octcode, this is a required element of the edit packet format, but we don't @@ -933,10 +930,9 @@ bool EntityItemProperties::decodeEntityEditPacket(NLPacket& packet, int& process // 2) if the edit is to a new entity, the created time is the last edited time // encoded id - QByteArray encodedID((const char*)dataAt, NUM_BYTES_RFC4122_UUID); // maximum possible size - QUuid editID = QUuid::fromRfc4122(encodedID); - dataAt += encodedID.size(); - processedBytes += encodedID.size(); + QUuid editID = QUuid::fromRfc4122(QByteArray::fromRawData(reinterpret_cast(dataAt), NUM_BYTES_RFC4122_UUID)); + dataAt += NUM_BYTES_RFC4122_UUID; + processedBytes += NUM_BYTES_RFC4122_UUID; entityID = editID; valid = true; diff --git a/libraries/entities/src/EntityItemProperties.h b/libraries/entities/src/EntityItemProperties.h index f9a4d499d2..4532ffd67b 100644 --- a/libraries/entities/src/EntityItemProperties.h +++ b/libraries/entities/src/EntityItemProperties.h @@ -179,7 +179,7 @@ public: static bool encodeEraseEntityMessage(const EntityItemID& entityItemID, QByteArray& buffer); - static bool decodeEntityEditPacket(NLPacket& packet, int& processedBytes, + static bool decodeEntityEditPacket(const unsigned char* data, int bytesToRead, int& processedBytes, EntityItemID& entityID, EntityItemProperties& properties); bool glowLevelChanged() const { return _glowLevelChanged; } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index 61bbde6f1a..d5f2026978 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -598,7 +598,8 @@ int EntityTree::processEditPacketData(NLPacket& packet, const unsigned char* edi EntityItemID entityItemID; EntityItemProperties properties; startDecode = usecTimestampNow(); - bool validEditPacket = EntityItemProperties::decodeEntityEditPacket(packet, processedBytes, + + bool validEditPacket = EntityItemProperties::decodeEntityEditPacket(editData, maxLength, processedBytes, entityItemID, properties); endDecode = usecTimestampNow(); diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 8fc13b440d..4df172008f 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -251,7 +251,7 @@ void OctreeEditPacketSender::queueOctreeEditMessage(PacketType::Value type, QByt std::unique_ptr& bufferedPacket = _pendingEditPackets[nodeUUID]; if (!bufferedPacket) { - bufferedPacket = std::move(NLPacket::create(type)); + bufferedPacket = initializePacket(type, node->getClockSkewUsec()); } else { // If we're switching type, then we send the last one and start over if ((type != bufferedPacket->getType() && bufferedPacket->getPayloadSize() > 0) || From 3d6b2467822c54dc2a52780946551a28c7751de6 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 16 Jul 2015 12:18:27 -0700 Subject: [PATCH 21/28] check version against version in OPP --- interface/src/octree/OctreePacketProcessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/octree/OctreePacketProcessor.cpp b/interface/src/octree/OctreePacketProcessor.cpp index 9558df196c..5fbc3101c4 100644 --- a/interface/src/octree/OctreePacketProcessor.cpp +++ b/interface/src/octree/OctreePacketProcessor.cpp @@ -71,7 +71,7 @@ void OctreePacketProcessor::processPacket(QSharedPointer packet, Share PacketType::Value packetType = packet->getType(); // check version of piggyback packet against expected version - if (packetType != versionForPacketType(packet->getType())) { + if (packet->getVersion() != versionForPacketType(packet->getType())) { static QMultiMap versionDebugSuppressMap; const QUuid& senderUUID = packet->getSourceID(); From 60ae02e4e91e1444a218596ea3f54353d6d12320 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 16 Jul 2015 12:38:39 -0700 Subject: [PATCH 22/28] some formatting changes in entities --- libraries/entities/src/EntityEditPacketSender.cpp | 2 +- libraries/entities/src/EntityEditPacketSender.h | 2 +- libraries/octree/src/Octree.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/entities/src/EntityEditPacketSender.cpp b/libraries/entities/src/EntityEditPacketSender.cpp index 9375208ac8..ee2eacfed2 100644 --- a/libraries/entities/src/EntityEditPacketSender.cpp +++ b/libraries/entities/src/EntityEditPacketSender.cpp @@ -1,6 +1,6 @@ // // EntityEditPacketSender.cpp -// libraries/models/src +// libraries/entities/src // // Created by Brad Hefta-Gaub on 8/12/13. // Copyright 2013 High Fidelity, Inc. diff --git a/libraries/entities/src/EntityEditPacketSender.h b/libraries/entities/src/EntityEditPacketSender.h index 2a982fecec..ac278daecd 100644 --- a/libraries/entities/src/EntityEditPacketSender.h +++ b/libraries/entities/src/EntityEditPacketSender.h @@ -1,6 +1,6 @@ // // EntityEditPacketSender.h -// libraries/models/src +// libraries/entities/src // // Created by Brad Hefta-Gaub on 8/12/13. // Copyright 2013 High Fidelity, Inc. diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 810bfa6097..288f6fa1ae 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -391,7 +391,7 @@ int Octree::readElementData(OctreeElement* destinationElement, const unsigned ch } void Octree::readBitstreamToTree(const unsigned char * bitstream, unsigned long int bufferSizeBytes, - ReadBitstreamToTreeParams& args) { + ReadBitstreamToTreeParams& args) { int bytesRead = 0; const unsigned char* bitstreamAt = bitstream; From 05dd49a4c5c73da8038eaccd3f86123ae7124291 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 16 Jul 2015 13:02:20 -0700 Subject: [PATCH 23/28] seek back after track of octree packet --- interface/src/octree/OctreePacketProcessor.cpp | 3 +++ libraries/octree/src/OctreeRenderer.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/interface/src/octree/OctreePacketProcessor.cpp b/interface/src/octree/OctreePacketProcessor.cpp index 5fbc3101c4..8b55c4ccd9 100644 --- a/interface/src/octree/OctreePacketProcessor.cpp +++ b/interface/src/octree/OctreePacketProcessor.cpp @@ -89,6 +89,9 @@ void OctreePacketProcessor::processPacket(QSharedPointer packet, Share } app->trackIncomingOctreePacket(*packet, sendingNode, wasStatsPacket); + + // seek back to beginning of packet after tracking + packet->seek(0); switch(packetType) { case PacketType::EntityErase: { diff --git a/libraries/octree/src/OctreeRenderer.cpp b/libraries/octree/src/OctreeRenderer.cpp index 44130edf25..ce9bd1e3fd 100644 --- a/libraries/octree/src/OctreeRenderer.cpp +++ b/libraries/octree/src/OctreeRenderer.cpp @@ -67,7 +67,7 @@ void OctreeRenderer::processDatagram(NLPacket& packet, SharedNodePointer sourceN PerformanceWarning warn(showTimingDetails, "OctreeRenderer::processDatagram expected PacketType", showTimingDetails); // if we are getting inbound packets, then our tree is also viewing, and we should remember that fact. _tree->setIsViewing(true); - + OCTREE_PACKET_FLAGS flags; packet.readPrimitive(&flags); From b4121eb464adf6a154535fb2120e3d77c5d512fe Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 16 Jul 2015 13:14:17 -0700 Subject: [PATCH 24/28] Remove unnecessary move --- interface/src/Application.cpp | 2 +- libraries/entities/src/EntityTree.cpp | 2 +- libraries/networking/src/LimitedNodeList.cpp | 4 ++-- libraries/networking/src/NLPacketList.cpp | 2 +- libraries/networking/src/udt/PacketList.cpp | 4 ++-- libraries/networking/src/udt/PacketList.h | 2 +- libraries/octree/src/JurisdictionMap.cpp | 4 ++-- libraries/octree/src/OctreeEditPacketSender.cpp | 3 +-- libraries/shared/src/GLMHelpers.cpp | 2 +- 9 files changed, 12 insertions(+), 13 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f61f725c4e..b03df3a1cc 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1797,7 +1797,7 @@ void Application::sendPingPackets() { return false; } }, [nodeList](const SharedNodePointer& node) { - nodeList->sendPacket(std::move(nodeList->constructPingPacket()), *node); + nodeList->sendPacket(nodeList->constructPingPacket(), *node); }); } diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index d5f2026978..ba2691aa3b 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -826,7 +826,7 @@ std::unique_ptr EntityTree::encodeEntitiesDeletedSince(OCTREE_PACKET_S deletesPacket->seek(numberOfIDsPos); deletesPacket->writePrimitive(numberOfIDs); - return std::move(deletesPacket); + return deletesPacket; } diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index badfbef60a..4a15602f95 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -290,7 +290,7 @@ qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& des packetList.closeCurrentPacket(); while (!packetList._packets.empty()) { - bytesSent += sendPacket(std::move(packetList.takeFront()), destinationNode); + bytesSent += sendPacket(packetList.takeFront(), destinationNode); } return bytesSent; @@ -304,7 +304,7 @@ qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockA packetList.closeCurrentPacket(); while (!packetList._packets.empty()) { - bytesSent += sendPacket(std::move(packetList.takeFront()), sockAddr, connectionSecret); + bytesSent += sendPacket(packetList.takeFront(), sockAddr, connectionSecret); } return bytesSent; diff --git a/libraries/networking/src/NLPacketList.cpp b/libraries/networking/src/NLPacketList.cpp index 85b413eda9..7ac9fe11c3 100644 --- a/libraries/networking/src/NLPacketList.cpp +++ b/libraries/networking/src/NLPacketList.cpp @@ -17,6 +17,6 @@ NLPacketList::NLPacketList(PacketType::Value packetType) : PacketList(packetType } std::unique_ptr NLPacketList::createPacket() { - return std::move(NLPacket::create(getType())); + return NLPacket::create(getType()); } diff --git a/libraries/networking/src/udt/PacketList.cpp b/libraries/networking/src/udt/PacketList.cpp index 4036e872fd..9e3921e325 100644 --- a/libraries/networking/src/udt/PacketList.cpp +++ b/libraries/networking/src/udt/PacketList.cpp @@ -31,7 +31,7 @@ void PacketList::endSegment() { std::unique_ptr PacketList::createPacket() { // use the static create method to create a new packet - return std::move(Packet::create(getType())); + return Packet::create(getType()); } std::unique_ptr PacketList::createPacketWithExtendedHeader() { @@ -46,7 +46,7 @@ std::unique_ptr PacketList::createPacketWithExtendedHeader() { } } - return std::move(packet); + return packet; } qint64 PacketList::writeData(const char* data, qint64 maxSize) { diff --git a/libraries/networking/src/udt/PacketList.h b/libraries/networking/src/udt/PacketList.h index f4b542155a..0a1bdd080a 100644 --- a/libraries/networking/src/udt/PacketList.h +++ b/libraries/networking/src/udt/PacketList.h @@ -80,7 +80,7 @@ template std::unique_ptr PacketList::takeFront() { auto packet = std::move(_packets.front()); _packets.pop_front(); - return std::move(std::unique_ptr(dynamic_cast(packet.release()))); + return std::unique_ptr(dynamic_cast(packet.release())); } #endif // hifi_PacketList_h \ No newline at end of file diff --git a/libraries/octree/src/JurisdictionMap.cpp b/libraries/octree/src/JurisdictionMap.cpp index 64e8a7bca5..255652a3cc 100644 --- a/libraries/octree/src/JurisdictionMap.cpp +++ b/libraries/octree/src/JurisdictionMap.cpp @@ -260,7 +260,7 @@ std::unique_ptr JurisdictionMap::packEmptyJurisdictionIntoMessage(Node // No root or end node details to pack! packet->writePrimitive(bytes); - return std::move(packet); // includes header! + return packet; // includes header! } std::unique_ptr JurisdictionMap::packIntoPacket() { @@ -295,7 +295,7 @@ std::unique_ptr JurisdictionMap::packIntoPacket() { packet->writePrimitive(bytes); } - return std::move(packet); + return packet; } int JurisdictionMap::unpackFromPacket(NLPacket& packet) { diff --git a/libraries/octree/src/OctreeEditPacketSender.cpp b/libraries/octree/src/OctreeEditPacketSender.cpp index 4df172008f..30e1630e36 100644 --- a/libraries/octree/src/OctreeEditPacketSender.cpp +++ b/libraries/octree/src/OctreeEditPacketSender.cpp @@ -121,8 +121,7 @@ void OctreeEditPacketSender::processPreServerExistsPackets() { // First send out all the single message packets... _pendingPacketsLock.lock(); while (!_preServerSingleMessagePackets.empty()) { - std::unique_ptr packet = std::move(_preServerSingleMessagePackets.front()); - queuePacketToNodes(std::move(packet)); + queuePacketToNodes(std::move(_preServerSingleMessagePackets.front())); _preServerSingleMessagePackets.pop_front(); } diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index 53b3b90560..d5b2917369 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -327,7 +327,7 @@ glm::vec2 toGlm(const QPointF & pt) { glm::vec3 toGlm(const xColor & color) { static const float MAX_COLOR = 255.0f; - return std::move(glm::vec3(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR)); + return glm::vec3(color.red, color.green, color.blue) / MAX_COLOR; } glm::vec4 toGlm(const QColor & color) { From 76d47eb4e7401a8479279fd031f795c9d7a56cbb Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 16 Jul 2015 13:22:18 -0700 Subject: [PATCH 25/28] mark the DataServerConfirm packet unused --- libraries/networking/src/udt/PacketHeaders.cpp | 1 - libraries/networking/src/udt/PacketHeaders.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/networking/src/udt/PacketHeaders.cpp b/libraries/networking/src/udt/PacketHeaders.cpp index ccbd56c674..9a39b6f5eb 100644 --- a/libraries/networking/src/udt/PacketHeaders.cpp +++ b/libraries/networking/src/udt/PacketHeaders.cpp @@ -135,7 +135,6 @@ QString nameForPacketType(PacketType::Value packetType) { PACKET_TYPE_NAME_LOOKUP(DomainConnectionDenied); PACKET_TYPE_NAME_LOOKUP(MuteEnvironment); PACKET_TYPE_NAME_LOOKUP(AudioStreamStats); - PACKET_TYPE_NAME_LOOKUP(DataServerConfirm); PACKET_TYPE_NAME_LOOKUP(OctreeStats); PACKET_TYPE_NAME_LOOKUP(Jurisdiction); PACKET_TYPE_NAME_LOOKUP(JurisdictionRequest); diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index a133654b05..5f63a2c840 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -48,7 +48,7 @@ namespace PacketType { DomainConnectionDenied, MuteEnvironment, AudioStreamStats, - DataServerConfirm, // 20 + UNUSED, // 20 DomainServerPathQuery, DomainServerPathResponse, DomainServerAddedNode, From 5d84d2ec3072853b63ad200ccba90e6dbd69e84a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 16 Jul 2015 13:39:14 -0700 Subject: [PATCH 26/28] add port to current address if not default --- libraries/networking/src/AddressManager.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 21bbbc82f6..2b9b8d42fb 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -548,7 +548,13 @@ void AddressManager::setHost(const QString& host, LookupTrigger trigger) { void AddressManager::setDomainInfo(const QString& hostname, quint16 port, LookupTrigger trigger) { - setHost(hostname, trigger); + + QString domainHostString = hostname; + if (port != DEFAULT_DOMAIN_SERVER_PORT) { + domainHostString.append(QString(":%1").arg(port)); + } + + setHost(domainHostString, trigger); _rootPlaceID = QUuid(); From ed928e8a6b3c33bacab9a7321f6e2c4dfe56c365 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 16 Jul 2015 13:52:18 -0700 Subject: [PATCH 27/28] actual fix for AddressManager address with port --- libraries/networking/src/AddressManager.cpp | 32 ++++++++++----------- libraries/networking/src/AddressManager.h | 8 +++--- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 2b9b8d42fb..3f3234a307 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -30,10 +30,7 @@ const QString SETTINGS_CURRENT_ADDRESS_KEY = "address"; Setting::Handle currentAddressHandle(QStringList() << ADDRESS_MANAGER_SETTINGS_GROUP << "address", DEFAULT_HIFI_ADDRESS); AddressManager::AddressManager() : - _host(), - _rootPlaceID(), - _positionGetter(NULL), - _orientationGetter(NULL) + _port(0) { } @@ -47,6 +44,11 @@ const QUrl AddressManager::currentAddress() const { hifiURL.setScheme(HIFI_URL_SCHEME); hifiURL.setHost(_host); + + if (_port != 0 && _port != DEFAULT_DOMAIN_SERVER_PORT) { + hifiURL.setPort(_port); + } + hifiURL.setPath(currentPath()); return hifiURL; @@ -535,26 +537,24 @@ bool AddressManager::handleUsername(const QString& lookupString) { return false; } -void AddressManager::setHost(const QString& host, LookupTrigger trigger) { - if (host != _host) { - +void AddressManager::setHost(const QString& host, LookupTrigger trigger, quint16 port) { + if (host != _host || port != _port) { + + _port = port; + // if the host is being changed we should store current address in the history addCurrentAddressToHistory(trigger); - _host = host; - emit hostChanged(_host); + if (host != _host) { + _host = host; + emit hostChanged(_host); + } } } void AddressManager::setDomainInfo(const QString& hostname, quint16 port, LookupTrigger trigger) { - - QString domainHostString = hostname; - if (port != DEFAULT_DOMAIN_SERVER_PORT) { - domainHostString.append(QString(":%1").arg(port)); - } - - setHost(domainHostString, trigger); + setHost(hostname, trigger, port); _rootPlaceID = QUuid(); diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index def9eb6042..fbb895795b 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -58,7 +58,6 @@ public: const QString& getHost() const { return _host; } - void setPositionGetter(PositionGetter positionGetter) { _positionGetter = positionGetter; } void setOrientationGetter(OrientationGetter orientationGetter) { _orientationGetter = orientationGetter; } @@ -109,7 +108,7 @@ private slots: void goToAddressFromObject(const QVariantMap& addressMap, const QNetworkReply& reply); private: - void setHost(const QString& host, LookupTrigger trigger); + void setHost(const QString& host, LookupTrigger trigger, quint16 port = 0); void setDomainInfo(const QString& hostname, quint16 port, LookupTrigger trigger); const JSONCallbackParameters& apiCallbackParameters(); @@ -129,9 +128,10 @@ private: void addCurrentAddressToHistory(LookupTrigger trigger); QString _host; + quint16 _port; QUuid _rootPlaceID; - PositionGetter _positionGetter; - OrientationGetter _orientationGetter; + PositionGetter _positionGetter { nullptr }; + OrientationGetter _orientationGetter { nullptr }; QStack _backStack; QStack _forwardStack; From 00fbff112f102925fa23db2c9194407b56628e1a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 16 Jul 2015 14:03:11 -0700 Subject: [PATCH 28/28] Process avatar data --- libraries/avatars/src/AvatarHashMap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 3243ff3f9a..0dbc1a5e46 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -22,7 +22,7 @@ AvatarHashMap::AvatarHashMap() { connect(DependencyManager::get().data(), &NodeList::uuidChanged, this, &AvatarHashMap::sessionUUIDChanged); auto& packetReceiver = DependencyManager::get()->getPacketReceiver(); - packetReceiver.registerListener(PacketType::BulkAvatarData, this, "processAvatarDataPacket"); + packetReceiver.registerListener(PacketType::AvatarData, this, "processAvatarDataPacket"); packetReceiver.registerListener(PacketType::KillAvatar, this, "processKillAvatar"); packetReceiver.registerListener(PacketType::AvatarIdentity, this, "processAvatarIdentityPacket"); packetReceiver.registerListener(PacketType::AvatarBillboard, this, "processAvatarBillboardPacket");