From f3cb25065f518b9569404aef7373a36c24072ef3 Mon Sep 17 00:00:00 2001 From: Sam Gondelman Date: Tue, 14 Jul 2015 17:36:22 -0700 Subject: [PATCH 01/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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 5b0b7229ba546ff6f34c03ecf8824ce73b61c66f Mon Sep 17 00:00:00 2001 From: bwent Date: Wed, 15 Jul 2015 11:10:39 -0700 Subject: [PATCH 09/35] Added a dialog box to display audio network statistics --- interface/src/Application.cpp | 10 +- interface/src/Application.h | 1 + interface/src/Menu.cpp | 28 +-- interface/src/Menu.h | 2 +- interface/src/ui/ApplicationOverlay.cpp | 5 +- interface/src/ui/AudioStatsDialog.cpp | 276 ++++++++++++++++++++++++ interface/src/ui/AudioStatsDialog.h | 107 +++++++++ interface/src/ui/DialogsManager.cpp | 14 ++ interface/src/ui/DialogsManager.h | 4 + 9 files changed, 429 insertions(+), 18 deletions(-) create mode 100644 interface/src/ui/AudioStatsDialog.cpp create mode 100644 interface/src/ui/AudioStatsDialog.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 06b086ccb3..745c8c1212 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -107,7 +107,7 @@ #include "avatar/AvatarManager.h" #include "audio/AudioToolBox.h" -#include "audio/AudioIOStatsRenderer.h" +//#include "audio/AudioIOStatsRenderer.h" #include "audio/AudioScope.h" #include "devices/CameraToolBox.h" @@ -274,7 +274,7 @@ bool setupEssentials(int& argc, char** argv) { auto faceshift = DependencyManager::set(); auto audio = DependencyManager::set(); auto audioScope = DependencyManager::set(); - auto audioIOStatsRenderer = DependencyManager::set(); +// auto audioIOStatsRenderer = DependencyManager::set(); auto deferredLightingEffect = DependencyManager::set(); auto ambientOcclusionEffect = DependencyManager::set(); auto textureCache = DependencyManager::set(); @@ -2443,6 +2443,12 @@ void Application::updateDialogs(float deltaTime) { PerformanceWarning warn(showWarnings, "Application::updateDialogs()"); auto dialogsManager = DependencyManager::get(); + // Update audio stats dialog, if any + AudioStatsDialog* audioStatsDialog = dialogsManager->getAudioStatsDialog(); + if(audioStatsDialog) { + audioStatsDialog->update(); + } + // Update bandwidth dialog, if any BandwidthDialog* bandwidthDialog = dialogsManager->getBandwidthDialog(); if (bandwidthDialog) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 3239b84c6c..4e0edbb13d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -57,6 +57,7 @@ #include "devices/SixenseManager.h" #include "scripting/ControllerScriptingInterface.h" #include "scripting/WebWindowClass.h" +#include "ui/AudioStatsDialog.h" #include "ui/BandwidthDialog.h" #include "ui/HMDToolsDialog.h" #include "ui/ModelsBrowser.h" diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 6671320f0c..ae7eb11e98 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -24,7 +24,7 @@ #include "Application.h" #include "AccountManager.h" -#include "audio/AudioIOStatsRenderer.h" +//#include "audio/AudioIOStatsRenderer.h" #include "audio/AudioScope.h" #include "avatar/AvatarManager.h" #include "devices/DdeFaceTracker.h" @@ -314,6 +314,8 @@ Menu::Menu() { addActionToQMenuAndActionHash(viewMenu, MenuOption::Log, Qt::CTRL | Qt::SHIFT | Qt::Key_L, qApp, SLOT(toggleLogDialog())); + addActionToQMenuAndActionHash(viewMenu, MenuOption::AudioNetworkStats, 0, + dialogsManager.data(), SLOT(audioStatsDetails())); addActionToQMenuAndActionHash(viewMenu, MenuOption::BandwidthDetails, 0, dialogsManager.data(), SLOT(bandwidthDetails())); addActionToQMenuAndActionHash(viewMenu, MenuOption::OctreeStats, 0, @@ -579,19 +581,19 @@ Menu::Menu() { audioScopeFramesGroup->addAction(fiftyFrames); } - auto statsRenderer = DependencyManager::get(); - addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioStats, - Qt::CTRL | Qt::SHIFT | Qt::Key_A, - false, - statsRenderer.data(), - SLOT(toggle())); - - addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioStatsShowInjectedStreams, - 0, - false, - statsRenderer.data(), - SLOT(toggleShowInjectedStreams())); +// auto statsRenderer = DependencyManager::get(); +// addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioStats, +// Qt::CTRL | Qt::SHIFT | Qt::Key_A, +// false, +// statsRenderer.data(), +// SLOT(toggle())); +// addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioStatsShowInjectedStreams, +// 0, +// false, +// statsRenderer.data(), +// SLOT(toggleShowInjectedStreams())); +// MenuWrapper* physicsOptionsMenu = developerMenu->addMenu("Physics"); addCheckableActionToQMenuAndActionHash(physicsOptionsMenu, MenuOption::PhysicsShowOwned); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index be0ac12d0d..c914cb2d12 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -145,7 +145,7 @@ namespace MenuOption { const QString AudioScopeFrames = "Display Frames"; const QString AudioScopePause = "Pause Scope"; const QString AudioScopeTwentyFrames = "Twenty"; - const QString AudioStats = "Audio Stats"; + const QString AudioNetworkStats = "Audio Network Stats"; const QString AudioStatsShowInjectedStreams = "Audio Stats Show Injected Streams"; const QString AutoMuteAudio = "Auto Mute Microphone"; const QString AvatarReceiveStats = "Show Receive Stats"; diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 2b58ad93fc..bdfa146197 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -23,7 +23,7 @@ #include #include "AudioClient.h" -#include "audio/AudioIOStatsRenderer.h" +//#include "audio/AudioIOStatsRenderer.h" #include "audio/AudioScope.h" #include "audio/AudioToolBox.h" #include "Application.h" @@ -935,7 +935,7 @@ void ApplicationOverlay::renderAudioMeter() { auto canvasSize = qApp->getCanvasSize(); DependencyManager::get()->render(canvasSize.x, canvasSize.y); - DependencyManager::get()->render(WHITE_TEXT, canvasSize.x, canvasSize.y); + //DependencyManager::get()->render(WHITE_TEXT, canvasSize.x, canvasSize.y); audioMeterY += AUDIO_METER_HEIGHT; @@ -994,6 +994,7 @@ void ApplicationOverlay::renderAudioMeter() { void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); + QSharedPointer bandwidthRecorder = DependencyManager::get(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); diff --git a/interface/src/ui/AudioStatsDialog.cpp b/interface/src/ui/AudioStatsDialog.cpp new file mode 100644 index 0000000000..9ee8716321 --- /dev/null +++ b/interface/src/ui/AudioStatsDialog.cpp @@ -0,0 +1,276 @@ +// +// AudioStatsDialog.cpp +// hifi +// +// Created by Bridget Went on 7/9/15. +// +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include "InterfaceConfig.h" + +#include +#include +#include +#include +#include +#include +#include + + +#include "AudioStatsDialog.h" + +const unsigned COLOR0 = 0x33cc99ff; +const unsigned COLOR1 = 0xffef40c0; +const unsigned COLOR2 = 0xd0d0d0a0; +const unsigned COLOR3 = 0x01DD7880; + + +AudioStatsDisplay::AudioStatsDisplay(QFormLayout* form, + QString text, unsigned colorRGBA) : +_text(text), +_colorRGBA(colorRGBA) +{ + _label = new QLabel(); + _label->setAlignment(Qt::AlignCenter); + + QPalette palette = _label->palette(); + unsigned rgb = colorRGBA >> 8; + rgb = ((rgb & 0xfefefeu) >> 1) + ((rgb & 0xf8f8f8) >> 3); + palette.setColor(QPalette::WindowText, QColor::fromRgb(rgb)); + _label->setPalette(palette); + + form->addRow(_label); +} + +void AudioStatsDisplay::paint() { + _label->setText(_strBuf); +} + +void AudioStatsDisplay::updatedDisplay(QString str) { + _strBuf = str; +} + + +AudioStatsDialog::AudioStatsDialog(QWidget* parent) : + QDialog(parent, Qt::Window | Qt::WindowCloseButtonHint | Qt::WindowStaysOnTopHint) { + + _shouldShowInjectedStreams = false; + + this->setWindowTitle("Audio Network Statistics"); + + // Get statistics from the Audio Client + _stats = &DependencyManager::get()->getStats(); + + // Create layouter + _form = new QFormLayout(); + this->QDialog::setLayout(_form); + + // Initialize vectors for stat channels + _audioMixerStats = new QVector(); + _upstreamClientStats = new QVector(); + _upstreamMixerStats = new QVector(); + _downstreamStats = new QVector(); + _upstreamInjectedStats = new QVector(); + + // Load and initilize + this->renderStats(); + + this->initializeChannel(_form, 0, _audioMixerStats, COLOR0); + this->initializeChannel(_form, 1, _upstreamClientStats, COLOR1); + this->initializeChannel(_form, 2, _upstreamMixerStats, COLOR2); + this->initializeChannel(_form, 3, _downstreamStats, COLOR3); + this->initializeChannel(_form, 4, _upstreamInjectedStats, COLOR0); + +} + +void AudioStatsDialog::initializeChannel(QFormLayout* form, const unsigned int index, QVector *stats, const unsigned color) { + + _audioDisplayChannels[index] = new QVector(); + + for (int i = 0; i < stats->size(); i++) + // Create new display label + _audioDisplayChannels[index]->push_back(new AudioStatsDisplay(form, stats->at(i), color)); + +} + +void AudioStatsDialog::updateStats(const unsigned int index, QVector* stats) { + // Update all stat displays at specified channel + for (int i = 0; i < stats->size(); i++) + _audioDisplayChannels[index]->at(i)->updatedDisplay(stats->at(i)); +} + + +void AudioStatsDialog::renderStats() { + + // Clear current stats from all vectors + this->clearAllChannels(); + + double audioInputBufferLatency = 0.0, + inputRingBufferLatency = 0.0, + networkRoundtripLatency = 0.0, + mixerRingBufferLatency = 0.0, + outputRingBufferLatency = 0.0, + audioOutputBufferLatency = 0.0; + + AudioStreamStats downstreamAudioStreamStats = _stats->getMixerDownstreamStats(); + SharedNodePointer audioMixerNodePointer = DependencyManager::get()->soloNodeOfType(NodeType::AudioMixer); + + if (!audioMixerNodePointer.isNull()) { + audioInputBufferLatency = (double)_stats->getAudioInputMsecsReadStats().getWindowAverage(); + inputRingBufferLatency = (double)_stats->getInputRungBufferMsecsAvailableStats().getWindowAverage(); + networkRoundtripLatency = (double) audioMixerNodePointer->getPingMs(); + mixerRingBufferLatency = (double)_stats->getMixerAvatarStreamStats()._framesAvailableAverage * AudioConstants::NETWORK_FRAME_MSECS; + outputRingBufferLatency = (double)downstreamAudioStreamStats._framesAvailableAverage * AudioConstants::NETWORK_FRAME_MSECS; + audioOutputBufferLatency = (double)_stats->getAudioOutputMsecsUnplayedStats().getWindowAverage(); + } + + double totalLatency = audioInputBufferLatency + inputRingBufferLatency + networkRoundtripLatency + mixerRingBufferLatency + + outputRingBufferLatency + audioOutputBufferLatency; + + _audioMixerStats->push_back(QString("Audio input buffer: %1ms").arg( + QString::number(audioInputBufferLatency, 'f', 2)) + QString(" - avg msecs of samples read to the audio input buffer in last 10s")); + + _audioMixerStats->push_back(QString("Input ring buffer: %1ms").arg( + QString::number(inputRingBufferLatency, 'f', 2)) + QString(" - avg msecs of samples read to the input ring buffer in last 10s")); + _audioMixerStats->push_back(QString("Network to mixer: %1ms").arg( + QString::number((networkRoundtripLatency / 2.0), 'f', 2)) + QString(" - half of last ping value calculated by the node list")); + _audioMixerStats->push_back(QString("Network to client: %1ms").arg( + QString::number((mixerRingBufferLatency / 2.0),'f', 2)) + QString(" - half of last ping value calculated by the node list")); + _audioMixerStats->push_back(QString("Output ring buffer: %1ms").arg( + QString::number(outputRingBufferLatency,'f', 2)) + QString(" - avg msecs of samples in output ring buffer in last 10s")); + _audioMixerStats->push_back(QString("Audio output buffer: %1ms").arg( + QString::number(mixerRingBufferLatency,'f', 2)) + QString(" - avg msecs of samples in audio output buffer in last 10s")); + _audioMixerStats->push_back(QString("TOTAL: %1ms").arg( + QString::number(totalLatency, 'f', 2)) +QString(" - avg msecs of samples in audio output buffer in last 10s")); + + + const MovingMinMaxAvg& packetSentTimeGaps = _stats->getPacketSentTimeGaps(); + + _upstreamClientStats->push_back( + QString("\nUpstream Mic Audio Packets Sent Gaps (by client):")); + + _upstreamClientStats->push_back( + QString("Inter-packet timegaps (overall) | min: %1, max: %2, avg: %3").arg(formatUsecTime(packetSentTimeGaps.getMin()).toLatin1().data()).arg(formatUsecTime( packetSentTimeGaps.getMax()).toLatin1().data()).arg(formatUsecTime( packetSentTimeGaps.getAverage()).toLatin1().data())); + _upstreamClientStats->push_back( + QString("Inter-packet timegaps (last 30s) | min: %1, max: %2, avg: %3").arg(formatUsecTime(packetSentTimeGaps.getWindowMin()).toLatin1().data()).arg(formatUsecTime(packetSentTimeGaps.getWindowMax()).toLatin1().data()).arg(formatUsecTime(packetSentTimeGaps.getWindowAverage()).toLatin1().data())); + + _upstreamMixerStats->push_back(QString("\nUpstream mic audio stats (received and reported by audio-mixer):")); + + renderAudioStreamStats(&_stats->getMixerAvatarStreamStats(), _upstreamMixerStats, true); + + _downstreamStats->push_back(QString("\nDownstream mixed audio stats:")); + + AudioStreamStats downstreamStats = _stats->getMixerDownstreamStats(); + + renderAudioStreamStats(&downstreamStats, _downstreamStats, true); + + + if (_shouldShowInjectedStreams) { + + foreach(const AudioStreamStats& injectedStreamAudioStats, _stats->getMixerInjectedStreamStatsMap()) { + + _upstreamInjectedStats->push_back(QString("\nUpstream injected audio stats: stream ID: %1").arg( injectedStreamAudioStats._streamIdentifier.toString().toLatin1().data())); + + renderAudioStreamStats(&injectedStreamAudioStats, _upstreamInjectedStats, true); + } + + } + + connect(averageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTimerTimeout())); + averageUpdateTimer->start(1000); +} + + +void AudioStatsDialog::renderAudioStreamStats(const AudioStreamStats* streamStats, QVector* audioStreamStats, bool isDownstreamStats) { + + + audioStreamStats->push_back( + QString("Packet loss | overall: %1% (%2 lost), last_30s: %3% (%4 lost)").arg(QString::number((int)(streamStats->_packetStreamStats.getLostRate() * 100.0f))).arg(QString::number((int)(streamStats->_packetStreamStats._lost))).arg(QString::number((int)(streamStats->_packetStreamWindowStats.getLostRate() * 100.0f))).arg(QString::number((int)(streamStats->_packetStreamWindowStats._lost))) + ); + + if (isDownstreamStats) { + audioStreamStats->push_back( + QString("Ringbuffer frames | desired: %1, avg_available(10s): %2 + %3, available: %4+%5").arg(QString::number(streamStats->_desiredJitterBufferFrames)).arg(QString::number(streamStats->_framesAvailableAverage)).arg(QString::number((int)((float)_stats->getAudioInputMsecsReadStats().getWindowAverage() / AudioConstants::NETWORK_FRAME_MSECS))).arg(QString::number(streamStats->_framesAvailable)).arg(QString::number((int)(_stats->getAudioOutputMsecsUnplayedStats().getCurrentIntervalLastSample() / AudioConstants::NETWORK_FRAME_MSECS)))); + } else { + audioStreamStats->push_back( + QString("Ringbuffer frames | desired: %1, avg_available(10s): %2, available: %3").arg(QString::number(streamStats->_desiredJitterBufferFrames)).arg(QString::number(streamStats->_framesAvailableAverage)).arg(QString::number(streamStats->_framesAvailable))); + } + + audioStreamStats->push_back( + QString("Ringbuffer stats | starves: %1, prev_starve_lasted: %2, frames_dropped: %3, overflows: %4").arg(QString::number(streamStats->_starveCount)).arg(QString::number(streamStats->_consecutiveNotMixedCount)).arg(QString::number(streamStats->_framesDropped)).arg(QString::number(streamStats->_overflowCount))); + audioStreamStats->push_back( + QString("Inter-packet timegaps (overall) | min: %1, max: %2, avg: %3").arg(formatUsecTime(streamStats->_timeGapMin).toLatin1().data()).arg(formatUsecTime(streamStats->_timeGapMax).toLatin1().data()).arg(formatUsecTime(streamStats->_timeGapAverage).toLatin1().data())); + audioStreamStats->push_back( + QString("Inter-packet timegaps (last 30s) | min: %1, max: %2, avg: %3").arg(formatUsecTime(streamStats->_timeGapWindowMin).toLatin1().data()).arg(formatUsecTime(streamStats->_timeGapWindowMax).toLatin1().data()).arg(QString::number(streamStats->_timeGapWindowAverage).toLatin1().data())); + +} + +void AudioStatsDialog::clearAllChannels() { + _audioMixerStats->clear(); + _upstreamClientStats->clear(); + _upstreamMixerStats->clear(); + _downstreamStats->clear(); + _upstreamInjectedStats->clear(); +} + + +void AudioStatsDialog::updateTimerTimeout() { + + // Update all audio stats + this->renderStats(); + + this->updateStats(0, _audioMixerStats); + this->updateStats(1, _upstreamClientStats); + this->updateStats(2, _upstreamMixerStats); + this->updateStats(3, _downstreamStats); + this->updateStats(4, _upstreamInjectedStats); + +} + + +void AudioStatsDialog::paintEvent(QPaintEvent* event) { + + // Repaint each statistic in each section + for (int i = 0; i < DISPLAY_CHANNELS; i++) { + for(int j = 0; j < _audioDisplayChannels[i]->size(); j++) { + _audioDisplayChannels[i]->at(j)->paint(); + } + } + this->QDialog::paintEvent(event); + this->setFixedSize(this->width(), this->height()); +} + +void AudioStatsDialog::reject() { + // Just regularly close upon ESC + this->QDialog::close(); +} + +void AudioStatsDialog::closeEvent(QCloseEvent* event) { + this->QDialog::closeEvent(event); + emit closed(); +} + +AudioStatsDialog::~AudioStatsDialog() { + this->clearAllChannels(); + + delete _audioMixerStats; + delete _upstreamClientStats; + delete _upstreamMixerStats; + delete _downstreamStats; + delete _upstreamInjectedStats; + + for (int i = 0; i < DISPLAY_CHANNELS; i++) { + _audioDisplayChannels[i]->clear(); + for(int j = 0; j < _audioDisplayChannels[i]->size(); j++) { + delete _audioDisplayChannels[i]->at(j); + } + } + +} + + diff --git a/interface/src/ui/AudioStatsDialog.h b/interface/src/ui/AudioStatsDialog.h new file mode 100644 index 0000000000..ce1e8027e3 --- /dev/null +++ b/interface/src/ui/AudioStatsDialog.h @@ -0,0 +1,107 @@ +// +// AudioStatsDialog.h +// hifi +// +// Created by Bridget Went on 7/9/15. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + + +#ifndef __hifi__AudioStatsDialog__ +#define __hifi__AudioStatsDialog__ + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +class AudioIOStats; +class AudioStreamStats; + +//display +class AudioStatsDisplay : public QObject, public Dependency { + Q_OBJECT + SINGLETON_DEPENDENCY +public: + AudioStatsDisplay(QFormLayout* form, QString text, unsigned colorRGBA); + void updatedDisplay(QString str); + void paint(); + +private: + QString _strBuf; + QLabel* _label; + QString _text; + unsigned _colorRGBA; + +}; + +//dialog +class AudioStatsDialog : public QDialog { + Q_OBJECT +public: + AudioStatsDialog(QWidget* parent); + ~AudioStatsDialog(); + + void paintEvent(QPaintEvent*); + +private: + // audio stats methods for rendering + QVector *_audioMixerStats; + QVector *_upstreamClientStats; + QVector *_upstreamMixerStats; + QVector *_downstreamStats; + QVector *_upstreamInjectedStats; + + void initializeChannel(QFormLayout* form, const unsigned int index, QVector* stats, const unsigned color); + void updateStats(const unsigned index, QVector* stats); + void renderStats(); + void clearAllChannels(); + void renderAudioStreamStats(const AudioStreamStats* streamStats, QVector* audioStreamstats, bool isDownstreamStats); + + const static int DISPLAY_CHANNELS = 5; + QVector *_audioDisplayChannels[DISPLAY_CHANNELS]; + + const AudioIOStats* _stats; + QFormLayout* _form; + + bool _isEnabled; + bool _shouldShowInjectedStreams; + + +signals: + + + void closed(); + + public slots: + + + void reject(); + void updateTimerTimeout(); + +protected: + + // Emits a 'closed' signal when this dialog is closed. + void closeEvent(QCloseEvent*); + +private: + QTimer* averageUpdateTimer = new QTimer(this); + +}; + + + + + +#endif /* defined(__hifi__AudioStatsDialog__) */ + diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index 81c7cd2770..04f532c59a 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -114,6 +114,20 @@ void DialogsManager::editAnimations() { } } +void DialogsManager::audioStatsDetails() { + if (! _audioStatsDialog) { + _audioStatsDialog = new AudioStatsDialog(qApp->getWindow()); + connect(_audioStatsDialog, SIGNAL(closed()), _audioStatsDialog, SLOT(deleteLater())); + + if (_hmdToolsDialog) { + _hmdToolsDialog->watchWindow(_audioStatsDialog->windowHandle()); + } + + _audioStatsDialog->show(); + } + _audioStatsDialog->raise(); +} + void DialogsManager::bandwidthDetails() { if (! _bandwidthDialog) { _bandwidthDialog = new BandwidthDialog(qApp->getWindow()); diff --git a/interface/src/ui/DialogsManager.h b/interface/src/ui/DialogsManager.h index 7eb716b73c..b15830e35c 100644 --- a/interface/src/ui/DialogsManager.h +++ b/interface/src/ui/DialogsManager.h @@ -24,6 +24,7 @@ class QAction; class AddressBarDialog; class AnimationsDialog; class AttachmentsDialog; +class AudioStatsDialog; class BandwidthDialog; class CachesSizeDialog; class DiskCacheEditor; @@ -42,6 +43,7 @@ class DialogsManager : public QObject, public Dependency { SINGLETON_DEPENDENCY public: + QPointer getAudioStatsDialog() const { return _audioStatsDialog; } QPointer getBandwidthDialog() const { return _bandwidthDialog; } QPointer getHMDToolsDialog() const { return _hmdToolsDialog; } QPointer getLodToolsDialog() const { return _lodToolsDialog; } @@ -58,6 +60,7 @@ public slots: void editPreferences(); void editAttachments(); void editAnimations(); + void audioStatsDetails(); void bandwidthDetails(); void lodTools(); void hmdTools(bool showTools); @@ -93,6 +96,7 @@ private: QPointer _addressBarDialog; QPointer _animationsDialog; QPointer _attachmentsDialog; + QPointer _audioStatsDialog; QPointer _bandwidthDialog; QPointer _cachesSizeDialog; QPointer _diskCacheEditor; From 2c24251b52df6555a0d4800d7f9d94909e46a0ff Mon Sep 17 00:00:00 2001 From: bwent Date: Wed, 15 Jul 2015 11:41:26 -0700 Subject: [PATCH 10/35] Clean up from previous commit --- interface/src/Application.cpp | 2 -- interface/src/Menu.cpp | 14 -------------- interface/src/ui/ApplicationOverlay.cpp | 4 ++-- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 745c8c1212..7b7fc53eb4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -107,7 +107,6 @@ #include "avatar/AvatarManager.h" #include "audio/AudioToolBox.h" -//#include "audio/AudioIOStatsRenderer.h" #include "audio/AudioScope.h" #include "devices/CameraToolBox.h" @@ -274,7 +273,6 @@ bool setupEssentials(int& argc, char** argv) { auto faceshift = DependencyManager::set(); auto audio = DependencyManager::set(); auto audioScope = DependencyManager::set(); -// auto audioIOStatsRenderer = DependencyManager::set(); auto deferredLightingEffect = DependencyManager::set(); auto ambientOcclusionEffect = DependencyManager::set(); auto textureCache = DependencyManager::set(); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index ae7eb11e98..7702f915a3 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -581,20 +581,6 @@ Menu::Menu() { audioScopeFramesGroup->addAction(fiftyFrames); } -// auto statsRenderer = DependencyManager::get(); -// addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioStats, -// Qt::CTRL | Qt::SHIFT | Qt::Key_A, -// false, -// statsRenderer.data(), -// SLOT(toggle())); - -// addCheckableActionToQMenuAndActionHash(audioDebugMenu, MenuOption::AudioStatsShowInjectedStreams, -// 0, -// false, -// statsRenderer.data(), -// SLOT(toggleShowInjectedStreams())); -// - MenuWrapper* physicsOptionsMenu = developerMenu->addMenu("Physics"); addCheckableActionToQMenuAndActionHash(physicsOptionsMenu, MenuOption::PhysicsShowOwned); addCheckableActionToQMenuAndActionHash(physicsOptionsMenu, MenuOption::PhysicsShowHulls); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index bdfa146197..9c17a14937 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -23,7 +23,6 @@ #include #include "AudioClient.h" -//#include "audio/AudioIOStatsRenderer.h" #include "audio/AudioScope.h" #include "audio/AudioToolBox.h" #include "Application.h" @@ -935,7 +934,6 @@ void ApplicationOverlay::renderAudioMeter() { auto canvasSize = qApp->getCanvasSize(); DependencyManager::get()->render(canvasSize.x, canvasSize.y); - //DependencyManager::get()->render(WHITE_TEXT, canvasSize.x, canvasSize.y); audioMeterY += AUDIO_METER_HEIGHT; @@ -995,6 +993,8 @@ void ApplicationOverlay::renderAudioMeter() { void ApplicationOverlay::renderStatsAndLogs() { Application* application = Application::getInstance(); + SharedNodePointer audioMixerNodePointer = DependencyManager::get()->soloNodeOfType(NodeType::AudioMixer); + QSharedPointer bandwidthRecorder = DependencyManager::get(); const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor(); From 819fa852b8ca4e74606df37357f489cf9550f722 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 12:47:59 -0700 Subject: [PATCH 11/35] first pass at GlowEctomy --- interface/src/Application.cpp | 22 ++++++++-------- interface/src/Menu.cpp | 4 --- interface/src/Menu.h | 2 -- interface/src/avatar/Avatar.cpp | 7 +----- interface/src/avatar/AvatarManager.cpp | 1 - interface/src/devices/OculusManager.cpp | 25 ++++--------------- interface/src/devices/TV3DManager.cpp | 8 +++++- interface/src/ui/overlays/Cube3DOverlay.cpp | 1 - interface/src/ui/overlays/Line3DOverlay.cpp | 1 - .../src/ui/overlays/LocalModelsOverlay.cpp | 12 +-------- interface/src/ui/overlays/ModelOverlay.cpp | 2 -- .../src/ui/overlays/Rectangle3DOverlay.cpp | 1 - interface/src/ui/overlays/Sphere3DOverlay.cpp | 1 - .../src/EntityTreeRenderer.cpp | 1 - .../src/RenderableWebEntityItem.cpp | 2 -- .../src/AmbientOcclusionEffect.cpp | 5 ++-- libraries/render-utils/src/Model.cpp | 4 +-- tests/ui/src/main.cpp | 1 - 18 files changed, 28 insertions(+), 72 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index dec179d479..373610087b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -65,7 +65,6 @@ #include #include #include -#include #include #include #include @@ -99,6 +98,8 @@ #include #include +#include // FIXME + #include "Application.h" #include "AudioClient.h" #include "DiscoverabilityManager.h" @@ -269,7 +270,7 @@ bool setupEssentials(int& argc, char** argv) { auto geometryCache = DependencyManager::set(); auto scriptCache = DependencyManager::set(); auto soundCache = DependencyManager::set(); - auto glowEffect = DependencyManager::set(); + auto glowEffect = DependencyManager::set(); // FIXME auto faceshift = DependencyManager::set(); auto audio = DependencyManager::set(); auto audioScope = DependencyManager::set(); @@ -974,7 +975,10 @@ void Application::paintGL() { } else { PROFILE_RANGE(__FUNCTION__ "/mainRender"); - DependencyManager::get()->prepare(&renderArgs); + auto primaryFBO = DependencyManager::get()->getPrimaryFramebuffer(); + GLuint fbo = gpu::GLBackend::getFramebufferID(primaryFBO); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Viewport is assigned to the size of the framebuffer QSize size = DependencyManager::get()->getFrameBufferSize(); @@ -993,8 +997,7 @@ void Application::paintGL() { renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE; - auto finalFbo = DependencyManager::get()->render(&renderArgs); - + auto finalFbo = DependencyManager::get()->getPrimaryFramebuffer(); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo)); @@ -1002,6 +1005,8 @@ void Application::paintGL() { 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(), GL_COLOR_BUFFER_BIT, GL_LINEAR); glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); + + glBindTexture(GL_TEXTURE_2D, 0); // ??? _compositor.displayOverlayTexture(&renderArgs); } @@ -2230,10 +2235,6 @@ void Application::init() { _entityClipboardRenderer.setViewFrustum(getViewFrustum()); _entityClipboardRenderer.setTree(&_entityClipboard); - // initialize the GlowEffect with our widget - bool glow = Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect); - DependencyManager::get()->init(glow); - // Make sure any new sounds are loaded as soon as know about them. connect(tree, &EntityTree::newCollisionSoundURL, DependencyManager::get().data(), &SoundCache::getSound); connect(_myAvatar, &MyAvatar::newCollisionSoundURL, DependencyManager::get().data(), &SoundCache::getSound); @@ -3193,9 +3194,6 @@ QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { glClear(GL_COLOR_BUFFER_BIT); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); - // the "glow" here causes an alpha of one - Glower glower(renderArgs); - const int BILLBOARD_SIZE = 64; // TODO: Pass a RenderArgs to renderAvatarBillboard renderRearViewMirror(renderArgs, QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE, diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index f292ff2d2a..7fd1e81edc 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include @@ -246,7 +245,6 @@ Menu::Menu() { addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::ScriptedMotorControl, 0, true, avatar, SLOT(updateMotionBehavior())); addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::NamesAboveHeads, 0, true); - addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::GlowWhenSpeaking, 0, true); addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::BlueSpeechSphere, 0, true); addCheckableActionToQMenuAndActionHash(avatarMenu, MenuOption::EnableCharacterController, 0, true, avatar, SLOT(updateMotionBehavior())); @@ -385,8 +383,6 @@ Menu::Menu() { addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Stars, 0, // QML Qt::Key_Asterisk, true); - addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::EnableGlowEffect, 0, true, - DependencyManager::get().data(), SLOT(toggleGlowEffect(bool))); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Wireframe, Qt::ALT | Qt::Key_W, false); addActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::LodTools, diff --git a/interface/src/Menu.h b/interface/src/Menu.h index b9efef0159..01cbcaffac 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -185,7 +185,6 @@ namespace MenuOption { const QString EditEntitiesHelp = "Edit Entities Help..."; const QString Enable3DTVMode = "Enable 3DTV Mode"; const QString EnableCharacterController = "Enable avatar collisions"; - const QString EnableGlowEffect = "Enable Glow Effect"; const QString EnableVRMode = "Enable VR Mode"; const QString ExpandMyAvatarSimulateTiming = "Expand /myAvatar/simulation"; const QString ExpandMyAvatarTiming = "Expand /myAvatar"; @@ -199,7 +198,6 @@ namespace MenuOption { const QString FrameTimer = "Show Timer"; const QString Fullscreen = "Fullscreen"; const QString FullscreenMirror = "Fullscreen Mirror"; - const QString GlowWhenSpeaking = "Glow When Speaking"; const QString HMDTools = "HMD Tools"; const QString IncreaseAvatarSize = "Increase Avatar Size"; const QString IndependentMode = "Independent Mode"; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index b9acc84e1f..d0268fd936 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -410,9 +409,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo float GLOW_FROM_AVERAGE_LOUDNESS = ((this == DependencyManager::get()->getMyAvatar()) ? 0.0f : MAX_GLOW * getHeadData()->getAudioLoudness() / GLOW_MAX_LOUDNESS); - if (!Menu::getInstance()->isOptionChecked(MenuOption::GlowWhenSpeaking)) { - GLOW_FROM_AVERAGE_LOUDNESS = 0.0f; - } + GLOW_FROM_AVERAGE_LOUDNESS = 0.0f; float glowLevel = _moving && distanceToTarget > GLOW_DISTANCE && renderArgs->_renderMode == RenderArgs::NORMAL_RENDER_MODE ? 1.0f @@ -579,8 +576,6 @@ void Avatar::renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, bool fixupModelsInScene(); { - Glower glower(renderArgs, glowLevel); - if (_shouldRenderBillboard || !(_skeletonModel.isRenderable() && getHead()->getFaceModel().isRenderable())) { if (postLighting || renderArgs->_renderMode == RenderArgs::SHADOW_RENDER_MODE) { // render the billboard until both models are loaded diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 8e7a03685b..41d637eb38 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -25,7 +25,6 @@ #endif -#include #include #include #include diff --git a/interface/src/devices/OculusManager.cpp b/interface/src/devices/OculusManager.cpp index 7bab6f58b9..ec3eaa0c03 100644 --- a/interface/src/devices/OculusManager.cpp +++ b/interface/src/devices/OculusManager.cpp @@ -24,7 +24,6 @@ #include #include -#include #include #include #include @@ -644,15 +643,9 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const return; } - //Bind our framebuffer object. If we are rendering the glow effect, we let the glow effect shader take care of it - if (Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)) { - DependencyManager::get()->prepare(renderArgs); - } else { - auto primaryFBO = DependencyManager::get()->getPrimaryFramebuffer(); - glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFBO)); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - } - + auto primaryFBO = DependencyManager::get()->getPrimaryFramebuffer(); + glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFBO)); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -723,15 +716,8 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const glPopMatrix(); gpu::FramebufferPointer finalFbo; - //Bind the output texture from the glow shader. If glow effect is disabled, we just grab the texture - if (Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect)) { - //Full texture viewport for glow effect - glViewport(0, 0, _renderTargetSize.w, _renderTargetSize.h); - finalFbo = DependencyManager::get()->render(renderArgs); - } else { - finalFbo = DependencyManager::get()->getPrimaryFramebuffer(); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - } + finalFbo = DependencyManager::get()->getPrimaryFramebuffer(); + glBindFramebuffer(GL_FRAMEBUFFER, 0); glMatrixMode(GL_PROJECTION); glPopMatrix(); @@ -824,7 +810,6 @@ glm::quat OculusManager::getOrientation() { return toGlm(trackingState.HeadPose.ThePose.Orientation); } -//Used to set the size of the glow framebuffers QSize OculusManager::getRenderTargetSize() { QSize rv; rv.setWidth(_renderTargetSize.w); diff --git a/interface/src/devices/TV3DManager.cpp b/interface/src/devices/TV3DManager.cpp index e945b5e79a..e9b28a3777 100644 --- a/interface/src/devices/TV3DManager.cpp +++ b/interface/src/devices/TV3DManager.cpp @@ -14,7 +14,6 @@ #include #include -#include #include "gpu/GLBackend.h" #include "Application.h" @@ -82,6 +81,9 @@ void TV3DManager::configureCamera(Camera& whichCamera, int screenWidth, int scre } void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) { + +#ifdef THIS_CURRENTLY_BROKEN_WAITING_FOR_DISPLAY_PLUGINS + double nearZ = DEFAULT_NEAR_CLIP; // near clipping plane double farZ = DEFAULT_FAR_CLIP; // far clipping plane @@ -94,6 +96,7 @@ void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) { int portalH = deviceSize.height(); + // FIXME - glow effect is removed, 3D TV mode broken until we get display plugins working DependencyManager::get()->prepare(renderArgs); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -128,6 +131,7 @@ void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) { glPopMatrix(); glDisable(GL_SCISSOR_TEST); + // FIXME - glow effect is removed, 3D TV mode broken until we get display plugins working auto finalFbo = DependencyManager::get()->render(renderArgs); auto fboSize = finalFbo->getSize(); // Get the ACTUAL device size for the BLIT @@ -142,6 +146,8 @@ void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) { // reset the viewport to how we started glViewport(0, 0, deviceSize.width(), deviceSize.height()); + +#endif } void TV3DManager::overrideOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal, diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 433a55e231..3455ce2e51 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -12,7 +12,6 @@ #include "InterfaceConfig.h" #include -#include #include #include diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 0abc86d7ad..4e2763d260 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -11,7 +11,6 @@ // include this before QGLWidget, which includes an earlier version of OpenGL #include "InterfaceConfig.h" -#include #include #include diff --git a/interface/src/ui/overlays/LocalModelsOverlay.cpp b/interface/src/ui/overlays/LocalModelsOverlay.cpp index 6e0b53f0c2..06b27f8f22 100644 --- a/interface/src/ui/overlays/LocalModelsOverlay.cpp +++ b/interface/src/ui/overlays/LocalModelsOverlay.cpp @@ -9,8 +9,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include - #include "Application.h" #include "LocalModelsOverlay.h" @@ -32,11 +30,7 @@ void LocalModelsOverlay::update(float deltatime) { void LocalModelsOverlay::render(RenderArgs* args) { if (_visible) { - float glowLevel = getGlowLevel(); - Glower* glower = NULL; - if (glowLevel > 0.0f) { - glower = new Glower(glowLevel); - } + float glowLevel = getGlowLevel(); // FIXME, glowing removed for now auto batch = args ->_batch; Application* app = Application::getInstance(); @@ -47,10 +41,6 @@ void LocalModelsOverlay::render(RenderArgs* args) { _entityTreeRenderer->render(args); transform.setTranslation(oldTranslation); batch->setViewTransform(transform); - - if (glower) { - delete glower; - } } } diff --git a/interface/src/ui/overlays/ModelOverlay.cpp b/interface/src/ui/overlays/ModelOverlay.cpp index 4476518efe..5a399aef76 100644 --- a/interface/src/ui/overlays/ModelOverlay.cpp +++ b/interface/src/ui/overlays/ModelOverlay.cpp @@ -12,8 +12,6 @@ #include "ModelOverlay.h" #include -#include - ModelOverlay::ModelOverlay() : _model(), diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index dfe5a3ad74..0ab9174da8 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -14,7 +14,6 @@ #include "Rectangle3DOverlay.h" #include -#include #include Rectangle3DOverlay::Rectangle3DOverlay() : diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index 259fe98acf..8d751c73c5 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -11,7 +11,6 @@ // include this before QGLWidget, which includes an earlier version of OpenGL #include "InterfaceConfig.h" -#include #include #include "Sphere3DOverlay.h" diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 0abd5b21cb..43f3492091 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index cf602971c2..95147ef2b1 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -14,7 +14,6 @@ #include -#include #include #include #include @@ -169,7 +168,6 @@ void RenderableWebEntityItem::render(RenderArgs* args) { _webSurface->resize(QSize(dims.x, dims.y)); currentContext->makeCurrent(currentSurface); - Glower glow(0.0f); PerformanceTimer perfTimer("RenderableWebEntityItem::render"); Q_ASSERT(getType() == EntityTypes::Web); static const glm::vec2 texMin(0.0f), texMax(1.0f), topLeft(-0.5f), bottomRight(0.5f); diff --git a/libraries/render-utils/src/AmbientOcclusionEffect.cpp b/libraries/render-utils/src/AmbientOcclusionEffect.cpp index f58419ec6e..8a77d4090a 100644 --- a/libraries/render-utils/src/AmbientOcclusionEffect.cpp +++ b/libraries/render-utils/src/AmbientOcclusionEffect.cpp @@ -21,7 +21,6 @@ #include "AbstractViewStateInterface.h" #include "AmbientOcclusionEffect.h" -#include "GlowEffect.h" #include "ProgramObject.h" #include "RenderUtil.h" #include "TextureCache.h" @@ -107,7 +106,7 @@ void AmbientOcclusionEffect::render() { glBindTexture(GL_TEXTURE_2D, _rotationTextureID); // render with the occlusion shader to the secondary/tertiary buffer - auto freeFramebuffer = DependencyManager::get()->getFreeFramebuffer(); + auto freeFramebuffer = nullptr; // DependencyManager::get()->getFreeFramebuffer(); // FIXME glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(freeFramebuffer)); float left, right, bottom, top, nearVal, farVal; @@ -150,7 +149,7 @@ void AmbientOcclusionEffect::render() { glEnable(GL_BLEND); glBlendFuncSeparate(GL_ZERO, GL_SRC_COLOR, GL_ZERO, GL_ONE); - auto freeFramebufferTexture = freeFramebuffer->getRenderBuffer(0); + auto freeFramebufferTexture = nullptr; // freeFramebuffer->getRenderBuffer(0); // FIXME glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(freeFramebufferTexture)); _blurProgram->bind(); diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 539dd02a78..6385041959 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -32,7 +32,6 @@ #include "AbstractViewStateInterface.h" #include "AnimationHandle.h" #include "DeferredLightingEffect.h" -#include "GlowEffect.h" #include "Model.h" #include "RenderUtilsLogging.h" @@ -2215,7 +2214,8 @@ void Model::pickPrograms(gpu::Batch& batch, RenderMode mode, bool translucent, f } if ((locations->glowIntensity > -1) && (mode != RenderArgs::SHADOW_RENDER_MODE)) { - GLBATCH(glUniform1f)(locations->glowIntensity, DependencyManager::get()->getIntensity()); + const float DEFAULT_GLOW_INTENSITY = 1.0f; // FIXME - glow is removed + GLBATCH(glUniform1f)(locations->glowIntensity, DEFAULT_GLOW_INTENSITY); } } diff --git a/tests/ui/src/main.cpp b/tests/ui/src/main.cpp index 1b0c7e0ab1..f5647bd176 100644 --- a/tests/ui/src/main.cpp +++ b/tests/ui/src/main.cpp @@ -131,7 +131,6 @@ public: EditEntitiesHelp, Enable3DTVMode, EnableCharacterController, - EnableGlowEffect, EnableVRMode, ExpandMyAvatarSimulateTiming, ExpandMyAvatarTiming, From c17794849d76fdb171b575448be12a4f60bfd9ae Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 12:58:15 -0700 Subject: [PATCH 12/35] more GlowEctomy --- interface/src/Application.cpp | 3 - .../src/DeferredLightingEffect.cpp | 5 +- libraries/render-utils/src/GlowEffect.cpp | 225 ------------------ libraries/render-utils/src/GlowEffect.h | 97 -------- 4 files changed, 2 insertions(+), 328 deletions(-) delete mode 100644 libraries/render-utils/src/GlowEffect.cpp delete mode 100644 libraries/render-utils/src/GlowEffect.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 373610087b..b85297c3cf 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -98,8 +98,6 @@ #include #include -#include // FIXME - #include "Application.h" #include "AudioClient.h" #include "DiscoverabilityManager.h" @@ -270,7 +268,6 @@ bool setupEssentials(int& argc, char** argv) { auto geometryCache = DependencyManager::set(); auto scriptCache = DependencyManager::set(); auto soundCache = DependencyManager::set(); - auto glowEffect = DependencyManager::set(); // FIXME auto faceshift = DependencyManager::set(); auto audio = DependencyManager::set(); auto audioScope = DependencyManager::set(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index b2db089bbe..4737929cf6 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -18,7 +18,6 @@ #include "AbstractViewStateInterface.h" #include "DeferredLightingEffect.h" #include "GeometryCache.h" -#include "GlowEffect.h" #include "RenderUtil.h" #include "TextureCache.h" @@ -238,7 +237,7 @@ void DeferredLightingEffect::render(RenderArgs* args) { QSize framebufferSize = textureCache->getFrameBufferSize(); // binding the first framebuffer - auto freeFBO = DependencyManager::get()->getFreeFramebuffer(); + auto freeFBO = DependencyManager::get()->getSecondaryFramebuffer(); batch.setFramebuffer(freeFBO); batch.clearColorFramebuffer(freeFBO->getBufferMask(), glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); @@ -547,7 +546,7 @@ void DeferredLightingEffect::copyBack(RenderArgs* args) { auto textureCache = DependencyManager::get(); QSize framebufferSize = textureCache->getFrameBufferSize(); - auto freeFBO = DependencyManager::get()->getFreeFramebuffer(); + auto freeFBO = DependencyManager::get()->getSecondaryFramebuffer(); batch.setFramebuffer(textureCache->getPrimaryFramebuffer()); batch.setPipeline(_blitLightBuffer); diff --git a/libraries/render-utils/src/GlowEffect.cpp b/libraries/render-utils/src/GlowEffect.cpp deleted file mode 100644 index 2e8b58c6c2..0000000000 --- a/libraries/render-utils/src/GlowEffect.cpp +++ /dev/null @@ -1,225 +0,0 @@ -// -// GlowEffect.cpp -// interface/src/renderer -// -// Created by Andrzej Kapolka on 8/7/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL -#include - -#include -#include - -#include -#include - -#include "GlowEffect.h" -#include "ProgramObject.h" -#include "RenderUtil.h" -#include "TextureCache.h" -#include "RenderUtilsLogging.h" - -#include "gpu/GLBackend.h" - -GlowEffect::GlowEffect() - : _initialized(false), - _isOddFrame(false), - _isFirstFrame(true), - _intensity(0.0f), - _enabled(false) { -} - -GlowEffect::~GlowEffect() { - if (_initialized) { - delete _addProgram; - delete _horizontalBlurProgram; - delete _verticalBlurAddProgram; - delete _verticalBlurProgram; - delete _addSeparateProgram; - delete _diffuseProgram; - } -} - -gpu::FramebufferPointer GlowEffect::getFreeFramebuffer() const { - return (_isOddFrame ? - DependencyManager::get()->getSecondaryFramebuffer(): - DependencyManager::get()->getTertiaryFramebuffer()); -} - -static ProgramObject* createProgram(const QString& name) { - ProgramObject* program = new ProgramObject(); - program->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/" + name + ".frag"); - program->link(); - - program->bind(); - program->setUniformValue("originalTexture", 0); - program->release(); - - return program; -} - -void GlowEffect::init(bool enabled) { - if (_initialized) { - qCDebug(renderutils, "[ERROR] GlowEffeect is already initialized."); - return; - } - - _addProgram = createProgram("glow_add"); - _horizontalBlurProgram = createProgram("horizontal_blur"); - _verticalBlurAddProgram = createProgram("vertical_blur_add"); - _verticalBlurProgram = createProgram("vertical_blur"); - _addSeparateProgram = createProgram("glow_add_separate"); - _diffuseProgram = createProgram("diffuse"); - - _verticalBlurAddProgram->bind(); - _verticalBlurAddProgram->setUniformValue("horizontallyBlurredTexture", 1); - _verticalBlurAddProgram->release(); - - _addSeparateProgram->bind(); - _addSeparateProgram->setUniformValue("blurredTexture", 1); - _addSeparateProgram->release(); - - _diffuseProgram->bind(); - _diffuseProgram->setUniformValue("diffusedTexture", 1); - _diffuseProgram->release(); - - _diffusionScaleLocation = _diffuseProgram->uniformLocation("diffusionScale"); - - _initialized = true; - _enabled = enabled; -} - -void GlowEffect::prepare(RenderArgs* renderArgs) { - auto primaryFBO = DependencyManager::get()->getPrimaryFramebuffer(); - GLuint fbo = gpu::GLBackend::getFramebufferID(primaryFBO); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - _isEmpty = true; - _isOddFrame = !_isOddFrame; -} - -void GlowEffect::begin(RenderArgs* renderArgs, float intensity) { - // store the current intensity and add the new amount - _intensityStack.push(_intensity); - glBlendColor(0.0f, 0.0f, 0.0f, _intensity += intensity); - _isEmpty &= (_intensity == 0.0f); -} - -void GlowEffect::end(RenderArgs* renderArgs) { - // restore the saved intensity - glBlendColor(0.0f, 0.0f, 0.0f, _intensity = _intensityStack.pop()); -} - -gpu::FramebufferPointer GlowEffect::render(RenderArgs* renderArgs) { - PerformanceTimer perfTimer("glowEffect"); - - auto textureCache = DependencyManager::get(); - - auto primaryFBO = gpu::GLBackend::getFramebufferID(textureCache->getPrimaryFramebuffer()); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - glBindTexture(GL_TEXTURE_2D, textureCache->getPrimaryColorTextureID()); - auto framebufferSize = textureCache->getFrameBufferSize(); - - glPushMatrix(); - glLoadIdentity(); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - - glDisable(GL_BLEND); - glDisable(GL_DEPTH_TEST); - glDepthMask(GL_FALSE); - - gpu::FramebufferPointer destFBO = textureCache->getSecondaryFramebuffer(); - if (!_enabled || _isEmpty) { - // copy the primary to the screen - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(destFBO)); - glBindFramebuffer(GL_READ_FRAMEBUFFER, primaryFBO); - glBlitFramebuffer( - 0, 0, framebufferSize.width(), framebufferSize.height(), - 0, 0, framebufferSize.width(), framebufferSize.height(), - GL_COLOR_BUFFER_BIT, GL_NEAREST); - } else { - // diffuse into the secondary/tertiary (alternating between frames) - auto oldDiffusedFBO = - textureCache->getSecondaryFramebuffer(); - auto newDiffusedFBO = - textureCache->getTertiaryFramebuffer(); - if (_isOddFrame) { - qSwap(oldDiffusedFBO, newDiffusedFBO); - } - glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(newDiffusedFBO)); - - if (_isFirstFrame) { - glClear(GL_COLOR_BUFFER_BIT); - - } else { - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(oldDiffusedFBO->getRenderBuffer(0))); - - _diffuseProgram->bind(); - - _diffuseProgram->setUniformValue(_diffusionScaleLocation, 1.0f / framebufferSize.width(), 1.0f / framebufferSize.height()); - - renderFullscreenQuad(); - - _diffuseProgram->release(); - } - - destFBO = oldDiffusedFBO; - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - // add diffused texture to the primary - glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(newDiffusedFBO->getRenderBuffer(0))); - - glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(destFBO)); - glViewport(0, 0, framebufferSize.width(), framebufferSize.height()); - _addSeparateProgram->bind(); - renderFullscreenQuad(); - _addSeparateProgram->release(); - glBindFramebuffer(GL_FRAMEBUFFER, 0); - - glBindTexture(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE0); - } - - glPopMatrix(); - - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - - glEnable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - glDepthMask(GL_TRUE); - glBindTexture(GL_TEXTURE_2D, 0); - - _isFirstFrame = false; - - return destFBO; -} - -void GlowEffect::toggleGlowEffect(bool enabled) { - _enabled = enabled; -} - -Glower::Glower(float amount) { - RenderArgs renderArgs; - DependencyManager::get()->begin(&renderArgs, amount); -} -Glower::Glower(RenderArgs* renderArgs, float amount) : _renderArgs(renderArgs) { - DependencyManager::get()->begin(_renderArgs, amount); -} - -Glower::~Glower() { - DependencyManager::get()->end(_renderArgs); -} - diff --git a/libraries/render-utils/src/GlowEffect.h b/libraries/render-utils/src/GlowEffect.h deleted file mode 100644 index 23a21a9575..0000000000 --- a/libraries/render-utils/src/GlowEffect.h +++ /dev/null @@ -1,97 +0,0 @@ -// -// GlowEffect.h -// interface/src/renderer -// -// Created by Andrzej Kapolka on 8/7/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_GlowEffect_h -#define hifi_GlowEffect_h - -#include -#include - -#include "RenderArgs.h" - -#include -#include -#include - -#include - -class ProgramObject; - -/// A generic full screen glow effect. -class GlowEffect : public QObject, public Dependency { - Q_OBJECT - SINGLETON_DEPENDENCY - -public: - - /// Returns a pointer to the framebuffer object that the glow effect is *not* using for persistent state - /// (either the secondary or the tertiary). - gpu::FramebufferPointer getFreeFramebuffer() const; - - void init(bool enabled); - - /// Prepares the glow effect for rendering the current frame. To be called before rendering the scene. - void prepare(RenderArgs* renderArgs); - - /// Starts using the glow effect. - /// \param intensity the desired glow intensity, from zero to one - void begin(RenderArgs* renderArgs, float intensity = 1.0f); - - /// Stops using the glow effect. - void end(RenderArgs* renderArgs); - - /// Returns the current glow intensity. - float getIntensity() const { return _intensity; } - - /// Renders the glow effect. To be called after rendering the scene. - /// \param toTexture whether to render to a texture, rather than to the frame buffer - /// \return the framebuffer object to which we rendered, or NULL if to the frame buffer - gpu::FramebufferPointer render(RenderArgs* renderArgs); - -public slots: - void toggleGlowEffect(bool enabled); - -private: - GlowEffect(); - virtual ~GlowEffect(); - - bool _initialized; - - ProgramObject* _addProgram; - ProgramObject* _horizontalBlurProgram; - ProgramObject* _verticalBlurAddProgram; - ProgramObject* _verticalBlurProgram; - ProgramObject* _addSeparateProgram; - ProgramObject* _diffuseProgram; - int _diffusionScaleLocation; - - bool _isEmpty; ///< set when nothing in the scene is currently glowing - bool _isOddFrame; ///< controls the alternation between texture targets in diffuse add mode - bool _isFirstFrame; ///< for persistent modes, notes whether this is the first frame rendered - - float _intensity; - QStack _intensityStack; - bool _enabled; -}; - -/// RAII-style glow handler. Applies glow when in scope. -class Glower { -public: - - Glower(float amount = 1.0f); - Glower(RenderArgs* renderArgs, float amount = 1.0f); - ~Glower(); - -private: - RenderArgs* _renderArgs; -}; - -#endif // hifi_GlowEffect_h From ff288fdd5d287118abafe5b528ce9777d2062f89 Mon Sep 17 00:00:00 2001 From: Chris Collins Date: Wed, 15 Jul 2015 13:09:55 -0700 Subject: [PATCH 13/35] While we work on FPS I have decreased the default LOD FPS While we work on FPS I have decreased the default LOD FPS. In a new users preferences this will now show as 15 desktop and 30 HMD. --- interface/src/LODManager.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h index 98ababbda0..b0185b528f 100644 --- a/interface/src/LODManager.h +++ b/interface/src/LODManager.h @@ -17,8 +17,8 @@ #include #include -const float DEFAULT_DESKTOP_LOD_DOWN_FPS = 30.0; -const float DEFAULT_HMD_LOD_DOWN_FPS = 60.0; +const float DEFAULT_DESKTOP_LOD_DOWN_FPS = 15.0; +const float DEFAULT_HMD_LOD_DOWN_FPS = 30.0; const float MAX_LIKELY_DESKTOP_FPS = 59.0; // this is essentially, V-synch - 1 fps const float MAX_LIKELY_HMD_FPS = 74.0; // this is essentially, V-synch - 1 fps const float INCREASE_LOD_GAP = 15.0f; From 849b584596c095e25c56c6d49fea90302a8cf939 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 13:16:38 -0700 Subject: [PATCH 14/35] more GlowEctomy --- interface/src/Menu.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 7fd1e81edc..8b14830c2d 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -9,6 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +// include this before QGLWidget, which includes an earlier version of OpenGL +#include "InterfaceConfig.h" + #include #include #include From a444d6a2a26abef25959b2f392ee3e280f03028f Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 15 Jul 2015 13:19:59 -0700 Subject: [PATCH 15/35] 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 16/35] 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 17/35] 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 18/35] 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 19/35] 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 20/35] 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 21/35] 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 22/35] 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 c159068701dd4548e9b16cb012112464b585c382 Mon Sep 17 00:00:00 2001 From: bwent Date: Wed, 15 Jul 2015 16:10:41 -0700 Subject: [PATCH 23/35] Make pointers member variables --- interface/src/ui/AudioStatsDialog.cpp | 117 ++++++++++++-------------- interface/src/ui/AudioStatsDialog.h | 12 +-- 2 files changed, 62 insertions(+), 67 deletions(-) diff --git a/interface/src/ui/AudioStatsDialog.cpp b/interface/src/ui/AudioStatsDialog.cpp index 9ee8716321..4eeae76229 100644 --- a/interface/src/ui/AudioStatsDialog.cpp +++ b/interface/src/ui/AudioStatsDialog.cpp @@ -61,54 +61,54 @@ AudioStatsDialog::AudioStatsDialog(QWidget* parent) : _shouldShowInjectedStreams = false; - this->setWindowTitle("Audio Network Statistics"); + setWindowTitle("Audio Network Statistics"); // Get statistics from the Audio Client _stats = &DependencyManager::get()->getStats(); // Create layouter _form = new QFormLayout(); - this->QDialog::setLayout(_form); + QDialog::setLayout(_form); - // Initialize vectors for stat channels - _audioMixerStats = new QVector(); - _upstreamClientStats = new QVector(); - _upstreamMixerStats = new QVector(); - _downstreamStats = new QVector(); - _upstreamInjectedStats = new QVector(); +// // Initialize vectors for stat channels +// _audioMixerStats = *new QVector(); +// _upstreamClientStats = *new QVector(); +// _upstreamMixerStats = *new QVector(); +// _downstreamStats = *new QVector(); +// _upstreamInjectedStats = *new QVector(); // Load and initilize - this->renderStats(); + renderStats(); - this->initializeChannel(_form, 0, _audioMixerStats, COLOR0); - this->initializeChannel(_form, 1, _upstreamClientStats, COLOR1); - this->initializeChannel(_form, 2, _upstreamMixerStats, COLOR2); - this->initializeChannel(_form, 3, _downstreamStats, COLOR3); - this->initializeChannel(_form, 4, _upstreamInjectedStats, COLOR0); + initializeChannel(_form, 0, &_audioMixerStats, COLOR0); + initializeChannel(_form, 1, &_upstreamClientStats, COLOR1); + initializeChannel(_form, 2, &_upstreamMixerStats, COLOR2); + initializeChannel(_form, 3, &_downstreamStats, COLOR3); + initializeChannel(_form, 4, &_upstreamInjectedStats, COLOR0); } void AudioStatsDialog::initializeChannel(QFormLayout* form, const unsigned int index, QVector *stats, const unsigned color) { - _audioDisplayChannels[index] = new QVector(); +// _audioDisplayChannels[index] = new QVector(); for (int i = 0; i < stats->size(); i++) // Create new display label - _audioDisplayChannels[index]->push_back(new AudioStatsDisplay(form, stats->at(i), color)); + _audioDisplayChannels[index].push_back(new AudioStatsDisplay(form, stats->at(i), color)); } void AudioStatsDialog::updateStats(const unsigned int index, QVector* stats) { // Update all stat displays at specified channel for (int i = 0; i < stats->size(); i++) - _audioDisplayChannels[index]->at(i)->updatedDisplay(stats->at(i)); + _audioDisplayChannels[index].at(i)->updatedDisplay(stats->at(i)); } void AudioStatsDialog::renderStats() { // Clear current stats from all vectors - this->clearAllChannels(); + clearAllChannels(); double audioInputBufferLatency = 0.0, inputRingBufferLatency = 0.0, @@ -132,51 +132,51 @@ void AudioStatsDialog::renderStats() { double totalLatency = audioInputBufferLatency + inputRingBufferLatency + networkRoundtripLatency + mixerRingBufferLatency + outputRingBufferLatency + audioOutputBufferLatency; - _audioMixerStats->push_back(QString("Audio input buffer: %1ms").arg( + _audioMixerStats.push_back(QString("Audio input buffer: %1ms").arg( QString::number(audioInputBufferLatency, 'f', 2)) + QString(" - avg msecs of samples read to the audio input buffer in last 10s")); - _audioMixerStats->push_back(QString("Input ring buffer: %1ms").arg( + _audioMixerStats.push_back(QString("Input ring buffer: %1ms").arg( QString::number(inputRingBufferLatency, 'f', 2)) + QString(" - avg msecs of samples read to the input ring buffer in last 10s")); - _audioMixerStats->push_back(QString("Network to mixer: %1ms").arg( + _audioMixerStats.push_back(QString("Network to mixer: %1ms").arg( QString::number((networkRoundtripLatency / 2.0), 'f', 2)) + QString(" - half of last ping value calculated by the node list")); - _audioMixerStats->push_back(QString("Network to client: %1ms").arg( + _audioMixerStats.push_back(QString("Network to client: %1ms").arg( QString::number((mixerRingBufferLatency / 2.0),'f', 2)) + QString(" - half of last ping value calculated by the node list")); - _audioMixerStats->push_back(QString("Output ring buffer: %1ms").arg( + _audioMixerStats.push_back(QString("Output ring buffer: %1ms").arg( QString::number(outputRingBufferLatency,'f', 2)) + QString(" - avg msecs of samples in output ring buffer in last 10s")); - _audioMixerStats->push_back(QString("Audio output buffer: %1ms").arg( + _audioMixerStats.push_back(QString("Audio output buffer: %1ms").arg( QString::number(mixerRingBufferLatency,'f', 2)) + QString(" - avg msecs of samples in audio output buffer in last 10s")); - _audioMixerStats->push_back(QString("TOTAL: %1ms").arg( + _audioMixerStats.push_back(QString("TOTAL: %1ms").arg( QString::number(totalLatency, 'f', 2)) +QString(" - avg msecs of samples in audio output buffer in last 10s")); const MovingMinMaxAvg& packetSentTimeGaps = _stats->getPacketSentTimeGaps(); - _upstreamClientStats->push_back( + _upstreamClientStats.push_back( QString("\nUpstream Mic Audio Packets Sent Gaps (by client):")); - _upstreamClientStats->push_back( + _upstreamClientStats.push_back( QString("Inter-packet timegaps (overall) | min: %1, max: %2, avg: %3").arg(formatUsecTime(packetSentTimeGaps.getMin()).toLatin1().data()).arg(formatUsecTime( packetSentTimeGaps.getMax()).toLatin1().data()).arg(formatUsecTime( packetSentTimeGaps.getAverage()).toLatin1().data())); - _upstreamClientStats->push_back( + _upstreamClientStats.push_back( QString("Inter-packet timegaps (last 30s) | min: %1, max: %2, avg: %3").arg(formatUsecTime(packetSentTimeGaps.getWindowMin()).toLatin1().data()).arg(formatUsecTime(packetSentTimeGaps.getWindowMax()).toLatin1().data()).arg(formatUsecTime(packetSentTimeGaps.getWindowAverage()).toLatin1().data())); - _upstreamMixerStats->push_back(QString("\nUpstream mic audio stats (received and reported by audio-mixer):")); + _upstreamMixerStats.push_back(QString("\nUpstream mic audio stats (received and reported by audio-mixer):")); - renderAudioStreamStats(&_stats->getMixerAvatarStreamStats(), _upstreamMixerStats, true); + renderAudioStreamStats(&_stats->getMixerAvatarStreamStats(), &_upstreamMixerStats, true); - _downstreamStats->push_back(QString("\nDownstream mixed audio stats:")); + _downstreamStats.push_back(QString("\nDownstream mixed audio stats:")); AudioStreamStats downstreamStats = _stats->getMixerDownstreamStats(); - renderAudioStreamStats(&downstreamStats, _downstreamStats, true); + renderAudioStreamStats(&downstreamStats, &_downstreamStats, true); if (_shouldShowInjectedStreams) { foreach(const AudioStreamStats& injectedStreamAudioStats, _stats->getMixerInjectedStreamStatsMap()) { - _upstreamInjectedStats->push_back(QString("\nUpstream injected audio stats: stream ID: %1").arg( injectedStreamAudioStats._streamIdentifier.toString().toLatin1().data())); + _upstreamInjectedStats.push_back(QString("\nUpstream injected audio stats: stream ID: %1").arg( injectedStreamAudioStats._streamIdentifier.toString().toLatin1().data())); - renderAudioStreamStats(&injectedStreamAudioStats, _upstreamInjectedStats, true); + renderAudioStreamStats(&injectedStreamAudioStats, &_upstreamInjectedStats, true); } } @@ -211,24 +211,24 @@ void AudioStatsDialog::renderAudioStreamStats(const AudioStreamStats* streamStat } void AudioStatsDialog::clearAllChannels() { - _audioMixerStats->clear(); - _upstreamClientStats->clear(); - _upstreamMixerStats->clear(); - _downstreamStats->clear(); - _upstreamInjectedStats->clear(); + _audioMixerStats.clear(); + _upstreamClientStats.clear(); + _upstreamMixerStats.clear(); + _downstreamStats.clear(); + _upstreamInjectedStats.clear(); } void AudioStatsDialog::updateTimerTimeout() { // Update all audio stats - this->renderStats(); + renderStats(); - this->updateStats(0, _audioMixerStats); - this->updateStats(1, _upstreamClientStats); - this->updateStats(2, _upstreamMixerStats); - this->updateStats(3, _downstreamStats); - this->updateStats(4, _upstreamInjectedStats); + updateStats(0, &_audioMixerStats); + updateStats(1, &_upstreamClientStats); + updateStats(2, &_upstreamMixerStats); + updateStats(3, &_downstreamStats); + updateStats(4, &_upstreamInjectedStats); } @@ -237,37 +237,32 @@ void AudioStatsDialog::paintEvent(QPaintEvent* event) { // Repaint each statistic in each section for (int i = 0; i < DISPLAY_CHANNELS; i++) { - for(int j = 0; j < _audioDisplayChannels[i]->size(); j++) { - _audioDisplayChannels[i]->at(j)->paint(); + for(int j = 0; j < _audioDisplayChannels[i].size(); j++) { + _audioDisplayChannels[i].at(j)->paint(); } } - this->QDialog::paintEvent(event); - this->setFixedSize(this->width(), this->height()); + QDialog::paintEvent(event); + setFixedSize(width(), height()); } void AudioStatsDialog::reject() { // Just regularly close upon ESC - this->QDialog::close(); + QDialog::close(); } void AudioStatsDialog::closeEvent(QCloseEvent* event) { - this->QDialog::closeEvent(event); + QDialog::closeEvent(event); emit closed(); } AudioStatsDialog::~AudioStatsDialog() { - this->clearAllChannels(); - - delete _audioMixerStats; - delete _upstreamClientStats; - delete _upstreamMixerStats; - delete _downstreamStats; - delete _upstreamInjectedStats; + clearAllChannels(); + for (int i = 0; i < DISPLAY_CHANNELS; i++) { - _audioDisplayChannels[i]->clear(); - for(int j = 0; j < _audioDisplayChannels[i]->size(); j++) { - delete _audioDisplayChannels[i]->at(j); + _audioDisplayChannels[i].clear(); + for(int j = 0; j < _audioDisplayChannels[i].size(); j++) { + delete _audioDisplayChannels[i].at(j); } } diff --git a/interface/src/ui/AudioStatsDialog.h b/interface/src/ui/AudioStatsDialog.h index ce1e8027e3..2f4fb44fbc 100644 --- a/interface/src/ui/AudioStatsDialog.h +++ b/interface/src/ui/AudioStatsDialog.h @@ -56,11 +56,11 @@ public: private: // audio stats methods for rendering - QVector *_audioMixerStats; - QVector *_upstreamClientStats; - QVector *_upstreamMixerStats; - QVector *_downstreamStats; - QVector *_upstreamInjectedStats; + QVector _audioMixerStats; + QVector _upstreamClientStats; + QVector _upstreamMixerStats; + QVector _downstreamStats; + QVector _upstreamInjectedStats; void initializeChannel(QFormLayout* form, const unsigned int index, QVector* stats, const unsigned color); void updateStats(const unsigned index, QVector* stats); @@ -69,7 +69,7 @@ private: void renderAudioStreamStats(const AudioStreamStats* streamStats, QVector* audioStreamstats, bool isDownstreamStats); const static int DISPLAY_CHANNELS = 5; - QVector *_audioDisplayChannels[DISPLAY_CHANNELS]; + QVector _audioDisplayChannels[DISPLAY_CHANNELS]; const AudioIOStats* _stats; QFormLayout* _form; From d5a6e87a029c2ce9c2d621b0b9e0e96b89a4a86f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 15 Jul 2015 16:34:23 -0700 Subject: [PATCH 24/35] 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 25/35] 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 0654bb5e3650ec61c5d9512f9f2a8b0109c74f8d Mon Sep 17 00:00:00 2001 From: bwent Date: Wed, 15 Jul 2015 16:40:55 -0700 Subject: [PATCH 26/35] Pass by reference into initialize and update function, remove dead code --- interface/src/ui/AudioStatsDialog.cpp | 41 +++++++++++---------------- interface/src/ui/AudioStatsDialog.h | 4 +-- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/interface/src/ui/AudioStatsDialog.cpp b/interface/src/ui/AudioStatsDialog.cpp index 4eeae76229..abe84a31a9 100644 --- a/interface/src/ui/AudioStatsDialog.cpp +++ b/interface/src/ui/AudioStatsDialog.cpp @@ -70,38 +70,29 @@ AudioStatsDialog::AudioStatsDialog(QWidget* parent) : _form = new QFormLayout(); QDialog::setLayout(_form); -// // Initialize vectors for stat channels -// _audioMixerStats = *new QVector(); -// _upstreamClientStats = *new QVector(); -// _upstreamMixerStats = *new QVector(); -// _downstreamStats = *new QVector(); -// _upstreamInjectedStats = *new QVector(); - // Load and initilize renderStats(); - initializeChannel(_form, 0, &_audioMixerStats, COLOR0); - initializeChannel(_form, 1, &_upstreamClientStats, COLOR1); - initializeChannel(_form, 2, &_upstreamMixerStats, COLOR2); - initializeChannel(_form, 3, &_downstreamStats, COLOR3); - initializeChannel(_form, 4, &_upstreamInjectedStats, COLOR0); + initializeChannel(_form, 0, _audioMixerStats, COLOR0); + initializeChannel(_form, 1, _upstreamClientStats, COLOR1); + initializeChannel(_form, 2, _upstreamMixerStats, COLOR2); + initializeChannel(_form, 3, _downstreamStats, COLOR3); + initializeChannel(_form, 4, _upstreamInjectedStats, COLOR0); } -void AudioStatsDialog::initializeChannel(QFormLayout* form, const unsigned int index, QVector *stats, const unsigned color) { +void AudioStatsDialog::initializeChannel(QFormLayout* form, const unsigned int index, QVector& stats, const unsigned color) { -// _audioDisplayChannels[index] = new QVector(); - - for (int i = 0; i < stats->size(); i++) + for (int i = 0; i < stats.size(); i++) // Create new display label - _audioDisplayChannels[index].push_back(new AudioStatsDisplay(form, stats->at(i), color)); + _audioDisplayChannels[index].push_back(new AudioStatsDisplay(form, stats.at(i), color)); } -void AudioStatsDialog::updateStats(const unsigned int index, QVector* stats) { +void AudioStatsDialog::updateStats(const unsigned int index, QVector& stats) { // Update all stat displays at specified channel - for (int i = 0; i < stats->size(); i++) - _audioDisplayChannels[index].at(i)->updatedDisplay(stats->at(i)); + for (int i = 0; i < stats.size(); i++) + _audioDisplayChannels[index].at(i)->updatedDisplay(stats.at(i)); } @@ -224,11 +215,11 @@ void AudioStatsDialog::updateTimerTimeout() { // Update all audio stats renderStats(); - updateStats(0, &_audioMixerStats); - updateStats(1, &_upstreamClientStats); - updateStats(2, &_upstreamMixerStats); - updateStats(3, &_downstreamStats); - updateStats(4, &_upstreamInjectedStats); + updateStats(0, _audioMixerStats); + updateStats(1, _upstreamClientStats); + updateStats(2, _upstreamMixerStats); + updateStats(3, _downstreamStats); + updateStats(4, _upstreamInjectedStats); } diff --git a/interface/src/ui/AudioStatsDialog.h b/interface/src/ui/AudioStatsDialog.h index 2f4fb44fbc..537a91726f 100644 --- a/interface/src/ui/AudioStatsDialog.h +++ b/interface/src/ui/AudioStatsDialog.h @@ -62,8 +62,8 @@ private: QVector _downstreamStats; QVector _upstreamInjectedStats; - void initializeChannel(QFormLayout* form, const unsigned int index, QVector* stats, const unsigned color); - void updateStats(const unsigned index, QVector* stats); + void initializeChannel(QFormLayout* form, const unsigned int index, QVector& stats, const unsigned color); + void updateStats(const unsigned index, QVector& stats); void renderStats(); void clearAllChannels(); void renderAudioStreamStats(const AudioStreamStats* streamStats, QVector* audioStreamstats, bool isDownstreamStats); From 4c70c197e66c668b2d70f39308b70e6840059d28 Mon Sep 17 00:00:00 2001 From: bwent Date: Wed, 15 Jul 2015 17:19:57 -0700 Subject: [PATCH 27/35] keep track of channel index with global variable --- interface/src/ui/AudioStatsDialog.cpp | 49 +++++++++++++++++---------- interface/src/ui/AudioStatsDialog.h | 5 +-- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/interface/src/ui/AudioStatsDialog.cpp b/interface/src/ui/AudioStatsDialog.cpp index abe84a31a9..3761d619fc 100644 --- a/interface/src/ui/AudioStatsDialog.cpp +++ b/interface/src/ui/AudioStatsDialog.cpp @@ -73,26 +73,37 @@ AudioStatsDialog::AudioStatsDialog(QWidget* parent) : // Load and initilize renderStats(); - initializeChannel(_form, 0, _audioMixerStats, COLOR0); - initializeChannel(_form, 1, _upstreamClientStats, COLOR1); - initializeChannel(_form, 2, _upstreamMixerStats, COLOR2); - initializeChannel(_form, 3, _downstreamStats, COLOR3); - initializeChannel(_form, 4, _upstreamInjectedStats, COLOR0); + _channelIndex = 0; + + addChannel(_form, _audioMixerStats, COLOR0); + addChannel(_form, _upstreamClientStats, COLOR1); + addChannel(_form, _upstreamMixerStats, COLOR2); + addChannel(_form, _downstreamStats, COLOR3); + addChannel(_form, _upstreamInjectedStats, COLOR0); } -void AudioStatsDialog::initializeChannel(QFormLayout* form, const unsigned int index, QVector& stats, const unsigned color) { +void AudioStatsDialog::addChannel(QFormLayout* form, QVector& stats, const unsigned color) { - for (int i = 0; i < stats.size(); i++) - // Create new display label - _audioDisplayChannels[index].push_back(new AudioStatsDisplay(form, stats.at(i), color)); + if(_channelIndex < DISPLAY_CHANNELS) { + for (int i = 0; i < stats.size(); i++) + // Create new display label + _audioDisplayChannels[_channelIndex].push_back(new AudioStatsDisplay(form, stats.at(i), color)); + + _channelIndex++; + } } -void AudioStatsDialog::updateStats(const unsigned int index, QVector& stats) { - // Update all stat displays at specified channel - for (int i = 0; i < stats.size(); i++) - _audioDisplayChannels[index].at(i)->updatedDisplay(stats.at(i)); +void AudioStatsDialog::updateStats(QVector& stats) { + + if(_channelIndex < DISPLAY_CHANNELS) { + // Update all stat displays at specified channel + for (int i = 0; i < stats.size(); i++) + _audioDisplayChannels[_channelIndex].at(i)->updatedDisplay(stats.at(i)); + + _channelIndex++; + } } @@ -215,11 +226,13 @@ void AudioStatsDialog::updateTimerTimeout() { // Update all audio stats renderStats(); - updateStats(0, _audioMixerStats); - updateStats(1, _upstreamClientStats); - updateStats(2, _upstreamMixerStats); - updateStats(3, _downstreamStats); - updateStats(4, _upstreamInjectedStats); + _channelIndex = 0; + + updateStats(_audioMixerStats); + updateStats(_upstreamClientStats); + updateStats(_upstreamMixerStats); + updateStats(_downstreamStats); + updateStats(_upstreamInjectedStats); } diff --git a/interface/src/ui/AudioStatsDialog.h b/interface/src/ui/AudioStatsDialog.h index 537a91726f..797cd3575b 100644 --- a/interface/src/ui/AudioStatsDialog.h +++ b/interface/src/ui/AudioStatsDialog.h @@ -62,8 +62,8 @@ private: QVector _downstreamStats; QVector _upstreamInjectedStats; - void initializeChannel(QFormLayout* form, const unsigned int index, QVector& stats, const unsigned color); - void updateStats(const unsigned index, QVector& stats); + void addChannel(QFormLayout* form, QVector& stats, const unsigned color); + void updateStats(QVector& stats); void renderStats(); void clearAllChannels(); void renderAudioStreamStats(const AudioStreamStats* streamStats, QVector* audioStreamstats, bool isDownstreamStats); @@ -74,6 +74,7 @@ private: const AudioIOStats* _stats; QFormLayout* _form; + int _channelIndex; bool _isEnabled; bool _shouldShowInjectedStreams; From cf0940a65d992f4cb3d2bee703e2cacc8223ba11 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 16 Jul 2015 11:07:01 -0700 Subject: [PATCH 28/35] 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 854a098180c4c8d4bd7c3402eb84716008707891 Mon Sep 17 00:00:00 2001 From: bwent Date: Thu, 16 Jul 2015 12:28:43 -0700 Subject: [PATCH 29/35] keep track of channel id's within addChannel function, pass in when updating --- interface/src/ui/AudioStatsDialog.cpp | 65 +++++++++++++-------------- interface/src/ui/AudioStatsDialog.h | 15 ++++--- 2 files changed, 41 insertions(+), 39 deletions(-) diff --git a/interface/src/ui/AudioStatsDialog.cpp b/interface/src/ui/AudioStatsDialog.cpp index 3761d619fc..b84b3f452b 100644 --- a/interface/src/ui/AudioStatsDialog.cpp +++ b/interface/src/ui/AudioStatsDialog.cpp @@ -69,41 +69,40 @@ AudioStatsDialog::AudioStatsDialog(QWidget* parent) : // Create layouter _form = new QFormLayout(); QDialog::setLayout(_form); - - // Load and initilize + + // Load and initilize all channels renderStats(); - _channelIndex = 0; + _audioDisplayChannels = QVector>(1); - addChannel(_form, _audioMixerStats, COLOR0); - addChannel(_form, _upstreamClientStats, COLOR1); - addChannel(_form, _upstreamMixerStats, COLOR2); - addChannel(_form, _downstreamStats, COLOR3); - addChannel(_form, _upstreamInjectedStats, COLOR0); + _audioMixerID = addChannel(_form, _audioMixerStats, COLOR0); + _upstreamClientID = addChannel(_form, _upstreamClientStats, COLOR1); + _upstreamMixerID = addChannel(_form, _upstreamMixerStats, COLOR2); + _downstreamID = addChannel(_form, _downstreamStats, COLOR3); + _upstreamInjectedID = addChannel(_form, _upstreamInjectedStats, COLOR0); } -void AudioStatsDialog::addChannel(QFormLayout* form, QVector& stats, const unsigned color) { +int AudioStatsDialog::addChannel(QFormLayout* form, QVector& stats, const unsigned color) { - if(_channelIndex < DISPLAY_CHANNELS) { - for (int i = 0; i < stats.size(); i++) - // Create new display label - _audioDisplayChannels[_channelIndex].push_back(new AudioStatsDisplay(form, stats.at(i), color)); - - _channelIndex++; - } + int channelID = _audioDisplayChannels.size() - 1; + for (int i = 0; i < stats.size(); i++) + // Create new display label + _audioDisplayChannels[channelID].push_back(new AudioStatsDisplay(form, stats.at(i), color)); + + // Expand vector to fit next channel + _audioDisplayChannels.resize(_audioDisplayChannels.size() + 1); + + return channelID; } -void AudioStatsDialog::updateStats(QVector& stats) { +void AudioStatsDialog::updateStats(QVector& stats, int channelID) { - if(_channelIndex < DISPLAY_CHANNELS) { - // Update all stat displays at specified channel - for (int i = 0; i < stats.size(); i++) - _audioDisplayChannels[_channelIndex].at(i)->updatedDisplay(stats.at(i)); + // Update all stat displays at specified channel + for (int i = 0; i < stats.size(); i++) + _audioDisplayChannels[channelID].at(i)->updatedDisplay(stats.at(i)); - _channelIndex++; - } } @@ -226,25 +225,24 @@ void AudioStatsDialog::updateTimerTimeout() { // Update all audio stats renderStats(); - _channelIndex = 0; - - updateStats(_audioMixerStats); - updateStats(_upstreamClientStats); - updateStats(_upstreamMixerStats); - updateStats(_downstreamStats); - updateStats(_upstreamInjectedStats); + updateStats(_audioMixerStats, _audioMixerID); + updateStats(_upstreamClientStats, _upstreamClientID); + updateStats(_upstreamMixerStats, _upstreamMixerID); + updateStats(_downstreamStats, _downstreamID); + updateStats(_upstreamInjectedStats, _upstreamInjectedID); } void AudioStatsDialog::paintEvent(QPaintEvent* event) { - // Repaint each statistic in each section - for (int i = 0; i < DISPLAY_CHANNELS; i++) { + // Repaint each stat in each channel + for (int i = 0; i < _audioDisplayChannels.size(); i++) { for(int j = 0; j < _audioDisplayChannels[i].size(); j++) { _audioDisplayChannels[i].at(j)->paint(); } } + QDialog::paintEvent(event); setFixedSize(width(), height()); } @@ -262,8 +260,7 @@ void AudioStatsDialog::closeEvent(QCloseEvent* event) { AudioStatsDialog::~AudioStatsDialog() { clearAllChannels(); - - for (int i = 0; i < DISPLAY_CHANNELS; i++) { + for (int i = 0; i < _audioDisplayChannels.size(); i++) { _audioDisplayChannels[i].clear(); for(int j = 0; j < _audioDisplayChannels[i].size(); j++) { delete _audioDisplayChannels[i].at(j); diff --git a/interface/src/ui/AudioStatsDialog.h b/interface/src/ui/AudioStatsDialog.h index 797cd3575b..7f14cd6018 100644 --- a/interface/src/ui/AudioStatsDialog.h +++ b/interface/src/ui/AudioStatsDialog.h @@ -62,19 +62,24 @@ private: QVector _downstreamStats; QVector _upstreamInjectedStats; - void addChannel(QFormLayout* form, QVector& stats, const unsigned color); - void updateStats(QVector& stats); + int _audioMixerID; + int _upstreamClientID; + int _upstreamMixerID; + int _downstreamID; + int _upstreamInjectedID; + + QVector> _audioDisplayChannels; + + int addChannel(QFormLayout* form, QVector& stats, const unsigned color); + void updateStats(QVector& stats, const int channelID); void renderStats(); void clearAllChannels(); void renderAudioStreamStats(const AudioStreamStats* streamStats, QVector* audioStreamstats, bool isDownstreamStats); - const static int DISPLAY_CHANNELS = 5; - QVector _audioDisplayChannels[DISPLAY_CHANNELS]; const AudioIOStats* _stats; QFormLayout* _form; - int _channelIndex; bool _isEnabled; bool _shouldShowInjectedStreams; From cf9365e616c66fd4a4154d74e6ea7c394cdc12eb Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 16 Jul 2015 22:46:41 -0700 Subject: [PATCH 30/35] Add new sample script with flocking --- examples/FlockOfbirds.js | 258 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 258 insertions(+) create mode 100644 examples/FlockOfbirds.js diff --git a/examples/FlockOfbirds.js b/examples/FlockOfbirds.js new file mode 100644 index 0000000000..a3ecd77311 --- /dev/null +++ b/examples/FlockOfbirds.js @@ -0,0 +1,258 @@ +// +// flockOfbirds.js +// examples +// +// Copyright 2014 High Fidelity, Inc. +// Creates a flock of birds that fly around and chirp, staying inside the corners of the box defined +// at the start of the script. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html + + + +// The area over which the birds will fly +var lowerCorner = { x: 1, y: 1, z: 1 }; +var upperCorner = { x: 10, y: 10, z: 10 }; +var STARTING_FRACTION = 0.25; + +var NUM_BIRDS = 50; +var playSounds = true; +var SOUND_PROBABILITY = 0.001; +var numPlaying = 0; +var BIRD_SIZE = 0.08; +var BIRD_MASTER_VOLUME = 0.1; +var FLAP_PROBABILITY = 0.005; +var RANDOM_FLAP_VELOCITY = 1.0; +var FLAP_UP = 1.0; +var BIRD_GRAVITY = -0.5; +var LINEAR_DAMPING = 0.2; +var FLAP_FALLING_PROBABILITY = 0.025; +var MIN_ALIGNMENT_VELOCITY = 0.0; +var MAX_ALIGNMENT_VELOCITY = 1.0; +var VERTICAL_ALIGNMENT_COUPLING = 0.0; +var ALIGNMENT_FORCE = 1.5; +var COHESION_FORCE = 1.0; +var MAX_COHESION_VELOCITY = 0.5; + +var floor = false; +var MAKE_FLOOR = false; + +var averageVelocity = { x: 0, y: 0, z: 0 }; +var averagePosition = { x: 0, y: 0, z: 0 }; + +var birds = []; +var playing = []; + +function randomVector(scale) { + return { x: Math.random() * scale - scale / 2.0, y: Math.random() * scale - scale / 2.0, z: Math.random() * scale - scale / 2.0 }; +} + +function updateBirds(deltaTime) { + var sumVelocity = { x: 0, y: 0, z: 0 }; + var sumPosition = { x: 0, y: 0, z: 0 }; + var birdPositionsCounted = 0; + var birdVelocitiesCounted = 0; + for (var i = 0; i < birds.length; i++) { + if (birds[i].entityId) { + var properties = Entities.getEntityProperties(birds[i].entityId); + // If Bird has been deleted, bail + if (properties.id != birds[i].entityId) { + birds[i].entityId = false; + return; + } + // Sum up average position and velocity + if (Vec3.length(properties.velocity) > MIN_ALIGNMENT_VELOCITY) { + sumVelocity = Vec3.sum(sumVelocity, properties.velocity); + birdVelocitiesCounted += 1; + } + sumPosition = Vec3.sum(sumPosition, properties.position); + birdPositionsCounted += 1; + + var downwardSpeed = (properties.velocity.y < 0) ? -properties.velocity.y : 0.0; + if ((properties.position.y < upperCorner.y) && (Math.random() < (FLAP_PROBABILITY + (downwardSpeed * FLAP_FALLING_PROBABILITY)))) { + // More likely to flap if falling + var randomVelocity = randomVector(RANDOM_FLAP_VELOCITY); + randomVelocity.y = FLAP_UP + Math.random() * FLAP_UP; + + // Alignment Velocity + var alignmentVelocityMagnitude = Math.min(MAX_ALIGNMENT_VELOCITY, Vec3.length(Vec3.multiply(ALIGNMENT_FORCE, averageVelocity))); + var alignmentVelocity = Vec3.multiply(alignmentVelocityMagnitude, Vec3.normalize(averageVelocity)); + alignmentVelocity.y *= VERTICAL_ALIGNMENT_COUPLING; + + // Cohesion + var distanceFromCenter = Vec3.length(Vec3.subtract(averagePosition, properties.position)); + var cohesionVelocitySize = Math.min(distanceFromCenter * COHESION_FORCE, MAX_COHESION_VELOCITY); + var cohesionVelocity = Vec3.multiply(cohesionVelocitySize, Vec3.normalize(Vec3.subtract(averagePosition, properties.position))); + + var newVelocity = Vec3.sum(randomVelocity, Vec3.sum(alignmentVelocity, cohesionVelocity)); + + Entities.editEntity(birds[i].entityId, { velocity: Vec3.sum(properties.velocity, newVelocity) }); + + } + + // Check whether to play a chirp + if (playSounds && (!birds[i].audioId || !birds[i].audioId.isPlaying) && (Math.random() < ((numPlaying > 0) ? SOUND_PROBABILITY / numPlaying : SOUND_PROBABILITY))) { + var options = { + position: properties.position, + volume: BIRD_MASTER_VOLUME + }; + // Play chirp + if (birds[i].audioId) { + birds[i].audioId.setOptions(options); + birds[i].audioId.restart(); + } else { + birds[i].audioId = Audio.playSound(birds[i].sound, options); + } + numPlaying++; + // Change size + Entities.editEntity(birds[i].entityId, { dimensions: Vec3.multiply(1.5, properties.dimensions)}); + + } + + if (birds[i].audioId) { + // If bird is playing a chirp + if (!birds[i].audioId.isPlaying) { + // clear ID if playing has stopped + Entities.editEntity(birds[i].entityId, { dimensions: { x: BIRD_SIZE, y: BIRD_SIZE, z: BIRD_SIZE }}); + birds[i].audioId = false; + numPlaying--; + print("num playing" + numPlaying); + } + } + + // Keep birds in their 'cage' + var bounce = false; + var newVelocity = properties.velocity; + var newPosition = properties.position; + if (properties.position.x < lowerCorner.x) { + newPosition.x = lowerCorner.x; + newVelocity.x *= -1.0; + bounce = true; + } else if (properties.position.x > upperCorner.x) { + newPosition.x = upperCorner.x; + newVelocity.x *= -1.0; + bounce = true; + } + if (properties.position.y < lowerCorner.y) { + newPosition.y = lowerCorner.y; + newVelocity.y *= -1.0; + bounce = true; + } else if (properties.position.y > upperCorner.y) { + newPosition.y = upperCorner.y; + newVelocity.y *= -1.0; + bounce = true; + } + if (properties.position.z < lowerCorner.z) { + newPosition.z = lowerCorner.z; + newVelocity.z *= -1.0; + bounce = true; + } else if (properties.position.z > upperCorner.z) { + newPosition.z = upperCorner.z; + newVelocity.z *= -1.0; + bounce = true; + } + if (bounce) { + Entities.editEntity(birds[i].entityId, { position: newPosition, velocity: newVelocity }); + } + } + } + // Update average velocity and position of flock + if (birdVelocitiesCounted > 0) { + averageVelocity = Vec3.multiply(1.0 / birdVelocitiesCounted, sumVelocity); + //print(Vec3.length(averageVelocity)); + } + if (birdPositionsCounted > 0) { + averagePosition = Vec3.multiply(1.0 / birdPositionsCounted, sumPosition); + } +} + +loadBirds(NUM_BIRDS); +if (MAKE_FLOOR) { + var FLOOR_THICKNESS = 0.05; + floor = Entities.addEntity({ type: "Box", position: { x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0, + y: lowerCorner.y, + z: lowerCorner.z + (upperCorner.z - lowerCorner.z) / 2.0 }, + dimensions: { x: (upperCorner.x - lowerCorner.x), y: FLOOR_THICKNESS, z: (upperCorner.z - lowerCorner.z)}, + color: {red: 100, green: 100, blue: 100} + }); +} +// Connect a call back that happens every frame +Script.update.connect(updateBirds); + +// Delete our little friends if script is stopped +Script.scriptEnding.connect(function() { + for (var i = 0; i < birds.length; i++) { + Entities.deleteEntity(birds[i].entityId); + } + if (floor) { + Entities.deleteEntity(floor); + } +}); + +function loadBirds(howMany) { + var sound_filenames = ["bushtit_1.raw", "bushtit_2.raw", "bushtit_3.raw"]; + /* Here are more sounds/species you can use + , "mexicanWhipoorwill.raw", + "rosyfacedlovebird.raw", "saysphoebe.raw", "westernscreechowl.raw", "bandtailedpigeon.wav", "bridledtitmouse.wav", + "browncrestedflycatcher.wav", "commonnighthawk.wav", "commonpoorwill.wav", "doublecrestedcormorant.wav", + "gambelsquail.wav", "goldcrownedkinglet.wav", "greaterroadrunner.wav","groovebilledani.wav","hairywoodpecker.wav", + "housewren.wav","hummingbird.wav", "mountainchickadee.wav", "nightjar.wav", "piebilledgrieb.wav", "pygmynuthatch.wav", + "whistlingduck.wav", "woodpecker.wav"]; + */ + + var colors = [ + { red: 242, green: 207, blue: 013 }, + { red: 238, green: 94, blue: 11 }, + { red: 81, green: 30, blue: 7 }, + { red: 195, green: 176, blue: 81 }, + { red: 235, green: 190, blue: 152 }, + { red: 167, green: 99, blue: 52 }, + { red: 199, green: 122, blue: 108 }, + { red: 246, green: 220, blue: 189 }, + { red: 208, green: 145, blue: 65 }, + { red: 173, green: 120 , blue: 71 }, + { red: 132, green: 147, blue: 174 }, + { red: 164, green: 74, blue: 40 }, + { red: 131, green: 127, blue: 134 }, + { red: 209, green: 157, blue: 117 }, + { red: 205, green: 191, blue: 193 }, + { red: 193, green: 154, blue: 118 }, + { red: 205, green: 190, blue: 169 }, + { red: 199, green: 111, blue: 69 }, + { red: 221, green: 223, blue: 228 }, + { red: 115, green: 92, blue: 87 }, + { red: 214, green: 165, blue: 137 }, + { red: 160, green: 124, blue: 33 }, + { red: 117, green: 91, blue: 86 }, + { red: 113, green: 104, blue: 107 }, + { red: 216, green: 153, blue: 99 }, + { red: 242, green: 226, blue: 64 } + ]; + + var SOUND_BASE_URL = "http://public.highfidelity.io/sounds/Animals/"; + + for (var i = 0; i < howMany; i++) { + var whichBird = Math.floor(Math.random() * sound_filenames.length); + var position = { + x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.x - lowerCorner.x) * STARTING_FRACTION, + y: lowerCorner.y + (upperCorner.y - lowerCorner.y) / 2.0 + (Math.random() - 0.5) * (upperCorner.y - lowerCorner.y) * STARTING_FRACTION, + z: lowerCorner.z + (upperCorner.z - lowerCorner.x) / 2.0 + (Math.random() - 0.5) * (upperCorner.z - lowerCorner.z) * STARTING_FRACTION + }; + + birds.push({ + sound: SoundCache.getSound(SOUND_BASE_URL + sound_filenames[whichBird]), + entityId: Entities.addEntity({ + type: "Sphere", + position: position, + dimensions: { x: BIRD_SIZE, y: BIRD_SIZE, z: BIRD_SIZE }, + gravity: { x: 0, y: BIRD_GRAVITY, z: 0 }, + velocity: { x: 0, y: -0.1, z: 0 }, + linearDamping: LINEAR_DAMPING, + collisionsWillMove: true, + color: colors[whichBird] + }), + audioId: false + }); + } +} \ No newline at end of file From 5c29eb97efda45c0f81cdba65df6934f627cd8f6 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 16 Jul 2015 23:32:40 -0700 Subject: [PATCH 31/35] remove debug --- examples/FlockOfbirds.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/FlockOfbirds.js b/examples/FlockOfbirds.js index a3ecd77311..e15f6764a0 100644 --- a/examples/FlockOfbirds.js +++ b/examples/FlockOfbirds.js @@ -117,7 +117,6 @@ function updateBirds(deltaTime) { Entities.editEntity(birds[i].entityId, { dimensions: { x: BIRD_SIZE, y: BIRD_SIZE, z: BIRD_SIZE }}); birds[i].audioId = false; numPlaying--; - print("num playing" + numPlaying); } } From db219905f3cce527a0822041cf8193c04d3397ec Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 17 Jul 2015 00:30:31 -0700 Subject: [PATCH 32/35] re-use audio injectors, don't check if isPlaying immediately after starting play out --- examples/FlockOfbirds.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/FlockOfbirds.js b/examples/FlockOfbirds.js index e15f6764a0..de30f2d374 100644 --- a/examples/FlockOfbirds.js +++ b/examples/FlockOfbirds.js @@ -108,14 +108,11 @@ function updateBirds(deltaTime) { // Change size Entities.editEntity(birds[i].entityId, { dimensions: Vec3.multiply(1.5, properties.dimensions)}); - } - - if (birds[i].audioId) { + } else if (birds[i].audioId) { // If bird is playing a chirp if (!birds[i].audioId.isPlaying) { // clear ID if playing has stopped Entities.editEntity(birds[i].entityId, { dimensions: { x: BIRD_SIZE, y: BIRD_SIZE, z: BIRD_SIZE }}); - birds[i].audioId = false; numPlaying--; } } @@ -251,7 +248,8 @@ function loadBirds(howMany) { collisionsWillMove: true, color: colors[whichBird] }), - audioId: false + audioId: false, + isPlaying: false }); } } \ No newline at end of file From 689b0e257158a452c64c7e687b7e4ca2e4da64e5 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 17 Jul 2015 09:41:48 -0700 Subject: [PATCH 33/35] Improve to run correctly on startup as AC --- examples/FlockOfbirds.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/examples/FlockOfbirds.js b/examples/FlockOfbirds.js index de30f2d374..a8a5aafe6d 100644 --- a/examples/FlockOfbirds.js +++ b/examples/FlockOfbirds.js @@ -41,6 +41,8 @@ var MAKE_FLOOR = false; var averageVelocity = { x: 0, y: 0, z: 0 }; var averagePosition = { x: 0, y: 0, z: 0 }; +var birdsLoaded = false; + var birds = []; var playing = []; @@ -49,6 +51,14 @@ function randomVector(scale) { } function updateBirds(deltaTime) { + if (!Entities.serversExist() || !Entities.canRez()) { + return; + } + if (!birdsLoaded) { + loadBirds(NUM_BIRDS); + birdsLoaded = true; + return; + } var sumVelocity = { x: 0, y: 0, z: 0 }; var sumPosition = { x: 0, y: 0, z: 0 }; var birdPositionsCounted = 0; @@ -163,16 +173,6 @@ function updateBirds(deltaTime) { } } -loadBirds(NUM_BIRDS); -if (MAKE_FLOOR) { - var FLOOR_THICKNESS = 0.05; - floor = Entities.addEntity({ type: "Box", position: { x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0, - y: lowerCorner.y, - z: lowerCorner.z + (upperCorner.z - lowerCorner.z) / 2.0 }, - dimensions: { x: (upperCorner.x - lowerCorner.x), y: FLOOR_THICKNESS, z: (upperCorner.z - lowerCorner.z)}, - color: {red: 100, green: 100, blue: 100} - }); -} // Connect a call back that happens every frame Script.update.connect(updateBirds); @@ -187,6 +187,8 @@ Script.scriptEnding.connect(function() { }); function loadBirds(howMany) { + while (!Entities.serversExist() || !Entities.canRez()) { + } var sound_filenames = ["bushtit_1.raw", "bushtit_2.raw", "bushtit_3.raw"]; /* Here are more sounds/species you can use , "mexicanWhipoorwill.raw", @@ -251,5 +253,14 @@ function loadBirds(howMany) { audioId: false, isPlaying: false }); - } + } + if (MAKE_FLOOR) { + var FLOOR_THICKNESS = 0.05; + floor = Entities.addEntity({ type: "Box", position: { x: lowerCorner.x + (upperCorner.x - lowerCorner.x) / 2.0, + y: lowerCorner.y, + z: lowerCorner.z + (upperCorner.z - lowerCorner.z) / 2.0 }, + dimensions: { x: (upperCorner.x - lowerCorner.x), y: FLOOR_THICKNESS, z: (upperCorner.z - lowerCorner.z)}, + color: {red: 100, green: 100, blue: 100} + }); + } } \ No newline at end of file From ee435d9732faccda4ea62479ef4d058ec4bcde36 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 17 Jul 2015 09:43:33 -0700 Subject: [PATCH 34/35] remove comment --- examples/FlockOfbirds.js | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/FlockOfbirds.js b/examples/FlockOfbirds.js index a8a5aafe6d..0e8c6d4731 100644 --- a/examples/FlockOfbirds.js +++ b/examples/FlockOfbirds.js @@ -121,7 +121,6 @@ function updateBirds(deltaTime) { } else if (birds[i].audioId) { // If bird is playing a chirp if (!birds[i].audioId.isPlaying) { - // clear ID if playing has stopped Entities.editEntity(birds[i].entityId, { dimensions: { x: BIRD_SIZE, y: BIRD_SIZE, z: BIRD_SIZE }}); numPlaying--; } From b22fd3f4a02ba0f9a628014a7766cc9f7e9ea66a Mon Sep 17 00:00:00 2001 From: bwent Date: Fri, 17 Jul 2015 10:58:30 -0700 Subject: [PATCH 35/35] fixed lagging issues --- interface/src/ui/AudioStatsDialog.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/interface/src/ui/AudioStatsDialog.cpp b/interface/src/ui/AudioStatsDialog.cpp index b84b3f452b..1d6d84a15b 100644 --- a/interface/src/ui/AudioStatsDialog.cpp +++ b/interface/src/ui/AudioStatsDialog.cpp @@ -1,9 +1,9 @@ // // AudioStatsDialog.cpp -// hifi +// interface/src/ui // // Created by Bridget Went on 7/9/15. -// +// Copyright 2015 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -72,7 +72,7 @@ AudioStatsDialog::AudioStatsDialog(QWidget* parent) : // Load and initilize all channels renderStats(); - + _audioDisplayChannels = QVector>(1); _audioMixerID = addChannel(_form, _audioMixerStats, COLOR0); @@ -80,7 +80,11 @@ AudioStatsDialog::AudioStatsDialog(QWidget* parent) : _upstreamMixerID = addChannel(_form, _upstreamMixerStats, COLOR2); _downstreamID = addChannel(_form, _downstreamStats, COLOR3); _upstreamInjectedID = addChannel(_form, _upstreamInjectedStats, COLOR0); - + + + connect(averageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTimerTimeout())); + averageUpdateTimer->start(1000); + } int AudioStatsDialog::addChannel(QFormLayout* form, QVector& stats, const unsigned color) { @@ -98,16 +102,13 @@ int AudioStatsDialog::addChannel(QFormLayout* form, QVector& stats, con } void AudioStatsDialog::updateStats(QVector& stats, int channelID) { - // Update all stat displays at specified channel for (int i = 0; i < stats.size(); i++) _audioDisplayChannels[channelID].at(i)->updatedDisplay(stats.at(i)); - } - void AudioStatsDialog::renderStats() { - + // Clear current stats from all vectors clearAllChannels(); @@ -181,9 +182,6 @@ void AudioStatsDialog::renderStats() { } } - - connect(averageUpdateTimer, SIGNAL(timeout()), this, SLOT(updateTimerTimeout())); - averageUpdateTimer->start(1000); } @@ -222,9 +220,9 @@ void AudioStatsDialog::clearAllChannels() { void AudioStatsDialog::updateTimerTimeout() { - // Update all audio stats renderStats(); + // Update all audio stats updateStats(_audioMixerStats, _audioMixerID); updateStats(_upstreamClientStats, _upstreamClientID); updateStats(_upstreamMixerStats, _upstreamMixerID); @@ -259,7 +257,6 @@ void AudioStatsDialog::closeEvent(QCloseEvent* event) { AudioStatsDialog::~AudioStatsDialog() { clearAllChannels(); - for (int i = 0; i < _audioDisplayChannels.size(); i++) { _audioDisplayChannels[i].clear(); for(int j = 0; j < _audioDisplayChannels[i].size(); j++) {