History

Merge branch 'master' of github.com:highfidelity/hifi into tablet-ui

Seth Alves committed 9 years ago

Commit cc4ddd12 parents b0b3fe2 b2abe5a78 files · +664 −3888Browse files

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

Unified · Split

interface/src/Application.cpp+49−127
@@ -217,18 +217,10 @@ static const QString FBX_EXTENSION = ".fbx"; · 216 unmodified lines
217static const QString OBJ_EXTENSION = ".obj";217static const QString OBJ_EXTENSION = ".obj";
218static const QString AVA_JSON_EXTENSION = ".ava.json";218static const QString AVA_JSON_EXTENSION = ".ava.json";
219 219
220static const int MIRROR_VIEW_TOP_PADDING = 5;
221static const int MIRROR_VIEW_LEFT_PADDING = 10;
222static const int MIRROR_VIEW_WIDTH = 265;
223static const int MIRROR_VIEW_HEIGHT = 215;
224static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f;220static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f;
225static const float MIRROR_REARVIEW_DISTANCE = 0.722f;
226static const float MIRROR_REARVIEW_BODY_DISTANCE = 2.56f;
227static const float MIRROR_FIELD_OF_VIEW = 30.0f;
228 221
229static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS_PER_SECOND;222static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS_PER_SECOND;
230 223
231static const QString INFO_WELCOME_PATH = "html/interface-welcome.html";
232static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html";224static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html";
233static const QString INFO_HELP_PATH = "html/help.html";225static const QString INFO_HELP_PATH = "html/help.html";
234 226
@@ -427,6 +419,7 @@ static const QString STATE_CAMERA_THIRD_PERSON = "CameraThirdPerson"; · 192 unmodified lines
427static const QString STATE_CAMERA_ENTITY = "CameraEntity";419static const QString STATE_CAMERA_ENTITY = "CameraEntity";
428static const QString STATE_CAMERA_INDEPENDENT = "CameraIndependent";420static const QString STATE_CAMERA_INDEPENDENT = "CameraIndependent";
429static const QString STATE_SNAP_TURN = "SnapTurn";421static const QString STATE_SNAP_TURN = "SnapTurn";
422static const QString STATE_ADVANCED_MOVEMENT_CONTROLS = "AdvancedMovement";
430static const QString STATE_GROUNDED = "Grounded";423static const QString STATE_GROUNDED = "Grounded";
431static const QString STATE_NAV_FOCUSED = "NavigationFocused";424static const QString STATE_NAV_FOCUSED = "NavigationFocused";
432 425
@@ -519,7 +512,7 @@ bool setupEssentials(int& argc, char** argv) { · 86 unmodified lines
519 DependencyManager::set<MessagesClient>();512 DependencyManager::set<MessagesClient>();
520 controller::StateController::setStateVariables({ { STATE_IN_HMD, STATE_CAMERA_FULL_SCREEN_MIRROR,513 controller::StateController::setStateVariables({ { STATE_IN_HMD, STATE_CAMERA_FULL_SCREEN_MIRROR,
521 STATE_CAMERA_FIRST_PERSON, STATE_CAMERA_THIRD_PERSON, STATE_CAMERA_ENTITY, STATE_CAMERA_INDEPENDENT,514 STATE_CAMERA_FIRST_PERSON, STATE_CAMERA_THIRD_PERSON, STATE_CAMERA_ENTITY, STATE_CAMERA_INDEPENDENT,
522 STATE_SNAP_TURN, STATE_GROUNDED, STATE_NAV_FOCUSED } });515 STATE_SNAP_TURN, STATE_ADVANCED_MOVEMENT_CONTROLS, STATE_GROUNDED, STATE_NAV_FOCUSED } });
523 DependencyManager::set<UserInputMapper>();516 DependencyManager::set<UserInputMapper>();
524 DependencyManager::set<controller::ScriptingInterface, ControllerScriptingInterface>();517 DependencyManager::set<controller::ScriptingInterface, ControllerScriptingInterface>();
525 DependencyManager::set<InterfaceParentFinder>();518 DependencyManager::set<InterfaceParentFinder>();
@@ -572,7 +565,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 46 unmodified lines
572 _entityClipboardRenderer(false, this, this),565 _entityClipboardRenderer(false, this, this),
573 _entityClipboard(new EntityTree()),566 _entityClipboard(new EntityTree()),
574 _lastQueriedTime(usecTimestampNow()),567 _lastQueriedTime(usecTimestampNow()),
575 _mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)),
576 _previousScriptLocation("LastScriptLocation", DESKTOP_LOCATION),568 _previousScriptLocation("LastScriptLocation", DESKTOP_LOCATION),
577 _fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES),569 _fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES),
578 _hmdTabletScale("hmdTabletScale", DEFAULT_HMD_TABLET_SCALE_PERCENT),570 _hmdTabletScale("hmdTabletScale", DEFAULT_HMD_TABLET_SCALE_PERCENT),
@@ -1139,6 +1131,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 560 unmodified lines
1139 _applicationStateDevice->setInputVariant(STATE_SNAP_TURN, []() -> float {1131 _applicationStateDevice->setInputVariant(STATE_SNAP_TURN, []() -> float {
1140 return qApp->getMyAvatar()->getSnapTurn() ? 1 : 0;1132 return qApp->getMyAvatar()->getSnapTurn() ? 1 : 0;
1141 });1133 });
1134 _applicationStateDevice->setInputVariant(STATE_ADVANCED_MOVEMENT_CONTROLS, []() -> float {
1135 return qApp->getMyAvatar()->useAdvancedMovementControls() ? 1 : 0;
1136 });
1137
1142 _applicationStateDevice->setInputVariant(STATE_GROUNDED, []() -> float {1138 _applicationStateDevice->setInputVariant(STATE_GROUNDED, []() -> float {
1143 return qApp->getMyAvatar()->getCharacterController()->onGround() ? 1 : 0;1139 return qApp->getMyAvatar()->getCharacterController()->onGround() ? 1 : 0;
1144 });1140 });
@@ -2129,21 +2125,6 @@ void Application::paintGL() { · 984 unmodified lines
2129 batch.resetStages();2125 batch.resetStages();
2130 });2126 });
2131 2127
2132 auto inputs = AvatarInputs::getInstance();
2133 if (inputs->mirrorVisible()) {
2134 PerformanceTimer perfTimer("Mirror");
2135
2136 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
2137 renderArgs._blitFramebuffer = DependencyManager::get<FramebufferCache>()->getSelfieFramebuffer();
2138
2139 _mirrorViewRect.moveTo(inputs->x(), inputs->y());
2140
2141 renderRearViewMirror(&renderArgs, _mirrorViewRect, inputs->mirrorZoomed());
2142
2143 renderArgs._blitFramebuffer.reset();
2144 renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
2145 }
2146
2147 {2128 {
2148 PerformanceTimer perfTimer("renderOverlay");2129 PerformanceTimer perfTimer("renderOverlay");
2149 // NOTE: There is no batch associated with this renderArgs2130 // NOTE: There is no batch associated with this renderArgs
@@ -2391,10 +2372,6 @@ void Application::setSettingConstrainToolbarPosition(bool setting) { · 241 unmodified lines
2391 DependencyManager::get<OffscreenUi>()->setConstrainToolbarToCenterX(setting);2372 DependencyManager::get<OffscreenUi>()->setConstrainToolbarToCenterX(setting);
2392}2373}
2393 2374
2394void Application::aboutApp() {
2395 InfoView::show(INFO_WELCOME_PATH);
2396}
2397
2398void Application::showHelp() {2375void Application::showHelp() {
2399 static const QString HAND_CONTROLLER_NAME_VIVE = "vive";2376 static const QString HAND_CONTROLLER_NAME_VIVE = "vive";
2400 static const QString HAND_CONTROLLER_NAME_OCULUS_TOUCH = "oculus";2377 static const QString HAND_CONTROLLER_NAME_OCULUS_TOUCH = "oculus";
@@ -2776,8 +2753,6 @@ void Application::keyPressEvent(QKeyEvent* event) { · 375 unmodified lines
2776 case Qt::Key_S:2753 case Qt::Key_S:
2777 if (isShifted && isMeta && !isOption) {2754 if (isShifted && isMeta && !isOption) {
2778 Menu::getInstance()->triggerOption(MenuOption::SuppressShortTimings);2755 Menu::getInstance()->triggerOption(MenuOption::SuppressShortTimings);
2779 } else if (isOption && !isShifted && !isMeta) {
2780 Menu::getInstance()->triggerOption(MenuOption::ScriptEditor);
2781 } else if (!isOption && !isShifted && isMeta) {2756 } else if (!isOption && !isShifted && isMeta) {
2782 takeSnapshot(true);2757 takeSnapshot(true);
2783 }2758 }
@@ -2896,51 +2871,49 @@ void Application::keyPressEvent(QKeyEvent* event) { · 112 unmodified lines
2896 break;2871 break;
2897#endif2872#endif
2898 2873
2899 case Qt::Key_H:2874 case Qt::Key_H: {
2900 if (isShifted) {2875 // whenever switching to/from full screen mirror from the keyboard, remember
2901 Menu::getInstance()->triggerOption(MenuOption::MiniMirror);2876 // the state you were in before full screen mirror, and return to that.
2902 } else {2877 auto previousMode = _myCamera.getMode();
2903 // whenever switching to/from full screen mirror from the keyboard, remember2878 if (previousMode != CAMERA_MODE_MIRROR) {
2904 // the state you were in before full screen mirror, and return to that.2879 switch (previousMode) {
2905 auto previousMode = _myCamera.getMode();2880 case CAMERA_MODE_FIRST_PERSON:
2906 if (previousMode != CAMERA_MODE_MIRROR) {2881 _returnFromFullScreenMirrorTo = MenuOption::FirstPerson;
2907 switch (previousMode) {2882 break;
2908 case CAMERA_MODE_FIRST_PERSON:2883 case CAMERA_MODE_THIRD_PERSON:
2909 _returnFromFullScreenMirrorTo = MenuOption::FirstPerson;2884 _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
2910 break;2885 break;
2911 case CAMERA_MODE_THIRD_PERSON:2886
2912 _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;2887 // FIXME - it's not clear that these modes make sense to return to...
2913 break;2888 case CAMERA_MODE_INDEPENDENT:
2914 2889 _returnFromFullScreenMirrorTo = MenuOption::IndependentMode;
2915 // FIXME - it's not clear that these modes make sense to return to...2890 break;
2916 case CAMERA_MODE_INDEPENDENT:2891 case CAMERA_MODE_ENTITY:
2917 _returnFromFullScreenMirrorTo = MenuOption::IndependentMode;2892 _returnFromFullScreenMirrorTo = MenuOption::CameraEntityMode;
2918 break;2893 break;
2919 case CAMERA_MODE_ENTITY:2894
2920 _returnFromFullScreenMirrorTo = MenuOption::CameraEntityMode;2895 default:
2921 break;2896 _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
2922 2897 break;
2923 default:
2924 _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
2925 break;
2926 }
2927 }2898 }
2899 }
2928 2900
2929 bool isMirrorChecked = Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror);2901 bool isMirrorChecked = Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror);
2930 Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, !isMirrorChecked);2902 Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, !isMirrorChecked);
2931 if (isMirrorChecked) {2903 if (isMirrorChecked) {
2932 2904
2933 // if we got here without coming in from a non-Full Screen mirror case, then our2905 // if we got here without coming in from a non-Full Screen mirror case, then our
2934 // _returnFromFullScreenMirrorTo is unknown. In that case we'll go to the old2906 // _returnFromFullScreenMirrorTo is unknown. In that case we'll go to the old
2935 // behavior of returning to ThirdPerson2907 // behavior of returning to ThirdPerson
2936 if (_returnFromFullScreenMirrorTo.isEmpty()) {2908 if (_returnFromFullScreenMirrorTo.isEmpty()) {
2937 _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;2909 _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
2938 }
2939 Menu::getInstance()->setIsOptionChecked(_returnFromFullScreenMirrorTo, true);
2940 }2910 }
2941 cameraMenuChanged();2911 Menu::getInstance()->setIsOptionChecked(_returnFromFullScreenMirrorTo, true);
2942 }2912 }
2913 cameraMenuChanged();
2943 break;2914 break;
2915 }
2916
2944 case Qt::Key_P: {2917 case Qt::Key_P: {
2945 if (!(isShifted || isMeta || isOption)) {2918 if (!(isShifted || isMeta || isOption)) {
2946 bool isFirstPersonChecked = Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson);2919 bool isFirstPersonChecked = Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson);
@@ -3855,8 +3828,6 @@ void Application::init() { · 908 unmodified lines
3855 DependencyManager::get<AvatarManager>()->init();3828 DependencyManager::get<AvatarManager>()->init();
3856 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);3829 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
3857 3830
3858 _mirrorCamera.setMode(CAMERA_MODE_MIRROR);
3859
3860 _timerStart.start();3831 _timerStart.start();
3861 _lastTimeUpdated.start();3832 _lastTimeUpdated.start();
3862 3833
@@ -4473,9 +4444,12 @@ void Application::update(float deltaTime) { · 610 unmodified lines
4473 4444
4474 getEntities()->getTree()->withWriteLock([&] {4445 getEntities()->getTree()->withWriteLock([&] {
4475 PerformanceTimer perfTimer("handleOutgoingChanges");4446 PerformanceTimer perfTimer("handleOutgoingChanges");
4476 const VectorOfMotionStates& outgoingChanges = _physicsEngine->getOutgoingChanges();4447 const VectorOfMotionStates& deactivations = _physicsEngine->getDeactivatedMotionStates();
4477 _entitySimulation->handleOutgoingChanges(outgoingChanges);4448 _entitySimulation->handleDeactivatedMotionStates(deactivations);
4478 avatarManager->handleOutgoingChanges(outgoingChanges);4449
4450 const VectorOfMotionStates& outgoingChanges = _physicsEngine->getChangedMotionStates();
4451 _entitySimulation->handleChangedMotionStates(outgoingChanges);
4452 avatarManager->handleChangedMotionStates(outgoingChanges);
4479 });4453 });
4480 4454
4481 if (!_aboutToQuit) {4455 if (!_aboutToQuit) {
@@ -5132,58 +5106,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 650 unmodified lines
5132 activeRenderingThread = nullptr;5106 activeRenderingThread = nullptr;
5133}5107}
5134 5108
5135void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool isZoomed) {
5136 auto originalViewport = renderArgs->_viewport;
5137 // Grab current viewport to reset it at the end
5138
5139 float aspect = (float)region.width() / region.height();
5140 float fov = MIRROR_FIELD_OF_VIEW;
5141
5142 auto myAvatar = getMyAvatar();
5143
5144 // bool eyeRelativeCamera = false;
5145 if (!isZoomed) {
5146 _mirrorCamera.setPosition(myAvatar->getChestPosition() +
5147 myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * myAvatar->getScale());
5148
5149 } else { // HEAD zoom level
5150 // FIXME note that the positioning of the camera relative to the avatar can suffer limited
5151 // precision as the user's position moves further away from the origin. Thus at
5152 // /1e7,1e7,1e7 (well outside the buildable volume) the mirror camera veers and sways
5153 // wildly as you rotate your avatar because the floating point values are becoming
5154 // larger, squeezing out the available digits of precision you have available at the
5155 // human scale for camera positioning.
5156
5157 // Previously there was a hack to correct this using the mechanism of repositioning
5158 // the avatar at the origin of the world for the purposes of rendering the mirror,
5159 // but it resulted in failing to render the avatar's head model in the mirror view
5160 // when in first person mode. Presumably this was because of some missed culling logic
5161 // that was not accounted for in the hack.
5162
5163 // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
5164 // investigated in order to adapt the technique while fixing the head rendering issue,
5165 // but the complexity of the hack suggests that a better approach
5166 _mirrorCamera.setPosition(myAvatar->getDefaultEyePosition() +
5167 myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * myAvatar->getScale());
5168 }
5169 _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
5170 _mirrorCamera.setOrientation(myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
5171
5172
5173 // set the bounds of rear mirror view
5174 // the region is in device independent coordinates; must convert to device
5175 float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
5176 int width = region.width() * ratio;
5177 int height = region.height() * ratio;
5178 gpu::Vec4i viewport = gpu::Vec4i(0, 0, width, height);
5179 renderArgs->_viewport = viewport;
5180
5181 // render rear mirror view
5182 displaySide(renderArgs, _mirrorCamera, true);
5183
5184 renderArgs->_viewport = originalViewport;
5185}
5186
5187void Application::resetSensors(bool andReload) {5109void Application::resetSensors(bool andReload) {
5188 DependencyManager::get<Faceshift>()->reset();5110 DependencyManager::get<Faceshift>()->reset();
5189 DependencyManager::get<DdeFaceTracker>()->reset();5111 DependencyManager::get<DdeFaceTracker>()->reset();