From 84d183b2bc1a9c3c929870e6e1bc0b8746ae38a4 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Mon, 16 Jun 2014 14:46:40 -0700 Subject: [PATCH 01/13] Switched Oculus magnify method to a manual mode --- interface/src/ui/ApplicationOverlay.cpp | 81 +++++++++++++++++-------- interface/src/ui/ApplicationOverlay.h | 18 ++++-- 2 files changed, 69 insertions(+), 30 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 471ff20d66..8d118e90c4 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -36,6 +36,9 @@ ApplicationOverlay::ApplicationOverlay() : _textureFov(DEFAULT_OCULUS_UI_ANGULAR_SIZE * RADIANS_PER_DEGREE), _crosshairTexture(0) { + _magActive[MOUSE] = false; + _magActive[LEFT_CONTROLLER] = false; + _magActive[RIGHT_CONTROLLER] = false; } ApplicationOverlay::~ApplicationOverlay() { @@ -45,7 +48,6 @@ ApplicationOverlay::~ApplicationOverlay() { } const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f }; - const float RETICLE_COLOR[] = { 0.0f, 198.0f / 255.0f, 244.0f / 255.0f }; // Renders the overlays either to a texture or to the screen @@ -158,7 +160,6 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { MyAvatar* myAvatar = application->getAvatar(); const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation(); - glActiveTexture(GL_TEXTURE0); glEnable(GL_BLEND); @@ -194,8 +195,11 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { glAlphaFunc(GL_GREATER, 0.01f); //Draw the magnifiers - for (int i = 0; i < _numMagnifiers; i++) { - renderMagnifier(_mouseX[i], _mouseY[i]); + for (int i = 0; i < 3; i++) { + + if (_magActive[i]) { + renderMagnifier(_magX[i], _magY[i]); + } } glDepthMask(GL_FALSE); @@ -220,7 +224,6 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { void ApplicationOverlay::renderPointers() { Application* application = Application::getInstance(); // Render a crosshair over the mouse when in Oculus - _numMagnifiers = 0; int mouseX = application->getMouseX(); int mouseY = application->getMouseY(); @@ -236,11 +239,19 @@ void ApplicationOverlay::renderPointers() { if (OculusManager::isConnected() && application->getLastMouseMoveType() == QEvent::MouseMove) { //If we are in oculus, render reticle later - _numMagnifiers = 1; - _mouseX[0] = application->getMouseX(); - _mouseY[0] = application->getMouseY(); + _reticleActive[MOUSE] = true; + _magActive[MOUSE] = true; + _mouseX[MOUSE] = application->getMouseX(); + _mouseY[MOUSE] = application->getMouseY(); + _magX[MOUSE] = _mouseX[MOUSE]; + _magY[MOUSE] = _mouseY[MOUSE]; + + _reticleActive[LEFT_CONTROLLER] = false; + _reticleActive[RIGHT_CONTROLLER] = false; + } else if (application->getLastMouseMoveType() == CONTROLLER_MOVE_EVENT && Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) { //only render controller pointer if we aren't already rendering a mouse pointer + _reticleActive[MOUSE] = false; renderControllerPointers(); } glBindTexture(GL_TEXTURE_2D, 0); @@ -256,6 +267,8 @@ void ApplicationOverlay::renderControllerPointers() { const HandData* handData = Application::getInstance()->getAvatar()->getHandData(); for (unsigned int palmIndex = 2; palmIndex < 4; palmIndex++) { + const int index = palmIndex - 1; + const PalmData* palmData = NULL; if (palmIndex >= handData->getPalms().size()) { @@ -268,6 +281,8 @@ void ApplicationOverlay::renderControllerPointers() { continue; } + int controllerButtons = palmData->getControllerButtons(); + // Get directon relative to avatar orientation glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * palmData->getFingerDirection(); @@ -281,22 +296,35 @@ void ApplicationOverlay::renderControllerPointers() { int mouseX = glWidget->width() / 2.0f + cursorRange * xAngle; int mouseY = glWidget->height() / 2.0f + cursorRange * yAngle; + // If the 2 button is pressed, we disable the magnifier for this controller + if (controllerButtons & BUTTON_2) { + _magActive[index] = false; + _magX[index] = mouseX; + _magY[index] = mouseY; + } + //If the cursor is out of the screen then don't render it if (mouseX < 0 || mouseX >= glWidget->width() || mouseY < 0 || mouseY >= glWidget->height()) { continue; } - + _reticleActive[index] = true; float pointerWidth = 40; float pointerHeight = 40; //if we have the oculus, we should make the cursor smaller since it will be //magnified if (OculusManager::isConnected()) { + + _mouseX[index] = mouseX; + _mouseY[index] = mouseY; - _mouseX[_numMagnifiers] = mouseX; - _mouseY[_numMagnifiers] = mouseY; - _numMagnifiers++; - //If oculus is enabled, we draw the crosshairs later + if (controllerButtons & BUTTON_3) { + _magActive[index] = true; + _magX[index] = mouseX; + _magY[index] = mouseY; + } + + // If oculus is enabled, we draw the crosshairs later continue; } @@ -328,7 +356,12 @@ void ApplicationOverlay::renderControllerPointersOculus() { glBindTexture(GL_TEXTURE_2D, _crosshairTexture); glDisable(GL_DEPTH_TEST); - for (int i = 0; i < _numMagnifiers; i++) { + for (int i = 0; i < 3; i++) { + + //Dont render the reticle if its inactive + if (!_reticleActive[i]) { + continue; + } float mouseX = (float)_mouseX[i]; float mouseY = (float)_mouseY[i]; @@ -385,26 +418,22 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY) const int widgetWidth = glWidget->width(); const int widgetHeight = glWidget->height(); - const float magnification = 4.0f; - float magnifyWidth = 80.0f; - float magnifyHeight = 60.0f; + mouseX -= MAGNIFY_WIDTH / 2; + mouseY -= MAGNIFY_HEIGHT / 2; - mouseX -= magnifyWidth / 2; - mouseY -= magnifyHeight / 2; - - float newWidth = magnifyWidth * magnification; - float newHeight = magnifyHeight * magnification; + float newWidth = MAGNIFY_WIDTH * MAGNIFY_MULT; + float newHeight = MAGNIFY_HEIGHT * MAGNIFY_MULT; // Magnification Texture Coordinates float magnifyULeft = mouseX / (float)widgetWidth; - float magnifyURight = (mouseX + magnifyWidth) / (float)widgetWidth; + float magnifyURight = (mouseX + MAGNIFY_WIDTH) / (float)widgetWidth; float magnifyVBottom = 1.0f - mouseY / (float)widgetHeight; - float magnifyVTop = 1.0f - (mouseY + magnifyHeight) / (float)widgetHeight; + float magnifyVTop = 1.0f - (mouseY + MAGNIFY_HEIGHT) / (float)widgetHeight; // Coordinates of magnification overlay - float newMouseX = (mouseX + magnifyWidth / 2) - newWidth / 2.0f; - float newMouseY = (mouseY + magnifyHeight / 2) + newHeight / 2.0f; + float newMouseX = (mouseX + MAGNIFY_WIDTH / 2) - newWidth / 2.0f; + float newMouseY = (mouseY + MAGNIFY_HEIGHT / 2) + newHeight / 2.0f; // Get position on hemisphere using angle diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 53a0125dae..80c7cd1ad8 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -15,18 +15,22 @@ class Overlays; class QOpenGLFramebufferObject; +const float MAGNIFY_WIDTH = 160.0f; +const float MAGNIFY_HEIGHT = 80.0f; +const float MAGNIFY_MULT = 4.0f; + // Handles the drawing of the overlays to the screen class ApplicationOverlay { public: ApplicationOverlay(); + ~ApplicationOverlay(); void renderOverlay(bool renderToTexture = false); void displayOverlayTexture(Camera& whichCamera); void displayOverlayTextureOculus(Camera& whichCamera); void computeOculusPickRay(float x, float y, glm::vec3& direction) const; - // Getters QOpenGLFramebufferObject* getFramebufferObject(); @@ -37,6 +41,8 @@ private: glm::vec2 uv; }; + enum MousePointerDevice { MOUSE, LEFT_CONTROLLER, RIGHT_CONTROLLER }; + typedef QPair VerticesIndices; void renderPointers(); @@ -52,9 +58,13 @@ private: float _oculusAngle; float _distance; float _textureFov; - int _mouseX[2]; - int _mouseY[2]; - int _numMagnifiers; + // 0 = Mouse, 1 = Left Controller, 2 = Right Controller + bool _reticleActive[3]; + int _mouseX[3]; + int _mouseY[3]; + bool _magActive[3]; + int _magX[3]; + int _magY[3]; GLuint _crosshairTexture; }; From 2b374470b0e382525d181712d8759f9a8a9cdf0e Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Mon, 16 Jun 2014 15:24:53 -0700 Subject: [PATCH 02/13] Allow clicking on magnified controls --- interface/src/devices/SixenseManager.cpp | 32 ++++++++++++++++-------- interface/src/ui/ApplicationOverlay.cpp | 22 ++++++++++++++++ interface/src/ui/ApplicationOverlay.h | 3 ++- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 2c62a58800..07536d0af8 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -341,8 +341,9 @@ void SixenseManager::updateCalibration(const sixenseControllerData* controllers) //Injecting mouse movements and clicks void SixenseManager::emulateMouse(PalmData* palm, int index) { - MyAvatar* avatar = Application::getInstance()->getAvatar(); - QGLWidget* widget = Application::getInstance()->getGLWidget(); + Application* application = Application::getInstance(); + MyAvatar* avatar = application->getAvatar(); + QGLWidget* widget = application->getGLWidget(); QPoint pos; // Get directon relative to avatar orientation glm::vec3 direction = glm::inverse(avatar->getOrientation()) * palm->getFingerDirection(); @@ -374,14 +375,14 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { if (_bumperPressed[index]) { QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, bumperButton, bumperButton, 0); - Application::getInstance()->mouseReleaseEvent(&mouseEvent); + application->mouseReleaseEvent(&mouseEvent); _bumperPressed[index] = false; } if (_triggerPressed[index]) { QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, triggerButton, triggerButton, 0); - Application::getInstance()->mouseReleaseEvent(&mouseEvent); + application->mouseReleaseEvent(&mouseEvent); _triggerPressed[index] = false; } @@ -396,17 +397,28 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { //This is specifically for edit voxels if (triggerButton == Qt::LeftButton) { if (!_triggerPressed[(int)(!index)]) { - Application::getInstance()->mouseMoveEvent(&mouseEvent); + application->mouseMoveEvent(&mouseEvent); } } else { if (!_bumperPressed[(int)(!index)]) { - Application::getInstance()->mouseMoveEvent(&mouseEvent); + application->mouseMoveEvent(&mouseEvent); } } } _oldX[index] = pos.x(); _oldY[index] = pos.y(); + + //We need separate coordinates for clicks, since we need to check if + //a magnification window was clicked on + int clickX = pos.x(); + int clickY = pos.y(); + //Checks for magnification window click + application->getApplicationOverlay().getClickLocation(clickX, clickY); + //Set pos to the new click location, which may be the same if no magnification window is open + pos.setX(clickX); + pos.setY(clickY); + //Check for bumper press ( Right Click ) if (palm->getControllerButtons() & BUTTON_FWD) { if (!_bumperPressed[index]) { @@ -414,12 +426,12 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { QMouseEvent mouseEvent(QEvent::MouseButtonPress, pos, bumperButton, bumperButton, 0); - Application::getInstance()->mousePressEvent(&mouseEvent); + application->mousePressEvent(&mouseEvent); } } else if (_bumperPressed[index]) { QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, bumperButton, bumperButton, 0); - Application::getInstance()->mouseReleaseEvent(&mouseEvent); + application->mouseReleaseEvent(&mouseEvent); _bumperPressed[index] = false; } @@ -431,12 +443,12 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) { QMouseEvent mouseEvent(QEvent::MouseButtonPress, pos, triggerButton, triggerButton, 0); - Application::getInstance()->mousePressEvent(&mouseEvent); + application->mousePressEvent(&mouseEvent); } } else if (_triggerPressed[index]) { QMouseEvent mouseEvent(QEvent::MouseButtonRelease, pos, triggerButton, triggerButton, 0); - Application::getInstance()->mouseReleaseEvent(&mouseEvent); + application->mouseReleaseEvent(&mouseEvent); _triggerPressed[index] = false; } diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 8d118e90c4..39d6956249 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -151,6 +151,28 @@ void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& direc direction = glm::normalize(rot * glm::vec3(x, y, z)); } +// Calculates the click location on the screen by taking into account any +// opened magnification windows. +void ApplicationOverlay::getClickLocation(int &x, int &y) const { + int dx; + int dy; + + //Loop through all magnification windows + for (int i = 0; i < 3; i++) { + if (_magActive[i]) { + dx = x - _magX[i]; + dy = y - _magY[i]; + //Check to see if they clicked inside a mag window + if (abs(dx) <= MAGNIFY_WIDTH * MAGNIFY_MULT && abs(dy) <= MAGNIFY_HEIGHT * MAGNIFY_MULT) { + //Move the click to the actual UI location by inverting the magnification + x = dx / MAGNIFY_MULT + _magX[i]; + y = dy / MAGNIFY_MULT + _magY[i]; + return; + } + } + } +} + // Draws the FBO texture for Oculus rift. TODO: Draw a curved texture instead of plane. void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 80c7cd1ad8..de6b376de6 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -24,13 +24,14 @@ class ApplicationOverlay { public: ApplicationOverlay(); - ~ApplicationOverlay(); void renderOverlay(bool renderToTexture = false); void displayOverlayTexture(Camera& whichCamera); void displayOverlayTextureOculus(Camera& whichCamera); void computeOculusPickRay(float x, float y, glm::vec3& direction) const; + void getClickLocation(int &x, int &y) const; + // Getters QOpenGLFramebufferObject* getFramebufferObject(); From b0e89c58101413dbc65ce5614d96d1f9a8ac9226 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Mon, 16 Jun 2014 17:34:18 -0700 Subject: [PATCH 03/13] Made magnification use only button 3 --- interface/src/ui/ApplicationOverlay.cpp | 59 ++++++++++++++++++++----- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 39d6956249..db703944c1 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -36,6 +36,9 @@ ApplicationOverlay::ApplicationOverlay() : _textureFov(DEFAULT_OCULUS_UI_ANGULAR_SIZE * RADIANS_PER_DEGREE), _crosshairTexture(0) { + _reticleActive[MOUSE] = false; + _reticleActive[LEFT_CONTROLLER] = false; + _reticleActive[RIGHT_CONTROLLER] = false; _magActive[MOUSE] = false; _magActive[LEFT_CONTROLLER] = false; _magActive[RIGHT_CONTROLLER] = false; @@ -156,14 +159,16 @@ void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& direc void ApplicationOverlay::getClickLocation(int &x, int &y) const { int dx; int dy; - + const float xRange = MAGNIFY_WIDTH * MAGNIFY_MULT / 2.0f; + const float yRange = MAGNIFY_WIDTH * MAGNIFY_MULT / 2.0f; + //Loop through all magnification windows for (int i = 0; i < 3; i++) { if (_magActive[i]) { dx = x - _magX[i]; dy = y - _magY[i]; //Check to see if they clicked inside a mag window - if (abs(dx) <= MAGNIFY_WIDTH * MAGNIFY_MULT && abs(dy) <= MAGNIFY_HEIGHT * MAGNIFY_MULT) { + if (abs(dx) <= xRange && abs(dy) <= yRange) { //Move the click to the actual UI location by inverting the magnification x = dx / MAGNIFY_MULT + _magX[i]; y = dy / MAGNIFY_MULT + _magY[i]; @@ -274,6 +279,7 @@ void ApplicationOverlay::renderPointers() { } else if (application->getLastMouseMoveType() == CONTROLLER_MOVE_EVENT && Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) { //only render controller pointer if we aren't already rendering a mouse pointer _reticleActive[MOUSE] = false; + _magActive[MOUSE] = false; renderControllerPointers(); } glBindTexture(GL_TEXTURE_2D, 0); @@ -286,6 +292,10 @@ void ApplicationOverlay::renderControllerPointers() { QGLWidget* glWidget = application->getGLWidget(); MyAvatar* myAvatar = application->getAvatar(); + static unsigned int pressedTime[2] = { 0, 0 }; + static bool isPressed[2] = { false, false }; + static bool stateWhenPressed[2] = { false, false }; + const HandData* handData = Application::getInstance()->getAvatar()->getHandData(); for (unsigned int palmIndex = 2; palmIndex < 4; palmIndex++) { @@ -305,6 +315,24 @@ void ApplicationOverlay::renderControllerPointers() { int controllerButtons = palmData->getControllerButtons(); + //Check for if we should toggle or drag the magnification window + if (controllerButtons & BUTTON_3) { + if (isPressed[index] == false) { + //We are now dragging the window + isPressed[index] = true; + //set the pressed time in ms + pressedTime[index] = SDL_GetTicks(); + stateWhenPressed[index] = _magActive[index]; + } + } else if (isPressed[index]) { + isPressed[index] = false; + //If the button has been pressed for less than 250 ms + //then disable it. + if (SDL_GetTicks() - pressedTime[index] < 250) { + _magActive[index] = !stateWhenPressed[index]; + } + } + // Get directon relative to avatar orientation glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * palmData->getFingerDirection(); @@ -318,13 +346,6 @@ void ApplicationOverlay::renderControllerPointers() { int mouseX = glWidget->width() / 2.0f + cursorRange * xAngle; int mouseY = glWidget->height() / 2.0f + cursorRange * yAngle; - // If the 2 button is pressed, we disable the magnifier for this controller - if (controllerButtons & BUTTON_2) { - _magActive[index] = false; - _magX[index] = mouseX; - _magY[index] = mouseY; - } - //If the cursor is out of the screen then don't render it if (mouseX < 0 || mouseX >= glWidget->width() || mouseY < 0 || mouseY >= glWidget->height()) { continue; @@ -340,7 +361,8 @@ void ApplicationOverlay::renderControllerPointers() { _mouseX[index] = mouseX; _mouseY[index] = mouseY; - if (controllerButtons & BUTTON_3) { + //When button 2 is pressed we drag the mag window + if (isPressed[index]) { _magActive[index] = true; _magX[index] = mouseX; _magY[index] = mouseY; @@ -437,7 +459,6 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY) Application* application = Application::getInstance(); QGLWidget* glWidget = application->getGLWidget(); - const int widgetWidth = glWidget->width(); const int widgetHeight = glWidget->height(); @@ -484,6 +505,22 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY) //Top Right dist = sqrt(rX * rX + tY * tY); float trZ = sqrt(1.0f - dist * dist); + glDisable(GL_TEXTURE_2D); + glLineWidth(1.0f); + //Outer Line + glBegin(GL_LINE_STRIP); + glColor3f(1.0f, 0.0f, 0.0f); + + glVertex3f(lX, tY, -tlZ); + glVertex3f(rX, tY, -trZ); + glVertex3f(rX, bY, -brZ); + glVertex3f(lX, bY, -blZ); + glVertex3f(lX, tY, -tlZ); + + glColor3f(1.0f, 1.0f, 1.0f); + + glEnd(); + glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); From 3052996a9e62e9bac2824d1765923114ba9ec451 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 10:37:15 -0700 Subject: [PATCH 04/13] Pressing trigger and bumper at same time toggles UI --- interface/src/Application.cpp | 9 +++- interface/src/ui/ApplicationOverlay.cpp | 72 ++++++++++++++++++++++--- interface/src/ui/ApplicationOverlay.h | 6 ++- 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6b44503af4..aed511601e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -654,7 +654,14 @@ void Application::paintGL() { { PerformanceTimer perfTimer("paintGL/renderOverlay"); - _applicationOverlay.renderOverlay(); + //If alpha is 1, we can render directly to the screen. + if (_applicationOverlay.getAlpha() == 1.0f) { + _applicationOverlay.renderOverlay(); + } else { + //Render to to texture so we can fade it + _applicationOverlay.renderOverlay(true); + _applicationOverlay.displayOverlayTexture(); + } } } diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index db703944c1..2f94776046 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -20,6 +20,8 @@ #include "ui/Stats.h" +const float FADE_SPEED = 0.02f; + // Fast helper functions inline float max(float a, float b) { return (a > b) ? a : b; @@ -34,7 +36,9 @@ ApplicationOverlay::ApplicationOverlay() : _oculusAngle(65.0f * RADIANS_PER_DEGREE), _distance(0.5f), _textureFov(DEFAULT_OCULUS_UI_ANGULAR_SIZE * RADIANS_PER_DEGREE), - _crosshairTexture(0) { + _crosshairTexture(0), + _alpha(1.0f), + _active(true) { _reticleActive[MOUSE] = false; _reticleActive[LEFT_CONTROLLER] = false; @@ -65,6 +69,20 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { QGLWidget* glWidget = application->getGLWidget(); MyAvatar* myAvatar = application->getAvatar(); + //Handle fadeing and deactivation/activation of UI + printf("%f\n", _alpha); + if (_active) { + _alpha += FADE_SPEED; + if (_alpha > 1.0f) { + _alpha = 1.0f; + } + } else { + _alpha -= FADE_SPEED; + if (_alpha <= 0.0f) { + _alpha = 0.0f; + } + } + if (renderToTexture) { getFramebufferObject()->bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -72,6 +90,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + // Render 2D overlay glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -109,7 +128,11 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { } // Draws the FBO texture for the screen -void ApplicationOverlay::displayOverlayTexture(Camera& whichCamera) { +void ApplicationOverlay::displayOverlayTexture() { + + if (_alpha == 0.0f) { + return; + } Application* application = Application::getInstance(); QGLWidget* glWidget = application->getGLWidget(); @@ -125,13 +148,16 @@ void ApplicationOverlay::displayOverlayTexture(Camera& whichCamera) { gluOrtho2D(0, glWidget->width(), glWidget->height(), 0); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); + glEnable(GL_BLEND); glBegin(GL_QUADS); + glColor4f(1.0f, 1.0f, 1.0f, _alpha); glTexCoord2f(0, 0); glVertex2i(0, glWidget->height()); glTexCoord2f(1, 0); glVertex2i(glWidget->width(), glWidget->height()); glTexCoord2f(1, 1); glVertex2i(glWidget->width(), 0); glTexCoord2f(0, 1); glVertex2i(0, 0); glEnd(); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glPopMatrix(); glDisable(GL_TEXTURE_2D); @@ -181,6 +207,10 @@ void ApplicationOverlay::getClickLocation(int &x, int &y) const { // Draws the FBO texture for Oculus rift. TODO: Draw a curved texture instead of plane. void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { + if (_alpha == 0.0f) { + return; + } + Application* application = Application::getInstance(); QGLWidget* glWidget = application->getGLWidget(); @@ -214,8 +244,6 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { glTranslatef(pos.x, pos.y, pos.z); glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z); - glColor3f(1.0f, 1.0f, 1.0f); - glDepthMask(GL_TRUE); glEnable(GL_ALPHA_TEST); @@ -232,6 +260,8 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { glDepthMask(GL_FALSE); glDisable(GL_ALPHA_TEST); + glColor4f(1.0f, 1.0f, 1.0f, _alpha); + renderTexturedHemisphere(); renderControllerPointersOculus(); @@ -245,6 +275,8 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); glEnable(GL_LIGHTING); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } //Renders optional pointers @@ -292,9 +324,12 @@ void ApplicationOverlay::renderControllerPointers() { QGLWidget* glWidget = application->getGLWidget(); MyAvatar* myAvatar = application->getAvatar(); + //Static variables used for storing controller state static unsigned int pressedTime[2] = { 0, 0 }; static bool isPressed[2] = { false, false }; static bool stateWhenPressed[2] = { false, false }; + static bool triggerPressed[2] = { false, false }; + static bool bumperPressed[2] = { false, false }; const HandData* handData = Application::getInstance()->getAvatar()->getHandData(); @@ -333,6 +368,29 @@ void ApplicationOverlay::renderControllerPointers() { } } + //Check for UI active toggle + if (palmData->getTrigger() == 1.0f) { + if (!triggerPressed[index]) { + if (bumperPressed[index]) { + _active = !_active; + } + triggerPressed[index] = true; + } + } else { + triggerPressed[index] = false; + } + if ((controllerButtons & BUTTON_FWD)) { + if (!bumperPressed[index]) { + if (triggerPressed[index]) { + _active = !_active; + } + bumperPressed[index] = true; + } + } else { + bumperPressed[index] = false; + } + + // Get directon relative to avatar orientation glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * palmData->getFingerDirection(); @@ -440,7 +498,7 @@ void ApplicationOverlay::renderControllerPointersOculus() { glBegin(GL_QUADS); - glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); + glColor4f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], _alpha); glTexCoord2f(0.0f, 0.0f); glVertex3f(lX, tY, -tlZ); glTexCoord2f(1.0f, 0.0f); glVertex3f(rX, tY, -trZ); @@ -509,7 +567,7 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY) glLineWidth(1.0f); //Outer Line glBegin(GL_LINE_STRIP); - glColor3f(1.0f, 0.0f, 0.0f); + glColor4f(1.0f, 0.0f, 0.0f, _alpha); glVertex3f(lX, tY, -tlZ); glVertex3f(rX, tY, -trZ); @@ -517,7 +575,7 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY) glVertex3f(lX, bY, -blZ); glVertex3f(lX, tY, -tlZ); - glColor3f(1.0f, 1.0f, 1.0f); + glColor4f(1.0f, 1.0f, 1.0f, _alpha); glEnd(); glEnable(GL_TEXTURE_2D); diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index de6b376de6..f8893420ac 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -27,13 +27,14 @@ public: ~ApplicationOverlay(); void renderOverlay(bool renderToTexture = false); - void displayOverlayTexture(Camera& whichCamera); + void displayOverlayTexture(); void displayOverlayTextureOculus(Camera& whichCamera); void computeOculusPickRay(float x, float y, glm::vec3& direction) const; void getClickLocation(int &x, int &y) const; // Getters QOpenGLFramebufferObject* getFramebufferObject(); + float getAlpha() const { return _alpha; } private: // Interleaved vertex data @@ -67,6 +68,9 @@ private: int _magX[3]; int _magY[3]; + float _alpha; + bool _active; + GLuint _crosshairTexture; }; From dc663dedf8bec14572097c0e5338035fc7831d9e Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 10:45:59 -0700 Subject: [PATCH 05/13] Fixed compiler warnings --- interface/src/ui/ApplicationOverlay.cpp | 7 ------- interface/src/ui/ApplicationOverlay.h | 2 -- 2 files changed, 9 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 2f94776046..4b0592d805 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -33,8 +33,6 @@ inline float min(float a, float b) { ApplicationOverlay::ApplicationOverlay() : _framebufferObject(NULL), - _oculusAngle(65.0f * RADIANS_PER_DEGREE), - _distance(0.5f), _textureFov(DEFAULT_OCULUS_UI_ANGULAR_SIZE * RADIANS_PER_DEGREE), _crosshairTexture(0), _alpha(1.0f), @@ -70,7 +68,6 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { MyAvatar* myAvatar = application->getAvatar(); //Handle fadeing and deactivation/activation of UI - printf("%f\n", _alpha); if (_active) { _alpha += FADE_SPEED; if (_alpha > 1.0f) { @@ -213,7 +210,6 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { Application* application = Application::getInstance(); - QGLWidget* glWidget = application->getGLWidget(); MyAvatar* myAvatar = application->getAvatar(); const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation(); @@ -282,9 +278,6 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { //Renders optional pointers void ApplicationOverlay::renderPointers() { Application* application = Application::getInstance(); - // Render a crosshair over the mouse when in Oculus - int mouseX = application->getMouseX(); - int mouseY = application->getMouseY(); //lazily load crosshair texture if (_crosshairTexture == 0) { diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index f8893420ac..172b16518c 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -57,8 +57,6 @@ private: QOpenGLFramebufferObject* _framebufferObject; float _trailingAudioLoudness; - float _oculusAngle; - float _distance; float _textureFov; // 0 = Mouse, 1 = Left Controller, 2 = Right Controller bool _reticleActive[3]; From 7bb8e4d5710136bab44e071d401faf20291eee8f Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 11:20:02 -0700 Subject: [PATCH 06/13] Animated magnification opening and closing --- interface/src/ui/ApplicationOverlay.cpp | 53 ++++++++++++++++--------- interface/src/ui/ApplicationOverlay.h | 3 +- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 4b0592d805..8a0ede2d1e 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -20,7 +20,10 @@ #include "ui/Stats.h" -const float FADE_SPEED = 0.02f; +// Used to fade the UI +const float FADE_SPEED = 0.08f; +// Used to animate the magnification windows +const float MAG_SPEED = 0.08f; // Fast helper functions inline float max(float a, float b) { @@ -38,12 +41,9 @@ ApplicationOverlay::ApplicationOverlay() : _alpha(1.0f), _active(true) { - _reticleActive[MOUSE] = false; - _reticleActive[LEFT_CONTROLLER] = false; - _reticleActive[RIGHT_CONTROLLER] = false; - _magActive[MOUSE] = false; - _magActive[LEFT_CONTROLLER] = false; - _magActive[RIGHT_CONTROLLER] = false; + memset(_reticleActive, 0, sizeof(_reticleActive)); + memset(_magActive, 0, sizeof(_reticleActive)); + memset(_magSizeMult, 0, sizeof(_magSizeMult)); } ApplicationOverlay::~ApplicationOverlay() { @@ -245,12 +245,24 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.01f); - //Draw the magnifiers + //Update and draw the magnifiers for (int i = 0; i < 3; i++) { if (_magActive[i]) { - renderMagnifier(_magX[i], _magY[i]); - } + _magSizeMult[i] += MAG_SPEED; + if (_magSizeMult[i] > 1.0f) { + _magSizeMult[i] = 1.0f; + } + } else { + _magSizeMult[i] -= MAG_SPEED; + if (_magSizeMult[i] < 0.0f) { + _magSizeMult[i] = 0.0f; + } + } + + if (_magSizeMult[i] > 0.0f) { + renderMagnifier(_magX[i], _magY[i], _magSizeMult[i]); + } } glDepthMask(GL_FALSE); @@ -505,7 +517,7 @@ void ApplicationOverlay::renderControllerPointersOculus() { } //Renders a small magnification of the currently bound texture at the coordinates -void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY) +void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY, float sizeMult) const { Application* application = Application::getInstance(); QGLWidget* glWidget = application->getGLWidget(); @@ -513,21 +525,24 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY) const int widgetWidth = glWidget->width(); const int widgetHeight = glWidget->height(); - mouseX -= MAGNIFY_WIDTH / 2; - mouseY -= MAGNIFY_HEIGHT / 2; + const float magnifyWidth = MAGNIFY_WIDTH * sizeMult; + const float magnifyHeight = MAGNIFY_HEIGHT * sizeMult; - float newWidth = MAGNIFY_WIDTH * MAGNIFY_MULT; - float newHeight = MAGNIFY_HEIGHT * MAGNIFY_MULT; + mouseX -= magnifyWidth; + mouseY -= magnifyHeight; + + float newWidth = magnifyWidth * MAGNIFY_MULT; + float newHeight = magnifyHeight * MAGNIFY_MULT; // Magnification Texture Coordinates float magnifyULeft = mouseX / (float)widgetWidth; - float magnifyURight = (mouseX + MAGNIFY_WIDTH) / (float)widgetWidth; + float magnifyURight = (mouseX + magnifyWidth) / (float)widgetWidth; float magnifyVBottom = 1.0f - mouseY / (float)widgetHeight; - float magnifyVTop = 1.0f - (mouseY + MAGNIFY_HEIGHT) / (float)widgetHeight; + float magnifyVTop = 1.0f - (mouseY + magnifyHeight) / (float)widgetHeight; // Coordinates of magnification overlay - float newMouseX = (mouseX + MAGNIFY_WIDTH / 2) - newWidth / 2.0f; - float newMouseY = (mouseY + MAGNIFY_HEIGHT / 2) + newHeight / 2.0f; + float newMouseX = (mouseX + magnifyWidth / 2) - newWidth / 2.0f; + float newMouseY = (mouseY + magnifyHeight / 2) + newHeight / 2.0f; // Get position on hemisphere using angle diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 172b16518c..2ed2d7e2db 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -50,7 +50,7 @@ private: void renderPointers(); void renderControllerPointers(); void renderControllerPointersOculus(); - void renderMagnifier(int mouseX, int mouseY); + void renderMagnifier(int mouseX, int mouseY, float sizeMult) const; void renderAudioMeter(); void renderStatsAndLogs(); void renderTexturedHemisphere(); @@ -65,6 +65,7 @@ private: bool _magActive[3]; int _magX[3]; int _magY[3]; + float _magSizeMult[3]; float _alpha; bool _active; From e775d645a76daad5d4460b1cc28b2444760fb383 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 12:19:15 -0700 Subject: [PATCH 07/13] Fixed NAN error with magnification windows --- interface/src/ui/ApplicationOverlay.cpp | 51 ++++++++++++++++++------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 8a0ede2d1e..9bc69a4438 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -411,11 +411,10 @@ void ApplicationOverlay::renderControllerPointers() { //If the cursor is out of the screen then don't render it if (mouseX < 0 || mouseX >= glWidget->width() || mouseY < 0 || mouseY >= glWidget->height()) { + _reticleActive[index] = false; continue; } _reticleActive[index] = true; - float pointerWidth = 40; - float pointerHeight = 40; //if we have the oculus, we should make the cursor smaller since it will be //magnified @@ -435,17 +434,19 @@ void ApplicationOverlay::renderControllerPointers() { continue; } - mouseX -= pointerWidth / 2.0f; - mouseY += pointerHeight / 2.0f; + const float reticleSize = 40.0f; + + mouseX -= reticleSize / 2.0f; + mouseY += reticleSize / 2.0f; glBegin(GL_QUADS); glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); glTexCoord2d(0.0f, 0.0f); glVertex2i(mouseX, mouseY); - glTexCoord2d(1.0f, 0.0f); glVertex2i(mouseX + pointerWidth, mouseY); - glTexCoord2d(1.0f, 1.0f); glVertex2i(mouseX + pointerWidth, mouseY - pointerHeight); - glTexCoord2d(0.0f, 1.0f); glVertex2i(mouseX, mouseY - pointerHeight); + glTexCoord2d(1.0f, 0.0f); glVertex2i(mouseX + reticleSize, mouseY); + glTexCoord2d(1.0f, 1.0f); glVertex2i(mouseX + reticleSize, mouseY - reticleSize); + glTexCoord2d(0.0f, 1.0f); glVertex2i(mouseX, mouseY - reticleSize); glEnd(); } @@ -528,8 +529,8 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY, float sizeMult) const float magnifyWidth = MAGNIFY_WIDTH * sizeMult; const float magnifyHeight = MAGNIFY_HEIGHT * sizeMult; - mouseX -= magnifyWidth; - mouseY -= magnifyHeight; + mouseX -= magnifyWidth / 2; + mouseY -= magnifyHeight / 2; float newWidth = magnifyWidth * MAGNIFY_MULT; float newHeight = magnifyHeight * MAGNIFY_MULT; @@ -558,19 +559,43 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY, float sizeMult) float bY = sin((newVBottom - 0.5f) * _textureFov); float tY = sin((newVTop - 0.5f) * _textureFov); + float blZ, tlZ, brZ, trZ; + float dist; + float discriminant; //Bottom Left dist = sqrt(lX * lX + bY * bY); - float blZ = sqrt(1.0f - dist * dist); + discriminant = 1.0f - dist * dist; + if (discriminant > 0) { + blZ = sqrt(discriminant); + } else { + blZ = 0; + } //Top Left dist = sqrt(lX * lX + tY * tY); - float tlZ = sqrt(1.0f - dist * dist); + discriminant = 1.0f - dist * dist; + if (discriminant > 0) { + tlZ = sqrt(discriminant); + } else { + tlZ = 0; + } //Bottom Right dist = sqrt(rX * rX + bY * bY); - float brZ = sqrt(1.0f - dist * dist); + discriminant = 1.0f - dist * dist; + if (discriminant > 0) { + brZ = sqrt(discriminant); + } else { + brZ = 0; + } //Top Right dist = sqrt(rX * rX + tY * tY); - float trZ = sqrt(1.0f - dist * dist); + discriminant = 1.0f - dist * dist; + if (discriminant > 0) { + trZ = sqrt(discriminant); + } else { + trZ = 0; + } + glDisable(GL_TEXTURE_2D); glLineWidth(1.0f); //Outer Line From bee84a064cafe93de5c9358f94192d95f2ade548 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 12:41:53 -0700 Subject: [PATCH 08/13] Dont render red border for mouse magnifier --- interface/src/ui/ApplicationOverlay.cpp | 32 +++++++++++++------------ interface/src/ui/ApplicationOverlay.h | 2 +- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 9bc69a4438..cb96a2182c 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -261,7 +261,8 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { } if (_magSizeMult[i] > 0.0f) { - renderMagnifier(_magX[i], _magY[i], _magSizeMult[i]); + //Render magnifier, but dont show border for mouse magnifier + renderMagnifier(_magX[i], _magY[i], _magSizeMult[i], i != MOUSE); } } @@ -518,7 +519,7 @@ void ApplicationOverlay::renderControllerPointersOculus() { } //Renders a small magnification of the currently bound texture at the coordinates -void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY, float sizeMult) const +void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY, float sizeMult, bool showBorder) const { Application* application = Application::getInstance(); QGLWidget* glWidget = application->getGLWidget(); @@ -596,23 +597,24 @@ void ApplicationOverlay::renderMagnifier(int mouseX, int mouseY, float sizeMult) trZ = 0; } - glDisable(GL_TEXTURE_2D); - glLineWidth(1.0f); - //Outer Line - glBegin(GL_LINE_STRIP); - glColor4f(1.0f, 0.0f, 0.0f, _alpha); + if (showBorder) { + glDisable(GL_TEXTURE_2D); + glLineWidth(1.0f); + //Outer Line + glBegin(GL_LINE_STRIP); + glColor4f(1.0f, 0.0f, 0.0f, _alpha); - glVertex3f(lX, tY, -tlZ); - glVertex3f(rX, tY, -trZ); - glVertex3f(rX, bY, -brZ); - glVertex3f(lX, bY, -blZ); - glVertex3f(lX, tY, -tlZ); + glVertex3f(lX, tY, -tlZ); + glVertex3f(rX, tY, -trZ); + glVertex3f(rX, bY, -brZ); + glVertex3f(lX, bY, -blZ); + glVertex3f(lX, tY, -tlZ); + glEnd(); + glEnable(GL_TEXTURE_2D); + } glColor4f(1.0f, 1.0f, 1.0f, _alpha); - glEnd(); - glEnable(GL_TEXTURE_2D); - glBegin(GL_QUADS); glTexCoord2f(magnifyULeft, magnifyVBottom); glVertex3f(lX, tY, -tlZ); diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 2ed2d7e2db..3a59dcd7d1 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -50,7 +50,7 @@ private: void renderPointers(); void renderControllerPointers(); void renderControllerPointersOculus(); - void renderMagnifier(int mouseX, int mouseY, float sizeMult) const; + void renderMagnifier(int mouseX, int mouseY, float sizeMult, bool showBorder) const; void renderAudioMeter(); void renderStatsAndLogs(); void renderTexturedHemisphere(); From 6c74650552d5ef97fa5904edf64f665eefd146d0 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 15:40:11 -0700 Subject: [PATCH 09/13] Attempt to fix build errors --- interface/src/ui/ApplicationOverlay.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index cb96a2182c..4a77253304 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -13,6 +13,7 @@ #include #include +#include #include "Application.h" #include "ApplicationOverlay.h" @@ -57,6 +58,7 @@ const float RETICLE_COLOR[] = { 0.0f, 198.0f / 255.0f, 244.0f / 255.0f }; // Renders the overlays either to a texture or to the screen void ApplicationOverlay::renderOverlay(bool renderToTexture) { + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()"); _textureFov = Menu::getInstance()->getOculusUIAngularSize() * RADIANS_PER_DEGREE; From 7cbb19551a36b7b9ee3bbaa78d6f35f00df72781 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 16:38:19 -0700 Subject: [PATCH 10/13] Switched time query method and fixed horrifying bug --- interface/src/ui/ApplicationOverlay.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 4a77253304..ee3c271267 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -13,7 +13,6 @@ #include #include -#include #include "Application.h" #include "ApplicationOverlay.h" @@ -116,6 +115,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) { glPopMatrix(); + glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); @@ -210,6 +210,7 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { return; } + Application* application = Application::getInstance(); MyAvatar* myAvatar = application->getAvatar(); @@ -333,11 +334,11 @@ void ApplicationOverlay::renderControllerPointers() { MyAvatar* myAvatar = application->getAvatar(); //Static variables used for storing controller state - static unsigned int pressedTime[2] = { 0, 0 }; - static bool isPressed[2] = { false, false }; - static bool stateWhenPressed[2] = { false, false }; - static bool triggerPressed[2] = { false, false }; - static bool bumperPressed[2] = { false, false }; + static quint64 pressedTime[3] = { 0, 0, 0 }; + static bool isPressed[3] = { false, false, false }; + static bool stateWhenPressed[3] = { false, false, false }; + static bool triggerPressed[3] = { false, false, false }; + static bool bumperPressed[3] = { false, false, false }; const HandData* handData = Application::getInstance()->getAvatar()->getHandData(); @@ -363,15 +364,15 @@ void ApplicationOverlay::renderControllerPointers() { if (isPressed[index] == false) { //We are now dragging the window isPressed[index] = true; - //set the pressed time in ms - pressedTime[index] = SDL_GetTicks(); + //set the pressed time in us + pressedTime[index] = usecTimestampNow(); stateWhenPressed[index] = _magActive[index]; } } else if (isPressed[index]) { - isPressed[index] = false; - //If the button has been pressed for less than 250 ms + isPressed[index] = false; + //If the button was only pressed for < 250 ms //then disable it. - if (SDL_GetTicks() - pressedTime[index] < 250) { + if (usecTimestampNow() - pressedTime[index] < 250000) { _magActive[index] = !stateWhenPressed[index]; } } From 9f66eeb37ff84b853aefb69a657a04572987165c Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 16:48:06 -0700 Subject: [PATCH 11/13] Added a const variable for readability --- interface/src/ui/ApplicationOverlay.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index ee3c271267..b7c3feca29 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -25,6 +25,8 @@ const float FADE_SPEED = 0.08f; // Used to animate the magnification windows const float MAG_SPEED = 0.08f; +const quint64 MSECS_TO_USECS = 1000ULL; + // Fast helper functions inline float max(float a, float b) { return (a > b) ? a : b; @@ -334,7 +336,7 @@ void ApplicationOverlay::renderControllerPointers() { MyAvatar* myAvatar = application->getAvatar(); //Static variables used for storing controller state - static quint64 pressedTime[3] = { 0, 0, 0 }; + static quint64 pressedTime[3] = { 0ULL, 0ULL, 0ULL }; static bool isPressed[3] = { false, false, false }; static bool stateWhenPressed[3] = { false, false, false }; static bool triggerPressed[3] = { false, false, false }; @@ -372,7 +374,9 @@ void ApplicationOverlay::renderControllerPointers() { isPressed[index] = false; //If the button was only pressed for < 250 ms //then disable it. - if (usecTimestampNow() - pressedTime[index] < 250000) { + + const int MAX_BUTTON_PRESS_TIME = 250 * MSECS_TO_USECS; + if (usecTimestampNow() - pressedTime[index] < MAX_BUTTON_PRESS_TIME) { _magActive[index] = !stateWhenPressed[index]; } } From fa32ad5b117f73df3c598491fb05ae05113e2cec Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 17:14:26 -0700 Subject: [PATCH 12/13] De-janked code by removing magic numbers --- interface/src/ui/ApplicationOverlay.cpp | 17 ++++++++--------- interface/src/ui/ApplicationOverlay.h | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index b7c3feca29..9be556cf62 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -190,7 +190,7 @@ void ApplicationOverlay::getClickLocation(int &x, int &y) const { const float yRange = MAGNIFY_WIDTH * MAGNIFY_MULT / 2.0f; //Loop through all magnification windows - for (int i = 0; i < 3; i++) { + for (int i = 0; i < NUMBER_OF_MAGNIFIERS; i++) { if (_magActive[i]) { dx = x - _magX[i]; dy = y - _magY[i]; @@ -212,7 +212,6 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { return; } - Application* application = Application::getInstance(); MyAvatar* myAvatar = application->getAvatar(); @@ -251,7 +250,7 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { glAlphaFunc(GL_GREATER, 0.01f); //Update and draw the magnifiers - for (int i = 0; i < 3; i++) { + for (int i = 0; i < NUMBER_OF_MAGNIFIERS; i++) { if (_magActive[i]) { _magSizeMult[i] += MAG_SPEED; @@ -336,11 +335,11 @@ void ApplicationOverlay::renderControllerPointers() { MyAvatar* myAvatar = application->getAvatar(); //Static variables used for storing controller state - static quint64 pressedTime[3] = { 0ULL, 0ULL, 0ULL }; - static bool isPressed[3] = { false, false, false }; - static bool stateWhenPressed[3] = { false, false, false }; - static bool triggerPressed[3] = { false, false, false }; - static bool bumperPressed[3] = { false, false, false }; + static quint64 pressedTime[NUMBER_OF_MAGNIFIERS] = { 0ULL, 0ULL, 0ULL }; + static bool isPressed[NUMBER_OF_MAGNIFIERS] = { false, false, false }; + static bool stateWhenPressed[NUMBER_OF_MAGNIFIERS] = { false, false, false }; + static bool triggerPressed[NUMBER_OF_MAGNIFIERS] = { false, false, false }; + static bool bumperPressed[NUMBER_OF_MAGNIFIERS] = { false, false, false }; const HandData* handData = Application::getInstance()->getAvatar()->getHandData(); @@ -472,7 +471,7 @@ void ApplicationOverlay::renderControllerPointersOculus() { glBindTexture(GL_TEXTURE_2D, _crosshairTexture); glDisable(GL_DEPTH_TEST); - for (int i = 0; i < 3; i++) { + for (int i = 0; i < NUMBER_OF_MAGNIFIERS; i++) { //Dont render the reticle if its inactive if (!_reticleActive[i]) { diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index 3a59dcd7d1..f8fd95d2f7 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -43,8 +43,6 @@ private: glm::vec2 uv; }; - enum MousePointerDevice { MOUSE, LEFT_CONTROLLER, RIGHT_CONTROLLER }; - typedef QPair VerticesIndices; void renderPointers(); @@ -59,13 +57,14 @@ private: float _trailingAudioLoudness; float _textureFov; // 0 = Mouse, 1 = Left Controller, 2 = Right Controller - bool _reticleActive[3]; - int _mouseX[3]; - int _mouseY[3]; - bool _magActive[3]; - int _magX[3]; - int _magY[3]; - float _magSizeMult[3]; + enum MagnifyDevices { MOUSE, LEFT_CONTROLLER, RIGHT_CONTROLLER, NUMBER_OF_MAGNIFIERS = RIGHT_CONTROLLER + 1 }; + bool _reticleActive[NUMBER_OF_MAGNIFIERS]; + int _mouseX[NUMBER_OF_MAGNIFIERS]; + int _mouseY[NUMBER_OF_MAGNIFIERS]; + bool _magActive[NUMBER_OF_MAGNIFIERS]; + int _magX[NUMBER_OF_MAGNIFIERS]; + int _magY[NUMBER_OF_MAGNIFIERS]; + float _magSizeMult[NUMBER_OF_MAGNIFIERS]; float _alpha; bool _active; From 64725dd21bf001e3111dcc76ebf32d77f18a1044 Mon Sep 17 00:00:00 2001 From: barnold1953 Date: Tue, 17 Jun 2014 17:15:43 -0700 Subject: [PATCH 13/13] Unneeded comment --- interface/src/ui/ApplicationOverlay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/ApplicationOverlay.h b/interface/src/ui/ApplicationOverlay.h index f8fd95d2f7..b9f9596ccf 100644 --- a/interface/src/ui/ApplicationOverlay.h +++ b/interface/src/ui/ApplicationOverlay.h @@ -56,7 +56,7 @@ private: QOpenGLFramebufferObject* _framebufferObject; float _trailingAudioLoudness; float _textureFov; - // 0 = Mouse, 1 = Left Controller, 2 = Right Controller + enum MagnifyDevices { MOUSE, LEFT_CONTROLLER, RIGHT_CONTROLLER, NUMBER_OF_MAGNIFIERS = RIGHT_CONTROLLER + 1 }; bool _reticleActive[NUMBER_OF_MAGNIFIERS]; int _mouseX[NUMBER_OF_MAGNIFIERS];