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
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"
@@ -339,7 +340,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 314 unmodified lines
339340 _aboutToQuit(false),
340341 _notifiedPacketVersionMismatchThisDomain(false),
341342 _domainConnectionRefusals(QList<QString>()),
342− _maxOctreePPS(maxOctreePacketsPerSecond.get())
343+ _maxOctreePPS(maxOctreePacketsPerSecond.get()),
344+ _lastFaceTrackerUpdate(0)
343345 {
344346 setInstance(this);
345347 #ifdef Q_OS_WIN
@@ -978,12 +980,11 @@ void Application::showEditEntitiesHelp() { · 632 unmodified lines
978980
979981 void Application::resetCamerasOnResizeGL(Camera& camera, const glm::uvec2& size) {
980982 if (OculusManager::isConnected()) {
981− OculusManager::configureCamera(camera, size.x, size.y);
983+ OculusManager::configureCamera(camera);
982984 } else if (TV3DManager::isConnected()) {
983985 TV3DManager::configureCamera(camera, size.x, size.y);
984986 } else {
985− camera.setAspectRatio((float)size.x / size.y);
986− camera.setFieldOfView(_fieldOfView.get());
987+ camera.setProjection(glm::perspective(glm::radians(_fieldOfView.get()), (float)size.x / size.y, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
987988 }
988989 }
989990
@@ -997,7 +998,7 @@ void Application::resizeGL() { · 7 unmodified lines
997998 renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale();
998999 }
9991000 if (_renderResolution == toGlm(renderSize)) {
1000− return;
1001+ return;
10011002 }
10021003
10031004 _renderResolution = toGlm(renderSize);
@@ -1024,25 +1025,15 @@ void Application::updateProjectionMatrix() { · 20 unmodified lines
10241025 }
10251026
10261027 void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {
1027− glMatrixMode(GL_PROJECTION);
1028− glLoadIdentity();
1028+ _projectionMatrix = camera.getProjection();
10291029
1030− float left, right, bottom, top, nearVal, farVal;
1031− glm::vec4 nearClipPlane, farClipPlane;
1030+ glMatrixMode(GL_PROJECTION);
1031+ glLoadMatrixf(glm::value_ptr(_projectionMatrix));
10321032
10331033 // Tell our viewFrustum about this change, using the application camera
10341034 if (updateViewFrustum) {
10351035 loadViewFrustum(camera, _viewFrustum);
1036− _viewFrustum.computeOffAxisFrustum(left, right, bottom, top, nearVal, farVal, nearClipPlane, farClipPlane);
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);
1036+ }
10461037
10471038 glMatrixMode(GL_MODELVIEW);
10481039 }
@@ -1263,6 +1254,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 214 unmodified lines
12631254 }
12641255 break;
12651256
1257+#if 0
12661258 case Qt::Key_I:
12671259 if (isShifted) {
12681260 _myCamera.setEyeOffsetOrientation(glm::normalize(
@@ -1327,6 +1319,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 58 unmodified lines
13271319 }
13281320 updateProjectionMatrix();
13291321 break;
1322+#endif
1323+
13301324 case Qt::Key_H:
13311325 if (isShifted) {
13321326 Menu::getInstance()->triggerOption(MenuOption::Mirror);
@@ -2417,7 +2411,27 @@ void Application::update(float deltaTime) { · 1084 unmodified lines
24172411 FaceTracker* tracker = getActiveFaceTracker();
24182412 if (tracker && !tracker->isMuted()) {
24192413 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;
24202433 }
2434+
24212435 SixenseManager::getInstance().update(deltaTime);
24222436 JoystickScriptingInterface::getInstance().update();
24232437 }
@@ -2470,7 +2484,6 @@ void Application::update(float deltaTime) { · 46 unmodified lines
24702484 if (_physicsEngine.hasOutgoingChanges()) {
24712485 _entitySimulation.lock();
24722486 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());
2473− _entitySimulation.handleCollisionEvents(_physicsEngine.getCollisionEvents());
24742487 _entitySimulation.unlock();
24752488
24762489 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());
@@ -2482,9 +2495,11 @@ void Application::update(float deltaTime) { · 5 unmodified lines
24822495
24832496 if (!_aboutToQuit) {
24842497 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
24862501 // and will simulate entity motion (the EntityTree has been given an EntitySimulation).
2487− _entities.update(); // update the models...
2502+ _entities.update(); // update the models...
24882503 }
24892504
24902505 {
@@ -2654,7 +2669,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 163 unmodified lines
26542669 _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio());
26552670 _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip());
26562671 _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip());
2657− _octreeQuery.setCameraEyeOffsetPosition(_viewFrustum.getEyeOffsetPosition());
2672+ _octreeQuery.setCameraEyeOffsetPosition(glm::vec3());
26582673 auto lodManager = DependencyManager::get<LODManager>();
26592674 _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale());
26602675 _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust());
@@ -2858,25 +2873,11 @@ QRect Application::getDesirableApplicationGeometry() { · 197 unmodified lines
28582873 //
28592874 void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) {
28602875 // We will use these below, from either the camera or head vectors calculated above
2861− glm::vec3 position(camera.getPosition());
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();
2876+ viewFrustum.setProjection(camera.getProjection());
28682877
28692878 // Set the viewFrustum up with the correct position and orientation of the camera
2870− viewFrustum.setPosition(position);
2871− viewFrustum.setOrientation(rotation);
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());
2879+ viewFrustum.setPosition(camera.getPosition());
2880+ viewFrustum.setOrientation(camera.getRotation());
28802881
28812882 // Ask the ViewFrustum class to calculate our corners
28822883 viewFrustum.calculate();
@@ -2977,13 +2978,7 @@ void Application::updateShadowMap() { · 94 unmodified lines
29772978 glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);
29782979 _shadowViewFrustum.setPosition(shadowFrustumCenter);
29792980 _shadowViewFrustum.setOrientation(rotation);
2980− _shadowViewFrustum.setOrthographic(true);
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());
2981+ _shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z));
29872982 _shadowViewFrustum.calculate();
29882983
29892984 glMatrixMode(GL_PROJECTION);
@@ -3181,12 +3176,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 191 unmodified lines
31813176 glFrontFace(GL_CCW);
31823177 }
31833178
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−
31903179 // transform view according to theCamera
31913180 // could be myCamera (if in normal mode)
31923181 // or could be viewFrustumOffsetCamera if in offset mode
@@ -3204,8 +3193,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 11 unmodified lines
32043193 Transform viewTransform;
32053194 viewTransform.setTranslation(theCamera.getPosition());
32063195 viewTransform.setRotation(rotation);
3207− viewTransform.postTranslate(eyeOffsetPos);
3208− viewTransform.postRotate(eyeOffsetOrient);
32093196 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
32103197 viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));
32113198 }
@@ -3299,7 +3286,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs · 87 unmodified lines
32993286
33003287 // finally render the starfield
33013288 if (hasStars) {
3302− _stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha);
3289+ _stars.render(_displayViewFrustum.getFieldOfView(), _displayViewFrustum.getAspectRatio(), _displayViewFrustum.getNearClip(), alpha);
33033290 }
33043291
33053292 // draw the sky dome
@@ -3533,15 +3520,16 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 227 unmodified lines
35333520 // Grab current viewport to reset it at the end
35343521 int viewport[4];
35353522 glGetIntegerv(GL_VIEWPORT, viewport);
3523+ float aspect = (float)region.width() / region.height();
3524+ float fov = MIRROR_FIELD_OF_VIEW;
35363525
35373526 // bool eyeRelativeCamera = false;
35383527 if (billboard) {
3539− _mirrorCamera.setFieldOfView(BILLBOARD_FIELD_OF_VIEW); // degees
3528+ fov = BILLBOARD_FIELD_OF_VIEW; // degees
35403529 _mirrorCamera.setPosition(_myAvatar->getPosition() +
35413530 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());
35423531
35433532 } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {
3544− _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
35453533 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +
35463534 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());
35473535
@@ -3562,12 +3550,10 @@ void Application::renderRearViewMirror(const QRect& region, bool billboard) { · 14 unmodified lines
35623550 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
35633551 // investigated in order to adapt the technique while fixing the head rendering issue,
35643552 // but the complexity of the hack suggests that a better approach
3565− _mirrorCamera.setFieldOfView(MIRROR_FIELD_OF_VIEW); // degrees
35663553 _mirrorCamera.setPosition(_myAvatar->getHead()->getEyePosition() +
35673554 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * _myAvatar->getScale());
35683555 }
3569− _mirrorCamera.setAspectRatio((float)region.width() / region.height());
3570−
3556+ _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
35713557 _mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
35723558
35733559 // set the bounds of rear mirror view