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