History

Revert "Revert "Fixing HMD asymmetrical projections (esp DK1) and santizing the transform stuff""

This reverts commit 6e8c067bcbc6e1e3bc2c012b59adca87f41d2871.

Brad Davis committed 11 years ago

Commit 41d587b1 parent 32c1b5e11 files · +159 −379Browse files

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

Unified · Split

interface/src/Application.cpp+21−57
@@ -19,6 +19,7 @@ · 18 unmodified lines
19#include <glm/gtx/component_wise.hpp>19#include <glm/gtx/component_wise.hpp>
20#include <glm/gtx/quaternion.hpp>20#include <glm/gtx/quaternion.hpp>
21#include <glm/gtx/vector_angle.hpp>21#include <glm/gtx/vector_angle.hpp>
22#include <glm/gtc/type_ptr.hpp>
22 23
23// include this before QGLWidget, which includes an earlier version of OpenGL24// include this before QGLWidget, which includes an earlier version of OpenGL
24#include "InterfaceConfig.h"25#include "InterfaceConfig.h"
@@ -965,12 +966,11 @@ void Application::showEditEntitiesHelp() { · 940 unmodified lines
965 966
966void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {967void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {
967 if (OculusManager::isConnected()) {968 if (OculusManager::isConnected()) {
968 OculusManager::configureCamera(camera, size.x, size.y);969 OculusManager::configureCamera(camera);
969 } else if (TV3DManager::isConnected()) {970 } else if (TV3DManager::isConnected()) {
970 TV3DManager::configureCamera(camera, size.x, size.y);971 TV3DManager::configureCamera(camera, size.x, size.y);
971 } else {972 } else {
972 camera.setAspectRatio((float)size.x / size.y);973 camera.setProjection(glm::perspective(glm::radians(_fieldOfView.get()), (float)size.x / size.y, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
973 camera.setFieldOfView(_fieldOfView.get());
974 }974 }
975}975}
976 976
@@ -984,7 +984,7 @@ void Application::resizeGL() { · 7 unmodified lines
984 renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale();984 renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale();
985 }985 }
986 if (_renderResolution == toGlm(renderSize)) {986 if (_renderResolution == toGlm(renderSize)) {
987 return;987 return;
988 }988 }
989 989
990 _renderResolution = toGlm(renderSize);990 _renderResolution = toGlm(renderSize);
@@ -1011,25 +1011,15 @@ void Application::updateProjectionMatrix() { · 20 unmodified lines
1011}1011}
1012 1012
1013void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {1013void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {
1014 glMatrixMode(GL_PROJECTION);1014 _projectionMatrix = camera.getProjection();
1015 glLoadIdentity();
1016 1015
1017 float left, right, bottom, top, nearVal, farVal;1016 glMatrixMode(GL_PROJECTION);
1018 glm::vec4 nearClipPlane, farClipPlane;1017 glLoadMatrixf(glm::value_ptr(_projectionMatrix));
1019 1018
1020 // Tell our viewFrustum about this change, using the application camera1019 // Tell our viewFrustum about this change, using the application camera
1021 if (updateViewFrustum) {1020 if (updateViewFrustum) {
1022 loadViewFrustum(camera, _viewFrustum);1021 loadViewFrustum(camera, _viewFrustum);
1023 _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);1022 }
1024 } else {
1025 ViewFrustum tempViewFrustum;
1026 loadViewFrustum(camera, tempViewFrustum);
1027 tempViewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
1028 }
1029 glFrustum(left, right, bottom, top, nearVal, farVal);
1030
1031 // save matrix
1032 glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)&_projectionMatrix);
1033 1023
1034 glMatrixMode(GL_MODELVIEW);1024 glMatrixMode(GL_MODELVIEW);
1035}1025}
@@ -1250,6 +1240,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 214 unmodified lines
1250 }1240 }
1251 break;1241 break;
1252 1242
1243#if 0
1253 case Qt::Key_I:1244 case Qt::Key_I:
1254 if (isShifted) {1245 if (isShifted) {
1255 _myCamera.setEyeOffsetOrientation(glm::normalize(1246 _myCamera.setEyeOffsetOrientation(glm::normalize(
@@ -1314,6 +1305,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 58 unmodified lines
1314 }1305 }
1315 updateProjectionMatrix();1306 updateProjectionMatrix();
1316 break;1307 break;
1308#endif
1309
1317 case Qt::Key_H:1310 case Qt::Key_H:
1318 if (isShifted) {1311 if (isShifted) {
1319 Menu::getInstance()->triggerOption(MenuOption::Mirror);1312 Menu::getInstance()->triggerOption(MenuOption::Mirror);
@@ -2631,7 +2624,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 1311 unmodified lines
2631 _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio());2624 _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio());
2632 _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip());2625 _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip());
2633 _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip());2626 _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip());
2634 _octreeQuery.setCameraEyeOffsetPosition(_viewFrustum.getEyeOffsetPosition());2627 _octreeQuery.setCameraEyeOffsetPosition(glm::vec3());
2635 auto lodManager = DependencyManager::get<LODManager>();2628 auto lodManager = DependencyManager::get<LODManager>();
2636 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());2629 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());
2637 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());2630 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());
@@ -2835,25 +2828,11 @@ QRect Application::getDesirableApplicationGeometry() { · 197 unmodified lines
2835//2828//
2836void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {2829void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
2837 // We will use these below, from either the camera or head vectors calculated above2830 // We will use these below, from either the camera or head vectors calculated above
2838 glm::vec3 position(camera.getPosition());2831 viewFrustum.setProjection(camera.getProjection());
2839 float fov = camera.getFieldOfView(); // degrees
2840 float nearClip = camera.getNearClip();
2841 float farClip = camera.getFarClip();
2842 float aspectRatio = camera.getAspectRatio();
2843
2844 glm::quat rotation = camera.getRotation();
2845 2832
2846 // Set the viewFrustum up with the correct position and orientation of the camera2833 // Set the viewFrustum up with the correct position and orientation of the camera
2847 viewFrustum.setPosition(position);2834 viewFrustum.setPosition(camera.getPosition());
2848 viewFrustum.setOrientation(rotation);2835 viewFrustum.setOrientation(camera.getRotation());
2849
2850 // Also make sure it's got the correct lens details from the camera
2851 viewFrustum.setAspectRatio(aspectRatio);
2852 viewFrustum.setFieldOfView(fov); // degrees
2853 viewFrustum.setNearClip(nearClip);
2854 viewFrustum.setFarClip(farClip);
2855 viewFrustum.setEyeOffsetPosition(camera.getEyeOffsetPosition());
2856 viewFrustum.setEyeOffsetOrientation(camera.getEyeOffsetOrientation());
2857 2836
2858 // Ask the ViewFrustum class to calculate our corners2837 // Ask the ViewFrustum class to calculate our corners
2859 viewFrustum.calculate();2838 viewFrustum.calculate();
@@ -2954,13 +2933,7 @@ void Application::updateShadowMap() { · 94 unmodified lines
2954 glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);2933 glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);
2955 _shadowViewFrustum.setPosition(shadowFrustumCenter);2934 _shadowViewFrustum.setPosition(shadowFrustumCenter);
2956 _shadowViewFrustum.setOrientation(rotation);2935 _shadowViewFrustum.setOrientation(rotation);
2957 _shadowViewFrustum.setOrthographic(true);2936 _shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z));
2958 _shadowViewFrustum.setWidth(maxima.x - minima.x);
2959 _shadowViewFrustum.setHeight(maxima.y - minima.y);
2960 _shadowViewFrustum.setNearClip(minima.z);
2961 _shadowViewFrustum.setFarClip(maxima.z);
2962 _shadowViewFrustum.setEyeOffsetPosition(glm::vec3());
2963 _shadowViewFrustum.setEyeOffsetOrientation(glm::quat());
2964 _shadowViewFrustum.calculate();2937 _shadowViewFrustum.calculate();
2965 2938
2966 glMatrixMode(GL_PROJECTION);2939 glMatrixMode(GL_PROJECTION);
@@ -3147,12 +3120,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 180 unmodified lines
3147 glFrontFace(GL_CCW);3120 glFrontFace(GL_CCW);
3148 }3121 }
3149 3122
3150 glm::vec3 eyeOffsetPos = theCamera.getEyeOffsetPosition();
3151 glm::quat eyeOffsetOrient = theCamera.getEyeOffsetOrientation();
3152 glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient);
3153 glRotatef(-glm::degrees(glm::angle(eyeOffsetOrient)), eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z);
3154 glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z);
3155
3156 // transform view according to theCamera3123 // transform view according to theCamera
3157 // could be myCamera (if in normal mode)3124 // could be myCamera (if in normal mode)
3158 // or could be viewFrustumOffsetCamera if in offset mode3125 // or could be viewFrustumOffsetCamera if in offset mode
@@ -3170,8 +3137,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 11 unmodified lines
3170 Transform viewTransform;3137 Transform viewTransform;
3171 viewTransform.setTranslation(theCamera.getPosition());3138 viewTransform.setTranslation(theCamera.getPosition());
3172 viewTransform.setRotation(rotation);3139 viewTransform.setRotation(rotation);
3173 viewTransform.postTranslate(eyeOffsetPos);
3174 viewTransform.postRotate(eyeOffsetOrient);
3175 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {3140 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
3176 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));3141 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));
3177 }3142 }
@@ -3265,7 +3230,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 87 unmodified lines
3265 3230
3266 // finally render the starfield3231 // finally render the starfield
3267 if (hasStars) {3232 if (hasStars) {
3268 _stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha);3233 _stars.render(_displayViewFrustum.getFieldOfView(), _displayViewFrustum.getAspectRatio(), _displayViewFrustum.getNearClip(), alpha);
3269 }3234 }
3270 3235
3271 // draw the sky dome3236 // draw the sky dome
@@ -3499,15 +3464,16 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 227 unmodified lines
3499 // Grab current viewport to reset it at the end3464 // Grab current viewport to reset it at the end
3500 int viewport[4];3465 int viewport[4];
3501 glGetIntegerv(GL_VIEWPORT, viewport);3466 glGetIntegerv(GL_VIEWPORT, viewport);
3467 float aspect = (float)region.width() / region.height();
3468 float fov = MIRROR_FIELD_OF_VIEW;
3502 3469
3503 // bool eyeRelativeCamera = false;3470 // bool eyeRelativeCamera = false;
3504 if (billboard) {3471 if (billboard) {
3505 _mirrorCamera.setFieldOfView(BILLBOARD_FIELD_OF_VIEW); // degees3472 fov = BILLBOARD_FIELD_OF_VIEW; // degees
3506 _mirrorCamera.setPosition(_myAvatar->getPosition() +3473 _mirrorCamera.setPosition(_myAvatar->getPosition() +
3507 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());3474 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());
3508 3475
3509 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {3476 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {
3510 _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
3511 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +3477 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +
3512 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());3478 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());
3513 3479
@@ -3528,12 +3494,10 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 14 unmodified lines
3528 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further 3494 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
3529 // investigated in order to adapt the technique while fixing the head rendering issue,3495 // investigated in order to adapt the technique while fixing the head rendering issue,
3530 // but the complexity of the hack suggests that a better approach 3496 // but the complexity of the hack suggests that a better approach
3531 _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
3532 _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +3497 _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +
3533 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());3498 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());
3534 }3499 }
3535 _mirrorCamera.setAspectRatio((float)region.width() / region.height());3500 _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
3536
3537 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));3501 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
3538 3502
3539 // set the bounds of rear mirror view3503 // set the bounds of rear mirror view