Showing the changes to interface/src/Application.cpp (1 of 1 file). Show all
Unified · Split
| @@ -553,9 +553,6 @@ void Application::paintGL() { · 552 unmodified lines | |||
| 553 | PerformanceWarning warn(showWarnings, "Application::paintGL()"); | 553 | PerformanceWarning warn(showWarnings, "Application::paintGL()"); |
| 554 | 554 | ||
| 555 | glEnable(GL_LINE_SMOOTH); | 555 | glEnable(GL_LINE_SMOOTH); |
| 556 | |||
| 557 | float pushback = 0.0f; | ||
| 558 | float pushbackFocalLength = 0.0f; | ||
| 559 | 556 | ||
| 560 | if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) { | 557 | if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) { |
| 561 | _myCamera.setTightness(0.0f); // In first person, camera follows (untweaked) head exactly without delay | 558 | _myCamera.setTightness(0.0f); // In first person, camera follows (untweaked) head exactly without delay |
| @@ -571,52 +568,25 @@ void Application::paintGL() { · 9 unmodified lines | |||
| 571 | _myCamera.setTightness(0.0f); | 568 | _myCamera.setTightness(0.0f); |
| 572 | glm::vec3 eyePosition = _myAvatar->getHead()->calculateAverageEyePosition(); | 569 | glm::vec3 eyePosition = _myAvatar->getHead()->calculateAverageEyePosition(); |
| 573 | float headHeight = eyePosition.y - _myAvatar->getPosition().y; | 570 | float headHeight = eyePosition.y - _myAvatar->getPosition().y; |
| 574 | _myCamera.setDistance(MIRROR_FULLSCREEN_DISTANCE * _myAvatar->getScale() * _scaleMirror); | 571 | _myCamera.setDistance(MIRROR_FULLSCREEN_DISTANCE * _scaleMirror); |
| 575 | _myCamera.setTargetPosition(_myAvatar->getPosition() + glm::vec3(0, headHeight + (_raiseMirror * _myAvatar->getScale()), 0)); | 572 | _myCamera.setTargetPosition(_myAvatar->getPosition() + glm::vec3(0, headHeight + (_raiseMirror * _myAvatar->getScale()), 0)); |
| 576 | _myCamera.setTargetRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f))); | 573 | _myCamera.setTargetRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f))); |
| 577 | |||
| 578 | // if the head would intersect the near clip plane, we must push the camera out | ||
| 579 | glm::vec3 relativePosition = glm::inverse(_myCamera.getTargetRotation()) * | ||
| 580 | (eyePosition - _myCamera.getTargetPosition()); | ||
| 581 | const float BASE_PUSHBACK_RADIUS = 0.2f; | ||
| 582 | float pushbackRadius = _myCamera.getNearClip() + _myAvatar->getScale() * BASE_PUSHBACK_RADIUS; | ||
| 583 | pushback = relativePosition.z + pushbackRadius - _myCamera.getDistance(); | ||
| 584 | pushbackFocalLength = _myCamera.getDistance(); | ||
| 585 | } | 574 | } |
| 586 | 575 | ||
| 587 | if (OculusManager::isConnected()) { | 576 | if (OculusManager::isConnected()) { |
| 588 | // OR in third person causes nausea, so only allow it if option is checked in dev menu | 577 | // Oculus in third person causes nausea, so only allow it if option is checked in dev menu |
| 589 | if (!Menu::getInstance()->isOptionChecked(MenuOption::AllowOculusCameraModeChange) || _myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) { | 578 | if (!Menu::getInstance()->isOptionChecked(MenuOption::AllowOculusCameraModeChange) || _myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) { |
| 590 | _myCamera.setDistance(0.0f); | 579 | _myCamera.setDistance(0.0f); |
| 591 | _myCamera.setTargetPosition(_myAvatar->getHead()->calculateAverageEyePosition()); | 580 | _myCamera.setTargetPosition(_myAvatar->getHead()->calculateAverageEyePosition()); |
| 592 | _myCamera.setTargetRotation(_myAvatar->getHead()->getCameraOrientation()); | 581 | _myCamera.setTargetRotation(_myAvatar->getHead()->getCameraOrientation()); |
| 593 | pushback = 0.0f; | ||
| 594 | pushbackFocalLength = 0.0f; | ||
| 595 | } | 582 | } |
| 596 | _myCamera.setUpShift(0.0f); | 583 | _myCamera.setUpShift(0.0f); |
| 597 | _myCamera.setTightness(0.0f); // Camera is directly connected to head without smoothing | 584 | _myCamera.setTightness(0.0f); // Camera is directly connected to head without smoothing |
| 598 | } | 585 | } |
| 599 | |||
| 600 | // handle pushback, if any | ||
| 601 | if (pushbackFocalLength > 0.0f) { | ||
| 602 | const float PUSHBACK_DECAY = 0.5f; | ||
| 603 | _cameraPushback = qMax(pushback, _cameraPushback * PUSHBACK_DECAY); | ||
| 604 | if (_cameraPushback > EPSILON) { | ||
| 605 | _myCamera.setTargetPosition(_myCamera.getTargetPosition() + | ||
| 606 | _myCamera.getTargetRotation() * glm::vec3(0.0f, 0.0f, _cameraPushback)); | ||
| 607 | float enlargement = pushbackFocalLength / (pushbackFocalLength + _cameraPushback); | ||
| 608 | _myCamera.setFieldOfView(glm::degrees(2.0f * atanf(enlargement * tanf( | ||
| 609 | glm::radians(Menu::getInstance()->getFieldOfView() * 0.5f))))); | ||
| 610 | } else { | ||
| 611 | _myCamera.setFieldOfView(Menu::getInstance()->getFieldOfView()); | ||
| 612 | } | ||
| 613 | updateProjectionMatrix(_myCamera, true); | ||
| 614 | } | ||
| 615 | 586 | ||
| 616 | // Update camera position | 587 | // Update camera position |
| 617 | _myCamera.update( 1.f/_fps ); | 588 | _myCamera.update( 1.f/_fps ); |
| 618 | 589 | ||
| 619 | |||
| 620 | // Note: whichCamera is used to pick between the normal camera myCamera for our | 590 | // Note: whichCamera is used to pick between the normal camera myCamera for our |
| 621 | // main camera, vs, an alternate camera. The alternate camera we support right now | 591 | // main camera, vs, an alternate camera. The alternate camera we support right now |
| 622 | // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism | 592 | // is the viewFrustumOffsetCamera. But theoretically, we could use this same mechanism |