History

merge upstream/master into andrew/bispinor

Andrew Meadows committed 11 years ago

Commit 461d08c2 parents bf225e4 da8f995104 files · +2045 −2778Browse files

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

Unified · Split

interface/src/Application.cpp+47−61
@@ -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"
@@ -339,7 +340,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 314 unmodified lines
339 _aboutToQuit(false),340 _aboutToQuit(false),
340 _notifiedPacketVersionMismatchThisDomain(false),341 _notifiedPacketVersionMismatchThisDomain(false),
341 _domainConnectionRefusals(QList<QString>()),342 _domainConnectionRefusals(QList<QString>()),
342 _maxOctreePPS(maxOctreePacketsPerSecond.get())343 _maxOctreePPS(maxOctreePacketsPerSecond.get()),
344 _lastFaceTrackerUpdate(0)
343{345{
344 setInstance(this);346 setInstance(this);
345#ifdef Q_OS_WIN347#ifdef Q_OS_WIN
@@ -978,12 +980,11 @@ void Application::showEditEntitiesHelp() { · 632 unmodified lines
978 980
979void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {981void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {
980 if (OculusManager::isConnected()) {982 if (OculusManager::isConnected()) {
981 OculusManager::configureCamera(camera, size.x, size.y);983 OculusManager::configureCamera(camera);
982 } else if (TV3DManager::isConnected()) {984 } else if (TV3DManager::isConnected()) {
983 TV3DManager::configureCamera(camera, size.x, size.y);985 TV3DManager::configureCamera(camera, size.x, size.y);
984 } else {986 } else {
985 camera.setAspectRatio((float)size.x / size.y);987 camera.setProjection(glm::perspective(glm::radians(_fieldOfView.get()), (float)size.x / size.y, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
986 camera.setFieldOfView(_fieldOfView.get());
987 }988 }
988}989}
989 990
@@ -997,7 +998,7 @@ void Application::resizeGL() { · 7 unmodified lines
997 renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale();998 renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale();
998 }999 }
999 if (_renderResolution == toGlm(renderSize)) {1000 if (_renderResolution == toGlm(renderSize)) {
1000 return;1001 return;
1001 }1002 }
1002 1003
1003 _renderResolution = toGlm(renderSize);1004 _renderResolution = toGlm(renderSize);
@@ -1024,25 +1025,15 @@ void Application::updateProjectionMatrix() { · 20 unmodified lines
1024}1025}
1025 1026
1026void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {1027void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {
1027 glMatrixMode(GL_PROJECTION);1028 _projectionMatrix = camera.getProjection();
1028 glLoadIdentity();
1029 1029
1030 float left, right, bottom, top, nearVal, farVal;1030 glMatrixMode(GL_PROJECTION);
1031 glm::vec4 nearClipPlane, farClipPlane;1031 glLoadMatrixf(glm::value_ptr(_projectionMatrix));
1032 1032
1033 // Tell our viewFrustum about this change, using the application camera1033 // Tell our viewFrustum about this change, using the application camera
1034 if (updateViewFrustum) {1034 if (updateViewFrustum) {
1035 loadViewFrustum(camera, _viewFrustum);1035 loadViewFrustum(camera, _viewFrustum);
1036 _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);1036 }
1037 } else {
1038 ViewFrustum tempViewFrustum;
1039 loadViewFrustum(camera, tempViewFrustum);
1040 tempViewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
1041 }
1042 glFrustum(left, right, bottom, top, nearVal, farVal);
1043
1044 // save matrix
1045 glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)&_projectionMatrix);
1046 1037
1047 glMatrixMode(GL_MODELVIEW);1038 glMatrixMode(GL_MODELVIEW);
1048}1039}
@@ -1263,6 +1254,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 214 unmodified lines
1263 }1254 }
1264 break;1255 break;
1265 1256
1257#if 0
1266 case Qt::Key_I:1258 case Qt::Key_I:
1267 if (isShifted) {1259 if (isShifted) {
1268 _myCamera.setEyeOffsetOrientation(glm::normalize(1260 _myCamera.setEyeOffsetOrientation(glm::normalize(
@@ -1327,6 +1319,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 58 unmodified lines
1327 }1319 }
1328 updateProjectionMatrix();1320 updateProjectionMatrix();
1329 break;1321 break;
1322#endif
1323
1330 case Qt::Key_H:1324 case Qt::Key_H:
1331 if (isShifted) {1325 if (isShifted) {
1332 Menu::getInstance()->triggerOption(MenuOption::Mirror);1326 Menu::getInstance()->triggerOption(MenuOption::Mirror);
@@ -2417,7 +2411,27 @@ void Application::update(float deltaTime) { · 1084 unmodified lines
2417 FaceTracker* tracker = getActiveFaceTracker();2411 FaceTracker* tracker = getActiveFaceTracker();
2418 if (tracker && !tracker->isMuted()) {2412 if (tracker && !tracker->isMuted()) {
2419 tracker->update(deltaTime);2413 tracker->update(deltaTime);
2414
2415 // Auto-mute microphone after losing face tracking?
2416 if (tracker->isTracking()) {
2417 _lastFaceTrackerUpdate = usecTimestampNow();
2418 } else {
2419 const quint64 MUTE_MICROPHONE_AFTER_USECS = 5000000; //5 secs
2420 Menu* menu = Menu::getInstance();
2421 if (menu->isOptionChecked(MenuOption::AutoMuteAudio) && !menu->isOptionChecked(MenuOption::MuteAudio)) {
2422 if (_lastFaceTrackerUpdate > 0
2423 && ((usecTimestampNow() - _lastFaceTrackerUpdate) > MUTE_MICROPHONE_AFTER_USECS)) {
2424 menu->triggerOption(MenuOption::MuteAudio);
2425 _lastFaceTrackerUpdate = 0;
2426 }
2427 } else {
2428 _lastFaceTrackerUpdate = 0;
2429 }
2430 }
2431 } else {
2432 _lastFaceTrackerUpdate = 0;
2420 }2433 }
2434
2421 SixenseManager::getInstance().update(deltaTime);2435 SixenseManager::getInstance().update(deltaTime);
2422 JoystickScriptingInterface::getInstance().update();2436 JoystickScriptingInterface::getInstance().update();
2423 }2437 }
@@ -2470,7 +2484,6 @@ void Application::update(float deltaTime) { · 46 unmodified lines
2470 if (_physicsEngine.hasOutgoingChanges()) {2484 if (_physicsEngine.hasOutgoingChanges()) {
2471 _entitySimulation.lock();2485 _entitySimulation.lock();
2472 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());2486 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());
2473 _entitySimulation.handleCollisionEvents(_physicsEngine.getCollisionEvents());
2474 _entitySimulation.unlock();2487 _entitySimulation.unlock();
2475 2488
2476 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());2489 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());
@@ -2482,9 +2495,11 @@ void Application::update(float deltaTime) { · 5 unmodified lines
2482 2495
2483 if (!_aboutToQuit) {2496 if (!_aboutToQuit) {
2484 PerformanceTimer perfTimer("entities");2497 PerformanceTimer perfTimer("entities");
2485 // NOTE: the _entities.update() call below will wait for lock 2498 // Collision events (and their scripts) must not be handled when we're locked, above. (That would risk deadlock.)
2499 _entitySimulation.handleCollisionEvents(_physicsEngine.getCollisionEvents());
2500 // NOTE: the _entities.update() call below will wait for lock
2486 // and will simulate entity motion (the EntityTree has been given an EntitySimulation). 2501 // and will simulate entity motion (the EntityTree has been given an EntitySimulation).
2487 _entities.update(); // update the models...2502 _entities.update(); // update the models...
2488 }2503 }
2489 2504
2490 {2505 {
@@ -2654,7 +2669,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 163 unmodified lines
2654 _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio());2669 _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio());
2655 _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip());2670 _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip());
2656 _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip());2671 _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip());
2657 _octreeQuery.setCameraEyeOffsetPosition(_viewFrustum.getEyeOffsetPosition());2672 _octreeQuery.setCameraEyeOffsetPosition(glm::vec3());
2658 auto lodManager = DependencyManager::get<LODManager>();2673 auto lodManager = DependencyManager::get<LODManager>();
2659 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());2674 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());
2660 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());2675 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());
@@ -2858,25 +2873,11 @@ QRect Application::getDesirableApplicationGeometry() { · 197 unmodified lines
2858//2873//
2859void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {2874void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
2860 // We will use these below, from either the camera or head vectors calculated above2875 // We will use these below, from either the camera or head vectors calculated above
2861 glm::vec3 position(camera.getPosition());2876 viewFrustum.setProjection(camera.getProjection());
2862 float fov = camera.getFieldOfView(); // degrees
2863 float nearClip = camera.getNearClip();
2864 float farClip = camera.getFarClip();
2865 float aspectRatio = camera.getAspectRatio();
2866
2867 glm::quat rotation = camera.getRotation();
2868 2877
2869 // Set the viewFrustum up with the correct position and orientation of the camera2878 // Set the viewFrustum up with the correct position and orientation of the camera
2870 viewFrustum.setPosition(position);2879 viewFrustum.setPosition(camera.getPosition());
2871 viewFrustum.setOrientation(rotation);2880 viewFrustum.setOrientation(camera.getRotation());
2872
2873 // Also make sure it's got the correct lens details from the camera
2874 viewFrustum.setAspectRatio(aspectRatio);
2875 viewFrustum.setFieldOfView(fov); // degrees
2876 viewFrustum.setNearClip(nearClip);
2877 viewFrustum.setFarClip(farClip);
2878 viewFrustum.setEyeOffsetPosition(camera.getEyeOffsetPosition());
2879 viewFrustum.setEyeOffsetOrientation(camera.getEyeOffsetOrientation());
2880 2881
2881 // Ask the ViewFrustum class to calculate our corners2882 // Ask the ViewFrustum class to calculate our corners
2882 viewFrustum.calculate();2883 viewFrustum.calculate();
@@ -2977,13 +2978,7 @@ void Application::updateShadowMap() { · 94 unmodified lines
2977 glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);2978 glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);
2978 _shadowViewFrustum.setPosition(shadowFrustumCenter);2979 _shadowViewFrustum.setPosition(shadowFrustumCenter);
2979 _shadowViewFrustum.setOrientation(rotation);2980 _shadowViewFrustum.setOrientation(rotation);
2980 _shadowViewFrustum.setOrthographic(true);2981 _shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z));
2981 _shadowViewFrustum.setWidth(maxima.x - minima.x);
2982 _shadowViewFrustum.setHeight(maxima.y - minima.y);
2983 _shadowViewFrustum.setNearClip(minima.z);
2984 _shadowViewFrustum.setFarClip(maxima.z);
2985 _shadowViewFrustum.setEyeOffsetPosition(glm::vec3());
2986 _shadowViewFrustum.setEyeOffsetOrientation(glm::quat());
2987 _shadowViewFrustum.calculate();2982 _shadowViewFrustum.calculate();
2988 2983
2989 glMatrixMode(GL_PROJECTION);2984 glMatrixMode(GL_PROJECTION);
@@ -3181,12 +3176,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 191 unmodified lines
3181 glFrontFace(GL_CCW);3176 glFrontFace(GL_CCW);
3182 }3177 }
3183 3178
3184 glm::vec3 eyeOffsetPos = theCamera.getEyeOffsetPosition();
3185 glm::quat eyeOffsetOrient = theCamera.getEyeOffsetOrientation();
3186 glm::vec3 eyeOffsetAxis = glm::axis(eyeOffsetOrient);
3187 glRotatef(-glm::degrees(glm::angle(eyeOffsetOrient)), eyeOffsetAxis.x, eyeOffsetAxis.y, eyeOffsetAxis.z);
3188 glTranslatef(-eyeOffsetPos.x, -eyeOffsetPos.y, -eyeOffsetPos.z);
3189
3190 // transform view according to theCamera3179 // transform view according to theCamera
3191 // could be myCamera (if in normal mode)3180 // could be myCamera (if in normal mode)
3192 // or could be viewFrustumOffsetCamera if in offset mode3181 // or could be viewFrustumOffsetCamera if in offset mode
@@ -3204,8 +3193,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 11 unmodified lines
3204 Transform viewTransform;3193 Transform viewTransform;
3205 viewTransform.setTranslation(theCamera.getPosition());3194 viewTransform.setTranslation(theCamera.getPosition());
3206 viewTransform.setRotation(rotation);3195 viewTransform.setRotation(rotation);
3207 viewTransform.postTranslate(eyeOffsetPos);
3208 viewTransform.postRotate(eyeOffsetOrient);
3209 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {3196 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
3210 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));3197 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));
3211 }3198 }
@@ -3299,7 +3286,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 87 unmodified lines
3299 3286
3300 // finally render the starfield3287 // finally render the starfield
3301 if (hasStars) {3288 if (hasStars) {
3302 _stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha);3289 _stars.render(_displayViewFrustum.getFieldOfView(), _displayViewFrustum.getAspectRatio(), _displayViewFrustum.getNearClip(), alpha);
3303 }3290 }
3304 3291
3305 // draw the sky dome3292 // draw the sky dome
@@ -3533,15 +3520,16 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 227 unmodified lines
3533 // Grab current viewport to reset it at the end3520 // Grab current viewport to reset it at the end
3534 int viewport[4];3521 int viewport[4];
3535 glGetIntegerv(GL_VIEWPORT, viewport);3522 glGetIntegerv(GL_VIEWPORT, viewport);
3523 float aspect = (float)region.width() / region.height();
3524 float fov = MIRROR_FIELD_OF_VIEW;
3536 3525
3537 // bool eyeRelativeCamera = false;3526 // bool eyeRelativeCamera = false;
3538 if (billboard) {3527 if (billboard) {
3539 _mirrorCamera.setFieldOfView(BILLBOARD_FIELD_OF_VIEW); // degees3528 fov = BILLBOARD_FIELD_OF_VIEW; // degees
3540 _mirrorCamera.setPosition(_myAvatar->getPosition() +3529 _mirrorCamera.setPosition(_myAvatar->getPosition() +
3541 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());3530 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());
3542 3531
3543 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {3532 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {
3544 _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
3545 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +3533 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +
3546 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());3534 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());
3547 3535
@@ -3562,12 +3550,10 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 14 unmodified lines
3562 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further 3550 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
3563 // investigated in order to adapt the technique while fixing the head rendering issue,3551 // investigated in order to adapt the technique while fixing the head rendering issue,
3564 // but the complexity of the hack suggests that a better approach 3552 // but the complexity of the hack suggests that a better approach
3565 _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
3566 _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +3553 _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +
3567 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());3554 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());
3568 }3555 }
3569 _mirrorCamera.setAspectRatio((float)region.width() / region.height());3556 _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
3570
3571 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));3557 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
3572 3558
3573 // set the bounds of rear mirror view3559 // set the bounds of rear mirror view