Support for multiple oculus overlay magnifiers

This commit is contained in:
barnold1953 2014-06-12 12:07:25 -07:00
parent 762751ef6a
commit 18543ff313
2 changed files with 139 additions and 121 deletions

View file

@ -16,6 +16,7 @@
#include "Application.h"
#include "ApplicationOverlay.h"
#include "devices/OculusManager.h"
#include "ui/Stats.h"
@ -35,7 +36,7 @@ ApplicationOverlay::~ApplicationOverlay() {
const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f };
void renderControllerPointer() {
void ApplicationOverlay::renderControllerPointer() {
Application* application = Application::getInstance();
QGLWidget* glWidget = application->getGLWidget();
MyAvatar* myAvatar = application->getAvatar();
@ -60,7 +61,7 @@ void renderControllerPointer() {
if (handData->getPalms()[palmIndex].isActive()) {
palmData = &handData->getPalms()[palmIndex];
} else {
return;
continue;
}
// Get directon relative to avatar orientation
@ -75,24 +76,25 @@ void renderControllerPointer() {
int mouseX = cursorRange * xAngle;
int mouseY = cursorRange * yAngle;
if (mouseX < 0) {
//mouseX = 0;
continue;
} else if (mouseX > glWidget->width()) {
//mouseX = glWidget->width();
continue;
}
if (mouseY < 0) {
//mouseY = 0;
continue;
} else if (mouseY > glWidget->width()) {
//mouseY = glWidget->width();
if (mouseX < 0 || mouseX >= glWidget->width() || mouseY < 0 || mouseY >= glWidget->height()) {
continue;
}
const float pointerWidth = 40;
const float pointerHeight = 40;
const float crossPad = 16;
float pointerWidth = 40;
float pointerHeight = 40;
float crossPad = 16;
//if we have the oculus, we should make the cursor smaller since it will be
//magnified
if (OculusManager::isConnected()) {
pointerWidth /= 4;
pointerHeight /= 4;
crossPad /= 4;
_mouseX[_numMagnifiers] = mouseX;
_mouseY[_numMagnifiers] = mouseY;
_numMagnifiers++;
}
mouseX -= pointerWidth / 2.0f;
mouseY += pointerHeight / 2.0f;
@ -131,6 +133,8 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
BandwidthMeter* bandwidthMeter = application->getBandwidthMeter();
NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay();
_numMagnifiers = 0;
int mouseX = application->getMouseX();
int mouseY = application->getMouseY();
bool renderPointer = renderToTexture;
@ -310,15 +314,21 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
overlays.render2D();
// Render a crosshair over the pointer when in Oculus
if (renderPointer) {
// Render a crosshair over the mouse when in Oculus
if (renderPointer && application->getLastMouseMoveType() == QEvent::MouseMove) {
const float pointerWidth = 10;
const float pointerHeight = 10;
const float crossPad = 4;
_numMagnifiers = 1;
_mouseX[0] = application->getMouseX();
_mouseY[0] = application->getMouseY();
mouseX -= pointerWidth / 2.0f;
mouseY += pointerHeight / 2.0f;
glBegin(GL_QUADS);
glColor3f(1, 0, 0);
@ -336,7 +346,7 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
glVertex2i(mouseX + crossPad, mouseY - pointerHeight);
glEnd();
} else if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseMouseInput)) {
} 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
renderControllerPointer();
}
@ -418,12 +428,8 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
MyAvatar* myAvatar = application->getAvatar();
const glm::vec3& viewMatrixTranslation = application->getViewMatrixTranslation();
int mouseX = application->getMouseX();
int mouseY = application->getMouseY();
const int widgetWidth = glWidget->width();
const int widgetHeight = glWidget->height();
float magnifyWidth = 80.0f;
float magnifyHeight = 60.0f;
const float magnification = 4.0f;
// Get vertical FoV of the displayed overlay texture
@ -480,8 +486,16 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.01f);
//Draw the magnifying glass
float leftX, rightX, leftZ, rightZ, topZ, bottomZ;
//Draw the magnifiers
for (int i = 0; i < _numMagnifiers; i++) {
float magnifyWidth = 80.0f;
float magnifyHeight = 60.0f;
int mouseX = _mouseX[i];
int mouseY = _mouseY[i];
mouseX -= magnifyWidth / 2;
mouseY -= magnifyHeight / 2;
@ -521,8 +535,6 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
float bottomAngle = (newMouseY / (float)widgetHeight) * _oculusAngle - halfVerticalAngle;
float topAngle = ((newMouseY - newHeight) / (float)widgetHeight) * _oculusAngle - halfVerticalAngle;
float leftX, rightX, leftZ, rightZ, topZ, bottomZ;
// Get position on hemisphere using angle
if (_uiType == HEMISPHERE) {
@ -588,6 +600,8 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
glEnd();
}
}
glDepthMask(GL_FALSE);
glDisable(GL_ALPHA_TEST);

View file

@ -46,6 +46,7 @@ private:
typedef QPair<GLuint, GLuint> VerticesIndices;
void renderControllerPointer();
void renderTexturedHemisphere();
QOpenGLFramebufferObject* _framebufferObject;
@ -53,6 +54,9 @@ private:
float _oculusAngle;
float _distance;
UIType _uiType;
int _mouseX[2];
int _mouseY[2];
int _numMagnifiers;
};
#endif // hifi_ApplicationOverlay_h