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
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>
2322
2423 // include this before QGLWidget, which includes an earlier version of OpenGL
2524 #include "InterfaceConfig.h"
@@ -966,11 +965,12 @@ void Application::showEditEntitiesHelp() { · 940 unmodified lines
966965
967966 void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {
968967 if (OculusManager::isConnected()) {
969− OculusManager::configureCamera(camera);
968+ OculusManager::configureCamera(camera, size.x, size.y);
970969 } else if (TV3DManager::isConnected()) {
971970 TV3DManager::configureCamera(camera, size.x, size.y);
972971 } 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());
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,15 +1011,25 @@ void Application::updateProjectionMatrix() { · 20 unmodified lines
10111011 }
10121012
10131013 void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {
1014− _projectionMatrix = camera.getProjection();
1015−
10161014 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;
10181019
10191020 // Tell our viewFrustum about this change, using the application camera
10201021 if (updateViewFrustum) {
10211022 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);
10231033
10241034 glMatrixMode(GL_MODELVIEW);
10251035 }
@@ -1240,7 +1250,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 214 unmodified lines
12401250 }
12411251 break;
12421252
1243−#if 0
12441253 case Qt::Key_I:
12451254 if (isShifted) {
12461255 _myCamera.setEyeOffsetOrientation(glm::normalize(
@@ -1305,8 +1314,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 58 unmodified lines
13051314 }
13061315 updateProjectionMatrix();
13071316 break;
1308−#endif
1309−
13101317 case Qt::Key_H:
13111318 if (isShifted) {
13121319 Menu::getInstance()->triggerOption(MenuOption::Mirror);
@@ -2624,7 +2631,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 1311 unmodified lines
26242631 _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio());
26252632 _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip());
26262633 _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip());
2627− _octreeQuery.setCameraEyeOffsetPosition(glm::vec3());
2634+ _octreeQuery.setCameraEyeOffsetPosition(_viewFrustum.getEyeOffsetPosition());
26282635 auto lodManager = DependencyManager::get<LODManager>();
26292636 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());
26302637 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());
@@ -2828,11 +2835,25 @@ QRect Application::getDesirableApplicationGeometry() { · 197 unmodified lines
28282835 //
28292836 void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
28302837 // 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();
28322845
28332846 // Set the viewFrustum up with the correct position and orientation of the camera
2834− viewFrustum.setPosition(camera.getPosition());
2835− viewFrustum.setOrientation(camera.getRotation());
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());
28362857
28372858 // Ask the ViewFrustum class to calculate our corners
28382859 viewFrustum.calculate();
@@ -2933,7 +2954,13 @@ void Application::updateShadowMap() { · 94 unmodified lines
29332954 glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);
29342955 _shadowViewFrustum.setPosition(shadowFrustumCenter);
29352956 _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());
29372964 _shadowViewFrustum.calculate();
29382965
29392966 glMatrixMode(GL_PROJECTION);
@@ -3120,6 +3147,12 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 180 unmodified lines
31203147 glFrontFace(GL_CCW);
31213148 }
31223149
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+
31233156 // transform view according to theCamera
31243157 // could be myCamera (if in normal mode)
31253158 // or could be viewFrustumOffsetCamera if in offset mode
@@ -3137,6 +3170,8 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 11 unmodified lines
31373170 Transform viewTransform;
31383171 viewTransform.setTranslation(theCamera.getPosition());
31393172 viewTransform.setRotation(rotation);
3173+ viewTransform.postTranslate(eyeOffsetPos);
3174+ viewTransform.postRotate(eyeOffsetOrient);
31403175 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
31413176 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));
31423177 }
@@ -3230,7 +3265,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 87 unmodified lines
32303265
32313266 // finally render the starfield
32323267 if (hasStars) {
3233− _stars.render(_displayViewFrustum.getFieldOfView(), _displayViewFrustum.getAspectRatio(), _displayViewFrustum.getNearClip(), alpha);
3268+ _stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha);
32343269 }
32353270
32363271 // draw the sky dome
@@ -3464,16 +3499,15 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 227 unmodified lines
34643499 // Grab current viewport to reset it at the end
34653500 int viewport[4];
34663501 glGetIntegerv(GL_VIEWPORT, viewport);
3467− float aspect = (float)region.width() / region.height();
3468− float fov = MIRROR_FIELD_OF_VIEW;
34693502
34703503 // bool eyeRelativeCamera = false;
34713504 if (billboard) {
3472− fov = BILLBOARD_FIELD_OF_VIEW; // degees
3505+ _mirrorCamera.setFieldOfView(BILLBOARD_FIELD_OF_VIEW); // degees
34733506 _mirrorCamera.setPosition(_myAvatar->getPosition() +
34743507 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());
34753508
34763509 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {
3510+ _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
34773511 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +
34783512 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());
34793513
@@ -3494,10 +3528,12 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 14 unmodified lines
34943528 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
34953529 // investigated in order to adapt the technique while fixing the head rendering issue,
34963530 // but the complexity of the hack suggests that a better approach
3531+ _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
34973532 _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +
34983533 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());
34993534 }
3500− _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
3535+ _mirrorCamera.setAspectRatio((float)region.width() / region.height());
3536+
35013537 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
35023538
35033539 // set the bounds of rear mirror view