History

merged master

ericrius1 committed 11 years ago

Commit cf720f92 parents 10cefe0 62b3ca9275 files · +8836 −7501Browse files

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

Unified · Split

interface/src/Application.cpp+209−172
@@ -66,6 +66,9 @@ · 65 unmodified lines
6666 #include <EntityScriptingInterface.h>
6767 #include <ErrorDialog.h>
6868 #include <GlowEffect.h>
69+#include <gpu/Batch.h>
70+#include <gpu/Context.h>
71+#include <gpu/GLBackend.h>
6972 #include <HFActionEvent.h>
7073 #include <HFBackEvent.h>
7174 #include <InfoView.h>
@@ -83,12 +86,14 @@ · 11 unmodified lines
8386 #include <PerfStat.h>
8487 #include <PhysicsEngine.h>
8588 #include <ProgramObject.h>
89+#include <RenderDeferredTask.h>
8690 #include <ResourceCache.h>
8791 #include <SceneScriptingInterface.h>
8892 #include <ScriptCache.h>
8993 #include <SettingHandle.h>
9094 #include <SoundCache.h>
9195 #include <TextRenderer.h>
96+#include <Tooltip.h>
9297 #include <UserActivityLogger.h>
9398 #include <UUID.h>
9499 #include <VrMenu.h>
@@ -106,11 +111,9 @@ · 11 unmodified lines
106111
107112 #include "avatar/AvatarManager.h"
108113
109−#include "audio/AudioToolBox.h"
110114 #include "audio/AudioIOStatsRenderer.h"
111115 #include "audio/AudioScope.h"
112116
113−#include "devices/CameraToolBox.h"
114117 #include "devices/DdeFaceTracker.h"
115118 #include "devices/Faceshift.h"
116119 #include "devices/Leapmotion.h"
@@ -120,12 +123,6 @@ · 3 unmodified lines
120123 #include "devices/OculusManager.h"
121124 #include "devices/TV3DManager.h"
122125
123−#include "gpu/Batch.h"
124−#include "gpu/Context.h"
125−#include "gpu/GLBackend.h"
126−
127−#include "RenderDeferredTask.h"
128−
129126 #include "scripting/AccountScriptingInterface.h"
130127 #include "scripting/AudioDeviceScriptingInterface.h"
131128 #include "scripting/ClipboardScriptingInterface.h"
@@ -141,6 +138,7 @@ · 9 unmodified lines
141138 #include "SpeechRecognizer.h"
142139 #endif
143140
141+#include "ui/AvatarInputs.h"
144142 #include "ui/DataWebDialog.h"
145143 #include "ui/DialogsManager.h"
146144 #include "ui/LoginDialog.h"
@@ -281,8 +279,6 @@ bool setupEssentials(int& argc, char** argv) { · 134 unmodified lines
281279 auto animationCache = DependencyManager::set<AnimationCache>();
282280 auto ddeFaceTracker = DependencyManager::set<DdeFaceTracker>();
283281 auto modelBlender = DependencyManager::set<ModelBlender>();
284− auto audioToolBox = DependencyManager::set<AudioToolBox>();
285− auto cameraToolBox = DependencyManager::set<CameraToolBox>();
286282 auto avatarManager = DependencyManager::set<AvatarManager>();
287283 auto lodManager = DependencyManager::set<LODManager>();
288284 auto jsConsole = DependencyManager::set<StandAloneJSConsole>();
@@ -335,8 +331,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 46 unmodified lines
335331 _cursorVisible(true),
336332 _lastMouseMove(usecTimestampNow()),
337333 _lastMouseMoveWasSimulated(false),
338− _touchAvgX(0.0f),
339− _touchAvgY(0.0f),
340334 _isTouchPressed(false),
341335 _mousePressed(false),
342336 _enableProcessOctreeThread(true),
@@ -610,6 +604,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 267 unmodified lines
610604 _settingsTimer.setSingleShot(false);
611605 _settingsTimer.setInterval(SAVE_SETTINGS_INTERVAL);
612606 _settingsThread.start();
607+
608+ if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) {
609+ Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, true);
610+ cameraMenuChanged();
611+ }
613612
614613 _trayIcon->show();
615614
@@ -814,9 +813,9 @@ void Application::initializeGL() { · 198 unmodified lines
814813 _idleLoopStdev.reset();
815814
816815 if (_justStarted) {
817− float startupTime = (float)_applicationStartupTime.elapsed() / 1000.0;
816+ float startupTime = (float)_applicationStartupTime.elapsed() / 1000.0f;
818817 _justStarted = false;
819− qCDebug(interfaceapp, "Startup time: %4.2f seconds.", startupTime);
818+ qCDebug(interfaceapp, "Startup time: %4.2f seconds.", (double)startupTime);
820819 }
821820
822821 // update before the first render
@@ -831,6 +830,7 @@ void Application::initializeUi() { · 8 unmodified lines
831830 LoginDialog::registerType();
832831 MessageDialog::registerType();
833832 VrMenu::registerType();
833+ Tooltip::registerType();
834834 UpdateDialog::registerType();
835835
836836 auto offscreenUi = DependencyManager::get<OffscreenUi>();
@@ -844,7 +844,7 @@ void Application::initializeUi() { · 7 unmodified lines
844844 VrMenu::executeQueuedLambdas();
845845 offscreenUi->setMouseTranslator([this](const QPointF& p){
846846 if (OculusManager::isConnected()) {
847− glm::vec2 pos = _applicationOverlay.screenToOverlay(toGlm(p));
847+ glm::vec2 pos = _compositor.screenToOverlay(toGlm(p));
848848 return QPointF(pos.x, pos.y);
849849 }
850850 return QPointF(p);
@@ -877,6 +877,7 @@ void Application::paintGL() { · 26 unmodified lines
877877 OculusManager::beginFrameTiming();
878878 }
879879
880+
880881 PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings));
881882 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
882883 PerformanceWarning warn(showWarnings, "Application::paintGL()");
@@ -884,13 +885,22 @@ void Application::paintGL() { · 1 unmodified line
884885
885886 {
886887 PerformanceTimer perfTimer("renderOverlay");
888+ /*
889+ gpu::Context context(new gpu::GLBackend());
890+ RenderArgs renderArgs(&context, nullptr, getViewFrustum(), lodManager->getOctreeSizeScale(),
891+ lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE,
892+ RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE);
893+ */
887894 _applicationOverlay.renderOverlay(&renderArgs);
888895 }
889896
890897 glEnable(GL_LINE_SMOOTH);
891898
892− Menu::getInstance()->setIsOptionChecked("First Person", _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
893− Application::getInstance()->cameraMenuChanged();
899+ if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON || _myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
900+ Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, _myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN);
901+ Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !(_myAvatar->getBoomLength() <= MyAvatar::ZOOM_MIN));
902+ Application::getInstance()->cameraMenuChanged();
903+ }
894904
895905 if (_myCamera.getMode() == CAMERA_MODE_FIRST_PERSON) {
896906 // Always use the default eye position, not the actual head eye position.
@@ -909,13 +919,18 @@ void Application::paintGL() { · 12 unmodified lines
909919 }
910920
911921 } else if (_myCamera.getMode() == CAMERA_MODE_THIRD_PERSON) {
912− _myCamera.setPosition(_myAvatar->getDefaultEyePosition() +
913− _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, 1.0f) * _myAvatar->getBoomLength() * _myAvatar->getScale());
914922 if (OculusManager::isConnected()) {
915923 _myCamera.setRotation(_myAvatar->getWorldAlignedOrientation());
916924 } else {
917925 _myCamera.setRotation(_myAvatar->getHead()->getOrientation());
918926 }
927+ if (Menu::getInstance()->isOptionChecked(MenuOption::CenterPlayerInView)) {
928+ _myCamera.setPosition(_myAvatar->getDefaultEyePosition() +
929+ _myCamera.getRotation() * glm::vec3(0.0f, 0.0f, 1.0f) * _myAvatar->getBoomLength() * _myAvatar->getScale());
930+ } else {
931+ _myCamera.setPosition(_myAvatar->getDefaultEyePosition() +
932+ _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, 1.0f) * _myAvatar->getBoomLength() * _myAvatar->getScale());
933+ }
919934
920935 } else if (_myCamera.getMode() == CAMERA_MODE_MIRROR) {
921936 _myCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI + _rotateMirror, 0.0f)));
@@ -964,9 +979,7 @@ void Application::paintGL() { · 42 unmodified lines
964979 glPopMatrix();
965980
966981 renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
967− if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
968− _rearMirrorTools->render(&renderArgs, true, _glWidget->mapFromGlobal(QCursor::pos()));
969− } else if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
982+ if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
970983 renderRearViewMirror(&renderArgs, _mirrorViewRect);
971984 }
972985
@@ -974,16 +987,18 @@ void Application::paintGL() { · 1 unmodified line
974987
975988 auto finalFbo = DependencyManager::get<GlowEffect>()->render(&renderArgs);
976989
990+
977991 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
978992 glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo));
979993 glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y,
980994 0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(),
981− GL_COLOR_BUFFER_BIT, GL_NEAREST);
995+ GL_COLOR_BUFFER_BIT, GL_LINEAR);
982996 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
983997
984− _applicationOverlay.displayOverlayTexture();
998+ _compositor.displayOverlayTexture(&renderArgs);
985999 }
9861000
1001+
9871002 if (!OculusManager::isConnected() || OculusManager::allowSwap()) {
9881003 _glWidget->swapBuffers();
9891004 }
@@ -1041,27 +1056,24 @@ void Application::resizeGL() { · 51 unmodified lines
10411056 } else {
10421057 renderSize = _glWidget->getDeviceSize() * getRenderResolutionScale();
10431058 }
1044− if (_renderResolution == toGlm(renderSize)) {
1045− return;
1046− }
10471059
1048− _renderResolution = toGlm(renderSize);
1049− DependencyManager::get<TextureCache>()->setFrameBufferSize(renderSize);
1050− resetCamerasOnResizeGL(_myCamera, _renderResolution);
1060+ if (_renderResolution != toGlm(renderSize)) {
1061+ _renderResolution = toGlm(renderSize);
1062+ DependencyManager::get<TextureCache>()->setFrameBufferSize(renderSize);
1063+ resetCamerasOnResizeGL(_myCamera, _renderResolution);
10511064
1052− glViewport(0, 0, _renderResolution.x, _renderResolution.y); // shouldn't this account for the menu???
1065+ glViewport(0, 0, _renderResolution.x, _renderResolution.y); // shouldn't this account for the menu???
10531066
1054− updateProjectionMatrix();
1055− glLoadIdentity();
1067+ updateProjectionMatrix();
1068+ glLoadIdentity();
1069+ }
10561070
10571071 auto offscreenUi = DependencyManager::get<OffscreenUi>();
1058− offscreenUi->resize(_glWidget->size());
1072+
1073+ auto canvasSize = _glWidget->size();
1074+ offscreenUi->resize(canvasSize);
10591075 _glWidget->makeCurrent();
10601076
1061− // update Stats width
1062− // let's set horizontal offset to give stats some margin to mirror
1063− int horizontalOffset = MIRROR_VIEW_WIDTH + MIRROR_VIEW_LEFT_PADDING * 2;
1064− Stats::getInstance()->resetWidth(_renderResolution.x, horizontalOffset);
10651077 }
10661078
10671079 void Application::updateProjectionMatrix() {
@@ -1380,11 +1392,17 @@ void Application::keyPressEvent(QKeyEvent* event) { · 312 unmodified lines
13801392 if (isShifted) {
13811393 Menu::getInstance()->triggerOption(MenuOption::Mirror);
13821394 } else {
1383− Menu::getInstance()->triggerOption(MenuOption::FullscreenMirror);
1395+ Menu::getInstance()->setIsOptionChecked(MenuOption::FullscreenMirror, !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror));
1396+ if (!Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
1397+ Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, true);
1398+ }
1399+ cameraMenuChanged();
13841400 }
13851401 break;
13861402 case Qt::Key_P:
1387− Menu::getInstance()->triggerOption(MenuOption::FirstPerson);
1403+ Menu::getInstance()->setIsOptionChecked(MenuOption::FirstPerson, !Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson));
1404+ Menu::getInstance()->setIsOptionChecked(MenuOption::ThirdPerson, !Menu::getInstance()->isOptionChecked(MenuOption::FirstPerson));
1405+ cameraMenuChanged();
13881406 break;
13891407 case Qt::Key_Slash:
13901408 Menu::getInstance()->triggerOption(MenuOption::Stats);
@@ -1559,27 +1577,9 @@ void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { · 168 unmodified lines
15591577 _keyboardMouseDevice.mousePressEvent(event);
15601578
15611579 if (event->button() == Qt::LeftButton) {
1562− _mouseDragStartedX = getTrueMouseX();
1563− _mouseDragStartedY = getTrueMouseY();
1580+ _mouseDragStarted = getTrueMouse();
15641581 _mousePressed = true;
15651582
1566− if (mouseOnScreen()) {
1567− if (DependencyManager::get<AudioToolBox>()->mousePressEvent(getMouseX(), getMouseY())) {
1568− // stop propagation
1569− return;
1570− }
1571−
1572− if (DependencyManager::get<CameraToolBox>()->mousePressEvent(getMouseX(), getMouseY())) {
1573− // stop propagation
1574− return;
1575− }
1576−
1577− if (_rearMirrorTools->mousePressEvent(getMouseX(), getMouseY())) {
1578− // stop propagation
1579− return;
1580− }
1581− }
1582−
15831583 // nobody handled this - make it an action event on the _window object
15841584 HFActionEvent actionEvent(HFActionEvent::startType(),
15851585 computePickRay(event->x(), event->y()));
@@ -1597,16 +1597,7 @@ void Application::mouseDoublePressEvent(QMouseEvent* event, unsigned int deviceI · 11 unmodified lines
15971597 return;
15981598 }
15991599
1600− if (activeWindow() == _window) {
1601− if (event->button() == Qt::LeftButton) {
1602− if (mouseOnScreen()) {
1603− if (DependencyManager::get<CameraToolBox>()->mouseDoublePressEvent(getMouseX(), getMouseY())) {
1604− // stop propagation
1605− return;
1606− }
1607− }
1608− }
1609− }
1600+ _controllerScriptingInterface.emitMouseDoublePressEvent(event);
16101601 }
16111602
16121603 void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) {
@@ -1628,13 +1619,6 @@ void Application::mouseReleaseEvent(QMouseEvent* event, unsigned int deviceID) { · 15 unmodified lines
16281619 if (event->button() == Qt::LeftButton) {
16291620 _mousePressed = false;
16301621
1631− if (Menu::getInstance()->isOptionChecked(MenuOption::Stats) && mouseOnScreen()) {
1632− // let's set horizontal offset to give stats some margin to mirror
1633− int horizontalOffset = MIRROR_VIEW_WIDTH;
1634− Stats::getInstance()->checkClick(getMouseX(), getMouseY(),
1635− getMouseDragStartedX(), getMouseDragStartedY(), horizontalOffset);
1636− }
1637−
16381622 // fire an action end event
16391623 HFActionEvent actionEvent(HFActionEvent::endType(),
16401624 computePickRay(event->x(), event->y()));
@@ -1662,22 +1646,18 @@ void Application::touchUpdateEvent(QTouchEvent* event) { · 21 unmodified lines
16621646 bool validTouch = false;
16631647 if (activeWindow() == _window) {
16641648 const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints();
1665− _touchAvgX = 0.0f;
1666− _touchAvgY = 0.0f;
1649+ _touchAvg = vec2();
16671650 int numTouches = tPoints.count();
16681651 if (numTouches > 1) {
16691652 for (int i = 0; i < numTouches; ++i) {
1670− _touchAvgX += tPoints[i].pos().x();
1671− _touchAvgY += tPoints[i].pos().y();
1653+ _touchAvg += toGlm(tPoints[i].pos());
16721654 }
1673− _touchAvgX /= (float)(numTouches);
1674− _touchAvgY /= (float)(numTouches);
1655+ _touchAvg /= (float)(numTouches);
16751656 validTouch = true;
16761657 }
16771658 }
16781659 if (!_isTouchPressed) {
1679− _touchDragStartedAvgX = _touchAvgX;
1680− _touchDragStartedAvgY = _touchAvgY;
1660+ _touchDragStartedAvg = _touchAvg;
16811661 }
16821662 _isTouchPressed = validTouch;
16831663 }
@@ -1713,8 +1693,7 @@ void Application::touchEndEvent(QTouchEvent* event) { · 29 unmodified lines
17131693 _keyboardMouseDevice.touchEndEvent(event);
17141694
17151695 // put any application specific touch behavior below here..
1716− _touchDragStartedAvgX = _touchAvgX;
1717− _touchDragStartedAvgY = _touchAvgY;
1696+ _touchDragStartedAvg = _touchAvg;
17181697 _isTouchPressed = false;
17191698
17201699 }
@@ -1863,9 +1842,9 @@ void Application::setFullscreen(bool fullscreen) { · 142 unmodified lines
18631842 Menu::getInstance()->getActionForOption(MenuOption::Fullscreen)->setChecked(fullscreen);
18641843 }
18651844
1866−// The following code block is useful on platforms that can have a visible
1867−// app menu in a fullscreen window. However the OSX mechanism hides the
1868−// application menu for fullscreen apps, so the check is not required.
1845+ // The following code block is useful on platforms that can have a visible
1846+ // app menu in a fullscreen window. However the OSX mechanism hides the
1847+ // application menu for fullscreen apps, so the check is not required.
18691848 #ifndef Q_OS_MAC
18701849 if (Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)) {
18711850 if (fullscreen) {
@@ -1939,11 +1918,6 @@ void Application::setEnableVRMode(bool enableVRMode) { · 67 unmodified lines
19391918 } else {
19401919 OculusManager::abandonCalibration();
19411920 OculusManager::disconnect();
1942−
1943− _mirrorCamera.setHmdPosition(glm::vec3());
1944− _mirrorCamera.setHmdRotation(glm::quat());
1945− _myCamera.setHmdPosition(glm::vec3());
1946− _myCamera.setHmdRotation(glm::quat());
19471921 }
19481922
19491923 resizeGL();
@@ -1955,44 +1929,34 @@ void Application::setLowVelocityFilter(bool lowVelocityFilter) { · 5 unmodified lines
19551929
19561930 bool Application::mouseOnScreen() const {
19571931 if (OculusManager::isConnected()) {
1958− return getMouseX() >= 0 && getMouseX() <= _glWidget->getDeviceWidth() &&
1959− getMouseY() >= 0 && getMouseY() <= _glWidget->getDeviceHeight();
1932+ ivec2 mouse = getMouse();
1933+ if (!glm::all(glm::greaterThanEqual(mouse, ivec2()))) {
1934+ return false;
1935+ }
1936+ ivec2 size = toGlm(_glWidget->getDeviceSize());
1937+ if (!glm::all(glm::lessThanEqual(mouse, size))) {
1938+ return false;
1939+ }
19601940 }
19611941 return true;
19621942 }
19631943
1964−int Application::getMouseX() const {
1965− if (OculusManager::isConnected()) {
1966− glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
1967− return pos.x;
1968− }
1969− return getTrueMouseX();
1970−}
1971−
1972−int Application::getMouseY() const {
1944+ivec2 Application::getMouse() const {
19731945 if (OculusManager::isConnected()) {
1974− glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseX(), getTrueMouseY()));
1975− return pos.y;
1946+ return _compositor.screenToOverlay(getTrueMouse());
19761947 }
1977− return getTrueMouseY();
1948+ return getTrueMouse();
19781949 }
19791950
1980−int Application::getMouseDragStartedX() const {
1951+ivec2 Application::getMouseDragStarted() const {
19811952 if (OculusManager::isConnected()) {
1982− glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),
1983− getTrueMouseDragStartedY()));
1984− return pos.x;
1953+ return _compositor.screenToOverlay(getTrueMouseDragStarted());
19851954 }
1986− return getTrueMouseDragStartedX();
1955+ return getTrueMouseDragStarted();
19871956 }
19881957
1989−int Application::getMouseDragStartedY() const {
1990− if (OculusManager::isConnected()) {
1991− glm::vec2 pos = _applicationOverlay.screenToOverlay(glm::vec2(getTrueMouseDragStartedX(),
1992− getTrueMouseDragStartedY()));
1993− return pos.y;
1994− }
1995− return getTrueMouseDragStartedY();
1958+ivec2 Application::getTrueMouseDragStarted() const {
1959+ return _mouseDragStarted;
19961960 }
19971961
19981962 FaceTracker* Application::getActiveFaceTracker() {
@@ -2237,13 +2201,6 @@ void Application::init() { · 238 unmodified lines
22372201 _entityClipboardRenderer.setViewFrustum(getViewFrustum());
22382202 _entityClipboardRenderer.setTree(&_entityClipboard);
22392203
2240− _rearMirrorTools = new RearMirrorTools(_mirrorViewRect);
2241−
2242− connect(_rearMirrorTools, SIGNAL(closeView()), SLOT(closeMirrorView()));
2243− connect(_rearMirrorTools, SIGNAL(restoreView()), SLOT(restoreMirrorView()));
2244− connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView()));
2245− connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors()));
2246−
22472204 // initialize the GlowEffect with our widget
22482205 bool glow = Menu::getInstance()->isOptionChecked(MenuOption::EnableGlowEffect);
22492206 DependencyManager::get<GlowEffect>()->init(glow);
@@ -2408,13 +2365,23 @@ void Application::cameraMenuChanged() { · 158 unmodified lines
24082365 _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
24092366 _myAvatar->setBoomLength(MyAvatar::ZOOM_MIN);
24102367 }
2411− } else {
2368+ } else if (Menu::getInstance()->isOptionChecked(MenuOption::ThirdPerson)) {
24122369 if (_myCamera.getMode() != CAMERA_MODE_THIRD_PERSON) {
24132370 _myCamera.setMode(CAMERA_MODE_THIRD_PERSON);
24142371 if (_myAvatar->getBoomLength() == MyAvatar::ZOOM_MIN) {
24152372 _myAvatar->setBoomLength(MyAvatar::ZOOM_DEFAULT);
24162373 }
24172374 }
2375+ } else if (Menu::getInstance()->isOptionChecked(MenuOption::IndependentMode)) {
2376+ if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
2377+ _myCamera.setMode(CAMERA_MODE_INDEPENDENT);
2378+ }
2379+ }
2380+}
2381+
2382+void Application::rotationModeChanged() {
2383+ if (!Menu::getInstance()->isOptionChecked(MenuOption::CenterPlayerInView)) {
2384+ _myAvatar->setHeadPitch(0);
24182385 }
24192386 }
24202387
@@ -2502,18 +2469,22 @@ void Application::update(float deltaTime) { · 81 unmodified lines
25022469
25032470 // Transfer the user inputs to the driveKeys
25042471 _myAvatar->clearDriveKeys();
2505− _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));
2506− _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));
2507− _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));
2508− _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));
2509− _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));
2510− _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));
2511− _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));
2512− _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));
2513− _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));
2514− _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT));
2515− _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN));
2516− _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT));
2472+ if (_myCamera.getMode() != CAMERA_MODE_INDEPENDENT) {
2473+ if (!_controllerScriptingInterface.areActionsCaptured()) {
2474+ _myAvatar->setDriveKeys(FWD, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_FORWARD));
2475+ _myAvatar->setDriveKeys(BACK, _userInputMapper.getActionState(UserInputMapper::LONGITUDINAL_BACKWARD));
2476+ _myAvatar->setDriveKeys(UP, _userInputMapper.getActionState(UserInputMapper::VERTICAL_UP));
2477+ _myAvatar->setDriveKeys(DOWN, _userInputMapper.getActionState(UserInputMapper::VERTICAL_DOWN));
2478+ _myAvatar->setDriveKeys(LEFT, _userInputMapper.getActionState(UserInputMapper::LATERAL_LEFT));
2479+ _myAvatar->setDriveKeys(RIGHT, _userInputMapper.getActionState(UserInputMapper::LATERAL_RIGHT));
2480+ _myAvatar->setDriveKeys(ROT_UP, _userInputMapper.getActionState(UserInputMapper::PITCH_UP));
2481+ _myAvatar->setDriveKeys(ROT_DOWN, _userInputMapper.getActionState(UserInputMapper::PITCH_DOWN));
2482+ _myAvatar->setDriveKeys(ROT_LEFT, _userInputMapper.getActionState(UserInputMapper::YAW_LEFT));
2483+ _myAvatar->setDriveKeys(ROT_RIGHT, _userInputMapper.getActionState(UserInputMapper::YAW_RIGHT));
2484+ }
2485+ _myAvatar->setDriveKeys(BOOM_IN, _userInputMapper.getActionState(UserInputMapper::BOOM_IN));
2486+ _myAvatar->setDriveKeys(BOOM_OUT, _userInputMapper.getActionState(UserInputMapper::BOOM_OUT));
2487+ }
25172488
25182489 updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process...
25192490
@@ -2530,24 +2501,45 @@ void Application::update(float deltaTime) { · 10 unmodified lines
25302501
25312502 _entitySimulation.lock();
25322503 _physicsEngine.deleteObjects(_entitySimulation.getObjectsToDelete());
2504+ _entitySimulation.unlock();
2505+
2506+ _entities.getTree()->lockForWrite();
2507+ _entitySimulation.lock();
25332508 _physicsEngine.addObjects(_entitySimulation.getObjectsToAdd());
2509+ _entitySimulation.unlock();
2510+ _entities.getTree()->unlock();
2511+
2512+ _entities.getTree()->lockForWrite();
2513+ _entitySimulation.lock();
25342514 _physicsEngine.changeObjects(_entitySimulation.getObjectsToChange());
2515+ _entitySimulation.unlock();
2516+ _entities.getTree()->unlock();
2517+
2518+ _entitySimulation.lock();
25352519 _entitySimulation.applyActionChanges();
25362520 _entitySimulation.unlock();
25372521
2522+
25382523 AvatarManager* avatarManager = DependencyManager::get<AvatarManager>().data();
25392524 _physicsEngine.deleteObjects(avatarManager->getObjectsToDelete());
25402525 _physicsEngine.addObjects(avatarManager->getObjectsToAdd());
25412526 _physicsEngine.changeObjects(avatarManager->getObjectsToChange());
25422527
2528+ _entities.getTree()->lockForWrite();
25432529 _physicsEngine.stepSimulation();
2530+ _entities.getTree()->unlock();
25442531
25452532 if (_physicsEngine.hasOutgoingChanges()) {
2533+ _entities.getTree()->lockForWrite();
25462534 _entitySimulation.lock();
25472535 _entitySimulation.handleOutgoingChanges(_physicsEngine.getOutgoingChanges(), _physicsEngine.getSessionID());
25482536 _entitySimulation.unlock();
2537+ _entities.getTree()->unlock();
25492538
2539+ _entities.getTree()->lockForWrite();
25502540 avatarManager->handleOutgoingChanges(_physicsEngine.getOutgoingChanges());
2541+ _entities.getTree()->unlock();
2542+
25512543 auto collisionEvents = _physicsEngine.getCollisionEvents();
25522544 avatarManager->handleCollisionEvents(collisionEvents);
25532545
@@ -3137,7 +3129,7 @@ PickRay Application::computePickRay(float x, float y) const { · 583 unmodified lines
31373129 y /= size.y;
31383130 PickRay result;
31393131 if (isHMDMode()) {
3140− getApplicationOverlay().computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction);
3132+ getApplicationCompositor().computeHmdPickRay(glm::vec2(x, y), result.origin, result.direction);
31413133 } else {
31423134 if (QThread::currentThread() == activeRenderingThread) {
31433135 getDisplayViewFrustum()->computePickRay(x, y, result.origin, result.direction);
@@ -3166,13 +3158,11 @@ QImage Application::renderAvatarBillboard(RenderArgs* renderArgs) { · 22 unmodified lines
31663158 renderRearViewMirror(renderArgs, QRect(0, _glWidget->getDeviceHeight() - BILLBOARD_SIZE,
31673159 BILLBOARD_SIZE, BILLBOARD_SIZE),
31683160 true);
3169−
31703161 QImage image(BILLBOARD_SIZE, BILLBOARD_SIZE, QImage::Format_ARGB32);
31713162 glReadPixels(0, 0, BILLBOARD_SIZE, BILLBOARD_SIZE, GL_BGRA, GL_UNSIGNED_BYTE, image.bits());
31723163 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
31733164
31743165 glBindFramebuffer(GL_FRAMEBUFFER, 0);
3175−
31763166 return image;
31773167 }
31783168
@@ -3357,6 +3347,11 @@ namespace render { · 178 unmodified lines
33573347
33583348
33593349 void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool selfAvatarOnly, bool billboard) {
3350+
3351+ // FIXME: This preRender call is temporary until we create a separate render::scene for the mirror rendering.
3352+ // Then we can move this logic into the Avatar::simulate call.
3353+ _myAvatar->preRender(renderArgs);
3354+
33603355 activeRenderingThread = QThread::currentThread();
33613356 PROFILE_RANGE(__FUNCTION__);
33623357 PerformanceTimer perfTimer("display");
@@ -3368,9 +3363,8 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 5 unmodified lines
33683363
33693364 // flip x if in mirror mode (also requires reversing winding order for backface culling)
33703365 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
3371− glScalef(-1.0f, 1.0f, 1.0f);
3372− glFrontFace(GL_CW);
3373−
3366+ //glScalef(-1.0f, 1.0f, 1.0f);
3367+ //glFrontFace(GL_CW);
33743368 } else {
33753369 glFrontFace(GL_CCW);
33763370 }
@@ -3393,7 +3387,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 16 unmodified lines
33933387 viewTransform.setTranslation(theCamera.getPosition());
33943388 viewTransform.setRotation(rotation);
33953389 if (theCamera.getMode() == CAMERA_MODE_MIRROR) {
3396− viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));
3390+// viewTransform.setScale(Transform::Vec3(-1.0f, 1.0f, 1.0f));
33973391 }
33983392 if (renderArgs->_renderSide != RenderArgs::MONO) {
33993393 glm::mat4 invView = glm::inverse(_untranslatedViewMatrix);
@@ -3530,6 +3524,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 130 unmodified lines
35303524
35313525 renderContext._maxDrawnOpaqueItems = sceneInterface->getEngineMaxDrawnOpaqueItems();
35323526 renderContext._maxDrawnTransparentItems = sceneInterface->getEngineMaxDrawnTransparentItems();
3527+ renderContext._maxDrawnOverlay3DItems = sceneInterface->getEngineMaxDrawnOverlay3DItems();
35333528
35343529 renderArgs->_shouldRender = LODManager::shouldRender;
35353530
@@ -3546,7 +3541,9 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 10 unmodified lines
35463541
35473542 sceneInterface->setEngineFeedTransparentItems(engineRC->_numFeedTransparentItems);
35483543 sceneInterface->setEngineDrawnTransparentItems(engineRC->_numDrawnTransparentItems);
3549−
3544+
3545+ sceneInterface->setEngineFeedOverlay3DItems(engineRC->_numFeedOverlay3DItems);
3546+ sceneInterface->setEngineDrawnOverlay3DItems(engineRC->_numDrawnOverlay3DItems);
35503547 }
35513548 //Render the sixense lasers
35523549 if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseLasers)) {
@@ -3654,8 +3651,8 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) { · 101 unmodified lines
36543651 // +-----------------------+
36553652 // -1,-1 1,-1
36563653
3657− glm::vec2 screenPoint((projectedPoint.x + 1.0) * horizontalScale,
3658− ((projectedPoint.y + 1.0) * -verticalScale) + _glWidget->getDeviceHeight());
3654+ glm::vec2 screenPoint((projectedPoint.x + 1.0f) * horizontalScale,
3655+ ((projectedPoint.y + 1.0f) * -verticalScale) + _glWidget->getDeviceHeight());
36593656
36603657 return screenPoint;
36613658 }
@@ -3673,7 +3670,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 11 unmodified lines
36733670 _mirrorCamera.setPosition(_myAvatar->getPosition() +
36743671 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * BILLBOARD_DISTANCE * _myAvatar->getScale());
36753672
3676− } else if (RearMirrorTools::rearViewZoomLevel.get() == BODY) {
3673+ } else if (!AvatarInputs::getInstance()->mirrorZoomed()) {
36773674 _mirrorCamera.setPosition(_myAvatar->getChestPosition() +
36783675 _myAvatar->getOrientation() * glm::vec3(0.0f, 0.0f, -1.0f) * MIRROR_REARVIEW_BODY_DISTANCE * _myAvatar->getScale());
36793676
@@ -3708,7 +3705,7 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 28 unmodified lines
37083705 } else {
37093706 // if not rendering the billboard, the region is in device independent coordinates; must convert to device
37103707 QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
3711− float ratio = QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
3708+ float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
37123709 int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;
37133710 glViewport(x, size.height() - y - height, width, height);
37143711 glScissor(x, size.height() - y - height, width, height);
@@ -3723,10 +3720,6 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi · 8 unmodified lines
37233720 displaySide(renderArgs, _mirrorCamera, true, billboard);
37243721 glPopMatrix();
37253722
3726− if (!billboard) {
3727− _rearMirrorTools->render(renderArgs, false, _glWidget->mapFromGlobal(QCursor::pos()));
3728− }
3729−
37303723 // reset Viewport and projection matrix
37313724 glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
37323725 glDisable(GL_SCISSOR_TEST);
@@ -3866,7 +3859,7 @@ void Application::nodeKilled(SharedNodePointer node) { · 133 unmodified lines
38663859 _entityServerJurisdictions.unlock();
38673860
38683861 qCDebug(interfaceapp, "model server going away...... v[%f, %f, %f, %f]",
3869− rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s);
3862+ (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s);
38703863
38713864 // Add the jurisditionDetails object to the list of "fade outs"
38723865 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnOctreeServerChanges)) {
@@ -3952,7 +3945,8 @@ int Application::parseOctreeStats(const QByteArray& packet, const SharedNodePoin · 79 unmodified lines
39523945 jurisdiction->unlock();
39533946
39543947 qCDebug(interfaceapp, "stats from new %s server... [%f, %f, %f, %f]",
3955− qPrintable(serverType), rootDetails.x, rootDetails.y, rootDetails.z, rootDetails.s);
3948+ qPrintable(serverType),
3949+ (double)rootDetails.x, (double)rootDetails.y, (double)rootDetails.z, (double)rootDetails.s);
39563950
39573951 // Add the jurisditionDetails object to the list of "fade outs"
39583952 if (!Menu::getInstance()->isOptionChecked(MenuOption::DontFadeOnOctreeServerChanges)) {
@@ -4059,6 +4053,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 100 unmodified lines
40594053 connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(scriptFinished(const QString&)));
40604054
40614055 connect(scriptEngine, SIGNAL(loadScript(const QString&, bool)), this, SLOT(loadScript(const QString&, bool)));
4056+ connect(scriptEngine, SIGNAL(reloadScript(const QString&, bool)), this, SLOT(reloadScript(const QString&, bool)));
40624057
40634058 scriptEngine->registerGlobalObject("Overlays", &_overlays);
40644059 qScriptRegisterMetaType(scriptEngine, OverlayPropertyResultToScriptValue, OverlayPropertyResultFromScriptValue);
@@ -4274,7 +4269,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) { · 209 unmodified lines
42744269 }
42754270
42764271 ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded,
4277− bool loadScriptFromEditor, bool activateMainWindow) {
4272+ bool loadScriptFromEditor, bool activateMainWindow, bool reload) {
42784273
42794274 if (isAboutToQuit()) {
42804275 return NULL;
@@ -4303,7 +4298,7 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 22 unmodified lines
43034298 connect(scriptEngine, &ScriptEngine::errorLoadingScript, this, &Application::handleScriptLoadError);
43044299
43054300 // get the script engine object to load the script at the designated script URL
4306− scriptEngine->loadURL(scriptUrl);
4301+ scriptEngine->loadURL(scriptUrl, reload);
43074302 }
43084303
43094304 // restore the main window's active state
@@ -4314,6 +4309,10 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser · 4 unmodified lines
43144309 return scriptEngine;
43154310 }
43164311
4312+void Application::reloadScript(const QString& scriptName, bool isUserLoaded) {
4313+ loadScript(scriptName, isUserLoaded, false, false, true);
4314+}
4315+
43174316 void Application::handleScriptEngineLoaded(const QString& scriptFilename) {
43184317 ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(sender());
43194318
@@ -4341,14 +4340,25 @@ void Application::scriptFinished(const QString& scriptName) { · 21 unmodified lines
43414340 }
43424341
43434342 void Application::stopAllScripts(bool restart) {
4344− // stops all current running scripts
4343+ if (restart) {
4344+ // Delete all running scripts from cache so that they are re-downloaded when they are restarted
4345+ auto scriptCache = DependencyManager::get<ScriptCache>();
4346+ for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
4347+ it != _scriptEnginesHash.constEnd(); it++) {
4348+ if (!it.value()->isFinished()) {
4349+ scriptCache->deleteScript(it.key());
4350+ }
4351+ }
4352+ }
4353+
4354+ // Stop and possibly restart all currently running scripts
43454355 for (QHash<QString, ScriptEngine*>::const_iterator it = _scriptEnginesHash.constBegin();
43464356 it != _scriptEnginesHash.constEnd(); it++) {
43474357 if (it.value()->isFinished()) {
43484358 continue;
43494359 }
43504360 if (restart && it.value()->isUserLoaded()) {
4351− connect(it.value(), SIGNAL(finished(const QString&)), SLOT(loadScript(const QString&)));
4361+ connect(it.value(), SIGNAL(finished(const QString&)), SLOT(reloadScript(const QString&)));
43524362 }
43534363 it.value()->stop();
43544364 qCDebug(interfaceapp) << "stopping script..." << it.key();
@@ -4356,13 +4366,20 @@ void Application::stopAllScripts(bool restart) { · 1 unmodified line
43564366 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
43574367 // whenever a script stops in case it happened to have been setting joint rotations.
43584368 // TODO: expose animation priorities and provide a layered animation control system.
4369+ _myAvatar->clearJointAnimationPriorities();
43594370 _myAvatar->clearScriptableSettings();
43604371 }
43614372
4362−void Application::stopScript(const QString &scriptName) {
4373+void Application::stopScript(const QString &scriptName, bool restart) {
43634374 const QString& scriptURLString = QUrl(scriptName).toString();
43644375 if (_scriptEnginesHash.contains(scriptURLString)) {
4365− _scriptEnginesHash.value(scriptURLString)->stop();
4376+ ScriptEngine* scriptEngine = _scriptEnginesHash[scriptURLString];
4377+ if (restart) {
4378+ auto scriptCache = DependencyManager::get<ScriptCache>();
4379+ scriptCache->deleteScript(scriptName);
4380+ connect(scriptEngine, SIGNAL(finished(const QString&)), SLOT(reloadScript(const QString&)));
4381+ }
4382+ scriptEngine->stop();
43664383 qCDebug(interfaceapp) << "stopping script..." << scriptName;
43674384 // HACK: ATM scripts cannot set/get their animation priorities, so we clear priorities
43684385 // whenever a script stops in case it happened to have been setting joint rotations.
@@ -4378,6 +4395,10 @@ void Application::reloadAllScripts() { · 9 unmodified lines
43784395 stopAllScripts(true);
43794396 }
43804397
4398+void Application::reloadOneScript(const QString& scriptName) {
4399+ stopScript(scriptName, true);
4400+}
4401+
43814402 void Application::loadDefaultScripts() {
43824403 if (!_scriptEnginesHash.contains(DEFAULT_SCRIPTS_JS_URL)) {
43834404 loadScript(DEFAULT_SCRIPTS_JS_URL);
@@ -4732,11 +4753,9 @@ void Application::postLambdaEvent(std::function<void()> f) { · 348 unmodified lines
47324753 }
47334754
47344755 void Application::initPlugins() {
4735− OculusManager::init();
47364756 }
47374757
47384758 void Application::shutdownPlugins() {
4739− OculusManager::deinit();
47404759 }
47414760
47424761 glm::vec3 Application::getHeadPosition() const {
@@ -4756,12 +4775,8 @@ QSize Application::getDeviceSize() const { · 13 unmodified lines
47564775 return _glWidget->getDeviceSize();
47574776 }
47584777
4759−int Application::getTrueMouseX() const {
4760− return _glWidget->mapFromGlobal(QCursor::pos()).x();
4761−}
4762−
4763−int Application::getTrueMouseY() const {
4764− return _glWidget->mapFromGlobal(QCursor::pos()).y();
4778+ivec2 Application::getTrueMouse() const {
4779+ return toGlm(_glWidget->mapFromGlobal(QCursor::pos()));
47654780 }
47664781
47674782 bool Application::isThrottleRendering() const {
@@ -4791,3 +4806,25 @@ qreal Application::getDevicePixelRatio() { · 23 unmodified lines
47914806 return _window ? _window->windowHandle()->devicePixelRatio() : 1.0;
47924807 }
47934808
4809+mat4 Application::getEyeProjection(int eye) const {
4810+ if (isHMDMode()) {
4811+ return OculusManager::getEyeProjection(eye);
4812+ }
4813+
4814+ return _viewFrustum.getProjection();
4815+}
4816+
4817+mat4 Application::getEyePose(int eye) const {
4818+ if (isHMDMode()) {
4819+ return OculusManager::getEyePose(eye);
4820+ }
4821+
4822+ return mat4();
4823+}
4824+
4825+mat4 Application::getHeadPose() const {
4826+ if (isHMDMode()) {
4827+ return OculusManager::getHeadPose();
4828+ }
4829+ return mat4();
4830+}