Showing the changes to interface/src/Application.cpp (1 of 11 files). Show all
Unified · Split
| @@ -1086,75 +1086,77 @@ void Application::paintGL() { · 1085 unmodified lines | |||
| 1086 | 1086 | ||
| 1087 | { | 1087 | { |
| 1088 | PerformanceTimer perfTimer("CameraUpdates"); | 1088 | PerformanceTimer perfTimer("CameraUpdates"); |
| 1089 | |||
| 1090 | auto myAvatar = getMyAvatar(); | 1089 | auto myAvatar = getMyAvatar(); |
| 1091 | 1090 | myAvatar->withReadLock([&] { | |
| 1092 | myAvatar->startCapture(); | 1091 | if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { |
| 1093 | if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { | 1092 | Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, |
| 1094 | Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN); | 1093 | myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN); |
| 1095 | Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN)); | 1094 | Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, |
| 1096 | cameraMenuChanged(); | 1095 | !(myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN)); |
| 1097 | } | 1096 | cameraMenuChanged(); |
| 1098 | |||
| 1099 | // The render mode is default or mirror if the camera is in mirror mode, assigned further below | ||
| 1100 | renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE; | ||
| 1101 | |||
| 1102 | // Always use the default eye position, not the actual head eye position. | ||
| 1103 | // Using the latter will cause the camera to wobble with idle animations, | ||
| 1104 | // or with changes from the face tracker | ||
| 1105 | if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) { | ||
| 1106 | if (isHMDMode()) { | ||
| 1107 | mat4 camMat = myAvatar->getSensorToWorldMatrix() * myAvatar->getHMDSensorMatrix(); | ||
| 1108 | _myCamera.setPosition(extractTranslation(camMat)); | ||
| 1109 | _myCamera.setRotation(glm::quat_cast(camMat)); | ||
| 1110 | } else { | ||
| 1111 | _myCamera.setPosition(myAvatar->getDefaultEyePosition()); | ||
| 1112 | _myCamera.setRotation(myAvatar->getHead()->getCameraOrientation()); | ||
| 1113 | } | 1097 | } |
| 1114 | } else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { | 1098 | |
| 1115 | if (isHMDMode()) { | 1099 | // The render mode is default or mirror if the camera is in mirror mode, assigned further below |
| 1116 | auto hmdWorldMat = myAvatar->getSensorToWorldMatrix() * myAvatar->getHMDSensorMatrix(); | 1100 | renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE; |
| 1117 | _myCamera.setRotation(glm::normalize(glm::quat_cast(hmdWorldMat))); | 1101 | |
| 1118 | auto worldBoomOffset = myAvatar->getOrientation() * (myAvatar->getScale() * myAvatar->getBoomLength() * glm::vec3(0.0f, 0.0f, 1.0f)); | 1102 | // Always use the default eye position, not the actual head eye position. |
| 1119 | _myCamera.setPosition(extractTranslation(hmdWorldMat) + worldBoomOffset); | 1103 | // Using the latter will cause the camera to wobble with idle animations, |
| 1120 | } else { | 1104 | // or with changes from the face tracker |
| 1121 | _myCamera.setRotation(myAvatar->getHead()->getOrientation()); | 1105 | if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) { |
| 1122 | if (Menu::getInstance()->isOptionChecked(MenuOption::CenterPlayerInView)) { | 1106 | if (isHMDMode()) { |
| 1107 | mat4 camMat = myAvatar->getSensorToWorldMatrix() * myAvatar->getHMDSensorMatrix(); | ||
| 1108 | _myCamera.setPosition(extractTranslation(camMat)); | ||
| 1109 | _myCamera.setRotation(glm::quat_cast(camMat)); | ||
| 1110 | } else { | ||
| 1111 | _myCamera.setPosition(myAvatar->getDefaultEyePosition()); | ||
| 1112 | _myCamera.setRotation(myAvatar->getHead()->getCameraOrientation()); | ||
| 1113 | } | ||
| 1114 | } else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) { | ||
| 1115 | if (isHMDMode()) { | ||
| 1116 | auto hmdWorldMat = myAvatar->getSensorToWorldMatrix() * myAvatar->getHMDSensorMatrix(); | ||
| 1117 | _myCamera.setRotation(glm::normalize(glm::quat_cast(hmdWorldMat))); | ||
| 1118 | auto worldBoomOffset = myAvatar->getOrientation() * | ||
| 1119 | (myAvatar->getScale() * myAvatar->getBoomLength() * glm::vec3(0.0f, 0.0f, 1.0f)); | ||
| 1120 | _myCamera.setPosition(extractTranslation(hmdWorldMat) + worldBoomOffset); | ||
| 1121 | } else { | ||
| 1122 | _myCamera.setRotation(myAvatar->getHead()->getOrientation()); | ||
| 1123 | if (Menu::getInstance()->isOptionChecked(MenuOption::CenterPlayerInView)) { | ||
| 1124 | _myCamera.setPosition(myAvatar->getDefaultEyePosition() | ||
| 1125 | + _myCamera.getRotation() * | ||
| 1126 | (myAvatar->getScale() * myAvatar->getBoomLength() * glm::vec3(0.0f, 0.0f, 1.0f))); | ||
| 1127 | } else { | ||
| 1128 | _myCamera.setPosition(myAvatar->getDefaultEyePosition() | ||
| 1129 | + myAvatar->getOrientation() * | ||
| 1130 | (myAvatar->getScale() * myAvatar->getBoomLength() * glm::vec3(0.0f, 0.0f, 1.0f))); | ||
| 1131 | } | ||
| 1132 | } | ||
| 1133 | } else if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { | ||
| 1134 | if (isHMDMode()) { | ||
| 1135 | glm::quat hmdRotation = extractRotation(myAvatar->getHMDSensorMatrix()); | ||
| 1136 | _myCamera.setRotation(myAvatar->getWorldAlignedOrientation() | ||
| 1137 | * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f)) * hmdRotation); | ||
| 1138 | glm::vec3 hmdOffset = extractTranslation(myAvatar->getHMDSensorMatrix()); | ||
| 1123 | _myCamera.setPosition(myAvatar->getDefaultEyePosition() | 1139 | _myCamera.setPosition(myAvatar->getDefaultEyePosition() |
| 1124 | + _myCamera.getRotation() | 1140 | + glm::vec3(0, _raiseMirror * myAvatar->getAvatarScale(), 0) |
| 1125 | * (myAvatar->getScale() * myAvatar->getBoomLength() * glm::vec3(0.0f, 0.0f, 1.0f))); | 1141 | + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) * |
| 1142 | glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror | ||
| 1143 | + (myAvatar->getOrientation() * | ||
| 1144 | glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f))) * hmdOffset); | ||
| 1126 | } else { | 1145 | } else { |
| 1146 | _myCamera.setRotation(myAvatar->getWorldAlignedOrientation() | ||
| 1147 | * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f))); | ||
| 1127 | _myCamera.setPosition(myAvatar->getDefaultEyePosition() | 1148 | _myCamera.setPosition(myAvatar->getDefaultEyePosition() |
| 1128 | + myAvatar->getOrientation() | 1149 | + glm::vec3(0, _raiseMirror * myAvatar->getAvatarScale(), 0) |
| 1129 | * (myAvatar->getScale() * myAvatar->getBoomLength() * glm::vec3(0.0f, 0.0f, 1.0f))); | 1150 | + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) * |
| 1151 | glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror); | ||
| 1130 | } | 1152 | } |
| 1153 | renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; | ||
| 1131 | } | 1154 | } |
| 1132 | } else if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { | 1155 | // Update camera position |
| 1133 | if (isHMDMode()) { | 1156 | if (!isHMDMode()) { |
| 1134 | glm::quat hmdRotation = extractRotation(myAvatar->getHMDSensorMatrix()); | 1157 | _myCamera.update(1.0f / _fps); |
| 1135 | _myCamera.setRotation(myAvatar->getWorldAlignedOrientation() | ||
| 1136 | * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f)) * hmdRotation); | ||
| 1137 | glm::vec3 hmdOffset = extractTranslation(myAvatar->getHMDSensorMatrix()); | ||
| 1138 | _myCamera.setPosition(myAvatar->getDefaultEyePosition() | ||
| 1139 | + glm::vec3(0, _raiseMirror * myAvatar->getAvatarScale(), 0) | ||
| 1140 | + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) * | ||
| 1141 | glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror | ||
| 1142 | + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f))) * hmdOffset); | ||
| 1143 | } else { | ||
| 1144 | _myCamera.setRotation(myAvatar->getWorldAlignedOrientation() | ||
| 1145 | * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f))); | ||
| 1146 | _myCamera.setPosition(myAvatar->getDefaultEyePosition() | ||
| 1147 | + glm::vec3(0, _raiseMirror * myAvatar->getAvatarScale(), 0) | ||
| 1148 | + (myAvatar->getOrientation() * glm::quat(glm::vec3(0.0f, _rotateMirror, 0.0f))) * | ||
| 1149 | glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_FULLSCREEN_DISTANCE * _scaleMirror); | ||
| 1150 | } | 1158 | } |
| 1151 | renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE; | 1159 | }); |
| 1152 | } | ||
| 1153 | // Update camera position | ||
| 1154 | if (!isHMDMode()) { | ||
| 1155 | _myCamera.update(1.0f / _fps); | ||
| 1156 | } | ||
| 1157 | myAvatar->endCapture(); | ||
| 1158 | } | 1160 | } |
| 1159 | 1161 | ||
| 1160 | // Primary rendering pass | 1162 | // Primary rendering pass |
| @@ -3386,9 +3388,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 2225 unmodified lines | |||
| 3386 | // FIXME: This preRender call is temporary until we create a separate render::scene for the mirror rendering. | 3388 | // FIXME: This preRender call is temporary until we create a separate render::scene for the mirror rendering. |
| 3387 | // Then we can move this logic into the Avatar::simulate call. | 3389 | // Then we can move this logic into the Avatar::simulate call. |
| 3388 | auto myAvatar = getMyAvatar(); | 3390 | auto myAvatar = getMyAvatar(); |
| 3389 | myAvatar->startRender(); | 3391 | myAvatar->withReadLock([&] { |
| 3390 | myAvatar->preRender(renderArgs); | 3392 | myAvatar->preRender(renderArgs); |
| 3391 | myAvatar->endRender(); | 3393 | }); |
| 3392 | 3394 | ||
| 3393 | 3395 | ||
| 3394 | activeRenderingThread = QThread::currentThread(); | 3396 | activeRenderingThread = QThread::currentThread(); |
| @@ -3502,9 +3504,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 107 unmodified lines | |||
| 3502 | _renderEngine->setRenderContext(renderContext); | 3504 | _renderEngine->setRenderContext(renderContext); |
| 3503 | 3505 | ||
| 3504 | // Before the deferred pass, let's try to use the render engine | 3506 | // Before the deferred pass, let's try to use the render engine |
| 3505 | myAvatar->startRenderRun(); | 3507 | myAvatar->withReadLock([&] { |
| 3506 | _renderEngine->run(); | 3508 | _renderEngine->run(); |
| 3507 | myAvatar->endRenderRun(); | 3509 | }); |
| 3508 | 3510 | ||
| 3509 | auto engineRC = _renderEngine->getRenderContext(); | 3511 | auto engineRC = _renderEngine->getRenderContext(); |
| 3510 | sceneInterface->setEngineFeedOpaqueItems(engineRC->_numFeedOpaqueItems); | 3512 | sceneInterface->setEngineFeedOpaqueItems(engineRC->_numFeedOpaqueItems); |