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
439439 // myCamera is. But we also want to do meaningful camera transforms on OpenGL for the offset camera
440440 Camera whichCamera = _myCamera;
441441
442− if (_viewFrustumFromOffset->isChecked() && _frustumOn->isChecked()) {
442+ if (_frustumOn->isChecked()) {
443443
444444 // set the camera to third-person view but offset so we can see the frustum
445445 _viewFrustumOffsetCamera.setTargetPosition(_myCamera.getTargetPosition());
@@ -467,56 +467,52 @@ void Application::paintGL() { · 21 unmodified lines
467467 _frameCount++;
468468 }
469469
470−void Application::resizeGL(int width, int height) {
470+void Application::resetCamerasOnResizeGL(Camera& camera, int width, int height) {
471471 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+
482473 if (OculusManager::isConnected()) {
483474 // more magic numbers; see Oculus SDK docs, p. 32
484475 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));
493477 } else {
494478 camera.setAspectRatio(aspectRatio);
495− camera.setFieldOfView(fov = _fieldOfView);
479+ camera.setFieldOfView(_fieldOfView);
496480 }
481+}
497482
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);
500499
501500 glViewport(0, 0, width, height); // shouldn't this account for the menu???
502501
503502 glMatrixMode(GL_PROJECTION);
504503 glLoadIdentity();
505504
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−
515505 // On window reshape, we need to tell OpenGL about our new setting
516506 float left, right, bottom, top, nearVal, farVal;
517507 glm::vec4 nearClipPlane, farClipPlane;
518− loadViewFrustum(camera, _viewFrustum);
519508 _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+ }
520516 glFrustum(left, right, bottom, top, nearVal, farVal);
521517
522518 glMatrixMode(GL_MODELVIEW);
@@ -819,11 +815,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 296 unmodified lines
819815 _colorVoxelMode->trigger();
820816 break;
821817 case Qt::Key_O:
822− if (isShifted) {
823− _viewFrustumFromOffset->trigger();
824− } else {
825− _selectVoxelMode->trigger();
826− }
818+ _selectVoxelMode->trigger();
827819 break;
828820 case Qt::Key_Slash:
829821 _renderStatsOn->trigger();
@@ -2060,8 +2052,6 @@ void Application::initMenu() { · 1230 unmodified lines
20602052 QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools");
20612053 (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true);
20622054 _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);
20652055 _frustumRenderModeAction = frustumMenu->addAction(
20662056 "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R);
20672057 updateFrustumRenderModeAction();
@@ -2776,6 +2766,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 708 unmodified lines
27762766 float fov = camera.getFieldOfView();
27772767 float nearClip = camera.getNearClip();
27782768 float farClip = camera.getFarClip();
2769+ float aspectRatio = camera.getAspectRatio();
27792770
27802771 glm::quat rotation = camera.getRotation();
27812772
@@ -2784,6 +2775,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 2 unmodified lines
27842775 viewFrustum.setOrientation(rotation);
27852776
27862777 // Also make sure it's got the correct lens details from the camera
2778+ viewFrustum.setAspectRatio(aspectRatio);
27872779 viewFrustum.setFieldOfView(fov);
27882780 viewFrustum.setNearClip(nearClip);
27892781 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