Showing the changes to interface/src/Application.cpp (1 of 19 files). Show all
Unified · Split
| @@ -144,6 +144,8 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : · 143 unmodified lines | |||
| 144 | _packetsPerSecond(0), | 144 | _packetsPerSecond(0), |
| 145 | _bytesPerSecond(0), | 145 | _bytesPerSecond(0), |
| 146 | _bytesCount(0), | 146 | _bytesCount(0), |
| 147 | _recentMaxPackets(0), | ||
| 148 | _resetRecentMaxPacketsSoon(true), | ||
| 147 | _swatch(NULL), | 149 | _swatch(NULL), |
| 148 | _pasteMode(false) | 150 | _pasteMode(false) |
| 149 | { | 151 | { |
| @@ -1304,7 +1306,10 @@ static glm::vec3 getFaceVector(BoxFace face) { · 1154 unmodified lines | |||
| 1304 | } | 1306 | } |
| 1305 | 1307 | ||
| 1306 | void Application::idle() { | 1308 | void Application::idle() { |
| 1307 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | 1309 | // Normally we check PipelineWarnings, but since idle will often take more than 10ms we only show these idle timing |
| 1310 | // details if we're in ExtraDebugging mode. However, the ::update() and it's subcomponents will show their timing | ||
| 1311 | // details normally. | ||
| 1312 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::ExtraDebugging); | ||
| 1308 | PerformanceWarning warn(showWarnings, "Application::idle()"); | 1313 | PerformanceWarning warn(showWarnings, "Application::idle()"); |
| 1309 | 1314 | ||
| 1310 | timeval check; | 1315 | timeval check; |
| @@ -1314,22 +1319,30 @@ void Application::idle() { · 3 unmodified lines | |||
| 1314 | 1319 | ||
| 1315 | double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check); | 1320 | double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check); |
| 1316 | if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) { | 1321 | if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) { |
| 1317 | 1322 | { | |
| 1318 | const float BIGGEST_DELTA_TIME_SECS = 0.25f; | 1323 | PerformanceWarning warn(showWarnings, "Application::idle()... update()"); |
| 1319 | update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS)); | 1324 | const float BIGGEST_DELTA_TIME_SECS = 0.25f; |
| 1320 | _glWidget->updateGL(); | 1325 | update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS)); |
| 1321 | _lastTimeUpdated = check; | 1326 | } |
| 1322 | _idleLoopStdev.addValue(timeSinceLastUpdate); | 1327 | { |
| 1323 | 1328 | PerformanceWarning warn(showWarnings, "Application::idle()... updateGL()"); | |
| 1324 | // Record standard deviation and reset counter if needed | 1329 | _glWidget->updateGL(); |
| 1325 | const int STDEV_SAMPLES = 500; | ||
| 1326 | if (_idleLoopStdev.getSamples() > STDEV_SAMPLES) { | ||
| 1327 | _idleLoopMeasuredJitter = _idleLoopStdev.getStDev(); | ||
| 1328 | _idleLoopStdev.reset(); | ||
| 1329 | } | 1330 | } |
| 1331 | { | ||
| 1332 | PerformanceWarning warn(showWarnings, "Application::idle()... rest of it"); | ||
| 1333 | _lastTimeUpdated = check; | ||
| 1334 | _idleLoopStdev.addValue(timeSinceLastUpdate); | ||
| 1335 | |||
| 1336 | // Record standard deviation and reset counter if needed | ||
| 1337 | const int STDEV_SAMPLES = 500; | ||
| 1338 | if (_idleLoopStdev.getSamples() > STDEV_SAMPLES) { | ||
| 1339 | _idleLoopMeasuredJitter = _idleLoopStdev.getStDev(); | ||
| 1340 | _idleLoopStdev.reset(); | ||
| 1341 | } | ||
| 1330 | 1342 | ||
| 1331 | // After finishing all of the above work, restart the idle timer, allowing 2ms to process events. | 1343 | // After finishing all of the above work, restart the idle timer, allowing 2ms to process events. |
| 1332 | idleTimer->start(2); | 1344 | idleTimer->start(2); |
| 1345 | } | ||
| 1333 | } | 1346 | } |
| 1334 | } | 1347 | } |
| 1335 | void Application::terminate() { | 1348 | void Application::terminate() { |
| @@ -1776,6 +1789,8 @@ static QUuid DEFAULT_NODE_ID_REF; · 440 unmodified lines | |||
| 1776 | 1789 | ||
| 1777 | void Application::updateLookatTargetAvatar(const glm::vec3& mouseRayOrigin, const glm::vec3& mouseRayDirection, | 1790 | void Application::updateLookatTargetAvatar(const glm::vec3& mouseRayOrigin, const glm::vec3& mouseRayDirection, |
| 1778 | glm::vec3& eyePosition) { | 1791 | glm::vec3& eyePosition) { |
| 1792 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 1793 | PerformanceWarning warn(showWarnings, "Application::updateLookatTargetAvatar()"); | ||
| 1779 | 1794 | ||
| 1780 | _lookatTargetAvatar = findLookatTargetAvatar(mouseRayOrigin, mouseRayDirection, eyePosition, DEFAULT_NODE_ID_REF); | 1795 | _lookatTargetAvatar = findLookatTargetAvatar(mouseRayOrigin, mouseRayDirection, eyePosition, DEFAULT_NODE_ID_REF); |
| 1781 | } | 1796 | } |
| @@ -1791,7 +1806,10 @@ Avatar* Application::findLookatTargetAvatar(const glm::vec3& mouseRayOrigin, con · 9 unmodified lines | |||
| 1791 | float distance; | 1806 | float distance; |
| 1792 | if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, | 1807 | if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, |
| 1793 | HEAD_SPHERE_RADIUS * avatar->getHead().getScale(), distance)) { | 1808 | HEAD_SPHERE_RADIUS * avatar->getHead().getScale(), distance)) { |
| 1794 | eyePosition = avatar->getHead().calculateAverageEyePosition(); | 1809 | // rescale to compensate for head embiggening |
| 1810 | eyePosition = (avatar->getHead().calculateAverageEyePosition() - avatar->getHead().getScalePivot()) * | ||
| 1811 | (avatar->getScale() / avatar->getHead().getScale()) + avatar->getHead().getScalePivot(); | ||
| 1812 | |||
| 1795 | _lookatIndicatorScale = avatar->getHead().getScale(); | 1813 | _lookatIndicatorScale = avatar->getHead().getScale(); |
| 1796 | _lookatOtherPosition = headPosition; | 1814 | _lookatOtherPosition = headPosition; |
| 1797 | nodeUUID = avatar->getOwningNode()->getUUID(); | 1815 | nodeUUID = avatar->getOwningNode()->getUUID(); |
| @@ -1907,17 +1925,13 @@ void Application::updateAvatars(float deltaTime, glm::vec3 mouseRayOrigin, glm:: · 109 unmodified lines | |||
| 1907 | } | 1925 | } |
| 1908 | } | 1926 | } |
| 1909 | 1927 | ||
| 1910 | void Application::update(float deltaTime) { | 1928 | void Application::updateMouseRay(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection) { |
| 1929 | |||
| 1911 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | 1930 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 1912 | PerformanceWarning warn(showWarnings, "Application::update()"); | 1931 | PerformanceWarning warn(showWarnings, "Application::updateMouseRay()"); |
| 1913 | 1932 | ||
| 1914 | // tell my avatar if the mouse is being pressed... | 1933 | _viewFrustum.computePickRay(_mouseX / (float)_glWidget->width(), _mouseY / (float)_glWidget->height(), |
| 1915 | _myAvatar.setMousePressed(_mousePressed); | 1934 | mouseRayOrigin, mouseRayDirection); |
| 1916 | |||
| 1917 | // check what's under the mouse and update the mouse voxel | ||
| 1918 | glm::vec3 mouseRayOrigin, mouseRayDirection; | ||
| 1919 | _viewFrustum.computePickRay(_mouseX / (float)_glWidget->width(), | ||
| 1920 | _mouseY / (float)_glWidget->height(), mouseRayOrigin, mouseRayDirection); | ||
| 1921 | 1935 | ||
| 1922 | // adjust for mirroring | 1936 | // adjust for mirroring |
| 1923 | if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { | 1937 | if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { |
| @@ -1928,12 +1942,18 @@ void Application::update(float deltaTime) { · 4 unmodified lines | |||
| 1928 | _viewFrustum.getRight() * glm::dot(_viewFrustum.getRight(), mouseRayDirection)); | 1942 | _viewFrustum.getRight() * glm::dot(_viewFrustum.getRight(), mouseRayDirection)); |
| 1929 | } | 1943 | } |
| 1930 | 1944 | ||
| 1945 | // tell my avatar if the mouse is being pressed... | ||
| 1946 | _myAvatar.setMousePressed(_mousePressed); | ||
| 1947 | |||
| 1931 | // tell my avatar the posiion and direction of the ray projected ino the world based on the mouse position | 1948 | // tell my avatar the posiion and direction of the ray projected ino the world based on the mouse position |
| 1932 | _myAvatar.setMouseRay(mouseRayOrigin, mouseRayDirection); | 1949 | _myAvatar.setMouseRay(mouseRayOrigin, mouseRayDirection); |
| 1933 | 1950 | } | |
| 1934 | // Set where I am looking based on my mouse ray (so that other people can see) | 1951 | |
| 1935 | glm::vec3 lookAtSpot; | 1952 | void Application::updateFaceshift() { |
| 1936 | 1953 | ||
| 1954 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 1955 | PerformanceWarning warn(showWarnings, "Application::updateFaceshift()"); | ||
| 1956 | |||
| 1937 | // Update faceshift | 1957 | // Update faceshift |
| 1938 | _faceshift.update(); | 1958 | _faceshift.update(); |
| 1939 | 1959 | ||
| @@ -1941,39 +1961,47 @@ void Application::update(float deltaTime) { · 1 unmodified line | |||
| 1941 | if (_faceshift.isActive()) { | 1961 | if (_faceshift.isActive()) { |
| 1942 | _myAvatar.getHead().setAngularVelocity(_faceshift.getHeadAngularVelocity()); | 1962 | _myAvatar.getHead().setAngularVelocity(_faceshift.getHeadAngularVelocity()); |
| 1943 | } | 1963 | } |
| 1964 | } | ||
| 1944 | 1965 | ||
| 1945 | // if we have faceshift, use that to compute the lookat direction | 1966 | void Application::updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot, glm::vec3& lookAtRayOrigin, |
| 1946 | glm::vec3 lookAtRayOrigin = mouseRayOrigin, lookAtRayDirection = mouseRayDirection; | 1967 | glm::vec3& lookAtRayDirection) { |
| 1947 | if (_faceshift.isActive()) { | ||
| 1948 | lookAtRayOrigin = _myAvatar.getHead().calculateAverageEyePosition(); | ||
| 1949 | lookAtRayDirection = _myAvatar.getHead().getOrientation() * glm::quat(glm::radians(glm::vec3( | ||
| 1950 | _faceshift.getEstimatedEyePitch(), _faceshift.getEstimatedEyeYaw(), 0.0f))) * glm::vec3(0.0f, 0.0f, -1.0f); | ||
| 1951 | } | ||
| 1952 | 1968 | ||
| 1953 | updateLookatTargetAvatar(mouseRayOrigin, mouseRayDirection, lookAtSpot); | 1969 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 1954 | if (_lookatTargetAvatar && !_faceshift.isActive()) { | 1970 | PerformanceWarning warn(showWarnings, "Application::updateMyAvatarLookAtPosition()"); |
| 1955 | // If the mouse is over another avatar's head... | ||
| 1956 | _myAvatar.getHead().setLookAtPosition(lookAtSpot); | ||
| 1957 | |||
| 1958 | } else if (_isHoverVoxel && !_faceshift.isActive()) { | ||
| 1959 | // Look at the hovered voxel | ||
| 1960 | lookAtSpot = getMouseVoxelWorldCoordinates(_hoverVoxel); | ||
| 1961 | _myAvatar.getHead().setLookAtPosition(lookAtSpot); | ||
| 1962 | |||
| 1963 | } else if (_myCamera.getMode() == CAMERA_MODE_MIRROR && !_faceshift.isActive()) { | ||
| 1964 | _myAvatar.getHead().setLookAtPosition(_myCamera.getPosition()); | ||
| 1965 | 1971 | ||
| 1966 | } else { | 1972 | if (!_lookatTargetAvatar) { |
| 1967 | // Just look in direction of the mouse ray | 1973 | if (_isHoverVoxel) { |
| 1968 | const float FAR_AWAY_STARE = TREE_SCALE; | 1974 | // Look at the hovered voxel |
| 1969 | lookAtSpot = lookAtRayOrigin + lookAtRayDirection * FAR_AWAY_STARE; | 1975 | lookAtSpot = getMouseVoxelWorldCoordinates(_hoverVoxel); |
| 1970 | _myAvatar.getHead().setLookAtPosition(lookAtSpot); | 1976 | |
| 1977 | } else if (_myCamera.getMode() == CAMERA_MODE_MIRROR) { | ||
| 1978 | lookAtSpot = _myCamera.getPosition(); | ||
| 1979 | |||
| 1980 | } else { | ||
| 1981 | // Just look in direction of the mouse ray | ||
| 1982 | const float FAR_AWAY_STARE = TREE_SCALE; | ||
| 1983 | lookAtSpot = lookAtRayOrigin + lookAtRayDirection * FAR_AWAY_STARE; | ||
| 1984 | } | ||
| 1971 | } | 1985 | } |
| 1986 | if (_faceshift.isActive()) { | ||
| 1987 | // deflect using Faceshift gaze data | ||
| 1988 | glm::vec3 origin = _myAvatar.getHead().calculateAverageEyePosition(); | ||
| 1989 | float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f; | ||
| 1990 | const float PITCH_SCALE = 0.5f; | ||
| 1991 | const float YAW_SCALE = 0.5f; | ||
| 1992 | lookAtSpot = origin + _myCamera.getRotation() * glm::quat(glm::radians(glm::vec3( | ||
| 1993 | _faceshift.getEstimatedEyePitch() * pitchSign * PITCH_SCALE, _faceshift.getEstimatedEyeYaw() * YAW_SCALE, 0.0f))) * | ||
| 1994 | glm::inverse(_myCamera.getRotation()) * (lookAtSpot - origin); | ||
| 1995 | } | ||
| 1996 | _myAvatar.getHead().setLookAtPosition(lookAtSpot); | ||
| 1997 | } | ||
| 1998 | |||
| 1999 | void Application::updateHoverVoxels(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, | ||
| 2000 | float& distance, BoxFace& face) { | ||
| 2001 | |||
| 2002 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2003 | PerformanceWarning warn(showWarnings, "Application::updateHoverVoxels()"); | ||
| 1972 | 2004 | ||
| 1973 | // Find the voxel we are hovering over, and respond if clicked | ||
| 1974 | float distance; | ||
| 1975 | BoxFace face; | ||
| 1976 | |||
| 1977 | // If we have clicked on a voxel, update it's color | 2005 | // If we have clicked on a voxel, update it's color |
| 1978 | if (_isHoverVoxelSounding) { | 2006 | if (_isHoverVoxelSounding) { |
| 1979 | VoxelNode* hoveredNode = _voxels.getVoxelAt(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); | 2007 | VoxelNode* hoveredNode = _voxels.getVoxelAt(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); |
| @@ -1995,23 +2023,38 @@ void Application::update(float deltaTime) { · 15 unmodified lines | |||
| 1995 | } else { | 2023 | } else { |
| 1996 | // Check for a new hover voxel | 2024 | // Check for a new hover voxel |
| 1997 | glm::vec4 oldVoxel(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); | 2025 | glm::vec4 oldVoxel(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s); |
| 1998 | _isHoverVoxel = _voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _hoverVoxel, distance, face); | 2026 | // only do this work if MAKE_SOUND_ON_VOXEL_HOVER or MAKE_SOUND_ON_VOXEL_CLICK is enabled, |
| 1999 | if (MAKE_SOUND_ON_VOXEL_HOVER && _isHoverVoxel && glm::vec4(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s) != oldVoxel) { | 2027 | // and make sure the tree is not already busy... because otherwise you'll have to wait. |
| 2000 | _hoverVoxelOriginalColor[0] = _hoverVoxel.red; | 2028 | if (!_voxels.treeIsBusy()) { |
| 2001 | _hoverVoxelOriginalColor[1] = _hoverVoxel.green; | 2029 | { |
| 2002 | _hoverVoxelOriginalColor[2] = _hoverVoxel.blue; | 2030 | PerformanceWarning warn(showWarnings, "Application::updateHoverVoxels() _voxels.findRayIntersection()"); |
| 2003 | _hoverVoxelOriginalColor[3] = 1; | 2031 | _isHoverVoxel = _voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _hoverVoxel, distance, face); |
| 2004 | _audio.startCollisionSound(1.0, HOVER_VOXEL_FREQUENCY * _hoverVoxel.s * TREE_SCALE, 0.0, HOVER_VOXEL_DECAY); | 2032 | } |
| 2005 | _isHoverVoxelSounding = true; | 2033 | if (MAKE_SOUND_ON_VOXEL_HOVER && _isHoverVoxel && |
| 2034 | glm::vec4(_hoverVoxel.x, _hoverVoxel.y, _hoverVoxel.z, _hoverVoxel.s) != oldVoxel) { | ||
| 2035 | |||
| 2036 | _hoverVoxelOriginalColor[0] = _hoverVoxel.red; | ||
| 2037 | _hoverVoxelOriginalColor[1] = _hoverVoxel.green; | ||
| 2038 | _hoverVoxelOriginalColor[2] = _hoverVoxel.blue; | ||
| 2039 | _hoverVoxelOriginalColor[3] = 1; | ||
| 2040 | _audio.startCollisionSound(1.0, HOVER_VOXEL_FREQUENCY * _hoverVoxel.s * TREE_SCALE, 0.0, HOVER_VOXEL_DECAY); | ||
| 2041 | _isHoverVoxelSounding = true; | ||
| 2042 | } | ||
| 2006 | } | 2043 | } |
| 2007 | } | 2044 | } |
| 2008 | 2045 | } | |
| 2046 | |||
| 2047 | void Application::updateMouseVoxels(float deltaTime, glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, | ||
| 2048 | float& distance, BoxFace& face) { | ||
| 2049 | |||
| 2050 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2051 | PerformanceWarning warn(showWarnings, "Application::updateMouseVoxels()"); | ||
| 2052 | |||
| 2009 | _mouseVoxel.s = 0.0f; | 2053 | _mouseVoxel.s = 0.0f; |
| 2010 | if (Menu::getInstance()->isVoxelModeActionChecked() && | 2054 | if (Menu::getInstance()->isVoxelModeActionChecked() && |
| 2011 | (fabs(_myAvatar.getVelocity().x) + | 2055 | (fabs(_myAvatar.getVelocity().x) + |
| 2012 | fabs(_myAvatar.getVelocity().y) + | 2056 | fabs(_myAvatar.getVelocity().y) + |
| 2013 | fabs(_myAvatar.getVelocity().z)) / 3 < MAX_AVATAR_EDIT_VELOCITY) { | 2057 | fabs(_myAvatar.getVelocity().z)) / 3 < MAX_AVATAR_EDIT_VELOCITY) { |
| 2014 | PerformanceWarning warn(showWarnings, "Application::update()... findRayIntersection()"); | ||
| 2015 | 2058 | ||
| 2016 | if (_voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _mouseVoxel, distance, face)) { | 2059 | if (_voxels.findRayIntersection(mouseRayOrigin, mouseRayDirection, _mouseVoxel, distance, face)) { |
| 2017 | if (distance < MAX_VOXEL_EDIT_DISTANCE) { | 2060 | if (distance < MAX_VOXEL_EDIT_DISTANCE) { |
| @@ -2080,12 +2123,17 @@ void Application::update(float deltaTime) { · 62 unmodified lines | |||
| 2080 | _justEditedVoxel = false; | 2123 | _justEditedVoxel = false; |
| 2081 | } | 2124 | } |
| 2082 | } | 2125 | } |
| 2083 | 2126 | } | |
| 2127 | |||
| 2128 | void Application::updateHandAndTouch(float deltaTime) { | ||
| 2129 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2130 | PerformanceWarning warn(showWarnings, "Application::updateHandAndTouch()"); | ||
| 2131 | |||
| 2084 | // walking triggers the handControl to stop | 2132 | // walking triggers the handControl to stop |
| 2085 | if (_myAvatar.getMode() == AVATAR_MODE_WALKING) { | 2133 | if (_myAvatar.getMode() == AVATAR_MODE_WALKING) { |
| 2086 | _handControl.stop(); | 2134 | _handControl.stop(); |
| 2087 | } | 2135 | } |
| 2088 | 2136 | ||
| 2089 | // Update from Touch | 2137 | // Update from Touch |
| 2090 | if (_isTouchPressed) { | 2138 | if (_isTouchPressed) { |
| 2091 | float TOUCH_YAW_SCALE = -0.25f; | 2139 | float TOUCH_YAW_SCALE = -0.25f; |
| @@ -2096,19 +2144,29 @@ void Application::update(float deltaTime) { · 4 unmodified lines | |||
| 2096 | _lastTouchAvgX = _touchAvgX; | 2144 | _lastTouchAvgX = _touchAvgX; |
| 2097 | _lastTouchAvgY = _touchAvgY; | 2145 | _lastTouchAvgY = _touchAvgY; |
| 2098 | } | 2146 | } |
| 2099 | 2147 | } | |
| 2100 | // Leap finger-sensing device | 2148 | |
| 2149 | void Application::updateLeap(float deltaTime) { | ||
| 2150 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2151 | PerformanceWarning warn(showWarnings, "Application::updateLeap()"); | ||
| 2152 | |||
| 2101 | LeapManager::enableFakeFingers(Menu::getInstance()->isOptionChecked(MenuOption::SimulateLeapHand)); | 2153 | LeapManager::enableFakeFingers(Menu::getInstance()->isOptionChecked(MenuOption::SimulateLeapHand)); |
| 2102 | _myAvatar.getHand().setRaveGloveActive(Menu::getInstance()->isOptionChecked(MenuOption::TestRaveGlove)); | 2154 | _myAvatar.getHand().setRaveGloveActive(Menu::getInstance()->isOptionChecked(MenuOption::TestRaveGlove)); |
| 2103 | LeapManager::nextFrame(_myAvatar); | 2155 | LeapManager::nextFrame(_myAvatar); |
| 2104 | 2156 | } | |
| 2105 | // Read serial port interface devices | 2157 | |
| 2158 | void Application::updateSerialDevices(float deltaTime) { | ||
| 2159 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2160 | PerformanceWarning warn(showWarnings, "Application::updateSerialDevices()"); | ||
| 2161 | |||
| 2106 | if (_serialHeadSensor.isActive()) { | 2162 | if (_serialHeadSensor.isActive()) { |
| 2107 | _serialHeadSensor.readData(deltaTime); | 2163 | _serialHeadSensor.readData(deltaTime); |
| 2108 | } | 2164 | } |
| 2109 | 2165 | } | |
| 2110 | // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes | 2166 | |
| 2111 | updateAvatar(deltaTime); | 2167 | void Application::updateThreads(float deltaTime) { |
| 2168 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2169 | PerformanceWarning warn(showWarnings, "Application::updateThreads()"); | ||
| 2112 | 2170 | ||
| 2113 | // read incoming packets from network | 2171 | // read incoming packets from network |
| 2114 | if (!_enableNetworkThread) { | 2172 | if (!_enableNetworkThread) { |
| @@ -2120,12 +2178,12 @@ void Application::update(float deltaTime) { · 5 unmodified lines | |||
| 2120 | _voxelProcessor.threadRoutine(); | 2178 | _voxelProcessor.threadRoutine(); |
| 2121 | _voxelEditSender.threadRoutine(); | 2179 | _voxelEditSender.threadRoutine(); |
| 2122 | } | 2180 | } |
| 2181 | } | ||
| 2182 | |||
| 2183 | void Application::updateMyAvatarSimulation(float deltaTime) { | ||
| 2184 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2185 | PerformanceWarning warn(showWarnings, "Application::updateMyAvatarSimulation()"); | ||
| 2123 | 2186 | ||
| 2124 | |||
| 2125 | //loop through all the other avatars and simulate them... | ||
| 2126 | updateAvatars(deltaTime, mouseRayOrigin, mouseRayDirection); | ||
| 2127 | |||
| 2128 | // Simulate myself | ||
| 2129 | if (Menu::getInstance()->isOptionChecked(MenuOption::Gravity)) { | 2187 | if (Menu::getInstance()->isOptionChecked(MenuOption::Gravity)) { |
| 2130 | _myAvatar.setGravity(_environment.getGravity(_myAvatar.getPosition())); | 2188 | _myAvatar.setGravity(_environment.getGravity(_myAvatar.getPosition())); |
| 2131 | } | 2189 | } |
| @@ -2138,12 +2196,21 @@ void Application::update(float deltaTime) { · 6 unmodified lines | |||
| 2138 | } else { | 2196 | } else { |
| 2139 | _myAvatar.simulate(deltaTime, NULL); | 2197 | _myAvatar.simulate(deltaTime, NULL); |
| 2140 | } | 2198 | } |
| 2141 | 2199 | } | |
| 2142 | // Simulate particle cloud movements | 2200 | |
| 2201 | void Application::updateParticles(float deltaTime) { | ||
| 2202 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2203 | PerformanceWarning warn(showWarnings, "Application::updateParticles()"); | ||
| 2204 | |||
| 2143 | if (Menu::getInstance()->isOptionChecked(MenuOption::ParticleCloud)) { | 2205 | if (Menu::getInstance()->isOptionChecked(MenuOption::ParticleCloud)) { |
| 2144 | _cloud.simulate(deltaTime); | 2206 | _cloud.simulate(deltaTime); |
| 2145 | } | 2207 | } |
| 2146 | 2208 | } | |
| 2209 | |||
| 2210 | void Application::updateTransmitter(float deltaTime) { | ||
| 2211 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2212 | PerformanceWarning warn(showWarnings, "Application::updateTransmitter()"); | ||
| 2213 | |||
| 2147 | // no transmitter drive implies transmitter pick | 2214 | // no transmitter drive implies transmitter pick |
| 2148 | if (!Menu::getInstance()->isOptionChecked(MenuOption::TransmitterDrive) && _myTransmitter.isConnected()) { | 2215 | if (!Menu::getInstance()->isOptionChecked(MenuOption::TransmitterDrive) && _myTransmitter.isConnected()) { |
| 2149 | _transmitterPickStart = _myAvatar.getSkeleton().joint[AVATAR_JOINT_CHEST].position; | 2216 | _transmitterPickStart = _myAvatar.getSkeleton().joint[AVATAR_JOINT_CHEST].position; |
| @@ -2178,7 +2245,12 @@ void Application::update(float deltaTime) { · 28 unmodified lines | |||
| 2178 | } else { | 2245 | } else { |
| 2179 | _transmitterPickStart = _transmitterPickEnd = glm::vec3(); | 2246 | _transmitterPickStart = _transmitterPickEnd = glm::vec3(); |
| 2180 | } | 2247 | } |
| 2181 | 2248 | } | |
| 2249 | |||
| 2250 | void Application::updateCamera(float deltaTime) { | ||
| 2251 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2252 | PerformanceWarning warn(showWarnings, "Application::updateCamera()"); | ||
| 2253 | |||
| 2182 | if (!OculusManager::isConnected()) { | 2254 | if (!OculusManager::isConnected()) { |
| 2183 | if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { | 2255 | if (Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) { |
| 2184 | if (_myCamera.getMode() != CAMERA_MODE_MIRROR) { | 2256 | if (_myCamera.getMode() != CAMERA_MODE_MIRROR) { |
| @@ -2213,7 +2285,12 @@ void Application::update(float deltaTime) { · 28 unmodified lines | |||
| 2213 | } | 2285 | } |
| 2214 | } | 2286 | } |
| 2215 | } | 2287 | } |
| 2216 | 2288 | } | |
| 2289 | |||
| 2290 | void Application::updateDialogs(float deltaTime) { | ||
| 2291 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2292 | PerformanceWarning warn(showWarnings, "Application::updateDialogs()"); | ||
| 2293 | |||
| 2217 | // Update bandwidth dialog, if any | 2294 | // Update bandwidth dialog, if any |
| 2218 | BandwidthDialog* bandwidthDialog = Menu::getInstance()->getBandwidthDialog(); | 2295 | BandwidthDialog* bandwidthDialog = Menu::getInstance()->getBandwidthDialog(); |
| 2219 | if (bandwidthDialog) { | 2296 | if (bandwidthDialog) { |
| @@ -2224,6 +2301,11 @@ void Application::update(float deltaTime) { · 4 unmodified lines | |||
| 2224 | if (voxelStatsDialog) { | 2301 | if (voxelStatsDialog) { |
| 2225 | voxelStatsDialog->update(); | 2302 | voxelStatsDialog->update(); |
| 2226 | } | 2303 | } |
| 2304 | } | ||
| 2305 | |||
| 2306 | void Application::updateAudio(float deltaTime) { | ||
| 2307 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2308 | PerformanceWarning warn(showWarnings, "Application::updateAudio()"); | ||
| 2227 | 2309 | ||
| 2228 | // Update audio stats for procedural sounds | 2310 | // Update audio stats for procedural sounds |
| 2229 | #ifndef _WIN32 | 2311 | #ifndef _WIN32 |
| @@ -2231,7 +2313,12 @@ void Application::update(float deltaTime) { · 1 unmodified line | |||
| 2231 | _audio.setLastVelocity(_myAvatar.getVelocity()); | 2313 | _audio.setLastVelocity(_myAvatar.getVelocity()); |
| 2232 | _audio.eventuallyAnalyzePing(); | 2314 | _audio.eventuallyAnalyzePing(); |
| 2233 | #endif | 2315 | #endif |
| 2234 | 2316 | } | |
| 2317 | |||
| 2318 | void Application::updateCursor(float deltaTime) { | ||
| 2319 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2320 | PerformanceWarning warn(showWarnings, "Application::updateCursor()"); | ||
| 2321 | |||
| 2235 | // watch mouse position, if it hasn't moved, hide the cursor | 2322 | // watch mouse position, if it hasn't moved, hide the cursor |
| 2236 | bool underMouse = _glWidget->underMouse(); | 2323 | bool underMouse = _glWidget->underMouse(); |
| 2237 | if (!_mouseHidden) { | 2324 | if (!_mouseHidden) { |
| @@ -2252,6 +2339,42 @@ void Application::update(float deltaTime) { · 14 unmodified lines | |||
| 2252 | } | 2339 | } |
| 2253 | } | 2340 | } |
| 2254 | 2341 | ||
| 2342 | void Application::update(float deltaTime) { | ||
| 2343 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | ||
| 2344 | PerformanceWarning warn(showWarnings, "Application::update()"); | ||
| 2345 | |||
| 2346 | // check what's under the mouse and update the mouse voxel | ||
| 2347 | glm::vec3 mouseRayOrigin, mouseRayDirection; | ||
| 2348 | updateMouseRay(deltaTime, mouseRayOrigin, mouseRayDirection); | ||
| 2349 | |||
| 2350 | // Set where I am looking based on my mouse ray (so that other people can see) | ||
| 2351 | glm::vec3 lookAtSpot; | ||
| 2352 | |||
| 2353 | updateFaceshift(); | ||
| 2354 | updateLookatTargetAvatar(mouseRayOrigin, mouseRayDirection, lookAtSpot); | ||
| 2355 | updateMyAvatarLookAtPosition(lookAtSpot, mouseRayOrigin, mouseRayDirection); | ||
| 2356 | |||
| 2357 | // Find the voxel we are hovering over, and respond if clicked | ||
| 2358 | float distance; | ||
| 2359 | BoxFace face; | ||
| 2360 | |||
| 2361 | updateHoverVoxels(deltaTime, mouseRayOrigin, mouseRayDirection, distance, face); // clicking on voxels and making sounds | ||
| 2362 | updateMouseVoxels(deltaTime, mouseRayOrigin, mouseRayDirection, distance, face); // UI/UX related to voxels | ||
| 2363 | updateHandAndTouch(deltaTime); // Update state for touch sensors | ||
| 2364 | updateLeap(deltaTime); // Leap finger-sensing device | ||
| 2365 | updateSerialDevices(deltaTime); // Read serial port interface devices | ||
| 2366 | updateAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes | ||
| 2367 | updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... | ||
| 2368 | updateAvatars(deltaTime, mouseRayOrigin, mouseRayDirection); //loop through all the other avatars and simulate them... | ||
| 2369 | updateMyAvatarSimulation(deltaTime); // Simulate myself | ||
| 2370 | updateParticles(deltaTime); // Simulate particle cloud movements | ||
| 2371 | updateTransmitter(deltaTime); // transmitter drive or pick | ||
| 2372 | updateCamera(deltaTime); // handle various camera tweaks like off axis projection | ||
| 2373 | updateDialogs(deltaTime); // update various stats dialogs if present | ||
| 2374 | updateAudio(deltaTime); // Update audio stats for procedural sounds | ||
| 2375 | updateCursor(deltaTime); // Handle cursor updates | ||
| 2376 | } | ||
| 2377 | |||
| 2255 | void Application::updateAvatar(float deltaTime) { | 2378 | void Application::updateAvatar(float deltaTime) { |
| 2256 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); | 2379 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 2257 | PerformanceWarning warn(showWarnings, "Application::updateAvatar()"); | 2380 | PerformanceWarning warn(showWarnings, "Application::updateAvatar()"); |
| @@ -2743,6 +2866,12 @@ void Application::setupWorldLight(Camera& whichCamera) { · 485 unmodified lines | |||
| 2743 | glMateriali(GL_FRONT, GL_SHININESS, 96); | 2866 | glMateriali(GL_FRONT, GL_SHININESS, 96); |
| 2744 | } | 2867 | } |
| 2745 | 2868 | ||
| 2869 | void Application::loadTranslatedViewMatrix(const glm::vec3& translation) { | ||
| 2870 | glLoadMatrixf((const GLfloat*)&_untranslatedViewMatrix); | ||
| 2871 | glTranslatef(translation.x + _viewMatrixTranslation.x, translation.y + _viewMatrixTranslation.y, | ||
| 2872 | translation.z + _viewMatrixTranslation.z); | ||
| 2873 | } | ||
| 2874 | |||
| 2746 | void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near, | 2875 | void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& near, |
| 2747 | float& far, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const { | 2876 | float& far, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const { |
| 2748 | 2877 | ||
| @@ -2776,7 +2905,11 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 27 unmodified lines | |||
| 2776 | glm::vec3 axis = glm::axis(rotation); | 2905 | glm::vec3 axis = glm::axis(rotation); |
| 2777 | glRotatef(-glm::angle(rotation), axis.x, axis.y, axis.z); | 2906 | glRotatef(-glm::angle(rotation), axis.x, axis.y, axis.z); |
| 2778 | 2907 | ||
| 2779 | glTranslatef(-whichCamera.getPosition().x, -whichCamera.getPosition().y, -whichCamera.getPosition().z); | 2908 | // store view matrix without translation, which we'll use for precision-sensitive objects |
| 2909 | glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix); | ||
| 2910 | _viewMatrixTranslation = -whichCamera.getPosition(); | ||
| 2911 | |||
| 2912 | glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z); | ||
| 2780 | 2913 | ||
| 2781 | // Setup 3D lights (after the camera transform, so that they are positioned in world space) | 2914 | // Setup 3D lights (after the camera transform, so that they are positioned in world space) |
| 2782 | setupWorldLight(whichCamera); | 2915 | setupWorldLight(whichCamera); |
| @@ -2934,10 +3067,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { · 151 unmodified lines | |||
| 2934 | if (!avatar->isInitialized()) { | 3067 | if (!avatar->isInitialized()) { |
| 2935 | avatar->init(); | 3068 | avatar->init(); |
| 2936 | } | 3069 | } |
| 2937 | // Set lookAt to myCamera on client side if other avatars are looking at client | ||
| 2938 | if (isLookingAtMyAvatar(avatar)) { | ||
| 2939 | avatar->getHead().setLookAtPosition(whichCamera.getPosition()); | ||
| 2940 | } | ||
| 2941 | avatar->render(false, Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)); | 3070 | avatar->render(false, Menu::getInstance()->isOptionChecked(MenuOption::AvatarAsBalls)); |
| 2942 | avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors)); | 3071 | avatar->setDisplayingLookatVectors(Menu::getInstance()->isOptionChecked(MenuOption::LookAtVectors)); |
| 2943 | } | 3072 | } |
| @@ -3258,6 +3387,8 @@ void Application::displayStats() { · 314 unmodified lines | |||
| 3258 | drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, avatarStats); | 3387 | drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, avatarStats); |
| 3259 | 3388 | ||
| 3260 | 3389 | ||
| 3390 | QLocale locale(QLocale::English); | ||
| 3391 | |||
| 3261 | std::stringstream voxelStats; | 3392 | std::stringstream voxelStats; |
| 3262 | voxelStats.precision(4); | 3393 | voxelStats.precision(4); |
| 3263 | voxelStats << "Voxels " << | 3394 | voxelStats << "Voxels " << |
| @@ -3289,9 +3420,9 @@ void Application::displayStats() { · 25 unmodified lines | |||
| 3289 | 3420 | ||
| 3290 | voxelStats.str(""); | 3421 | voxelStats.str(""); |
| 3291 | voxelStats << | 3422 | voxelStats << |
| 3292 | "Local Voxels Total: " << VoxelNode::getNodeCount() << ", " << | 3423 | "Local Voxels Total: " << localTotalString.toLocal8Bit().constData() << " / " << |
| 3293 | "Internal: " << VoxelNode::getInternalNodeCount() << " , " << | 3424 | "Internal: " << localInternalString.toLocal8Bit().constData() << " / " << |
| 3294 | "Leaves: " << VoxelNode::getLeafNodeCount() << ""; | 3425 | "Leaves: " << localLeavesString.toLocal8Bit().constData() << ""; |
| 3295 | statsVerticalOffset += PELS_PER_LINE; | 3426 | statsVerticalOffset += PELS_PER_LINE; |
| 3296 | drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)voxelStats.str().c_str()); | 3427 | drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)voxelStats.str().c_str()); |
| 3297 | 3428 | ||
| @@ -3360,7 +3491,28 @@ void Application::displayStats() { · 62 unmodified lines | |||
| 3360 | statsVerticalOffset += PELS_PER_LINE; | 3491 | statsVerticalOffset += PELS_PER_LINE; |
| 3361 | drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)voxelStats.str().c_str()); | 3492 | drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)voxelStats.str().c_str()); |
| 3362 | 3493 | ||
| 3363 | 3494 | voxelStats.str(""); | |
| 3495 | int voxelPacketsToProcess = _voxelProcessor.packetsToProcessCount(); | ||
| 3496 | QString packetsString = locale.toString((int)voxelPacketsToProcess); | ||
| 3497 | QString maxString = locale.toString((int)_recentMaxPackets); | ||
| 3498 | |||
| 3499 | voxelStats << "Voxel Packets to Process: " << packetsString.toLocal8Bit().constData() | ||
| 3500 | << " [Recent Max: " << maxString.toLocal8Bit().constData() << "]"; | ||
| 3501 | |||
| 3502 | if (_resetRecentMaxPacketsSoon && voxelPacketsToProcess > 0) { | ||
| 3503 | _recentMaxPackets = 0; | ||
| 3504 | _resetRecentMaxPacketsSoon = false; | ||
| 3505 | } | ||
| 3506 | if (voxelPacketsToProcess == 0) { | ||
| 3507 | _resetRecentMaxPacketsSoon = true; | ||
| 3508 | } else { | ||
| 3509 | if (voxelPacketsToProcess > _recentMaxPackets) { | ||
| 3510 | _recentMaxPackets = voxelPacketsToProcess; | ||
| 3511 | } | ||
| 3512 | } | ||
| 3513 | statsVerticalOffset += PELS_PER_LINE; | ||
| 3514 | drawtext(10, statsVerticalOffset, 0.10f, 0, 1.0, 0, (char*)voxelStats.str().c_str()); | ||
| 3515 | |||
| 3364 | Node *avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); | 3516 | Node *avatarMixer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); |
| 3365 | char avatarMixerStats[200]; | 3517 | char avatarMixerStats[200]; |
| 3366 | 3518 | ||