History

cleanup resizeGL, and Display Frustum menus

ZappoMan committed 13 years ago

Commit f4820141 parent 40025612 files · +32 −41Browse files

Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all

Unified · Split

interface/src/Application.cpp+32−40
@@ -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 camera439 // 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 frustum444 // 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,52 @@ void Application::paintGL() { · 21 unmodified lines
467 _frameCount++;467 _frameCount++;
468}468}
469 469
470void Application::resizeGL(int width, int height) {470void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) {
471 float aspectRatio = ((float)width/(float)height); // based on screen resize471 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. 32474 // 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);
496 }480 }
481}
497 482
498 // Tell our viewFrustum about this change483void Application::resizeGL(int width, int height) {
499 _viewFrustum.setAspectRatio(aspectRatio);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 glViewport(0, 0, width, height); // shouldn't this account for the menu???500 glViewport(0, 0, width, height); // shouldn't this account for the menu???
502 501
503 glMatrixMode(GL_PROJECTION);502 glMatrixMode(GL_PROJECTION);
504 glLoadIdentity();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 // On window reshape, we need to tell OpenGL about our new setting505 // On window reshape, we need to tell OpenGL about our new setting
516 float left, right, bottom, top, nearVal, farVal;506 float left, right, bottom, top, nearVal, farVal;
517 glm::vec4 nearClipPlane, farClipPlane;507 glm::vec4 nearClipPlane, farClipPlane;
518 loadViewFrustum(camera, _viewFrustum);
519 _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);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 glFrustum(left, right, bottom, top, nearVal, farVal);516 glFrustum(left, right, bottom, top, nearVal, farVal);
521 517
522 glMatrixMode(GL_MODELVIEW);518 glMatrixMode(GL_MODELVIEW);
@@ -819,11 +815,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 296 unmodified lines
819 _colorVoxelMode->trigger();815 _colorVoxelMode->trigger();
820 break;816 break;
821 case Qt::Key_O:817 case Qt::Key_O:
822 if (isShifted) {818 _selectVoxelMode->trigger();
823 _viewFrustumFromOffset->trigger();
824 } else {
825 _selectVoxelMode->trigger();
826 }
827 break;819 break;
828 case Qt::Key_Slash:820 case Qt::Key_Slash:
829 _renderStatsOn->trigger();821 _renderStatsOn->trigger();
@@ -2060,8 +2052,6 @@ void Application::initMenu() { · 1230 unmodified lines
2060 QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools");2052 QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools");
2061 (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true); 2053 (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true);
2062 _frustumOn->setShortcut(Qt::SHIFT | Qt::Key_F);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 _frustumRenderModeAction = frustumMenu->addAction(2055 _frustumRenderModeAction = frustumMenu->addAction(
2066 "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R);2056 "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R);
2067 updateFrustumRenderModeAction();2057 updateFrustumRenderModeAction();
@@ -2776,6 +2766,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 708 unmodified lines
2776 float fov = camera.getFieldOfView();2766 float fov = camera.getFieldOfView();
2777 float nearClip = camera.getNearClip();2767 float nearClip = camera.getNearClip();
2778 float farClip = camera.getFarClip();2768 float farClip = camera.getFarClip();
2769 float aspectRatio = camera.getAspectRatio();
2779 2770
2780 glm::quat rotation = camera.getRotation();2771 glm::quat rotation = camera.getRotation();
2781 2772
@@ -2784,6 +2775,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 2 unmodified lines
2784 viewFrustum.setOrientation(rotation);2775 viewFrustum.setOrientation(rotation);
2785 2776
2786 // Also make sure it's got the correct lens details from the camera2777 // Also make sure it's got the correct lens details from the camera
2778 viewFrustum.setAspectRatio(aspectRatio);
2787 viewFrustum.setFieldOfView(fov);2779 viewFrustum.setFieldOfView(fov);
2788 viewFrustum.setNearClip(nearClip);2780 viewFrustum.setNearClip(nearClip);
2789 viewFrustum.setFarClip(farClip);2781 viewFrustum.setFarClip(farClip);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t