History

Removing access to the gl widget and display managers

Brad Davis committed 11 years ago

Commit 302aa9d1 parent 539063035 files · +401 −440Browse files

Showing the changes to interface/src/ui/ApplicationOverlay.cpp (1 of 35 files). Show all

Unified · Split

interface/src/ui/ApplicationOverlay.cpp+106−98
@@ -12,10 +12,13 @@ · 11 unmodified lines
1212 #include "InterfaceConfig.h"
1313
1414 #include <QOpenGLFramebufferObject>
15+#include <QOpenGLTexture>
1516
1617 #include <avatar/AvatarManager.h>
1718 #include <GLMHelpers.h>
1819 #include <PathUtils.h>
20+#include <gpu/GLBackend.h>
21+#include <GLMHelpers.h>
1922 #include <PerfStat.h>
2023 #include <OffscreenUi.h>
2124
@@ -25,7 +28,6 @@ · 3 unmodified lines
2528 #include "audio/AudioToolBox.h"
2629 #include "Application.h"
2730 #include "ApplicationOverlay.h"
28−#include "devices/OculusManager.h"
2931
3032 #include "Util.h"
3133 #include "ui/Stats.h"
@@ -45,7 +47,7 @@ const float CONNECTION_STATUS_BORDER_LINE_WIDTH = 4.0f; · 13 unmodified lines
4547
4648 static const float MOUSE_PITCH_RANGE = 1.0f * PI;
4749 static const float MOUSE_YAW_RANGE = 0.5f * TWO_PI;
48−
50+static const glm::vec2 MOUSE_RANGE(MOUSE_YAW_RANGE, MOUSE_PITCH_RANGE);
4951
5052 // Return a point's cartesian coordinates on a sphere from pitch and yaw
5153 glm::vec3 getPoint(float yaw, float pitch) {
@@ -133,7 +135,7 @@ void ApplicationOverlay::renderReticle(glm::quat orientation, float alpha) { · 81 unmodified lines
133135 }
134136
135137 ApplicationOverlay::ApplicationOverlay() :
136− _textureFov(glm::radians(DEFAULT_OCULUS_UI_ANGULAR_SIZE)),
138+ _textureFov(glm::radians(DEFAULT_HMD_UI_ANGULAR_SIZE)),
137139 _textureAspectRatio(1.0f),
138140 _lastMouseMove(0),
139141 _magnifier(true),
@@ -185,10 +187,10 @@ ApplicationOverlay::~ApplicationOverlay() { · 45 unmodified lines
185187 void ApplicationOverlay::renderOverlay() {
186188 PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "ApplicationOverlay::displayOverlay()");
187189 Overlays& overlays = qApp->getOverlays();
188− auto glCanvas = Application::getInstance()->getGLWidget();
189190
190− _textureFov = glm::radians(_oculusUIAngularSize);
191− _textureAspectRatio = (float)glCanvas->getDeviceWidth() / (float)glCanvas->getDeviceHeight();
191+ _textureFov = glm::radians(_hmdUIAngularSize);
192+ auto deviceSize = Application::getInstance()->getDeviceSize();
193+ _textureAspectRatio = (float)deviceSize.width() / (float)deviceSize.height();
192194
193195 //Handle fading and deactivation/activation of UI
194196
@@ -201,12 +203,12 @@ void ApplicationOverlay::renderOverlay() { · 6 unmodified lines
201203 _overlays.buildFramebufferObject();
202204 _overlays.bind();
203205 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
204−
206+
205207 glPushMatrix(); {
206208 const float NEAR_CLIP = -10000;
207209 const float FAR_CLIP = 10000;
208210 glLoadIdentity();
209− glOrtho(0, glCanvas->width(), glCanvas->height(), 0, NEAR_CLIP, FAR_CLIP);
211+ glOrtho(0, deviceSize.width(), deviceSize.height(), 0, NEAR_CLIP, FAR_CLIP);
210212
211213 glMatrixMode(GL_MODELVIEW);
212214
@@ -278,7 +280,7 @@ void ApplicationOverlay::displayOverlayTexture() { · 65 unmodified lines
278280 }
279281
280282 // Draws the FBO texture for Oculus rift.
281−void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) {
283+void ApplicationOverlay::displayOverlayTextureHmd(Camera& whichCamera) {
282284 if (_alpha == 0.0f) {
283285 return;
284286 }
@@ -356,7 +358,7 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { · 71 unmodified lines
356358 }
357359
358360 // Draws the FBO texture for 3DTV.
359−void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float aspectRatio, float fov) {
361+void ApplicationOverlay::displayOverlayTextureStereo(Camera& whichCamera, float aspectRatio, float fov) {
360362 if (_alpha == 0.0f) {
361363 return;
362364 }
@@ -411,19 +413,19 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as · 48 unmodified lines
411413 overlayColor);
412414 });
413415
414− auto glCanvas = Application::getInstance()->getGLWidget();
415− if (_crosshairTexture == 0) {
416− _crosshairTexture = glCanvas->bindTexture(QImage(PathUtils::resourcesPath() + "images/sixense-reticle.png"));
416+ if (!_crosshairTexture) {
417+ _crosshairTexture = DependencyManager::get<TextureCache>()->
418+ getImageTexture(PathUtils::resourcesPath() + "images/sixense-reticle.png");
417419 }
418420
419421 //draw the mouse pointer
420− glBindTexture(GL_TEXTURE_2D, _crosshairTexture);
421−
422− const float reticleSize = 40.0f / glCanvas->width() * quadWidth;
422+ glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(_crosshairTexture));
423+ glm::vec2 canvasSize = qApp->getCanvasSize();
424+ const float reticleSize = 40.0f / canvasSize.x * quadWidth;
423425 x -= reticleSize / 2.0f;
424426 y += reticleSize / 2.0f;
425− const float mouseX = (qApp->getMouseX() / (float)glCanvas->width()) * quadWidth;
426− const float mouseY = (1.0 - (qApp->getMouseY() / (float)glCanvas->height())) * quadHeight;
427+ const float mouseX = (qApp->getMouseX() / (float)canvasSize.x) * quadWidth;
428+ const float mouseY = (1.0 - (qApp->getMouseY() / (float)canvasSize.y)) * quadHeight;
427429
428430 glm::vec4 reticleColor = { RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], 1.0f };
429431
@@ -447,24 +449,23 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as · 17 unmodified lines
447449 glEnable(GL_LIGHTING);
448450 }
449451
450−void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const {
452+void ApplicationOverlay::computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) {
451453 const MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
452− const float pitch = (0.5f - y) * MOUSE_PITCH_RANGE;
453− const float yaw = (0.5f - x) * MOUSE_YAW_RANGE;
454− const glm::quat orientation(glm::vec3(pitch, yaw, 0.0f));
454+ cursorPos = 0.5f - cursorPos;
455+ cursorPos *= MOUSE_RANGE;
456+ const glm::quat orientation(glm::vec3(cursorPos, 0.0f));
455457 const glm::vec3 localDirection = orientation * IDENTITY_FRONT;
456458
457459 // Get cursor position
458− const glm::vec3 cursorPos = myAvatar->getDefaultEyePosition() + myAvatar->getOrientation() * localDirection;
460+ const glm::vec3 cursorDir = myAvatar->getDefaultEyePosition() + myAvatar->getOrientation() * localDirection;
459461
460462 // Ray start where the eye position is and stop where the cursor is
461463 origin = myAvatar->getEyePosition();
462− direction = cursorPos - origin;
464+ direction = cursorDir - origin;
463465 }
464466
465467 //Caculate the click location using one of the sixense controllers. Scale is not applied
466468 QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const {
467− auto glCanvas = Application::getInstance()->getGLWidget();
468469 MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
469470
470471 glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm);
@@ -475,8 +476,8 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { · 4 unmodified lines
475476 glm::vec3 tipPos = invOrientation * (tip - eyePos);
476477
477478 QPoint rv;
478−
479− if (OculusManager::isConnected()) {
479+ auto canvasSize = qApp->getCanvasSize();
480+ if (qApp->isHMDMode()) {
480481 float t;
481482
482483 //We back the ray up by dir to ensure that it will not start inside the UI.
@@ -495,8 +496,8 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { · 12 unmodified lines
495496 float u = asin(collisionPos.x) / (_textureFov)+0.5f;
496497 float v = 1.0 - (asin(collisionPos.y) / (_textureFov)+0.5f);
497498
498− rv.setX(u * glCanvas->width());
499− rv.setY(v * glCanvas->height());
499+ rv.setX(u * canvasSize.x);
500+ rv.setY(v * canvasSize.y);
500501 }
501502 } else {
502503 //if they did not click on the overlay, just set the coords to INT_MAX
@@ -513,8 +514,8 @@ QPoint ApplicationOverlay::getPalmClickLocation(const PalmData *palm) const { · 10 unmodified lines
513514 ndcSpacePos = glm::vec3(clipSpacePos) / clipSpacePos.w;
514515 }
515516
516− rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * glCanvas->width());
517− rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * glCanvas->height());
517+ rv.setX(((ndcSpacePos.x + 1.0) / 2.0) * canvasSize.x);
518+ rv.setY((1.0 - ((ndcSpacePos.y + 1.0) / 2.0)) * canvasSize.y);
518519 }
519520 return rv;
520521 }
@@ -539,18 +540,17 @@ bool ApplicationOverlay::calculateRayUICollisionPoint(const glm::vec3& position, · 18 unmodified lines
539540
540541 //Renders optional pointers
541542 void ApplicationOverlay::renderPointers() {
542− auto glCanvas = Application::getInstance()->getGLWidget();
543−
544543 //lazily load crosshair texture
545544 if (_crosshairTexture == 0) {
546− _crosshairTexture = glCanvas->bindTexture(QImage(PathUtils::resourcesPath() + "images/sixense-reticle.png"));
545+ _crosshairTexture = DependencyManager::get<TextureCache>()->
546+ getImageTexture(PathUtils::resourcesPath() + "images/sixense-reticle.png");
547547 }
548548 glEnable(GL_TEXTURE_2D);
549549
550550 glActiveTexture(GL_TEXTURE0);
551− glBindTexture(GL_TEXTURE_2D, _crosshairTexture);
552−
553− if (OculusManager::isConnected() && !qApp->getLastMouseMoveWasSimulated() && !qApp->isMouseHidden()) {
551+ glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(_crosshairTexture));
552+
553+ if (qApp->isHMDMode() && !qApp->getLastMouseMoveWasSimulated() && !qApp->isMouseHidden()) {
554554 //If we are in oculus, render reticle later
555555 if (_lastMouseMove == 0) {
556556 _lastMouseMove = usecTimestampNow();
@@ -561,9 +561,9 @@ void ApplicationOverlay::renderPointers() { · 4 unmodified lines
561561 if (_reticlePosition[MOUSE] != position) {
562562 _lastMouseMove = usecTimestampNow();
563563 } else if (usecTimestampNow() - _lastMouseMove > MAX_IDLE_TIME * USECS_PER_SECOND) {
564− float pitch = 0.0f, yaw = 0.0f, roll = 0.0f; // radians
565− OculusManager::getEulerAngles(yaw, pitch, roll);
566− glm::quat orientation(glm::vec3(pitch, yaw, roll));
564+ //float pitch = 0.0f, yaw = 0.0f, roll = 0.0f; // radians
565+ //OculusManager::getEulerAngles(yaw, pitch, roll);
566+ glm::quat orientation = qApp->getHeadOrientation(); // (glm::vec3(pitch, yaw, roll));
567567 glm::vec3 result;
568568
569569 MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
@@ -574,7 +574,8 @@ void ApplicationOverlay::renderPointers() { · 4 unmodified lines
574574 glm::vec2 spericalPos = directionToSpherical(glm::normalize(lookAtDirection));
575575 glm::vec2 screenPos = sphericalToScreen(spericalPos);
576576 position = QPoint(screenPos.x, screenPos.y);
577− glCanvas->cursor().setPos(glCanvas->mapToGlobal(position));
577+ // FIXME
578+ //glCanvas->cursor().setPos(glCanvas->mapToGlobal(position));
578579 } else {
579580 qDebug() << "No collision point";
580581 }
@@ -597,7 +598,6 @@ void ApplicationOverlay::renderPointers() { · 16 unmodified lines
597598 }
598599
599600 void ApplicationOverlay::renderControllerPointers() {
600− auto glCanvas = Application::getInstance()->getGLWidget();
601601 MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
602602
603603 //Static variables used for storing controller state
@@ -646,7 +646,7 @@ void ApplicationOverlay::renderControllerPointers() { · 42 unmodified lines
646646
647647 //if we have the oculus, we should make the cursor smaller since it will be
648648 //magnified
649− if (OculusManager::isConnected()) {
649+ if (qApp->isHMDMode()) {
650650
651651 QPoint point = getPalmClickLocation(palmData);
652652
@@ -661,6 +661,7 @@ void ApplicationOverlay::renderControllerPointers() { · 8 unmodified lines
661661 continue;
662662 }
663663
664+ auto canvasSize = qApp->getCanvasSize();
664665 int mouseX, mouseY;
665666 if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers)) {
666667 QPoint res = getPalmClickLocation(palmData);
@@ -675,14 +676,14 @@ void ApplicationOverlay::renderControllerPointers() { · 8 unmodified lines
675676 float yAngle = 0.5f - ((atan2(direction.z, direction.y) + M_PI_2));
676677
677678 // Get the pixel range over which the xAngle and yAngle are scaled
678− float cursorRange = glCanvas->width() * SixenseManager::getInstance().getCursorPixelRangeMult();
679+ float cursorRange = canvasSize.x * SixenseManager::getInstance().getCursorPixelRangeMult();
679680
680− mouseX = (glCanvas->width() / 2.0f + cursorRange * xAngle);
681− mouseY = (glCanvas->height() / 2.0f + cursorRange * yAngle);
681+ mouseX = (canvasSize.x / 2.0f + cursorRange * xAngle);
682+ mouseY = (canvasSize.y / 2.0f + cursorRange * yAngle);
682683 }
683684
684685 //If the cursor is out of the screen then don't render it
685− if (mouseX < 0 || mouseX >= glCanvas->width() || mouseY < 0 || mouseY >= glCanvas->height()) {
686+ if (mouseX < 0 || mouseX >= canvasSize.x || mouseY < 0 || mouseY >= canvasSize.y) {
686687 _reticleActive[index] = false;
687688 continue;
688689 }
@@ -707,7 +708,7 @@ void ApplicationOverlay::renderControllerPointers() { · 18 unmodified lines
707708 }
708709
709710 void ApplicationOverlay::renderPointersOculus(const glm::vec3& eyePos) {
710− glBindTexture(GL_TEXTURE_2D, _crosshairTexture);
711+ glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(_crosshairTexture));
711712 glDisable(GL_DEPTH_TEST);
712713 glMatrixMode(GL_MODELVIEW);
713714
@@ -744,10 +745,10 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool · 30 unmodified lines
744745 if (!_magnifier) {
745746 return;
746747 }
747− auto glCanvas = Application::getInstance()->getGLWidget();
748+ auto canvasSize = qApp->getCanvasSize();
748749
749− const int widgetWidth = glCanvas->width();
750− const int widgetHeight = glCanvas->height();
750+ const int widgetWidth = canvasSize.x;
751+ const int widgetHeight = canvasSize.y;
751752
752753 const float halfWidth = (MAGNIFY_WIDTH / _textureAspectRatio) * sizeMult / 2.0f;
753754 const float halfHeight = MAGNIFY_HEIGHT * sizeMult / 2.0f;
@@ -809,7 +810,6 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool · 55 unmodified lines
809810 }
810811
811812 void ApplicationOverlay::renderAudioMeter() {
812− auto glCanvas = Application::getInstance()->getGLWidget();
813813 auto audio = DependencyManager::get<AudioClient>();
814814
815815 // Audio VU Meter and Mute Icon
@@ -822,7 +822,7 @@ void ApplicationOverlay::renderAudioMeter() { · 6 unmodified lines
822822 const int AUDIO_METER_X = MIRROR_VIEW_LEFT_PADDING + MUTE_ICON_SIZE + AUDIO_METER_GAP;
823823
824824 int audioMeterY;
825− bool smallMirrorVisible = Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && !OculusManager::isConnected();
825+ bool smallMirrorVisible = Menu::getInstance()->isOptionChecked(MenuOption::Mirror) && !qApp->isHMDMode();
826826 bool boxed = smallMirrorVisible &&
827827 !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror);
828828 if (boxed) {
@@ -857,16 +857,17 @@ void ApplicationOverlay::renderAudioMeter() { · 28 unmodified lines
857857 }
858858 bool isClipping = ((audio->getTimeSinceLastClip() > 0.0f) && (audio->getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME));
859859
860+ auto canvasSize = qApp->getCanvasSize();
860861 if ((audio->getTimeSinceLastClip() > 0.0f) && (audio->getTimeSinceLastClip() < CLIPPING_INDICATOR_TIME)) {
861862 const float MAX_MAGNITUDE = 0.7f;
862863 float magnitude = MAX_MAGNITUDE * (1 - audio->getTimeSinceLastClip() / CLIPPING_INDICATOR_TIME);
863− renderCollisionOverlay(glCanvas->width(), glCanvas->height(), magnitude, 1.0f);
864+ renderCollisionOverlay(canvasSize.x, canvasSize.y, magnitude, 1.0f);
864865 }
865866
866867 DependencyManager::get<AudioToolBox>()->render(MIRROR_VIEW_LEFT_PADDING + AUDIO_METER_GAP, audioMeterY, boxed);
867868
868− DependencyManager::get<AudioScope>()->render(glCanvas->width(), glCanvas->height());
869− DependencyManager::get<AudioIOStatsRenderer>()->render(WHITE_TEXT, glCanvas->width(), glCanvas->height());
869+ DependencyManager::get<AudioScope>()->render(canvasSize.x, canvasSize.y);
870+ DependencyManager::get<AudioIOStatsRenderer>()->render(WHITE_TEXT, canvasSize.x, canvasSize.y);
870871
871872 audioMeterY += AUDIO_METER_HEIGHT;
872873
@@ -927,7 +928,6 @@ void ApplicationOverlay::renderStatsAndLogs() { · 54 unmodified lines
927928 Application* application = Application::getInstance();
928929 QSharedPointer<BandwidthRecorder> bandwidthRecorder = DependencyManager::get<BandwidthRecorder>();
929930
930− auto glCanvas = Application::getInstance()->getGLWidget();
931931 const OctreePacketProcessor& octreePacketProcessor = application->getOctreePacketProcessor();
932932 NodeBounds& nodeBoundsDisplay = application->getNodeBoundsDisplay();
933933
@@ -950,12 +950,13 @@ void ApplicationOverlay::renderStatsAndLogs() { · 16 unmodified lines
950950
951951 // Show on-screen msec timer
952952 if (Menu::getInstance()->isOptionChecked(MenuOption::FrameTimer)) {
953+ auto canvasSize = qApp->getCanvasSize();
953954 quint64 mSecsNow = floor(usecTimestampNow() / 1000.0 + 0.5);
954955 QString frameTimer = QString("%1\n").arg((int)(mSecsNow % 1000));
955956 int timerBottom =
956957 (Menu::getInstance()->isOptionChecked(MenuOption::Stats))
957958 ? 80 : 20;
958− drawText(glCanvas->width() - 100, glCanvas->height() - timerBottom,
959+ drawText(canvasSize.x - 100, canvasSize.y - timerBottom,
959960 0.30f, 0.0f, 0, frameTimer.toUtf8().constData(), WHITE_TEXT);
960961 }
961962 nodeBoundsDisplay.drawOverlay();
@@ -965,25 +966,22 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { · 3 unmodified lines
965966 auto nodeList = DependencyManager::get<NodeList>();
966967
967968 if (nodeList && !nodeList->getDomainHandler().isConnected()) {
968− auto glCanvas = Application::getInstance()->getGLWidget();
969969 auto geometryCache = DependencyManager::get<GeometryCache>();
970− int width = glCanvas->width();
971− int height = glCanvas->height();
972−
973− if (width != _previousBorderWidth || height != _previousBorderHeight) {
970+ auto canvasSize = qApp->getCanvasSize();
971+ if (canvasSize.x != _previousBorderWidth || canvasSize.y != _previousBorderHeight) {
974972 glm::vec4 color(CONNECTION_STATUS_BORDER_COLOR[0],
975973 CONNECTION_STATUS_BORDER_COLOR[1],
976974 CONNECTION_STATUS_BORDER_COLOR[2], 1.0f);
977975
978976 QVector<glm::vec2> border;
979977 border << glm::vec2(0, 0);
980− border << glm::vec2(0, height);
981− border << glm::vec2(width, height);
982− border << glm::vec2(width, 0);
978+ border << glm::vec2(0, canvasSize.y);
979+ border << glm::vec2(canvasSize.x, canvasSize.y);
980+ border << glm::vec2(canvasSize.x, 0);
983981 border << glm::vec2(0, 0);
984982 geometryCache->updateVertices(_domainStatusBorder, border, color);
985− _previousBorderWidth = width;
986− _previousBorderHeight = height;
983+ _previousBorderWidth = canvasSize.x;
984+ _previousBorderHeight = canvasSize.y;
987985 }
988986
989987 glLineWidth(CONNECTION_STATUS_BORDER_LINE_WIDTH);
@@ -1101,8 +1099,8 @@ void ApplicationOverlay::TexturedHemisphere::cleanupVBO() { · 111 unmodified lines
11011099 }
11021100
11031101 void ApplicationOverlay::TexturedHemisphere::buildFramebufferObject() {
1104− QSize size = Application::getInstance()->getGLWidget()->getDeviceSize();
1105− if (_framebufferObject != NULL && size == _framebufferObject->size()) {
1102+ auto deviceSize = qApp->getDeviceSize();
1103+ if (_framebufferObject != NULL && deviceSize == _framebufferObject->size()) {
11061104 // Already build
11071105 return;
11081106 }
@@ -1111,7 +1109,7 @@ void ApplicationOverlay::TexturedHemisphere::buildFramebufferObject() { · 2 unmodified lines
11111109 delete _framebufferObject;
11121110 }
11131111
1114− _framebufferObject = new QOpenGLFramebufferObject(size, QOpenGLFramebufferObject::Depth);
1112+ _framebufferObject = new QOpenGLFramebufferObject(deviceSize, QOpenGLFramebufferObject::Depth);
11151113 glBindTexture(GL_TEXTURE_2D, getTexture());
11161114 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
11171115 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -1154,7 +1152,7 @@ GLuint ApplicationOverlay::TexturedHemisphere::getTexture() { · 36 unmodified lines
11541152 return _framebufferObject->texture();
11551153 }
11561154
1157−glm::vec2 ApplicationOverlay::directionToSpherical(glm::vec3 direction) const {
1155+glm::vec2 ApplicationOverlay::directionToSpherical(const glm::vec3& direction) {
11581156 glm::vec2 result;
11591157 // Compute yaw
11601158 glm::vec3 normalProjection = glm::normalize(glm::vec3(direction.x, 0.0f, direction.z));
@@ -1170,47 +1168,57 @@ glm::vec2 ApplicationOverlay::directionToSpherical(glm::vec3 direction) const { · 9 unmodified lines
11701168 return result;
11711169 }
11721170
1173−glm::vec3 ApplicationOverlay::sphericalToDirection(glm::vec2 sphericalPos) const {
1171+glm::vec3 ApplicationOverlay::sphericalToDirection(const glm::vec2& sphericalPos) {
11741172 glm::quat rotation(glm::vec3(sphericalPos.y, sphericalPos.x, 0.0f));
11751173 return rotation * IDENTITY_FRONT;
11761174 }
11771175
1178−glm::vec2 ApplicationOverlay::screenToSpherical(glm::vec2 screenPos) const {
1179− QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize();
1180− float yaw = -(screenPos.x / screenSize.width() - 0.5f) * MOUSE_YAW_RANGE;
1181− float pitch = (screenPos.y / screenSize.height() - 0.5f) * MOUSE_PITCH_RANGE;
1176+glm::vec2 ApplicationOverlay::screenToSpherical(const glm::vec2& screenPos) {
1177+ auto screenSize = qApp->getCanvasSize();
1178+ glm::vec2 result;
1179+ result.x = -(screenPos.x / screenSize.x - 0.5f);
1180+ result.y = (screenPos.y / screenSize.y - 0.5f);
1181+ result.x *= MOUSE_YAW_RANGE;
1182+ result.y *= MOUSE_PITCH_RANGE;
11821183
1183− return glm::vec2(yaw, pitch);
1184+ return result;
11841185 }
11851186
1186−glm::vec2 ApplicationOverlay::sphericalToScreen(glm::vec2 sphericalPos) const {
1187− QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize();
1188− float x = (-sphericalPos.x / MOUSE_YAW_RANGE + 0.5f) * screenSize.width();
1189− float y = (sphericalPos.y / MOUSE_PITCH_RANGE + 0.5f) * screenSize.height();
1190−
1191− return glm::vec2(x, y);
1187+glm::vec2 ApplicationOverlay::sphericalToScreen(const glm::vec2& sphericalPos) {
1188+ glm::vec2 result = sphericalPos;
1189+ result.x *= -1.0;
1190+ result /= MOUSE_RANGE;
1191+ result += 0.5f;
1192+ result *= qApp->getCanvasSize();
1193+ return result;
11921194 }
11931195
1194−glm::vec2 ApplicationOverlay::sphericalToOverlay(glm::vec2 sphericalPos) const {
1195− QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize();
1196− float x = (-sphericalPos.x / (_textureFov * _textureAspectRatio) + 0.5f) * screenSize.width();
1197− float y = (sphericalPos.y / _textureFov + 0.5f) * screenSize.height();
1198−
1199− return glm::vec2(x, y);
1196+glm::vec2 ApplicationOverlay::sphericalToOverlay(const glm::vec2& sphericalPos) const {
1197+ glm::vec2 result = sphericalPos;
1198+ result.x *= -1.0;
1199+ result /= _textureFov;
1200+ result.x /= _textureAspectRatio;
1201+ result += 0.5f;
1202+ result.x = (-sphericalPos.x / (_textureFov * _textureAspectRatio) + 0.5f);
1203+ result.y = (sphericalPos.y / _textureFov + 0.5f);
1204+ result *= qApp->getCanvasSize();
1205+ return result;
12001206 }
12011207
1202−glm::vec2 ApplicationOverlay::overlayToSpherical(glm::vec2 overlayPos) const {
1203− QSize screenSize = Application::getInstance()->getGLWidget()->getDeviceSize();
1204− float yaw = -(overlayPos.x / screenSize.width() - 0.5f) * _textureFov * _textureAspectRatio;
1205− float pitch = (overlayPos.y / screenSize.height() - 0.5f) * _textureFov;
1206−
1207− return glm::vec2(yaw, pitch);
1208+glm::vec2 ApplicationOverlay::overlayToSpherical(const glm::vec2& overlayPos) const {
1209+ glm::vec2 result = overlayPos;
1210+ result.x *= -1.0;
1211+ result /= qApp->getCanvasSize();
1212+ result -= 0.5f;
1213+ result *= _textureFov;
1214+ result.x *= _textureAspectRatio;
1215+ return result;
12081216 }
12091217
1210−glm::vec2 ApplicationOverlay::screenToOverlay(glm::vec2 screenPos) const {
1218+glm::vec2 ApplicationOverlay::screenToOverlay(const glm::vec2& screenPos) const {
12111219 return sphericalToOverlay(screenToSpherical(screenPos));
12121220 }
12131221
1214−glm::vec2 ApplicationOverlay::overlayToScreen(glm::vec2 overlayPos) const {
1222+glm::vec2 ApplicationOverlay::overlayToScreen(const glm::vec2& overlayPos) const {
12151223 return sphericalToScreen(overlayToSpherical(overlayPos));
12161224 }