Display Frustum and resizeGL() cleanup
Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all
Unified · Split
| @@ -439,7 +439,7 @@ void Application::paintGL() { · 438 unmodified lines | |||
| 439 | // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera | 439 | // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera |
| 440 | Camera whichCamera = _myCamera; | 440 | Camera whichCamera = _myCamera; |
| 441 | 441 | ||
| 442 | if (_viewFrustumFromOffset->isChecked() && _frustumOn->isChecked()) { | 442 | if (_frustumOn->isChecked()) { |
| 443 | 443 | ||
| 444 | // set the camera to third-person view but offset so we can see the frustum | 444 | // set the camera to third-person view but offset so we can see the frustum |
| 445 | _viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition()); | 445 | _viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition()); |
| @@ -467,56 +467,49 @@ void Application::paintGL() { · 21 unmodified lines | |||
| 467 | _frameCount++; | 467 | _frameCount++; |
| 468 | } | 468 | } |
| 469 | 469 | ||
| 470 | void Application::resizeGL(int width, int height) { | 470 | void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) { |
| 471 | float aspectRatio = ((float)width/(float)height); // based on screen resize | 471 | float aspectRatio = ((float)width/(float)height); // based on screen resize |
| 472 | 472 | ||
| 473 | // reset the camera FOV to our preference... | ||
| 474 | _myCamera.setFieldOfView(_fieldOfView); | ||
| 475 | |||
| 476 | // get the lens details from the current camera | ||
| 477 | Camera& camera = _viewFrustumFromOffset->isChecked() ? _viewFrustumOffsetCamera : _myCamera; | ||
| 478 | float nearClip = camera.getNearClip(); | ||
| 479 | float farClip = camera.getFarClip(); | ||
| 480 | float fov; | ||
| 481 | |||
| 482 | if (OculusManager::isConnected()) { | 473 | if (OculusManager::isConnected()) { |
| 483 | // more magic numbers; see Oculus SDK docs, p. 32 | 474 | // more magic numbers; see Oculus SDK docs, p. 32 |
| 484 | camera.setAspectRatio(aspectRatio *= 0.5); | 475 | camera.setAspectRatio(aspectRatio *= 0.5); |
| 485 | camera.setFieldOfView(fov = 2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); | 476 | camera.setFieldOfView(2 * atan((0.0468 * _oculusDistortionScale) / 0.041) * (180 / PIf)); |
| 486 | |||
| 487 | // resize the render texture | ||
| 488 | if (_oculusTextureID != 0) { | ||
| 489 | glBindTexture(GL_TEXTURE_2D, _oculusTextureID); | ||
| 490 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | ||
| 491 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 492 | } | ||
| 493 | } else { | 477 | } else { |
| 494 | camera.setAspectRatio(aspectRatio); | 478 | camera.setAspectRatio(aspectRatio); |
| 495 | camera.setFieldOfView(fov = _fieldOfView); | 479 | camera.setFieldOfView(_fieldOfView); |
| 480 | } | ||
| 481 | } | ||
| 482 | |||
| 483 | void Application::resizeGL(int width, int height) { | ||
| 484 | resetCamerasOnResizeGL(_viewFrustumOffsetCamera, width, height); | ||
| 485 | resetCamerasOnResizeGL(_myCamera, width, height); | ||
| 486 | |||
| 487 | // resize the render texture | ||
| 488 | if (OculusManager::isConnected() && _oculusTextureID != 0) { | ||
| 489 | glBindTexture(GL_TEXTURE_2D, _oculusTextureID); | ||
| 490 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); | ||
| 491 | glBindTexture(GL_TEXTURE_2D, 0); | ||
| 496 | } | 492 | } |
| 497 | 493 | ||
| 498 | // Tell our viewFrustum about this change | 494 | // Tell our viewFrustum about this change, using the application camera |
| 499 | _viewFrustum.setAspectRatio(aspectRatio); | 495 | loadViewFrustum(_myCamera, _viewFrustum); |
| 500 | 496 | ||
| 501 | glViewport(0, 0, width, height); // shouldn't this account for the menu??? | 497 | glViewport(0, 0, width, height); // shouldn't this account for the menu??? |
| 502 | 498 | ||
| 503 | glMatrixMode(GL_PROJECTION); | 499 | glMatrixMode(GL_PROJECTION); |
| 504 | glLoadIdentity(); | 500 | glLoadIdentity(); |
| 505 | 501 | ||
| 506 | // XXXBHG - If we're in view frustum mode, then we need to do this little bit of hackery so that | ||
| 507 | // OpenGL won't clip our frustum rendering lines. This is a debug hack for sure! Basically, this makes | ||
| 508 | // the near clip a little bit closer (therefor you see more) and the far clip a little bit farther (also, | ||
| 509 | // to see more.) | ||
| 510 | if (_frustumOn->isChecked()) { | ||
| 511 | nearClip -= 0.01f; | ||
| 512 | farClip += 0.01f; | ||
| 513 | } | ||
| 514 | |||
| 515 | // On window reshape, we need to tell OpenGL about our new setting | 502 | // On window reshape, we need to tell OpenGL about our new setting |
| 516 | float left, right, bottom, top, nearVal, farVal; | 503 | float left, right, bottom, top, nearVal, farVal; |
| 517 | glm::vec4 nearClipPlane, farClipPlane; | 504 | glm::vec4 nearClipPlane, farClipPlane; |
| 518 | loadViewFrustum(camera, _viewFrustum); | ||
| 519 | _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); | 505 | _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane); |
| 506 | |||
| 507 | // If we're in Display Frustum mode, then we want to use the slightly adjust near/far clip values of the | ||
| 508 | // _viewFrustumOffsetCamera, so that we can see more of the application content in the application's frustum | ||
| 509 | if (_frustumOn->isChecked()) { | ||
| 510 | nearVal = _viewFrustumOffsetCamera.getNearClip(); | ||
| 511 | farVal = _viewFrustumOffsetCamera.getFarClip(); | ||
| 512 | } | ||
| 520 | glFrustum(left, right, bottom, top, nearVal, farVal); | 513 | glFrustum(left, right, bottom, top, nearVal, farVal); |
| 521 | 514 | ||
| 522 | glMatrixMode(GL_MODELVIEW); | 515 | glMatrixMode(GL_MODELVIEW); |
| @@ -819,11 +812,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 296 unmodified lines | |||
| 819 | _colorVoxelMode->trigger(); | 812 | _colorVoxelMode->trigger(); |
| 820 | break; | 813 | break; |
| 821 | case Qt::Key_O: | 814 | case Qt::Key_O: |
| 822 | if (isShifted) { | 815 | _selectVoxelMode->trigger(); |
| 823 | _viewFrustumFromOffset->trigger(); | ||
| 824 | } else { | ||
| 825 | _selectVoxelMode->trigger(); | ||
| 826 | } | ||
| 827 | break; | 816 | break; |
| 828 | case Qt::Key_Slash: | 817 | case Qt::Key_Slash: |
| 829 | _renderStatsOn->trigger(); | 818 | _renderStatsOn->trigger(); |
| @@ -2060,8 +2049,6 @@ void Application::initMenu() { · 1230 unmodified lines | |||
| 2060 | QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools"); | 2049 | QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools"); |
| 2061 | (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true); | 2050 | (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true); |
| 2062 | _frustumOn->setShortcut(Qt::SHIFT | Qt::Key_F); | 2051 | _frustumOn->setShortcut(Qt::SHIFT | Qt::Key_F); |
| 2063 | (_viewFrustumFromOffset = frustumMenu->addAction( | ||
| 2064 | "Use Offset Camera", this, SLOT(setFrustumOffset(bool)), Qt::SHIFT | Qt::Key_O))->setCheckable(true); | ||
| 2065 | _frustumRenderModeAction = frustumMenu->addAction( | 2052 | _frustumRenderModeAction = frustumMenu->addAction( |
| 2066 | "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R); | 2053 | "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R); |
| 2067 | updateFrustumRenderModeAction(); | 2054 | updateFrustumRenderModeAction(); |
| @@ -2776,6 +2763,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 708 unmodified lines | |||
| 2776 | float fov = camera.getFieldOfView(); | 2763 | float fov = camera.getFieldOfView(); |
| 2777 | float nearClip = camera.getNearClip(); | 2764 | float nearClip = camera.getNearClip(); |
| 2778 | float farClip = camera.getFarClip(); | 2765 | float farClip = camera.getFarClip(); |
| 2766 | float aspectRatio = camera.getAspectRatio(); | ||
| 2779 | 2767 | ||
| 2780 | glm::quat rotation = camera.getRotation(); | 2768 | glm::quat rotation = camera.getRotation(); |
| 2781 | 2769 | ||
| @@ -2784,6 +2772,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 2 unmodified lines | |||
| 2784 | viewFrustum.setOrientation(rotation); | 2772 | viewFrustum.setOrientation(rotation); |
| 2785 | 2773 | ||
| 2786 | // Also make sure it's got the correct lens details from the camera | 2774 | // Also make sure it's got the correct lens details from the camera |
| 2775 | viewFrustum.setAspectRatio(aspectRatio); | ||
| 2787 | viewFrustum.setFieldOfView(fov); | 2776 | viewFrustum.setFieldOfView(fov); |
| 2788 | viewFrustum.setNearClip(nearClip); | 2777 | viewFrustum.setNearClip(nearClip); |
| 2789 | viewFrustum.setFarClip(farClip); | 2778 | viewFrustum.setFarClip(farClip); |