History

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

samcake committed 11 years ago

Commit 6e8c0671 parent 7c2557311 files · +382 −160Browse files

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

Unified · Split

interface/src/Application.cpp+57−21
@@ -19,7 +19,6 @@ · 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>
23 22
24// include this before QGLWidget, which includes an earlier version of OpenGL23// include this before QGLWidget, which includes an earlier version of OpenGL
25#include "InterfaceConfig.h"24#include "InterfaceConfig.h"
@@ -966,11 +965,12 @@ void Application::showEditEntitiesHelp() { · 940 unmodified lines
966 965
967void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {966void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {
968 if (OculusManager::isConnected()) {967 if (OculusManager::isConnected()) {
969 OculusManager::configureCamera(camera);968 OculusManager::configureCamera(camera, size.x, size.y);
970 } else if (TV3DManager::isConnected()) {969 } else if (TV3DManager::isConnected()) {
971 TV3DManager::configureCamera(camera, size.x, size.y);970 TV3DManager::configureCamera(camera, size.x, size.y);
972 } else {971 } else {
973 camera.setProjection(glm::perspective(glm::radians(_fieldOfView.get()), (float)size.x / size.y, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));972 camera.setAspectRatio((float)size.x / size.y);
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,15 +1011,25 @@ 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 _projectionMatrix = camera.getProjection();
1015
1016 glMatrixMode(GL_PROJECTION);1014 glMatrixMode(GL_PROJECTION);
1017 glLoadMatrixf(glm::value_ptr(_projectionMatrix));1015 glLoadIdentity();
1016
1017 float left, right, bottom, top, nearVal, farVal;
1018 glm::vec4 nearClipPlane, farClipPlane;
1018 1019
1019 // Tell our viewFrustum about this change, using the application camera1020 // Tell our viewFrustum about this change, using the application camera
1020 if (updateViewFrustum) {1021 if (updateViewFrustum) {
1021 loadViewFrustum(camera, _viewFrustum);1022 loadViewFrustum(camera, _viewFrustum);
1022 } 1023 _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
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);
1023 1033
1024 glMatrixMode(GL_MODELVIEW);1034 glMatrixMode(GL_MODELVIEW);
1025}1035}
@@ -1240,7 +1250,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 214 unmodified lines
1240 }1250 }
1241 break;1251 break;
1242 1252
1243#if 0
1244 case Qt::Key_I:1253 case Qt::Key_I:
1245 if (isShifted) {1254 if (isShifted) {
1246 _myCamera.setEyeOffsetOrientation(glm::normalize(1255 _myCamera.setEyeOffsetOrientation(glm::normalize(
@@ -1305,8 +1314,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 58 unmodified lines
1305 }1314 }
1306 updateProjectionMatrix();1315 updateProjectionMatrix();
1307 break;1316 break;
1308#endif
1309
1310 case Qt::Key_H:1317 case Qt::Key_H:
1311 if (isShifted) {1318 if (isShifted) {
1312 Menu::getInstance()->triggerOption(MenuOption::Mirror);1319 Menu::getInstance()->triggerOption(MenuOption::Mirror);
@@ -2624,7 +2631,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 1311 unmodified lines
2624 _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio());2631 _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio());
2625 _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip());2632 _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip());
2626 _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip());2633 _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip());
2627 _octreeQuery.setCameraEyeOffsetPosition(glm::vec3());2634 _octreeQuery.setCameraEyeOffsetPosition(_viewFrustum.getEyeOffsetPosition());
2628 auto lodManager = DependencyManager::get<LODManager>();2635 auto lodManager = DependencyManager::get<LODManager>();
2629 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());2636 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());
2630 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());2637 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());
@@ -2828,11 +2835,25 @@ QRect Application::getDesirableApplicationGeometry() { · 197 unmodified lines
2828//2835//
2829void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {2836void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
2830 // We will use these below, from either the camera or head vectors calculated above2837 // We will use these below, from either the camera or head vectors calculated above
2831 viewFrustum.setProjection(camera.getProjection());2838 glm::vec3 position(camera.getPosition());
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();
2832 2845
2833 // Set the viewFrustum up with the correct position and orientation of the camera2846 // Set the viewFrustum up with the correct position and orientation of the camera
2834 viewFrustum.setPosition(camera.getPosition());2847 viewFrustum.setPosition(position);
2835 viewFrustum.setOrientation(camera.getRotation());2848 viewFrustum.setOrientation(rotation);
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());
2836 2857
2837 // Ask the ViewFrustum class to calculate our corners2858 // Ask the ViewFrustum class to calculate our corners
2838 viewFrustum.calculate();2859 viewFrustum.calculate();
@@ -2933,7 +2954,13 @@ void Application::updateShadowMap() { · 94 unmodified lines
2933 glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);2954 glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);
2934 _shadowViewFrustum.setPosition(shadowFrustumCenter);2955 _shadowViewFrustum.setPosition(shadowFrustumCenter);
2935 _shadowViewFrustum.setOrientation(rotation);2956 _shadowViewFrustum.setOrientation(rotation);
2936 _shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z));2957 _shadowViewFrustum.setOrthographic(true);
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());
2937 _shadowViewFrustum.calculate();2964 _shadowViewFrustum.calculate();
2938 2965
2939 glMatrixMode(GL_PROJECTION);2966 glMatrixMode(GL_PROJECTION);
@@ -3120,6 +3147,12 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 180 unmodified lines
3120 glFrontFace(GL_CCW);3147 glFrontFace(GL_CCW);
3121 }3148 }
3122 3149
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
3123 // transform view according to theCamera3156 // transform view according to theCamera
3124 // could be myCamera (if in normal mode)3157 // could be myCamera (if in normal mode)
3125 // or could be viewFrustumOffsetCamera if in offset mode3158 // or could be viewFrustumOffsetCamera if in offset mode
@@ -3137,6 +3170,8 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 11 unmodified lines
3137 Transform viewTransform;3170 Transform viewTransform;
3138 viewTransform.setTranslation(theCamera.getPosition());3171 viewTransform.setTranslation(theCamera.getPosition());
3139 viewTransform.setRotation(rotation);3172 viewTransform.setRotation(rotation);
3173 viewTransform.postTranslate(eyeOffsetPos);
3174 viewTransform.postRotate(eyeOffsetOrient);
3140 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {3175 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
3141 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));3176 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));
3142 }3177 }
@@ -3230,7 +3265,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 87 unmodified lines
3230 3265
3231 // finally render the starfield3266 // finally render the starfield
3232 if (hasStars) {3267 if (hasStars) {
3233 _stars.render(_displayViewFrustum.getFieldOfView(), _displayViewFrustum.getAspectRatio(), _displayViewFrustum.getNearClip(), alpha);3268 _stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha);
3234 }3269 }
3235 3270
3236 // draw the sky dome3271 // draw the sky dome
@@ -3464,16 +3499,15 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 227 unmodified lines
3464 // Grab current viewport to reset it at the end3499 // Grab current viewport to reset it at the end
3465 int viewport[4];3500 int viewport[4];
3466 glGetIntegerv(GL_VIEWPORT, viewport);3501 glGetIntegerv(GL_VIEWPORT, viewport);
3467 float aspect = (float)region.width() / region.height();
3468 float fov = MIRROR_FIELD_OF_VIEW;
3469 3502
3470 // bool eyeRelativeCamera = false;3503 // bool eyeRelativeCamera = false;
3471 if (billboard) {3504 if (billboard) {
3472 fov = BILLBOARD_FIELD_OF_VIEW; // degees3505 _mirrorCamera.setFieldOfView(BILLBOARD_FIELD_OF_VIEW); // degees
3473 _mirrorCamera.setPosition(_myAvatar->getPosition() +3506 _mirrorCamera.setPosition(_myAvatar->getPosition() +
3474 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());3507 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());
3475 3508
3476 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {3509 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {
3510 _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
3477 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +3511 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +
3478 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());3512 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());
3479 3513
@@ -3494,10 +3528,12 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 14 unmodified lines
3494 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further 3528 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
3495 // investigated in order to adapt the technique while fixing the head rendering issue,3529 // investigated in order to adapt the technique while fixing the head rendering issue,
3496 // but the complexity of the hack suggests that a better approach 3530 // but the complexity of the hack suggests that a better approach
3531 _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
3497 _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +3532 _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +
3498 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());3533 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());
3499 }3534 }
3500 _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));3535 _mirrorCamera.setAspectRatio((float)region.width() / region.height());
3536
3501 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));3537 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
3502 3538
3503 // set the bounds of rear mirror view3539 // set the bounds of rear mirror view