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
1919 #include <glm/gtx/component_wise.hpp>
2020 #include <glm/gtx/quaternion.hpp>
2121 #include <glm/gtx/vector_angle.hpp>
22+#include <glm/gtc/type_ptr.hpp>
2223
2324 // include this before QGLWidget, which includes an earlier version of OpenGL
2425 #include "InterfaceConfig.h"
@@ -965,12 +966,11 @@ void Application::showEditEntitiesHelp() { · 940 unmodified lines
965966
966967 void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {
967968 if (OculusManager::isConnected()) {
968− OculusManager::configureCamera(camera, size.x, size.y);
969+ OculusManager::configureCamera(camera);
969970 } else if (TV3DManager::isConnected()) {
970971 TV3DManager::configureCamera(camera, size.x, size.y);
971972 } else {
972− camera.setAspectRatio((float)size.x / size.y);
973− camera.setFieldOfView(_fieldOfView.get());
973+ camera.setProjection(glm::perspective(glm::radians(_fieldOfView.get()), (float)size.x / size.y, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
974974 }
975975 }
976976
@@ -984,7 +984,7 @@ void Application::resizeGL() { · 7 unmodified lines
984984 renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale();
985985 }
986986 if (_renderResolution == toGlm(renderSize)) {
987− return;
987+ return;
988988 }
989989
990990 _renderResolution = toGlm(renderSize);
@@ -1011,25 +1011,15 @@ void Application::updateProjectionMatrix() { · 20 unmodified lines
10111011 }
10121012
10131013 void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {
1014− glMatrixMode(GL_PROJECTION);
1015− glLoadIdentity();
1014+ _projectionMatrix = camera.getProjection();
10161015
1017− float left, right, bottom, top, nearVal, farVal;
1018− glm::vec4 nearClipPlane, farClipPlane;
1016+ glMatrixMode(GL_PROJECTION);
1017+ glLoadMatrixf(glm::value_ptr(_projectionMatrix));
10191018
10201019 // Tell our viewFrustum about this change, using the application camera
10211020 if (updateViewFrustum) {
10221021 loadViewFrustum(camera, _viewFrustum);
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);
1022+ }
10331023
10341024 glMatrixMode(GL_MODELVIEW);
10351025 }
@@ -1250,6 +1240,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 214 unmodified lines
12501240 }
12511241 break;
12521242
1243+#if 0
12531244 case Qt::Key_I:
12541245 if (isShifted) {
12551246 _myCamera.setEyeOffsetOrientation(glm::normalize(
@@ -1314,6 +1305,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 58 unmodified lines
13141305 }
13151306 updateProjectionMatrix();
13161307 break;
1308+#endif
1309+
13171310 case Qt::Key_H:
13181311 if (isShifted) {
13191312 Menu::getInstance()->triggerOption(MenuOption::Mirror);
@@ -2631,7 +2624,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 1311 unmodified lines
26312624 _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio());
26322625 _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip());
26332626 _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip());
2634− _octreeQuery.setCameraEyeOffsetPosition(_viewFrustum.getEyeOffsetPosition());
2627+ _octreeQuery.setCameraEyeOffsetPosition(glm::vec3());
26352628 auto lodManager = DependencyManager::get<LODManager>();
26362629 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());
26372630 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());
@@ -2835,25 +2828,11 @@ QRect Application::getDesirableApplicationGeometry() { · 197 unmodified lines
28352828 //
28362829 void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
28372830 // We will use these below, from either the camera or head vectors calculated above
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();
2831+ viewFrustum.setProjection(camera.getProjection());
28452832
28462833 // Set the viewFrustum up with the correct position and orientation of the camera
2847− viewFrustum.setPosition(position);
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());
2834+ viewFrustum.setPosition(camera.getPosition());
2835+ viewFrustum.setOrientation(camera.getRotation());
28572836
28582837 // Ask the ViewFrustum class to calculate our corners
28592838 viewFrustum.calculate();
@@ -2954,13 +2933,7 @@ void Application::updateShadowMap() { · 94 unmodified lines
29542933 glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);
29552934 _shadowViewFrustum.setPosition(shadowFrustumCenter);
29562935 _shadowViewFrustum.setOrientation(rotation);
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());
2936+ _shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z));
29642937 _shadowViewFrustum.calculate();
29652938
29662939 glMatrixMode(GL_PROJECTION);
@@ -3147,12 +3120,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 180 unmodified lines
31473120 glFrontFace(GL_CCW);
31483121 }
31493122
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−
31563123 // transform view according to theCamera
31573124 // could be myCamera (if in normal mode)
31583125 // or could be viewFrustumOffsetCamera if in offset mode
@@ -3170,8 +3137,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 11 unmodified lines
31703137 Transform viewTransform;
31713138 viewTransform.setTranslation(theCamera.getPosition());
31723139 viewTransform.setRotation(rotation);
3173− viewTransform.postTranslate(eyeOffsetPos);
3174− viewTransform.postRotate(eyeOffsetOrient);
31753140 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
31763141 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));
31773142 }
@@ -3265,7 +3230,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 87 unmodified lines
32653230
32663231 // finally render the starfield
32673232 if (hasStars) {
3268− _stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha);
3233+ _stars.render(_displayViewFrustum.getFieldOfView(), _displayViewFrustum.getAspectRatio(), _displayViewFrustum.getNearClip(), alpha);
32693234 }
32703235
32713236 // draw the sky dome
@@ -3499,15 +3464,16 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 227 unmodified lines
34993464 // Grab current viewport to reset it at the end
35003465 int viewport[4];
35013466 glGetIntegerv(GL_VIEWPORT, viewport);
3467+ float aspect = (float)region.width() / region.height();
3468+ float fov = MIRROR_FIELD_OF_VIEW;
35023469
35033470 // bool eyeRelativeCamera = false;
35043471 if (billboard) {
3505− _mirrorCamera.setFieldOfView(BILLBOARD_FIELD_OF_VIEW); // degees
3472+ fov = BILLBOARD_FIELD_OF_VIEW; // degees
35063473 _mirrorCamera.setPosition(_myAvatar->getPosition() +
35073474 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());
35083475
35093476 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {
3510− _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
35113477 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +
35123478 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());
35133479
@@ -3528,12 +3494,10 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 14 unmodified lines
35283494 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
35293495 // investigated in order to adapt the technique while fixing the head rendering issue,
35303496 // but the complexity of the hack suggests that a better approach
3531− _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
35323497 _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +
35333498 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());
35343499 }
3535− _mirrorCamera.setAspectRatio((float)region.width() / region.height());
3536−
3500+ _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
35373501 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
35383502
35393503 // set the bounds of rear mirror view