History

Merge remote-tracking branch 'upstream/master' into smarter_textures

Brad Davis committed 9 years ago

Commit e482eac2 parents 5a6478c 92e3f87123 files · +3184 −1521Browse files

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

Unified · Split

interface/src/Application.cpp+59−134
@@ -177,6 +177,8 @@ · 176 unmodified lines
177177 #include "FrameTimingsScriptingInterface.h"
178178 #include <GPUIdent.h>
179179 #include <gl/GLHelpers.h>
180+#include <EntityScriptClient.h>
181+#include <ModelScriptingInterface.h>
180182
181183 // On Windows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU
182184 // FIXME seems to be broken.
@@ -213,18 +215,10 @@ static const QString FBX_EXTENSION = ".fbx"; · 30 unmodified lines
213215 static const QString OBJ_EXTENSION = ".obj";
214216 static const QString AVA_JSON_EXTENSION = ".ava.json";
215217
216−static const int MIRROR_VIEW_TOP_PADDING = 5;
217−static const int MIRROR_VIEW_LEFT_PADDING = 10;
218−static const int MIRROR_VIEW_WIDTH = 265;
219−static const int MIRROR_VIEW_HEIGHT = 215;
220218 static const float MIRROR_FULLSCREEN_DISTANCE = 0.389f;
221−static const float MIRROR_REARVIEW_DISTANCE = 0.722f;
222−static const float MIRROR_REARVIEW_BODY_DISTANCE = 2.56f;
223−static const float MIRROR_FIELD_OF_VIEW = 30.0f;
224219
225220 static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS_PER_SECOND;
226221
227−static const QString INFO_WELCOME_PATH = "html/interface-welcome.html";
228222 static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html";
229223 static const QString INFO_HELP_PATH = "html/help.html";
230224
@@ -423,6 +417,7 @@ static const QString STATE_CAMERA_THIRD_PERSON = "CameraThirdPerson"; · 192 unmodified lines
423417 static const QString STATE_CAMERA_ENTITY = "CameraEntity";
424418 static const QString STATE_CAMERA_INDEPENDENT = "CameraIndependent";
425419 static const QString STATE_SNAP_TURN = "SnapTurn";
420+static const QString STATE_ADVANCED_MOVEMENT_CONTROLS = "AdvancedMovement";
426421 static const QString STATE_GROUNDED = "Grounded";
427422 static const QString STATE_NAV_FOCUSED = "NavigationFocused";
428423
@@ -513,7 +508,7 @@ bool setupEssentials(int& argc, char** argv) { · 84 unmodified lines
513508 DependencyManager::set<MessagesClient>();
514509 controller::StateController::setStateVariables({ { STATE_IN_HMD, STATE_CAMERA_FULL_SCREEN_MIRROR,
515510 STATE_CAMERA_FIRST_PERSON, STATE_CAMERA_THIRD_PERSON, STATE_CAMERA_ENTITY, STATE_CAMERA_INDEPENDENT,
516− STATE_SNAP_TURN, STATE_GROUNDED, STATE_NAV_FOCUSED } });
511+ STATE_SNAP_TURN, STATE_ADVANCED_MOVEMENT_CONTROLS, STATE_GROUNDED, STATE_NAV_FOCUSED } });
517512 DependencyManager::set<UserInputMapper>();
518513 DependencyManager::set<controller::ScriptingInterface, ControllerScriptingInterface>();
519514 DependencyManager::set<InterfaceParentFinder>();
@@ -565,7 +560,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 45 unmodified lines
565560 _entityClipboardRenderer(false, this, this),
566561 _entityClipboard(new EntityTree()),
567562 _lastQueriedTime(usecTimestampNow()),
568− _mirrorViewRect(QRect(MIRROR_VIEW_LEFT_PADDING, MIRROR_VIEW_TOP_PADDING, MIRROR_VIEW_WIDTH, MIRROR_VIEW_HEIGHT)),
569563 _previousScriptLocation("LastScriptLocation", DESKTOP_LOCATION),
570564 _fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES),
571565 _hmdTabletScale("hmdTabletScale", DEFAULT_HMD_TABLET_SCALE_PERCENT),
@@ -1129,6 +1123,10 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 557 unmodified lines
11291123 _applicationStateDevice->setInputVariant(STATE_SNAP_TURN, []() -> float {
11301124 return qApp->getMyAvatar()->getSnapTurn() ? 1 : 0;
11311125 });
1126+ _applicationStateDevice->setInputVariant(STATE_ADVANCED_MOVEMENT_CONTROLS, []() -> float {
1127+ return qApp->getMyAvatar()->useAdvancedMovementControls() ? 1 : 0;
1128+ });
1129+
11321130 _applicationStateDevice->setInputVariant(STATE_GROUNDED, []() -> float {
11331131 return qApp->getMyAvatar()->getCharacterController()->onGround() ? 1 : 0;
11341132 });
@@ -2119,21 +2117,6 @@ void Application::paintGL() { · 984 unmodified lines
21192117 batch.resetStages();
21202118 });
21212119
2122− auto inputs = AvatarInputs::getInstance();
2123− if (inputs->mirrorVisible()) {
2124− PerformanceTimer perfTimer("Mirror");
2125−
2126− renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
2127− renderArgs._blitFramebuffer = DependencyManager::get<FramebufferCache>()->getSelfieFramebuffer();
2128−
2129− _mirrorViewRect.moveTo(inputs->x(), inputs->y());
2130−
2131− renderRearViewMirror(&renderArgs, _mirrorViewRect, inputs->mirrorZoomed());
2132−
2133− renderArgs._blitFramebuffer.reset();
2134− renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
2135− }
2136−
21372120 {
21382121 PerformanceTimer perfTimer("renderOverlay");
21392122 // NOTE: There is no batch associated with this renderArgs
@@ -2381,10 +2364,6 @@ void Application::setSettingConstrainToolbarPosition(bool setting) { · 241 unmodified lines
23812364 DependencyManager::get<OffscreenUi>()->setConstrainToolbarToCenterX(setting);
23822365 }
23832366
2384−void Application::aboutApp() {
2385− InfoView::show(INFO_WELCOME_PATH);
2386−}
2387−
23882367 void Application::showHelp() {
23892368 static const QString HAND_CONTROLLER_NAME_VIVE = "vive";
23902369 static const QString HAND_CONTROLLER_NAME_OCULUS_TOUCH = "oculus";
@@ -2886,51 +2865,49 @@ void Application::keyPressEvent(QKeyEvent* event) { · 495 unmodified lines
28862865 break;
28872866 #endif
28882867
2889− case Qt::Key_H:
2890− if (isShifted) {
2891− Menu::getInstance()->triggerOption(MenuOption::MiniMirror);
2892− } else {
2893− // whenever switching to/from full screen mirror from the keyboard, remember
2894− // the state you were in before full screen mirror, and return to that.
2895− auto previousMode = _myCamera.getMode();
2896− if (previousMode != CAMERA_MODE_MIRROR) {
2897− switch (previousMode) {
2898− case CAMERA_MODE_FIRST_PERSON:
2899− _returnFromFullScreenMirrorTo = MenuOption::FirstPerson;
2900− break;
2901− case CAMERA_MODE_THIRD_PERSON:
2902− _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
2903− break;
2904−
2905− // FIXME - it's not clear that these modes make sense to return to...
2906− case CAMERA_MODE_INDEPENDENT:
2907− _returnFromFullScreenMirrorTo = MenuOption::IndependentMode;
2908− break;
2909− case CAMERA_MODE_ENTITY:
2910− _returnFromFullScreenMirrorTo = MenuOption::CameraEntityMode;
2911− break;
2912−
2913− default:
2914− _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
2915− break;
2916− }
2868+ case Qt::Key_H: {
2869+ // whenever switching to/from full screen mirror from the keyboard, remember
2870+ // the state you were in before full screen mirror, and return to that.
2871+ auto previousMode = _myCamera.getMode();
2872+ if (previousMode != CAMERA_MODE_MIRROR) {
2873+ switch (previousMode) {
2874+ case CAMERA_MODE_FIRST_PERSON:
2875+ _returnFromFullScreenMirrorTo = MenuOption::FirstPerson;
2876+ break;
2877+ case CAMERA_MODE_THIRD_PERSON:
2878+ _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
2879+ break;
2880+
2881+ // FIXME - it's not clear that these modes make sense to return to...
2882+ case CAMERA_MODE_INDEPENDENT:
2883+ _returnFromFullScreenMirrorTo = MenuOption::IndependentMode;
2884+ break;
2885+ case CAMERA_MODE_ENTITY:
2886+ _returnFromFullScreenMirrorTo = MenuOption::CameraEntityMode;
2887+ break;
2888+
2889+ default:
2890+ _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
2891+ break;
29172892 }
2893+ }
29182894
2919− bool isMirrorChecked = Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror);
2920− Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, !isMirrorChecked);
2921− if (isMirrorChecked) {
2895+ bool isMirrorChecked = Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror);
2896+ Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, !isMirrorChecked);
2897+ if (isMirrorChecked) {
29222898
2923− // if we got here without coming in from a non-Full Screen mirror case, then our
2924− // _returnFromFullScreenMirrorTo is unknown. In that case we'll go to the old
2925− // behavior of returning to ThirdPerson
2926− if (_returnFromFullScreenMirrorTo.isEmpty()) {
2927− _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
2928− }
2929− Menu::getInstance()->setIsOptionChecked(_returnFromFullScreenMirrorTo, true);
2899+ // if we got here without coming in from a non-Full Screen mirror case, then our
2900+ // _returnFromFullScreenMirrorTo is unknown. In that case we'll go to the old
2901+ // behavior of returning to ThirdPerson
2902+ if (_returnFromFullScreenMirrorTo.isEmpty()) {
2903+ _returnFromFullScreenMirrorTo = MenuOption::ThirdPerson;
29302904 }
2931− cameraMenuChanged();
2905+ Menu::getInstance()->setIsOptionChecked(_returnFromFullScreenMirrorTo, true);
29322906 }
2907+ cameraMenuChanged();
29332908 break;
2909+ }
2910+
29342911 case Qt::Key_P: {
29352912 if (!(isShifted || isMeta || isOption)) {
29362913 bool isFirstPersonChecked = Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson);
@@ -3845,8 +3822,6 @@ void Application::init() { · 908 unmodified lines
38453822 DependencyManager::get<AvatarManager>()->init();
38463823 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
38473824
3848− _mirrorCamera.setMode(CAMERA_MODE_MIRROR);
3849−
38503825 _timerStart.start();
38513826 _lastTimeUpdated.start();
38523827
@@ -4383,16 +4358,16 @@ void Application::update(float deltaTime) { · 530 unmodified lines
43834358 myAvatar->clearDriveKeys();
43844359 if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
43854360 if (!_controllerScriptingInterface->areActionsCaptured()) {
4386− myAvatar->setDriveKeys(TRANSLATE_Z, -1.0f * userInputMapper->getActionState(controller::Action::TRANSLATE_Z));
4387− myAvatar->setDriveKeys(TRANSLATE_Y, userInputMapper->getActionState(controller::Action::TRANSLATE_Y));
4388− myAvatar->setDriveKeys(TRANSLATE_X, userInputMapper->getActionState(controller::Action::TRANSLATE_X));
4361+ myAvatar->setDriveKey(MyAvatar::TRANSLATE_Z, -1.0f * userInputMapper->getActionState(controller::Action::TRANSLATE_Z));
4362+ myAvatar->setDriveKey(MyAvatar::TRANSLATE_Y, userInputMapper->getActionState(controller::Action::TRANSLATE_Y));
4363+ myAvatar->setDriveKey(MyAvatar::TRANSLATE_X, userInputMapper->getActionState(controller::Action::TRANSLATE_X));
43894364 if (deltaTime > FLT_EPSILON) {
4390− myAvatar->setDriveKeys(PITCH, -1.0f * userInputMapper->getActionState(controller::Action::PITCH));
4391− myAvatar->setDriveKeys(YAW, -1.0f * userInputMapper->getActionState(controller::Action::YAW));
4392− myAvatar->setDriveKeys(STEP_YAW, -1.0f * userInputMapper->getActionState(controller::Action::STEP_YAW));
4365+ myAvatar->setDriveKey(MyAvatar::PITCH, -1.0f * userInputMapper->getActionState(controller::Action::PITCH));
4366+ myAvatar->setDriveKey(MyAvatar::YAW, -1.0f * userInputMapper->getActionState(controller::Action::YAW));
4367+ myAvatar->setDriveKey(MyAvatar::STEP_YAW, -1.0f * userInputMapper->getActionState(controller::Action::STEP_YAW));
43934368 }
43944369 }
4395− myAvatar->setDriveKeys(ZOOM, userInputMapper->getActionState(controller::Action::TRANSLATE_CAMERA_Z));
4370+ myAvatar->setDriveKey(MyAvatar::ZOOM, userInputMapper->getActionState(controller::Action::TRANSLATE_CAMERA_Z));
43964371 }
43974372
43984373 controller::Pose leftHandPose = userInputMapper->getPoseState(controller::Action::LEFT_HAND);
@@ -4463,9 +4438,12 @@ void Application::update(float deltaTime) { · 64 unmodified lines
44634438
44644439 getEntities()->getTree()->withWriteLock([&] {
44654440 PerformanceTimer perfTimer("handleOutgoingChanges");
4466− const VectorOfMotionStates& outgoingChanges = _physicsEngine->getOutgoingChanges();
4467− _entitySimulation->handleOutgoingChanges(outgoingChanges);
4468− avatarManager->handleOutgoingChanges(outgoingChanges);
4441+ const VectorOfMotionStates& deactivations = _physicsEngine->getDeactivatedMotionStates();
4442+ _entitySimulation->handleDeactivatedMotionStates(deactivations);
4443+
4444+ const VectorOfMotionStates& outgoingChanges = _physicsEngine->getChangedMotionStates();
4445+ _entitySimulation->handleChangedMotionStates(outgoingChanges);
4446+ avatarManager->handleChangedMotionStates(outgoingChanges);
44694447 });
44704448
44714449 if (!_aboutToQuit) {
@@ -5122,58 +5100,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 650 unmodified lines
51225100 activeRenderingThread = nullptr;
51235101 }
51245102
5125−void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool isZoomed) {
5126− auto originalViewport = renderArgs->_viewport;
5127− // Grab current viewport to reset it at the end
5128−
5129− float aspect = (float)region.width() / region.height();
5130− float fov = MIRROR_FIELD_OF_VIEW;
5131−
5132− auto myAvatar = getMyAvatar();
5133−
5134− // bool eyeRelativeCamera = false;
5135− if (!isZoomed) {
5136− _mirrorCamera.setPosition(myAvatar->getChestPosition() +
5137− myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * myAvatar->getScale());
5138−
5139− } else { // HEAD zoom level
5140− // FIXME note that the positioning of the camera relative to the avatar can suffer limited
5141− // precision as the user's position moves further away from the origin. Thus at
5142− // /1e7,1e7,1e7 (well outside the buildable volume) the mirror camera veers and sways
5143− // wildly as you rotate your avatar because the floating point values are becoming
5144− // larger, squeezing out the available digits of precision you have available at the
5145− // human scale for camera positioning.
5146−
5147− // Previously there was a hack to correct this using the mechanism of repositioning
5148− // the avatar at the origin of the world for the purposes of rendering the mirror,
5149− // but it resulted in failing to render the avatar's head model in the mirror view
5150− // when in first person mode. Presumably this was because of some missed culling logic
5151− // that was not accounted for in the hack.
5152−
5153− // This was removed in commit 71e59cfa88c6563749594e25494102fe01db38e9 but could be further
5154− // investigated in order to adapt the technique while fixing the head rendering issue,
5155− // but the complexity of the hack suggests that a better approach
5156− _mirrorCamera.setPosition(myAvatar->getDefaultEyePosition() +
5157− myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_DISTANCE * myAvatar->getScale());
5158− }
5159− _mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
5160− _mirrorCamera.setOrientation(myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
5161−
5162−
5163− // set the bounds of rear mirror view
5164− // the region is in device independent coordinates; must convert to device
5165− float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
5166− int width = region.width() * ratio;
5167− int height = region.height() * ratio;
5168− gpu::Vec4i viewport = gpu::Vec4i(0, 0, width, height);
5169− renderArgs->_viewport = viewport;
5170−
5171− // render rear mirror view
5172− displaySide(renderArgs, _mirrorCamera, true);
5173−
5174− renderArgs->_viewport = originalViewport;
5175−}
5176−
51775103 void Application::resetSensors(bool andReload) {
51785104 DependencyManager::get<Faceshift>()->reset();
51795105 DependencyManager::get<DdeFaceTracker>()->reset();
@@ -5503,8 +5429,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 323 unmodified lines
55035429 scriptEngine->registerGlobalObject("Rates", new RatesScriptingInterface(this));
55045430
55055431 // hook our avatar and avatar hash map object into this script engine
5506− scriptEngine->registerGlobalObject("MyAvatar", getMyAvatar().get());
5507− qScriptRegisterMetaType(scriptEngine, audioListenModeToScriptValue, audioListenModeFromScriptValue);
5432+ getMyAvatar()->registerMetaTypes(scriptEngine);
55085433
55095434 scriptEngine->registerGlobalObject("AvatarList", DependencyManager::get<AvatarManager>().data());
55105435