History

Merge pull request #823 from ZappoMan/master

Display Frustum and resizeGL() cleanup

Andrzej Kapolka committed 13 years ago

Commit 9dbec352 parents 9f5f7d9 cb211fb2 files · +30 −41Browse files

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

Unified · Split

interface/src/Application.cpp+29−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,49 @@ 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);
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);
496492 }
497493
498− // Tell our viewFrustum about this change
499− _viewFrustum.setAspectRatio(aspectRatio);
494+ // Tell our viewFrustum about this change, using the application camera
495+ loadViewFrustum(_myCamera, _viewFrustum);
500496
501497 glViewport(0, 0, width, height); // shouldn't this account for the menu???
502498
503499 glMatrixMode(GL_PROJECTION);
504500 glLoadIdentity();
505501
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−
515502 // On window reshape, we need to tell OpenGL about our new setting
516503 float left, right, bottom, top, nearVal, farVal;
517504 glm::vec4 nearClipPlane, farClipPlane;
518− loadViewFrustum(camera, _viewFrustum);
519505 _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+ }
520513 glFrustum(left, right, bottom, top, nearVal, farVal);
521514
522515 glMatrixMode(GL_MODELVIEW);
@@ -819,11 +812,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 296 unmodified lines
819812 _colorVoxelMode->trigger();
820813 break;
821814 case Qt::Key_O:
822− if (isShifted) {
823− _viewFrustumFromOffset->trigger();
824− } else {
825− _selectVoxelMode->trigger();
826− }
815+ _selectVoxelMode->trigger();
827816 break;
828817 case Qt::Key_Slash:
829818 _renderStatsOn->trigger();
@@ -2060,8 +2049,6 @@ void Application::initMenu() { · 1230 unmodified lines
20602049 QMenu* frustumMenu = debugMenu->addMenu("View Frustum Debugging Tools");
20612050 (_frustumOn = frustumMenu->addAction("Display Frustum"))->setCheckable(true);
20622051 _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);
20652052 _frustumRenderModeAction = frustumMenu->addAction(
20662053 "Render Mode", this, SLOT(cycleFrustumRenderMode()), Qt::SHIFT | Qt::Key_R);
20672054 updateFrustumRenderModeAction();
@@ -2776,6 +2763,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 708 unmodified lines
27762763 float fov = camera.getFieldOfView();
27772764 float nearClip = camera.getNearClip();
27782765 float farClip = camera.getFarClip();
2766+ float aspectRatio = camera.getAspectRatio();
27792767
27802768 glm::quat rotation = camera.getRotation();
27812769
@@ -2784,6 +2772,7 @@ void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { · 2 unmodified lines
27842772 viewFrustum.setOrientation(rotation);
27852773
27862774 // Also make sure it's got the correct lens details from the camera
2775+ viewFrustum.setAspectRatio(aspectRatio);
27872776 viewFrustum.setFieldOfView(fov);
27882777 viewFrustum.setNearClip(nearClip);
27892778 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