Unified · Split
| @@ -0,0 +1,22 @@ | |||
| 1 | <?xml version="1.0" encoding="utf-8"?> | ||
| 2 | <!-- Generator: Adobe Illustrator 17.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> | ||
| 3 | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> | ||
| 4 | <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" | ||
| 5 | width="152px" height="152px" viewBox="0 0 152 152" enable-background="new 0 0 152 152" xml:space="preserve"> | ||
| 6 | <path fill="#333333" d="M76,13.441C41.45,13.441,13.442,41.45,13.442,76S41.45,138.558,76,138.558S138.558,110.55,138.558,76 | ||
| 7 | S110.55,13.441,76,13.441z M76,107.279c-17.275,0-31.279-14.004-31.279-31.279S58.725,44.721,76,44.721S107.279,58.725,107.279,76 | ||
| 8 | S93.275,107.279,76,107.279z"/> | ||
| 9 | <g id="XMLID_46_"> | ||
| 10 | <g> | ||
| 11 | <path fill="#EAEAEA" d="M41.465,38.653c0.483-0.558-1.506-5.81-0.071-6.338c1.041-0.38,0.971,1.524,1.041,2.08 | ||
| 12 | c0.102,1.143,0.346,2.528,0.727,3.567c0.346-1.663,0.312-3.36,0.381-5.056c0.034-0.521,0.173-1.697,0.865-1.629 | ||
| 13 | c1.628,0.105-0.242,5.576,0.832,6.269c0.727-0.832,0.935-2.979,1.212-4.052c0.104-0.45,0.245-1.873,1.246-1.281 | ||
| 14 | c0.763,0.451,0.138,3.291-0.103,4.19c-0.244,0.935-0.244,1.592-0.521,2.667c-0.067,0.728-0.206,1.524,0.277,2.078 | ||
| 15 | c0.867,0,2.859-2.46,3.829-1.699c0.658,0.485,0.331,1.109-0.12,1.403c-3.326,2.149-2.808,4.815-4.402,5.126 | ||
| 16 | c0,2.73-0.165,2.833,0.11,5.551c-1.731,0.287-3.542,0.216-5.199,0.106c0-0.001,0-0.001,0-0.001 | ||
| 17 | c0.113-1.432,0.067-0.342,0.173-1.931c0.079-1.235,0.103-2.339,0.139-3.551l-0.036-0.138c-1.038-0.278-1.349-2.095-1.696-3.307 | ||
| 18 | c-0.38-1.318,0.069-2.495-0.416-3.775c-0.308-0.97-1.62-3.381-0.795-4.086c0.487-0.417,0.761-0.07,1.142,0.83 | ||
| 19 | C40.392,36.408,40.549,38.549,41.465,38.653z"/> | ||
| 20 | </g> | ||
| 21 | </g> | ||
| 22 | </svg> | ||
| @@ -852,6 +852,8 @@ void Application::mouseMoveEvent(QMouseEvent* event) { · 851 unmodified lines | |||
| 852 | deleteVoxelUnderCursor(); | 852 | deleteVoxelUnderCursor(); |
| 853 | } | 853 | } |
| 854 | } | 854 | } |
| 855 | |||
| 856 | _pieMenu.mouseMoveEvent(_mouseX, _mouseY); | ||
| 855 | } | 857 | } |
| 856 | } | 858 | } |
| 857 | 859 | ||
| @@ -869,7 +871,12 @@ void Application::mousePressEvent(QMouseEvent* event) { · 11 unmodified lines | |||
| 869 | _mouseDragStartedY = _mouseY; | 871 | _mouseDragStartedY = _mouseY; |
| 870 | _mouseVoxelDragging = _mouseVoxel; | 872 | _mouseVoxelDragging = _mouseVoxel; |
| 871 | _mousePressed = true; | 873 | _mousePressed = true; |
| 872 | maybeEditVoxelUnderCursor(); | 874 | |
| 875 | |||
| 876 | if (!maybeEditVoxelUnderCursor()) { | ||
| 877 | _pieMenu.mousePressEvent(_mouseX, _mouseY); | ||
| 878 | } | ||
| 879 | |||
| 873 | if (MAKE_SOUND_ON_VOXEL_CLICK && _isHoverVoxel && !_isHoverVoxelSounding) { | 880 | if (MAKE_SOUND_ON_VOXEL_CLICK && _isHoverVoxel && !_isHoverVoxelSounding) { |
| 874 | _hoverVoxelOriginalColor[0] = _hoverVoxel.red; | 881 | _hoverVoxelOriginalColor[0] = _hoverVoxel.red; |
| 875 | _hoverVoxelOriginalColor[1] = _hoverVoxel.green; | 882 | _hoverVoxelOriginalColor[1] = _hoverVoxel.green; |
| @@ -892,6 +899,8 @@ void Application::mouseReleaseEvent(QMouseEvent* event) { · 16 unmodified lines | |||
| 892 | _mouseY = event->y(); | 899 | _mouseY = event->y(); |
| 893 | _mousePressed = false; | 900 | _mousePressed = false; |
| 894 | checkBandwidthMeterClick(); | 901 | checkBandwidthMeterClick(); |
| 902 | |||
| 903 | _pieMenu.mouseReleaseEvent(_mouseX, _mouseY); | ||
| 895 | } | 904 | } |
| 896 | } | 905 | } |
| 897 | } | 906 | } |
| @@ -1383,6 +1392,10 @@ void Application::doFalseColorizeOccludedV2() { · 485 unmodified lines | |||
| 1383 | _voxels.falseColorizeOccludedV2(); | 1392 | _voxels.falseColorizeOccludedV2(); |
| 1384 | } | 1393 | } |
| 1385 | 1394 | ||
| 1395 | void Application::doFalseColorizeBySource() { | ||
| 1396 | _voxels.falseColorizeBySource(); | ||
| 1397 | } | ||
| 1398 | |||
| 1386 | void Application::doTrueVoxelColors() { | 1399 | void Application::doTrueVoxelColors() { |
| 1387 | _voxels.trueColorize(); | 1400 | _voxels.trueColorize(); |
| 1388 | } | 1401 | } |
| @@ -1804,6 +1817,7 @@ void Application::initMenu() { · 415 unmodified lines | |||
| 1804 | _testPing->setChecked(true); | 1817 | _testPing->setChecked(true); |
| 1805 | (_fullScreenMode = optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F))->setCheckable(true); | 1818 | (_fullScreenMode = optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F))->setCheckable(true); |
| 1806 | optionsMenu->addAction("Webcam", &_webcam, SLOT(setEnabled(bool)))->setCheckable(true); | 1819 | optionsMenu->addAction("Webcam", &_webcam, SLOT(setEnabled(bool)))->setCheckable(true); |
| 1820 | optionsMenu->addAction("Toggle Skeleton Tracking", &_webcam, SLOT(setSkeletonTrackingOn(bool)))->setCheckable(true); | ||
| 1807 | optionsMenu->addAction("Cycle Webcam Send Mode", _webcam.getGrabber(), SLOT(cycleVideoSendMode())); | 1821 | optionsMenu->addAction("Cycle Webcam Send Mode", _webcam.getGrabber(), SLOT(cycleVideoSendMode())); |
| 1808 | optionsMenu->addAction("Go Home", this, SLOT(goHome())); | 1822 | optionsMenu->addAction("Go Home", this, SLOT(goHome())); |
| 1809 | 1823 | ||
| @@ -1832,7 +1846,6 @@ void Application::initMenu() { · 22 unmodified lines | |||
| 1832 | (_renderLookatIndicatorOn = renderMenu->addAction("Lookat Indicator"))->setCheckable(true); | 1846 | (_renderLookatIndicatorOn = renderMenu->addAction("Lookat Indicator"))->setCheckable(true); |
| 1833 | _renderLookatIndicatorOn->setChecked(true); | 1847 | _renderLookatIndicatorOn->setChecked(true); |
| 1834 | (_renderParticleSystemOn = renderMenu->addAction("Particle System"))->setCheckable(true); | 1848 | (_renderParticleSystemOn = renderMenu->addAction("Particle System"))->setCheckable(true); |
| 1835 | _renderParticleSystemOn->setChecked(true); | ||
| 1836 | (_manualFirstPerson = renderMenu->addAction( | 1849 | (_manualFirstPerson = renderMenu->addAction( |
| 1837 | "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true); | 1850 | "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true); |
| 1838 | (_manualThirdPerson = renderMenu->addAction( | 1851 | (_manualThirdPerson = renderMenu->addAction( |
| @@ -1919,6 +1932,7 @@ void Application::initMenu() { · 80 unmodified lines | |||
| 1919 | renderDebugMenu->addAction("FALSE Color Voxel Out of View", this, SLOT(doFalseColorizeInView())); | 1932 | renderDebugMenu->addAction("FALSE Color Voxel Out of View", this, SLOT(doFalseColorizeInView())); |
| 1920 | renderDebugMenu->addAction("FALSE Color Occluded Voxels", this, SLOT(doFalseColorizeOccluded()), Qt::CTRL | Qt::Key_O); | 1933 | renderDebugMenu->addAction("FALSE Color Occluded Voxels", this, SLOT(doFalseColorizeOccluded()), Qt::CTRL | Qt::Key_O); |
| 1921 | renderDebugMenu->addAction("FALSE Color Occluded V2 Voxels", this, SLOT(doFalseColorizeOccludedV2()), Qt::CTRL | Qt::Key_P); | 1934 | renderDebugMenu->addAction("FALSE Color Occluded V2 Voxels", this, SLOT(doFalseColorizeOccludedV2()), Qt::CTRL | Qt::Key_P); |
| 1935 | renderDebugMenu->addAction("FALSE Color By Source", this, SLOT(doFalseColorizeBySource()), Qt::CTRL | Qt::SHIFT | Qt::Key_S); | ||
| 1922 | renderDebugMenu->addAction("Show TRUE Colors", this, SLOT(doTrueVoxelColors()), Qt::CTRL | Qt::Key_T); | 1936 | renderDebugMenu->addAction("Show TRUE Colors", this, SLOT(doTrueVoxelColors()), Qt::CTRL | Qt::Key_T); |
| 1923 | 1937 | ||
| 1924 | (_shouldLowPassFilter = debugMenu->addAction("Test: LowPass filter"))->setCheckable(true); | 1938 | (_shouldLowPassFilter = debugMenu->addAction("Test: LowPass filter"))->setCheckable(true); |
| @@ -2057,7 +2071,15 @@ void Application::init() { · 132 unmodified lines | |||
| 2057 | _palette.addTool(&_swatch); | 2071 | _palette.addTool(&_swatch); |
| 2058 | _palette.addAction(_colorVoxelMode, 0, 2); | 2072 | _palette.addAction(_colorVoxelMode, 0, 2); |
| 2059 | _palette.addAction(_eyedropperMode, 0, 3); | 2073 | _palette.addAction(_eyedropperMode, 0, 3); |
| 2060 | _palette.addAction(_selectVoxelMode, 0, 4); | 2074 | _palette.addAction(_selectVoxelMode, 0, 4); |
| 2075 | |||
| 2076 | _pieMenu.init("./resources/images/hifi-interface-tools-v2-pie.svg", | ||
| 2077 | _glWidget->width(), | ||
| 2078 | _glWidget->height()); | ||
| 2079 | |||
| 2080 | _followMode = new QAction(this); | ||
| 2081 | connect(_followMode, SIGNAL(triggered()), this, SLOT(toggleFollowMode())); | ||
| 2082 | _pieMenu.addAction(_followMode); | ||
| 2061 | } | 2083 | } |
| 2062 | 2084 | ||
| 2063 | 2085 | ||
| @@ -2069,7 +2091,7 @@ const float HEAD_SPHERE_RADIUS = 0.07; · 5 unmodified lines | |||
| 2069 | static uint16_t DEFAULT_NODE_ID_REF = 1; | 2091 | static uint16_t DEFAULT_NODE_ID_REF = 1; |
| 2070 | 2092 | ||
| 2071 | 2093 | ||
| 2072 | bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, | 2094 | Avatar* Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, |
| 2073 | glm::vec3& eyePosition, uint16_t& nodeID = DEFAULT_NODE_ID_REF) { | 2095 | glm::vec3& eyePosition, uint16_t& nodeID = DEFAULT_NODE_ID_REF) { |
| 2074 | 2096 | ||
| 2075 | NodeList* nodeList = NodeList::getInstance(); | 2097 | NodeList* nodeList = NodeList::getInstance(); |
| @@ -2082,11 +2104,11 @@ bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& m · 6 unmodified lines | |||
| 2082 | _lookatIndicatorScale = avatar->getScale(); | 2104 | _lookatIndicatorScale = avatar->getScale(); |
| 2083 | _lookatOtherPosition = headPosition; | 2105 | _lookatOtherPosition = headPosition; |
| 2084 | nodeID = avatar->getOwningNode()->getNodeID(); | 2106 | nodeID = avatar->getOwningNode()->getNodeID(); |
| 2085 | return true; | 2107 | return avatar; |
| 2086 | } | 2108 | } |
| 2087 | } | 2109 | } |
| 2088 | } | 2110 | } |
| 2089 | return false; | 2111 | return NULL; |
| 2090 | } | 2112 | } |
| 2091 | 2113 | ||
| 2092 | void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera) { | 2114 | void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera) { |
| @@ -2101,6 +2123,7 @@ void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& which · 8 unmodified lines | |||
| 2101 | } | 2123 | } |
| 2102 | 2124 | ||
| 2103 | void Application::update(float deltaTime) { | 2125 | void Application::update(float deltaTime) { |
| 2126 | |||
| 2104 | // Use Transmitter Hand to move hand if connected, else use mouse | 2127 | // Use Transmitter Hand to move hand if connected, else use mouse |
| 2105 | if (_myTransmitter.isConnected()) { | 2128 | if (_myTransmitter.isConnected()) { |
| 2106 | const float HAND_FORCE_SCALING = 0.01f; | 2129 | const float HAND_FORCE_SCALING = 0.01f; |
| @@ -2997,6 +3020,10 @@ void Application::displayOverlay() { · 890 unmodified lines | |||
| 2997 | _swatch.checkColor(); | 3020 | _swatch.checkColor(); |
| 2998 | } | 3021 | } |
| 2999 | 3022 | ||
| 3023 | if (_pieMenu.isDisplayed()) { | ||
| 3024 | _pieMenu.render(); | ||
| 3025 | } | ||
| 3026 | |||
| 3000 | glPopMatrix(); | 3027 | glPopMatrix(); |
| 3001 | } | 3028 | } |
| 3002 | 3029 | ||
| @@ -3009,19 +3036,35 @@ void Application::displayStats() { · 6 unmodified lines | |||
| 3009 | drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats); | 3036 | drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats); |
| 3010 | 3037 | ||
| 3011 | if (_testPing->isChecked()) { | 3038 | if (_testPing->isChecked()) { |
| 3012 | int pingAudio = 0, pingAvatar = 0, pingVoxel = 0; | 3039 | int pingAudio = 0, pingAvatar = 0, pingVoxel = 0, pingVoxelMax = 0; |
| 3013 | 3040 | ||
| 3014 | NodeList *nodeList = NodeList::getInstance(); | 3041 | NodeList* nodeList = NodeList::getInstance(); |
| 3015 | Node *audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER); | 3042 | Node* audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER); |
| 3016 | Node *avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); | 3043 | Node* avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER); |
| 3017 | Node *voxelServerNode = nodeList->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); | ||
| 3018 | 3044 | ||
| 3019 | pingAudio = audioMixerNode ? audioMixerNode->getPingMs() : 0; | 3045 | pingAudio = audioMixerNode ? audioMixerNode->getPingMs() : 0; |
| 3020 | pingAvatar = avatarMixerNode ? avatarMixerNode->getPingMs() : 0; | 3046 | pingAvatar = avatarMixerNode ? avatarMixerNode->getPingMs() : 0; |
| 3021 | pingVoxel = voxelServerNode ? voxelServerNode->getPingMs() : 0; | 3047 | |
| 3048 | |||
| 3049 | // Now handle voxel servers, since there could be more than one, we average their ping times | ||
| 3050 | unsigned long totalPingVoxel = 0; | ||
| 3051 | int voxelServerCount = 0; | ||
| 3052 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | ||
| 3053 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { | ||
| 3054 | totalPingVoxel += node->getPingMs(); | ||
| 3055 | voxelServerCount++; | ||
| 3056 | if (pingVoxelMax < node->getPingMs()) { | ||
| 3057 | pingVoxelMax = node->getPingMs(); | ||
| 3058 | } | ||
| 3059 | } | ||
| 3060 | } | ||
| 3061 | if (voxelServerCount) { | ||
| 3062 | pingVoxel = totalPingVoxel/voxelServerCount; | ||
| 3063 | } | ||
| 3064 | |||
| 3022 | 3065 | ||
| 3023 | char pingStats[200]; | 3066 | char pingStats[200]; |
| 3024 | sprintf(pingStats, "Ping audio/avatar/voxel: %d / %d / %d ", pingAudio, pingAvatar, pingVoxel); | 3067 | sprintf(pingStats, "Ping audio/avatar/voxel: %d / %d / %d avg %d max ", pingAudio, pingAvatar, pingVoxel, pingVoxelMax); |
| 3025 | drawtext(10, statsVerticalOffset + 35, 0.10f, 0, 1.0, 0, pingStats); | 3068 | drawtext(10, statsVerticalOffset + 35, 0.10f, 0, 1.0, 0, pingStats); |
| 3026 | } | 3069 | } |
| 3027 | 3070 | ||
| @@ -3396,7 +3439,7 @@ void Application::shiftPaintingColor() { · 368 unmodified lines | |||
| 3396 | } | 3439 | } |
| 3397 | 3440 | ||
| 3398 | 3441 | ||
| 3399 | void Application::maybeEditVoxelUnderCursor() { | 3442 | bool Application::maybeEditVoxelUnderCursor() { |
| 3400 | if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) { | 3443 | if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) { |
| 3401 | if (_mouseVoxel.s != 0) { | 3444 | if (_mouseVoxel.s != 0) { |
| 3402 | PACKET_TYPE message = (_destructiveAddVoxel->isChecked() ? | 3445 | PACKET_TYPE message = (_destructiveAddVoxel->isChecked() ? |
| @@ -3467,7 +3510,11 @@ void Application::maybeEditVoxelUnderCursor() { · 64 unmodified lines | |||
| 3467 | deleteVoxelUnderCursor(); | 3510 | deleteVoxelUnderCursor(); |
| 3468 | } else if (_eyedropperMode->isChecked()) { | 3511 | } else if (_eyedropperMode->isChecked()) { |
| 3469 | eyedropperVoxelUnderCursor(); | 3512 | eyedropperVoxelUnderCursor(); |
| 3513 | } else { | ||
| 3514 | return false; | ||
| 3470 | } | 3515 | } |
| 3516 | |||
| 3517 | return true; | ||
| 3471 | } | 3518 | } |
| 3472 | 3519 | ||
| 3473 | void Application::deleteVoxelUnderCursor() { | 3520 | void Application::deleteVoxelUnderCursor() { |
| @@ -3510,6 +3557,22 @@ void Application::goHome() { · 36 unmodified lines | |||
| 3510 | _myAvatar.setPosition(START_LOCATION); | 3557 | _myAvatar.setPosition(START_LOCATION); |
| 3511 | } | 3558 | } |
| 3512 | 3559 | ||
| 3560 | |||
| 3561 | void Application::toggleFollowMode() { | ||
| 3562 | glm::vec3 mouseRayOrigin, mouseRayDirection; | ||
| 3563 | _viewFrustum.computePickRay(_pieMenu.getX() / (float)_glWidget->width(), | ||
| 3564 | _pieMenu.getY() / (float)_glWidget->height(), | ||
| 3565 | mouseRayOrigin, mouseRayDirection); | ||
| 3566 | glm::vec3 eyePositionIgnored; | ||
| 3567 | uint16_t nodeIDIgnored; | ||
| 3568 | Avatar* leadingAvatar = isLookingAtOtherAvatar(mouseRayOrigin, | ||
| 3569 | mouseRayDirection, | ||
| 3570 | eyePositionIgnored, | ||
| 3571 | nodeIDIgnored); | ||
| 3572 | |||
| 3573 | _myAvatar.follow(leadingAvatar); | ||
| 3574 | } | ||
| 3575 | |||
| 3513 | void Application::resetSensors() { | 3576 | void Application::resetSensors() { |
| 3514 | _headMouseX = _mouseX = _glWidget->width() / 2; | 3577 | _headMouseX = _mouseX = _glWidget->width() / 2; |
| 3515 | _headMouseY = _mouseY = _glWidget->height() / 2; | 3578 | _headMouseY = _mouseY = _glWidget->height() / 2; |
| @@ -3622,13 +3685,15 @@ void* Application::networkReceive(void* args) { · 106 unmodified lines | |||
| 3622 | } // fall through to piggyback message | 3685 | } // fall through to piggyback message |
| 3623 | 3686 | ||
| 3624 | if (app->_renderVoxels->isChecked()) { | 3687 | if (app->_renderVoxels->isChecked()) { |
| 3625 | Node* voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER); | 3688 | Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress); |
| 3626 | if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) { | 3689 | if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) { |
| 3627 | voxelServer->lock(); | 3690 | voxelServer->lock(); |
| 3628 | if (messageData[0] == PACKET_TYPE_ENVIRONMENT_DATA) { | 3691 | if (messageData[0] == PACKET_TYPE_ENVIRONMENT_DATA) { |
| 3629 | app->_environment.parseData(&senderAddress, messageData, messageLength); | 3692 | app->_environment.parseData(&senderAddress, messageData, messageLength); |
| 3630 | } else { | 3693 | } else { |
| 3694 | app->_voxels.setDataSourceID(voxelServer->getNodeID()); | ||
| 3631 | app->_voxels.parseData(messageData, messageLength); | 3695 | app->_voxels.parseData(messageData, messageLength); |
| 3696 | app->_voxels.setDataSourceID(UNKNOWN_NODE_ID); | ||
| 3632 | } | 3697 | } |
| 3633 | voxelServer->unlock(); | 3698 | voxelServer->unlock(); |
| 3634 | } | 3699 | } |
| @@ -39,6 +39,7 @@ · 38 unmodified lines | |||
| 39 | #include "ViewFrustum.h" | 39 | #include "ViewFrustum.h" |
| 40 | #include "VoxelSystem.h" | 40 | #include "VoxelSystem.h" |
| 41 | #include "Webcam.h" | 41 | #include "Webcam.h" |
| 42 | #include "PieMenu.h" | ||
| 42 | #include "avatar/Avatar.h" | 43 | #include "avatar/Avatar.h" |
| 43 | #include "avatar/HandControl.h" | 44 | #include "avatar/HandControl.h" |
| 44 | #include "ui/BandwidthDialog.h" | 45 | #include "ui/BandwidthDialog.h" |
| @@ -149,6 +150,7 @@ private slots: · 104 unmodified lines | |||
| 149 | void doFalseColorizeByDistance(); | 150 | void doFalseColorizeByDistance(); |
| 150 | void doFalseColorizeOccluded(); | 151 | void doFalseColorizeOccluded(); |
| 151 | void doFalseColorizeOccludedV2(); | 152 | void doFalseColorizeOccludedV2(); |
| 153 | void doFalseColorizeBySource(); | ||
| 152 | void doFalseColorizeInView(); | 154 | void doFalseColorizeInView(); |
| 153 | void doTrueVoxelColors(); | 155 | void doTrueVoxelColors(); |
| 154 | void doTreeStats(); | 156 | void doTreeStats(); |
| @@ -186,6 +188,8 @@ private slots: · 31 unmodified lines | |||
| 186 | glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint); | 188 | glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint); |
| 187 | void goHome(); | 189 | void goHome(); |
| 188 | 190 | ||
| 191 | void toggleFollowMode(); | ||
| 192 | |||
| 189 | private: | 193 | private: |
| 190 | 194 | ||
| 191 | static void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, | 195 | static void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes, |
| @@ -205,7 +209,7 @@ private: · 13 unmodified lines | |||
| 205 | void init(); | 209 | void init(); |
| 206 | 210 | ||
| 207 | void update(float deltaTime); | 211 | void update(float deltaTime); |
| 208 | bool isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, | 212 | Avatar* isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, |
| 209 | glm::vec3& eyePosition, uint16_t& nodeID); | 213 | glm::vec3& eyePosition, uint16_t& nodeID); |
| 210 | 214 | ||
| 211 | void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera); | 215 | void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera); |
| @@ -222,7 +226,7 @@ private: · 10 unmodified lines | |||
| 222 | 226 | ||
| 223 | void setupPaintingVoxel(); | 227 | void setupPaintingVoxel(); |
| 224 | void shiftPaintingColor(); | 228 | void shiftPaintingColor(); |
| 225 | void maybeEditVoxelUnderCursor(); | 229 | bool maybeEditVoxelUnderCursor(); |
| 226 | void deleteVoxelUnderCursor(); | 230 | void deleteVoxelUnderCursor(); |
| 227 | void eyedropperVoxelUnderCursor(); | 231 | void eyedropperVoxelUnderCursor(); |
| 228 | void resetSensors(); | 232 | void resetSensors(); |
| @@ -290,6 +294,8 @@ private: · 61 unmodified lines | |||
| 290 | 294 | ||
| 291 | QAction* _simulateLeapHand; // When there's no Leap, use this to pretend there is one and feed fake hand data | 295 | QAction* _simulateLeapHand; // When there's no Leap, use this to pretend there is one and feed fake hand data |
| 292 | QAction* _testRaveGlove; // Test fancy sparkle-rave-glove mode | 296 | QAction* _testRaveGlove; // Test fancy sparkle-rave-glove mode |
| 297 | |||
| 298 | QAction* _followMode; | ||
| 293 | 299 | ||
| 294 | BandwidthMeter _bandwidthMeter; | 300 | BandwidthMeter _bandwidthMeter; |
| 295 | BandwidthDialog* _bandwidthDialog; | 301 | BandwidthDialog* _bandwidthDialog; |
| @@ -429,6 +435,8 @@ private: · 133 unmodified lines | |||
| 429 | 435 | ||
| 430 | ToolsPalette _palette; | 436 | ToolsPalette _palette; |
| 431 | Swatch _swatch; | 437 | Swatch _swatch; |
| 438 | |||
| 439 | PieMenu _pieMenu; | ||
| 432 | 440 | ||
| 433 | VoxelSceneStats _voxelSceneStats; | 441 | VoxelSceneStats _voxelSceneStats; |
| 434 | }; | 442 | }; |
| @@ -27,6 +27,7 @@ ParticleSystem::ParticleSystem() { · 26 unmodified lines | |||
| 27 | for (unsigned int emitterIndex = 0; emitterIndex < MAX_EMITTERS; emitterIndex++) { | 27 | for (unsigned int emitterIndex = 0; emitterIndex < MAX_EMITTERS; emitterIndex++) { |
| 28 | 28 | ||
| 29 | Emitter * e = &_emitter[emitterIndex]; | 29 | Emitter * e = &_emitter[emitterIndex]; |
| 30 | e->active = false; | ||
| 30 | e->position = glm::vec3(0.0f, 0.0f, 0.0f); | 31 | e->position = glm::vec3(0.0f, 0.0f, 0.0f); |
| 31 | e->previousPosition = glm::vec3(0.0f, 0.0f, 0.0f); | 32 | e->previousPosition = glm::vec3(0.0f, 0.0f, 0.0f); |
| 32 | e->direction = glm::vec3(0.0f, 1.0f, 0.0f); | 33 | e->direction = glm::vec3(0.0f, 1.0f, 0.0f); |
| @@ -72,25 +73,16 @@ void ParticleSystem::simulate(float deltaTime) { · 39 unmodified lines | |||
| 72 | 73 | ||
| 73 | _timer += deltaTime; | 74 | _timer += deltaTime; |
| 74 | 75 | ||
| 75 | // emit particles | 76 | // update emitters |
| 76 | for (int e = 0; e < _numEmitters; e++) { | 77 | for (int emitterIndex = 0; emitterIndex < _numEmitters; emitterIndex++) { |
| 77 | 78 | assert(emitterIndex <= MAX_EMITTERS); | |
| 78 | assert(e >= 0); | ||
| 79 | assert(e <= MAX_EMITTERS); | ||
| 80 | assert(_emitter[e].rate >= 0); | ||
| 81 | 79 | ||
| 82 | _emitter[e].emitReserve += _emitter[e].rate * deltaTime; | 80 | if (_emitter[emitterIndex].active) { |
| 83 | _emitter[e].numParticlesEmittedThisTime = (int)_emitter[e].emitReserve; | 81 | updateEmitter(emitterIndex, deltaTime); |
| 84 | _emitter[e].emitReserve -= _emitter[e].numParticlesEmittedThisTime; | ||
| 85 | |||
| 86 | for (int p = 0; p < _emitter[e].numParticlesEmittedThisTime; p++) { | ||
| 87 | float timeFraction = (float)p / (float)_emitter[e].numParticlesEmittedThisTime; | ||
| 88 | createParticle(e, timeFraction); | ||
| 89 | } | 82 | } |
| 90 | } | 83 | } |
| 91 | |||
| 92 | // update particles | ||
| 93 | 84 | ||
| 85 | // update particles | ||
| 94 | for (int p = 0; p < MAX_PARTICLES; p++) { | 86 | for (int p = 0; p < MAX_PARTICLES; p++) { |
| 95 | if (_particle[p].alive) { | 87 | if (_particle[p].alive) { |
| 96 | if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) { | 88 | if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) { |
| @@ -102,6 +94,20 @@ void ParticleSystem::simulate(float deltaTime) { · 5 unmodified lines | |||
| 102 | } | 94 | } |
| 103 | } | 95 | } |
| 104 | 96 | ||
| 97 | |||
| 98 | void ParticleSystem::updateEmitter(int emitterIndex, float deltaTime) { | ||
| 99 | |||
| 100 | _emitter[emitterIndex].emitReserve += _emitter[emitterIndex].rate * deltaTime; | ||
| 101 | _emitter[emitterIndex].numParticlesEmittedThisTime = (int)_emitter[emitterIndex].emitReserve; | ||
| 102 | _emitter[emitterIndex].emitReserve -= _emitter[emitterIndex].numParticlesEmittedThisTime; | ||
| 103 | |||
| 104 | for (int p = 0; p < _emitter[emitterIndex].numParticlesEmittedThisTime; p++) { | ||
| 105 | float timeFraction = (float)p / (float)_emitter[emitterIndex].numParticlesEmittedThisTime; | ||
| 106 | createParticle(emitterIndex, timeFraction); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | |||
| 105 | void ParticleSystem::createParticle(int e, float timeFraction) { | 111 | void ParticleSystem::createParticle(int e, float timeFraction) { |
| 106 | 112 | ||
| 107 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { | 113 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { |
| @@ -212,7 +218,6 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleLifeStage l · 104 unmodified lines | |||
| 212 | } | 218 | } |
| 213 | 219 | ||
| 214 | 220 | ||
| 215 | |||
| 216 | void ParticleSystem::updateParticle(int p, float deltaTime) { | 221 | void ParticleSystem::updateParticle(int p, float deltaTime) { |
| 217 | 222 | ||
| 218 | Emitter myEmitter = _emitter[_particle[p].emitterIndex]; | 223 | Emitter myEmitter = _emitter[_particle[p].emitterIndex]; |
| @@ -363,14 +368,16 @@ void ParticleSystem::killAllParticles() { · 144 unmodified lines | |||
| 363 | void ParticleSystem::render() { | 368 | void ParticleSystem::render() { |
| 364 | 369 | ||
| 365 | // render the emitters | 370 | // render the emitters |
| 366 | for (int e = 0; e < _numEmitters; e++) { | 371 | for (int e = 0; e < MAX_EMITTERS; e++) { |
| 367 | 372 | ||
| 368 | if (_emitter[e].showingBaseParticle) { | 373 | if (_emitter[e].active) { |
| 369 | glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a); | 374 | if (_emitter[e].showingBaseParticle) { |
| 370 | glPushMatrix(); | 375 | glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a); |
| 371 | glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z); | 376 | glPushMatrix(); |
| 372 | glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution); | 377 | glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z); |
| 373 | glPopMatrix(); | 378 | glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution); |
| 379 | glPopMatrix(); | ||
| 380 | } | ||
| 374 | } | 381 | } |
| 375 | 382 | ||
| 376 | if (_emitter[e].visible) { | 383 | if (_emitter[e].visible) { |
| @@ -10,10 +10,10 @@ · 9 unmodified lines | |||
| 10 | 10 | ||
| 11 | #include <glm/gtc/quaternion.hpp> | 11 | #include <glm/gtc/quaternion.hpp> |
| 12 | 12 | ||
| 13 | const int MAX_PARTICLES = 5000; | ||
| 14 | const int NULL_EMITTER = -1; | 13 | const int NULL_EMITTER = -1; |
| 15 | const int NULL_PARTICLE = -1; | 14 | const int NULL_PARTICLE = -1; |
| 16 | const int MAX_EMITTERS = 100; | 15 | const int MAX_EMITTERS = 100; |
| 16 | const int MAX_PARTICLES = 5000; | ||
| 17 | 17 | ||
| 18 | enum ParticleRenderStyle | 18 | enum ParticleRenderStyle |
| 19 | { | 19 | { |
| @@ -78,6 +78,7 @@ public: · 58 unmodified lines | |||
| 78 | void setParticleAttributes (int emitterIndex, ParticleAttributes attributes); // set attributes for whole life of particles | 78 | void setParticleAttributes (int emitterIndex, ParticleAttributes attributes); // set attributes for whole life of particles |
| 79 | void setParticleAttributes (int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes); // set attributes for this life stage | 79 | void setParticleAttributes (int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes); // set attributes for this life stage |
| 80 | void setEmitterPosition (int emitterIndex, glm::vec3 position ); | 80 | void setEmitterPosition (int emitterIndex, glm::vec3 position ); |
| 81 | void setEmitterActive (int emitterIndex, bool active ) {_emitter[emitterIndex].active = active; } | ||
| 81 | void setEmitterParticleResolution (int emitterIndex, int resolution ) {_emitter[emitterIndex].particleResolution = resolution; } | 82 | void setEmitterParticleResolution (int emitterIndex, int resolution ) {_emitter[emitterIndex].particleResolution = resolution; } |
| 82 | void setEmitterDirection (int emitterIndex, glm::vec3 direction ) {_emitter[emitterIndex].direction = direction; } | 83 | void setEmitterDirection (int emitterIndex, glm::vec3 direction ) {_emitter[emitterIndex].direction = direction; } |
| 83 | void setShowingEmitter (int emitterIndex, bool showing ) {_emitter[emitterIndex].visible = showing; } | 84 | void setShowingEmitter (int emitterIndex, bool showing ) {_emitter[emitterIndex].visible = showing; } |
| @@ -101,6 +102,7 @@ private: · 17 unmodified lines | |||
| 101 | }; | 102 | }; |
| 102 | 103 | ||
| 103 | struct Emitter { | 104 | struct Emitter { |
| 105 | bool active; // if false, the emitter is disabled - allows for easy switching on and off | ||
| 104 | glm::vec3 position; // the position of the emitter in world coordinates | 106 | glm::vec3 position; // the position of the emitter in world coordinates |
| 105 | glm::vec3 previousPosition; // the position of the emitter in the previous time step | 107 | glm::vec3 previousPosition; // the position of the emitter in the previous time step |
| 106 | glm::vec3 direction; // a normalized vector used as an axis for particle emission and other effects | 108 | glm::vec3 direction; // a normalized vector used as an axis for particle emission and other effects |
| @@ -124,6 +126,7 @@ private: · 17 unmodified lines | |||
| 124 | float _timer; | 126 | float _timer; |
| 125 | 127 | ||
| 126 | // private methods | 128 | // private methods |
| 129 | void updateEmitter(int emitterIndex, float deltaTime); | ||
| 127 | void updateParticle(int index, float deltaTime); | 130 | void updateParticle(int index, float deltaTime); |
| 128 | void createParticle(int e, float timeFraction); | 131 | void createParticle(int e, float timeFraction); |
| 129 | void killParticle(int p); | 132 | void killParticle(int p); |
| @@ -0,0 +1,138 @@ | |||
| 1 | // | ||
| 2 | // PieMenu.cpp | ||
| 3 | // hifi | ||
| 4 | // | ||
| 5 | // Created by Clement Brisset on 7/18/13. | ||
| 6 | // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #include "PieMenu.h" | ||
| 10 | |||
| 11 | #include <cmath> | ||
| 12 | |||
| 13 | #include <QAction> | ||
| 14 | #include <QSvgRenderer> | ||
| 15 | #include <QPainter> | ||
| 16 | #include <QGLWidget> | ||
| 17 | #include <SharedUtil.h> | ||
| 18 | |||
| 19 | PieMenu::PieMenu() : | ||
| 20 | _radiusIntern(30), | ||
| 21 | _radiusExtern(70), | ||
| 22 | _magnification(1.2f), | ||
| 23 | _isDisplayed(false) { | ||
| 24 | } | ||
| 25 | |||
| 26 | void PieMenu::init(const char *fileName, int screenWidth, int screenHeight) { | ||
| 27 | // Load SVG | ||
| 28 | switchToResourcesParentIfRequired(); | ||
| 29 | QSvgRenderer renderer((QString) QString(fileName)); | ||
| 30 | |||
| 31 | // Prepare a QImage with desired characteritisc | ||
| 32 | QImage image(2 * _radiusExtern, 2 * _radiusExtern, QImage::Format_ARGB32); | ||
| 33 | image.fill(0x0); | ||
| 34 | |||
| 35 | // Get QPainter that paints to the image | ||
| 36 | QPainter painter(&image); | ||
| 37 | renderer.render(&painter); | ||
| 38 | |||
| 39 | //get the OpenGL-friendly image | ||
| 40 | _textureImage = QGLWidget::convertToGLFormat(image); | ||
| 41 | |||
| 42 | glGenTextures(1, &_textureID); | ||
| 43 | glBindTexture(GL_TEXTURE_2D, _textureID); | ||
| 44 | |||
| 45 | //generate the texture | ||
| 46 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, | ||
| 47 | _textureImage.width(), | ||
| 48 | _textureImage.height(), | ||
| 49 | 0, GL_RGBA, GL_UNSIGNED_BYTE, | ||
| 50 | _textureImage.bits()); | ||
| 51 | |||
| 52 | //texture parameters | ||
| 53 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
| 54 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
| 55 | } | ||
| 56 | |||
| 57 | void PieMenu::addAction(QAction* action){ | ||
| 58 | _actions.push_back(action); | ||
| 59 | } | ||
| 60 | |||
| 61 | void PieMenu::render() { | ||
| 62 | if (_actions.size() == 0) { | ||
| 63 | return; | ||
| 64 | } | ||
| 65 | |||
| 66 | float start = M_PI / 2.0f; | ||
| 67 | float end = start + 2.0f * M_PI; | ||
| 68 | float step = 2.0f * M_PI / 100.0f; | ||
| 69 | float distance = sqrt((_mouseX - _x) * (_mouseX - _x) + | ||
| 70 | (_mouseY - _y) * (_mouseY - _y)); | ||
| 71 | |||
| 72 | glEnable(GL_TEXTURE_2D); | ||
| 73 | glBindTexture(GL_TEXTURE_2D, _textureID); | ||
| 74 | |||
| 75 | glColor3f(1.0f, 1.0f, 1.0f); | ||
| 76 | |||
| 77 | if (_radiusIntern < distance) { | ||
| 78 | float angle = atan2((_mouseY - _y), (_mouseX - _x)) - start; | ||
| 79 | angle = (0.0f < angle) ? angle : angle + 2.0f * M_PI; | ||
| 80 | |||
| 81 | _selectedAction = floor(angle / (2.0f * M_PI / _actions.size())); | ||
| 82 | |||
| 83 | start = start + _selectedAction * 2.0f * M_PI / _actions.size(); | ||
| 84 | end = start + 2.0f * M_PI / _actions.size(); | ||
| 85 | glBegin(GL_TRIANGLE_FAN); | ||
| 86 | glTexCoord2f(0.5f, 0.5f); | ||
| 87 | glVertex2f(_x, _y); | ||
| 88 | for (float i = start; i < end; i += step) { | ||
| 89 | glTexCoord2f(0.5f + 0.5f * cos(i), 0.5f - 0.5f * sin(i)); | ||
| 90 | glVertex2f(_x + _magnification * _radiusExtern * cos(i), | ||
| 91 | _y + _magnification * _radiusExtern * sin(i)); | ||
| 92 | } | ||
| 93 | glTexCoord2f(0.5f + 0.5f * cos(end), 0.5f + - 0.5f * sin(end)); | ||
| 94 | glVertex2f(_x + _magnification * _radiusExtern * cos(end), | ||
| 95 | _y + _magnification * _radiusExtern * sin(end)); | ||
| 96 | glEnd(); | ||
| 97 | } else { | ||
| 98 | _selectedAction = -1; | ||
| 99 | |||
| 100 | glBegin(GL_QUADS); | ||
| 101 | glTexCoord2f(1, 1); | ||
| 102 | glVertex2f(_x + _radiusExtern, _y - _radiusExtern); | ||
| 103 | |||
| 104 | glTexCoord2f(1, 0); | ||
| 105 | glVertex2f(_x + _radiusExtern, _y + _radiusExtern); | ||
| 106 | |||
| 107 | glTexCoord2f(0, 0); | ||
| 108 | glVertex2f(_x - _radiusExtern, _y + _radiusExtern); | ||
| 109 | |||
| 110 | glTexCoord2f(0, 1); | ||
| 111 | glVertex2f(_x - _radiusExtern, _y - _radiusExtern); | ||
| 112 | glEnd(); | ||
| 113 | } | ||
| 114 | glDisable(GL_TEXTURE_2D); | ||
| 115 | } | ||
| 116 | |||
| 117 | void PieMenu::resize(int screenWidth, int screenHeight) { | ||
| 118 | } | ||
| 119 | |||
| 120 | void PieMenu::mouseMoveEvent(int x, int y) { | ||
| 121 | _mouseX = x; | ||
| 122 | _mouseY = y; | ||
| 123 | } | ||
| 124 | |||
| 125 | void PieMenu::mousePressEvent(int x, int y) { | ||
| 126 | _x = _mouseX = x; | ||
| 127 | _y = _mouseY = y; | ||
| 128 | _selectedAction = -1; | ||
| 129 | _isDisplayed = true; | ||
| 130 | } | ||
| 131 | |||
| 132 | void PieMenu::mouseReleaseEvent(int x, int y) { | ||
| 133 | if (0 <= _selectedAction && _selectedAction < _actions.size() && _actions[_selectedAction]) { | ||
| 134 | _actions[_selectedAction]->trigger(); | ||
| 135 | } | ||
| 136 | |||
| 137 | _isDisplayed = false; | ||
| 138 | } | ||
| @@ -0,0 +1,59 @@ | |||
| 1 | // | ||
| 2 | // PieMenu.h | ||
| 3 | // hifi | ||
| 4 | // | ||
| 5 | // Created by Clement Brisset on 7/18/13. | ||
| 6 | // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #ifndef __hifi__PieMenu__ | ||
| 10 | #define __hifi__PieMenu__ | ||
| 11 | |||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | #include "InterfaceConfig.h" | ||
| 15 | #include "Util.h" | ||
| 16 | |||
| 17 | #include <QImage> | ||
| 18 | |||
| 19 | class QAction; | ||
| 20 | |||
| 21 | class PieMenu { | ||
| 22 | public: | ||
| 23 | PieMenu(); | ||
| 24 | |||
| 25 | void init(const char* fileName, int screenWidth, int screenHeight); | ||
| 26 | void addAction(QAction* action); | ||
| 27 | void render(); | ||
| 28 | void resize(int screenWidth, int screenHeight); | ||
| 29 | |||
| 30 | bool isDisplayed() const {return _isDisplayed;} | ||
| 31 | int getX () const {return _x;} | ||
| 32 | int getY () const {return _y;} | ||
| 33 | |||
| 34 | void mouseMoveEvent (int x, int y); | ||
| 35 | void mousePressEvent (int x, int y); | ||
| 36 | void mouseReleaseEvent(int x, int y); | ||
| 37 | |||
| 38 | private: | ||
| 39 | QImage _textureImage; | ||
| 40 | GLuint _textureID; | ||
| 41 | |||
| 42 | // position of the menu | ||
| 43 | int _x; | ||
| 44 | int _y; | ||
| 45 | int _radiusIntern; | ||
| 46 | int _radiusExtern; | ||
| 47 | float _magnification; | ||
| 48 | |||
| 49 | int _mouseX; | ||
| 50 | int _mouseY; | ||
| 51 | |||
| 52 | int _selectedAction; | ||
| 53 | |||
| 54 | bool _isDisplayed; | ||
| 55 | |||
| 56 | std::vector<QAction*> _actions; | ||
| 57 | }; | ||
| 58 | |||
| 59 | #endif /* defined(__hifi__PieMenu__) */ | ||
| @@ -23,6 +23,8 @@ · 22 unmodified lines | |||
| 23 | #include <PacketHeaders.h> | 23 | #include <PacketHeaders.h> |
| 24 | #include <PerfStat.h> | 24 | #include <PerfStat.h> |
| 25 | #include <SharedUtil.h> | 25 | #include <SharedUtil.h> |
| 26 | #include <NodeList.h> | ||
| 27 | #include <NodeTypes.h> | ||
| 26 | 28 | ||
| 27 | #include "Application.h" | 29 | #include "Application.h" |
| 28 | #include "CoverageMap.h" | 30 | #include "CoverageMap.h" |
| @@ -61,6 +63,8 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : · 32 unmodified lines | |||
| 61 | 63 | ||
| 62 | VoxelNode::addDeleteHook(this); | 64 | VoxelNode::addDeleteHook(this); |
| 63 | _abandonedVBOSlots = 0; | 65 | _abandonedVBOSlots = 0; |
| 66 | _falseColorizeBySource = false; | ||
| 67 | _dataSourceID = UNKNOWN_NODE_ID; | ||
| 64 | } | 68 | } |
| 65 | 69 | ||
| 66 | void VoxelSystem::nodeDeleted(VoxelNode* node) { | 70 | void VoxelSystem::nodeDeleted(VoxelNode* node) { |
| @@ -153,13 +157,15 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 86 unmodified lines | |||
| 153 | case PACKET_TYPE_VOXEL_DATA: { | 157 | case PACKET_TYPE_VOXEL_DATA: { |
| 154 | PerformanceWarning warn(_renderWarningsOn, "readBitstreamToTree()"); | 158 | PerformanceWarning warn(_renderWarningsOn, "readBitstreamToTree()"); |
| 155 | // ask the VoxelTree to read the bitstream into the tree | 159 | // ask the VoxelTree to read the bitstream into the tree |
| 156 | _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, WANT_COLOR, WANT_EXISTS_BITS); | 160 | ReadBitstreamToTreeParams args(WANT_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceID()); |
| 161 | _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args); | ||
| 157 | } | 162 | } |
| 158 | break; | 163 | break; |
| 159 | case PACKET_TYPE_VOXEL_DATA_MONOCHROME: { | 164 | case PACKET_TYPE_VOXEL_DATA_MONOCHROME: { |
| 160 | PerformanceWarning warn(_renderWarningsOn, "readBitstreamToTree()"); | 165 | PerformanceWarning warn(_renderWarningsOn, "readBitstreamToTree()"); |
| 161 | // ask the VoxelTree to read the MONOCHROME bitstream into the tree | 166 | // ask the VoxelTree to read the MONOCHROME bitstream into the tree |
| 162 | _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, NO_COLOR, WANT_EXISTS_BITS); | 167 | ReadBitstreamToTreeParams args(NO_COLOR, WANT_EXISTS_BITS, NULL, getDataSourceID()); |
| 168 | _tree->readBitstreamToTree(voxelData, numBytes - numBytesPacketHeader, args); | ||
| 163 | } | 169 | } |
| 164 | break; | 170 | break; |
| 165 | case PACKET_TYPE_Z_COMMAND: | 171 | case PACKET_TYPE_Z_COMMAND: |
| @@ -747,6 +753,7 @@ void VoxelSystem::randomizeVoxelColors() { · 581 unmodified lines | |||
| 747 | _nodeCount = 0; | 753 | _nodeCount = 0; |
| 748 | _tree->recurseTreeWithOperation(randomColorOperation); | 754 | _tree->recurseTreeWithOperation(randomColorOperation); |
| 749 | qDebug("setting randomized true color for %d nodes\n", _nodeCount); | 755 | qDebug("setting randomized true color for %d nodes\n", _nodeCount); |
| 756 | _tree->setDirtyBit(); | ||
| 750 | setupNewVoxelsForDrawing(); | 757 | setupNewVoxelsForDrawing(); |
| 751 | } | 758 | } |
| 752 | 759 | ||
| @@ -761,6 +768,7 @@ void VoxelSystem::falseColorizeRandom() { · 8 unmodified lines | |||
| 761 | _nodeCount = 0; | 768 | _nodeCount = 0; |
| 762 | _tree->recurseTreeWithOperation(falseColorizeRandomOperation); | 769 | _tree->recurseTreeWithOperation(falseColorizeRandomOperation); |
| 763 | qDebug("setting randomized false color for %d nodes\n", _nodeCount); | 770 | qDebug("setting randomized false color for %d nodes\n", _nodeCount); |
| 771 | _tree->setDirtyBit(); | ||
| 764 | setupNewVoxelsForDrawing(); | 772 | setupNewVoxelsForDrawing(); |
| 765 | } | 773 | } |
| 766 | 774 | ||
| @@ -775,6 +783,7 @@ void VoxelSystem::trueColorize() { · 8 unmodified lines | |||
| 775 | _nodeCount = 0; | 783 | _nodeCount = 0; |
| 776 | _tree->recurseTreeWithOperation(trueColorizeOperation); | 784 | _tree->recurseTreeWithOperation(trueColorizeOperation); |
| 777 | qDebug("setting true color for %d nodes\n", _nodeCount); | 785 | qDebug("setting true color for %d nodes\n", _nodeCount); |
| 786 | _tree->setDirtyBit(); | ||
| 778 | setupNewVoxelsForDrawing(); | 787 | setupNewVoxelsForDrawing(); |
| 779 | } | 788 | } |
| 780 | 789 | ||
| @@ -795,6 +804,80 @@ void VoxelSystem::falseColorizeInView(ViewFrustum* viewFrustum) { · 14 unmodified lines | |||
| 795 | _nodeCount = 0; | 804 | _nodeCount = 0; |
| 796 | _tree->recurseTreeWithOperation(falseColorizeInViewOperation,(void*)viewFrustum); | 805 | _tree->recurseTreeWithOperation(falseColorizeInViewOperation,(void*)viewFrustum); |
| 797 | qDebug("setting in view false color for %d nodes\n", _nodeCount); | 806 | qDebug("setting in view false color for %d nodes\n", _nodeCount); |
| 807 | _tree->setDirtyBit(); | ||
| 808 | setupNewVoxelsForDrawing(); | ||
| 809 | } | ||
| 810 | |||
| 811 | // helper classes and args for falseColorizeBySource | ||
| 812 | class groupColor { | ||
| 813 | public: | ||
| 814 | unsigned char red, green, blue; | ||
| 815 | groupColor(unsigned char red, unsigned char green, unsigned char blue) : | ||
| 816 | red(red), green(green), blue(blue) { }; | ||
| 817 | |||
| 818 | groupColor() : | ||
| 819 | red(0), green(0), blue(0) { }; | ||
| 820 | }; | ||
| 821 | |||
| 822 | class colorizeBySourceArgs { | ||
| 823 | public: | ||
| 824 | std::map<uint16_t, groupColor> colors; | ||
| 825 | }; | ||
| 826 | |||
| 827 | // Will false colorize voxels that are not in view | ||
| 828 | bool VoxelSystem::falseColorizeBySourceOperation(VoxelNode* node, void* extraData) { | ||
| 829 | colorizeBySourceArgs* args = (colorizeBySourceArgs*)extraData; | ||
| 830 | _nodeCount++; | ||
| 831 | if (node->isColored()) { | ||
| 832 | // pick a color based on the source - we want each source to be obviously different | ||
| 833 | uint16_t nodeID = node->getSourceID(); | ||
| 834 | |||
| 835 | //printf("false colorizing from source %d, color: %d, %d, %d\n", nodeID, | ||
| 836 | // args->colors[nodeID].red, args->colors[nodeID].green, args->colors[nodeID].blue); | ||
| 837 | |||
| 838 | node->setFalseColor(args->colors[nodeID].red, args->colors[nodeID].green, args->colors[nodeID].blue); | ||
| 839 | } | ||
| 840 | return true; // keep going! | ||
| 841 | } | ||
| 842 | |||
| 843 | void VoxelSystem::falseColorizeBySource() { | ||
| 844 | _nodeCount = 0; | ||
| 845 | colorizeBySourceArgs args; | ||
| 846 | const int NUMBER_OF_COLOR_GROUPS = 3; | ||
| 847 | const unsigned char MIN_COLOR = 128; | ||
| 848 | int voxelServerCount = 0; | ||
| 849 | groupColor groupColors[NUMBER_OF_COLOR_GROUPS] = { groupColor(255, 0, 0), | ||
| 850 | groupColor(0, 255, 0), | ||
| 851 | groupColor(0, 0, 255)}; | ||
| 852 | |||
| 853 | // create a bunch of colors we'll use during colorization | ||
| 854 | NodeList* nodeList = NodeList::getInstance(); | ||
| 855 | for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { | ||
| 856 | if (node->getType() == NODE_TYPE_VOXEL_SERVER) { | ||
| 857 | uint16_t nodeID = node->getNodeID(); | ||
| 858 | int groupColor = voxelServerCount % NUMBER_OF_COLOR_GROUPS; | ||
| 859 | args.colors[nodeID] = groupColors[groupColor]; | ||
| 860 | |||
| 861 | //printf("assigning color for source %d, color: %d, %d, %d\n", nodeID, | ||
| 862 | // args.colors[nodeID].red, args.colors[nodeID].green, args.colors[nodeID].blue); | ||
| 863 | |||
| 864 | if (groupColors[groupColor].red > 0) { | ||
| 865 | groupColors[groupColor].red = ((groupColors[groupColor].red - MIN_COLOR)/2) + MIN_COLOR; | ||
| 866 | } | ||
| 867 | if (groupColors[groupColor].green > 0) { | ||
| 868 | groupColors[groupColor].green = ((groupColors[groupColor].green - MIN_COLOR)/2) + MIN_COLOR; | ||
| 869 | } | ||
| 870 | if (groupColors[groupColor].blue > 0) { | ||
| 871 | groupColors[groupColor].blue = ((groupColors[groupColor].blue - MIN_COLOR)/2) + MIN_COLOR; | ||
| 872 | } | ||
| 873 | |||
| 874 | voxelServerCount++; | ||
| 875 | } | ||
| 876 | } | ||
| 877 | |||
| 878 | _tree->recurseTreeWithOperation(falseColorizeBySourceOperation, &args); | ||
| 879 | qDebug("setting false color by source for %d nodes\n", _nodeCount); | ||
| 880 | _tree->setDirtyBit(); | ||
| 798 | setupNewVoxelsForDrawing(); | 881 | setupNewVoxelsForDrawing(); |
| 799 | } | 882 | } |
| 800 | 883 | ||
| @@ -848,6 +931,7 @@ void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) { · 47 unmodified lines | |||
| 848 | _nodeCount = 0; | 931 | _nodeCount = 0; |
| 849 | _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); | 932 | _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum); |
| 850 | qDebug("setting in distance false color for %d nodes\n", _nodeCount); | 933 | qDebug("setting in distance false color for %d nodes\n", _nodeCount); |
| 934 | _tree->setDirtyBit(); | ||
| 851 | setupNewVoxelsForDrawing(); | 935 | setupNewVoxelsForDrawing(); |
| 852 | } | 936 | } |
| 853 | 937 | ||
| @@ -1027,6 +1111,7 @@ void VoxelSystem::falseColorizeRandomEveryOther() { · 173 unmodified lines | |||
| 1027 | _tree->recurseTreeWithOperation(falseColorizeRandomEveryOtherOperation,&args); | 1111 | _tree->recurseTreeWithOperation(falseColorizeRandomEveryOtherOperation,&args); |
| 1028 | qDebug("randomized false color for every other node: total %ld, colorable %ld, colored %ld\n", | 1112 | qDebug("randomized false color for every other node: total %ld, colorable %ld, colored %ld\n", |
| 1029 | args.totalNodes, args.colorableNodes, args.coloredNodes); | 1113 | args.totalNodes, args.colorableNodes, args.coloredNodes); |
| 1114 | _tree->setDirtyBit(); | ||
| 1030 | setupNewVoxelsForDrawing(); | 1115 | setupNewVoxelsForDrawing(); |
| 1031 | } | 1116 | } |
| 1032 | 1117 | ||
| @@ -1331,6 +1416,7 @@ void VoxelSystem::falseColorizeOccluded() { · 298 unmodified lines | |||
| 1331 | 1416 | ||
| 1332 | //myCoverageMap.erase(); | 1417 | //myCoverageMap.erase(); |
| 1333 | 1418 | ||
| 1419 | _tree->setDirtyBit(); | ||
| 1334 | setupNewVoxelsForDrawing(); | 1420 | setupNewVoxelsForDrawing(); |
| 1335 | } | 1421 | } |
| 1336 | 1422 | ||
| @@ -1447,6 +1533,7 @@ void VoxelSystem::falseColorizeOccludedV2() { · 110 unmodified lines | |||
| 1447 | //myCoverageMapV2.erase(); | 1533 | //myCoverageMapV2.erase(); |
| 1448 | 1534 | ||
| 1449 | 1535 | ||
| 1536 | _tree->setDirtyBit(); | ||
| 1450 | setupNewVoxelsForDrawing(); | 1537 | setupNewVoxelsForDrawing(); |
| 1451 | } | 1538 | } |
| 1452 | 1539 | ||
| @@ -33,6 +33,9 @@ public: · 32 unmodified lines | |||
| 33 | VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM); | 33 | VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM); |
| 34 | ~VoxelSystem(); | 34 | ~VoxelSystem(); |
| 35 | 35 | ||
| 36 | void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; }; | ||
| 37 | int getDataSourceID() const { return _dataSourceID; }; | ||
| 38 | |||
| 36 | int parseData(unsigned char* sourceBuffer, int numBytes); | 39 | int parseData(unsigned char* sourceBuffer, int numBytes); |
| 37 | 40 | ||
| 38 | virtual void init(); | 41 | virtual void init(); |
| @@ -62,6 +65,8 @@ public: · 23 unmodified lines | |||
| 62 | void falseColorizeRandomEveryOther(); | 65 | void falseColorizeRandomEveryOther(); |
| 63 | void falseColorizeOccluded(); | 66 | void falseColorizeOccluded(); |
| 64 | void falseColorizeOccludedV2(); | 67 | void falseColorizeOccludedV2(); |
| 68 | void falseColorizeBySource(); | ||
| 69 | |||
| 65 | 70 | ||
| 66 | void killLocalVoxels(); | 71 | void killLocalVoxels(); |
| 67 | void setRenderPipelineWarnings(bool on) { _renderWarningsOn = on; }; | 72 | void setRenderPipelineWarnings(bool on) { _renderWarningsOn = on; }; |
| @@ -94,7 +99,7 @@ public: · 26 unmodified lines | |||
| 94 | CoverageMap myCoverageMap; | 99 | CoverageMap myCoverageMap; |
| 95 | 100 | ||
| 96 | virtual void nodeDeleted(VoxelNode* node); | 101 | virtual void nodeDeleted(VoxelNode* node); |
| 97 | 102 | ||
| 98 | protected: | 103 | protected: |
| 99 | float _treeScale; | 104 | float _treeScale; |
| 100 | int _maxVoxels; | 105 | int _maxVoxels; |
| @@ -134,7 +139,7 @@ private: · 33 unmodified lines | |||
| 134 | static bool falseColorizeOccludedOperation(VoxelNode* node, void* extraData); | 139 | static bool falseColorizeOccludedOperation(VoxelNode* node, void* extraData); |
| 135 | static bool falseColorizeSubTreeOperation(VoxelNode* node, void* extraData); | 140 | static bool falseColorizeSubTreeOperation(VoxelNode* node, void* extraData); |
| 136 | static bool falseColorizeOccludedV2Operation(VoxelNode* node, void* extraData); | 141 | static bool falseColorizeOccludedV2Operation(VoxelNode* node, void* extraData); |
| 137 | 142 | static bool falseColorizeBySourceOperation(VoxelNode* node, void* extraData); | |
| 138 | 143 | ||
| 139 | int updateNodeInArraysAsFullVBO(VoxelNode* node); | 144 | int updateNodeInArraysAsFullVBO(VoxelNode* node); |
| 140 | int updateNodeInArraysAsPartialVBO(VoxelNode* node); | 145 | int updateNodeInArraysAsPartialVBO(VoxelNode* node); |
| @@ -195,6 +200,9 @@ private: · 54 unmodified lines | |||
| 195 | 200 | ||
| 196 | void freeBufferIndex(glBufferIndex index); | 201 | void freeBufferIndex(glBufferIndex index); |
| 197 | void clearFreeBufferIndexes(); | 202 | void clearFreeBufferIndexes(); |
| 203 | |||
| 204 | bool _falseColorizeBySource; | ||
| 205 | int _dataSourceID; | ||
| 198 | }; | 206 | }; |
| 199 | 207 | ||
| 200 | #endif | 208 | #endif |
| @@ -33,7 +33,7 @@ int jointVectorMetaType = qRegisterMetaType<JointVector>("JointVector"); · 32 unmodified lines | |||
| 33 | int matMetaType = qRegisterMetaType<Mat>("cv::Mat"); | 33 | int matMetaType = qRegisterMetaType<Mat>("cv::Mat"); |
| 34 | int rotatedRectMetaType = qRegisterMetaType<RotatedRect>("cv::RotatedRect"); | 34 | int rotatedRectMetaType = qRegisterMetaType<RotatedRect>("cv::RotatedRect"); |
| 35 | 35 | ||
| 36 | Webcam::Webcam() : _enabled(false), _active(false), _colorTextureID(0), _depthTextureID(0) { | 36 | Webcam::Webcam() : _enabled(false), _active(false), _colorTextureID(0), _depthTextureID(0), _skeletonTrackingOn(false) { |
| 37 | // the grabber simply runs as fast as possible | 37 | // the grabber simply runs as fast as possible |
| 38 | _grabber = new FrameGrabber(); | 38 | _grabber = new FrameGrabber(); |
| 39 | _grabber->moveToThread(&_grabberThread); | 39 | _grabber->moveToThread(&_grabberThread); |
| @@ -197,7 +197,7 @@ void Webcam::setFrame(const Mat& color, int format, const Mat& depth, float midF · 157 unmodified lines | |||
| 197 | _aspectRatio = aspectRatio; | 197 | _aspectRatio = aspectRatio; |
| 198 | _faceRect = faceRect; | 198 | _faceRect = faceRect; |
| 199 | _sending = sending; | 199 | _sending = sending; |
| 200 | _joints = joints; | 200 | _joints = _skeletonTrackingOn ? joints : JointVector(); |
| 201 | _frameCount++; | 201 | _frameCount++; |
| 202 | 202 | ||
| 203 | const int MAX_FPS = 60; | 203 | const int MAX_FPS = 60; |
| @@ -47,6 +47,7 @@ public: · 46 unmodified lines | |||
| 47 | FrameGrabber* getGrabber() { return _grabber; } | 47 | FrameGrabber* getGrabber() { return _grabber; } |
| 48 | 48 | ||
| 49 | bool isActive() const { return _active; } | 49 | bool isActive() const { return _active; } |
| 50 | |||
| 50 | bool isSending() const { return _sending; } | 51 | bool isSending() const { return _sending; } |
| 51 | 52 | ||
| 52 | GLuint getColorTextureID() const { return _colorTextureID; } | 53 | GLuint getColorTextureID() const { return _colorTextureID; } |
| @@ -62,13 +63,14 @@ public: · 9 unmodified lines | |||
| 62 | const JointVector& getEstimatedJoints() const { return _estimatedJoints; } | 63 | const JointVector& getEstimatedJoints() const { return _estimatedJoints; } |
| 63 | 64 | ||
| 64 | void reset(); | 65 | void reset(); |
| 65 | void renderPreview(int screenWidth, int screenHeight); | 66 | void renderPreview(int screenWidth, int screenHeight); |
| 66 | 67 | ||
| 67 | public slots: | 68 | public slots: |
| 68 | 69 | ||
| 69 | void setEnabled(bool enabled); | 70 | void setEnabled(bool enabled); |
| 70 | void setFrame(const cv::Mat& color, int format, const cv::Mat& depth, float midFaceDepth, | 71 | void setFrame(const cv::Mat& color, int format, const cv::Mat& depth, float midFaceDepth, |
| 71 | float aspectRatio, const cv::RotatedRect& faceRect, bool sending, const JointVector& joints); | 72 | float aspectRatio, const cv::RotatedRect& faceRect, bool sending, const JointVector& joints); |
| 73 | void setSkeletonTrackingOn(bool toggle) { _skeletonTrackingOn = toggle; }; | ||
| 72 | 74 | ||
| 73 | private: | 75 | private: |
| 74 | 76 | ||
| @@ -95,6 +97,8 @@ private: · 20 unmodified lines | |||
| 95 | glm::vec3 _estimatedPosition; | 97 | glm::vec3 _estimatedPosition; |
| 96 | glm::vec3 _estimatedRotation; | 98 | glm::vec3 _estimatedRotation; |
| 97 | JointVector _estimatedJoints; | 99 | JointVector _estimatedJoints; |
| 100 | |||
| 101 | bool _skeletonTrackingOn; | ||
| 98 | }; | 102 | }; |
| 99 | 103 | ||
| 100 | class FrameGrabber : public QObject { | 104 | class FrameGrabber : public QObject { |
| @@ -101,7 +101,8 @@ Avatar::Avatar(Node* owningNode) : · 100 unmodified lines | |||
| 101 | _lastCollisionPosition(0, 0, 0), | 101 | _lastCollisionPosition(0, 0, 0), |
| 102 | _speedBrakes(false), | 102 | _speedBrakes(false), |
| 103 | _isThrustOn(false), | 103 | _isThrustOn(false), |
| 104 | _voxels(this) | 104 | _voxels(this), |
| 105 | _leadingAvatar(NULL) | ||
| 105 | { | 106 | { |
| 106 | // give the pointer to our head to inherited _headData variable from AvatarData | 107 | // give the pointer to our head to inherited _headData variable from AvatarData |
| 107 | _headData = &_head; | 108 | _headData = &_head; |
| @@ -404,6 +405,33 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { · 296 unmodified lines | |||
| 404 | _thrust += _scale * THRUST_JUMP * up; | 405 | _thrust += _scale * THRUST_JUMP * up; |
| 405 | _shouldJump = false; | 406 | _shouldJump = false; |
| 406 | } | 407 | } |
| 408 | |||
| 409 | // Add thrusts from leading avatar | ||
| 410 | if (_leadingAvatar != NULL) { | ||
| 411 | glm::vec3 toTarget = _leadingAvatar->getPosition() - _position; | ||
| 412 | |||
| 413 | if (.5f < up.x * toTarget.x + up.y * toTarget.y + up.z * toTarget.z) { | ||
| 414 | _thrust += _scale * THRUST_MAG_UP * deltaTime * up; | ||
| 415 | } else if (up.x * toTarget.x + up.y * toTarget.y + up.z * toTarget.z < -.5f) { | ||
| 416 | _thrust -= _scale * THRUST_MAG_UP * deltaTime * up; | ||
| 417 | } | ||
| 418 | |||
| 419 | if (glm::length(_position - _leadingAvatar->getPosition()) > _scale * _stringLength) { | ||
| 420 | _thrust += _scale * THRUST_MAG_FWD * deltaTime * front; | ||
| 421 | } else { | ||
| 422 | toTarget = _leadingAvatar->getHead().getLookAtPosition() - _position; | ||
| 423 | getHead().setLookAtPosition(_leadingAvatar->getHead().getLookAtPosition()); | ||
| 424 | } | ||
| 425 | |||
| 426 | float yawAngle = angleBetween(front, glm::vec3(toTarget.x, 0.f, toTarget.z)); | ||
| 427 | if (yawAngle < -10.f || 10.f < yawAngle){ | ||
| 428 | if (right.x * toTarget.x + right.y * toTarget.y + right.z * toTarget.z > 0) { | ||
| 429 | _bodyYawDelta -= YAW_MAG * deltaTime; | ||
| 430 | } else { | ||
| 431 | _bodyYawDelta += YAW_MAG * deltaTime; | ||
| 432 | } | ||
| 433 | } | ||
| 434 | } | ||
| 407 | 435 | ||
| 408 | // Add thrusts from Transmitter | 436 | // Add thrusts from Transmitter |
| 409 | if (transmitter) { | 437 | if (transmitter) { |
| @@ -447,6 +475,18 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { · 37 unmodified lines | |||
| 447 | _isThrustOn = (glm::length(_thrust) > EPSILON); | 475 | _isThrustOn = (glm::length(_thrust) > EPSILON); |
| 448 | } | 476 | } |
| 449 | 477 | ||
| 478 | void Avatar::follow(Avatar* leadingAvatar) { | ||
| 479 | const float MAX_STRING_LENGTH = 2; | ||
| 480 | |||
| 481 | _leadingAvatar = leadingAvatar; | ||
| 482 | if (_leadingAvatar != NULL) { | ||
| 483 | _stringLength = glm::length(_position - _leadingAvatar->getPosition()) / _scale; | ||
| 484 | if (_stringLength > MAX_STRING_LENGTH) { | ||
| 485 | _stringLength = MAX_STRING_LENGTH; | ||
| 486 | } | ||
| 487 | } | ||
| 488 | } | ||
| 489 | |||
| 450 | void Avatar::simulate(float deltaTime, Transmitter* transmitter) { | 490 | void Avatar::simulate(float deltaTime, Transmitter* transmitter) { |
| 451 | 491 | ||
| 452 | glm::quat orientation = getOrientation(); | 492 | glm::quat orientation = getOrientation(); |
| @@ -475,6 +515,13 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { · 22 unmodified lines | |||
| 475 | if (isMyAvatar()) { | 515 | if (isMyAvatar()) { |
| 476 | updateThrust(deltaTime, transmitter); | 516 | updateThrust(deltaTime, transmitter); |
| 477 | } | 517 | } |
| 518 | |||
| 519 | // Ajust, scale, thrust and lookAt position when following an other avatar | ||
| 520 | if (isMyAvatar() && _leadingAvatar && _scale != _leadingAvatar->getScale()) { | ||
| 521 | float scale = 0.95f * _scale + 0.05f * _leadingAvatar->getScale(); | ||
| 522 | setScale(scale); | ||
| 523 | Application::getInstance()->getCamera()->setScale(scale); | ||
| 524 | } | ||
| 478 | 525 | ||
| 479 | // copy velocity so we can use it later for acceleration | 526 | // copy velocity so we can use it later for acceleration |
| 480 | glm::vec3 oldVelocity = getVelocity(); | 527 | glm::vec3 oldVelocity = getVelocity(); |
| @@ -681,7 +728,9 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { · 200 unmodified lines | |||
| 681 | _head.setScale(_scale); | 728 | _head.setScale(_scale); |
| 682 | _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); | 729 | _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2])); |
| 683 | _head.simulate(deltaTime, isMyAvatar()); | 730 | _head.simulate(deltaTime, isMyAvatar()); |
| 684 | 731 | ||
| 732 | |||
| 733 | |||
| 685 | // use speed and angular velocity to determine walking vs. standing | 734 | // use speed and angular velocity to determine walking vs. standing |
| 686 | if (_speed + fabs(_bodyYawDelta) > 0.2) { | 735 | if (_speed + fabs(_bodyYawDelta) > 0.2) { |
| 687 | _mode = AVATAR_MODE_WALKING; | 736 | _mode = AVATAR_MODE_WALKING; |
| @@ -114,6 +114,7 @@ public: · 113 unmodified lines | |||
| 114 | void reset(); | 114 | void reset(); |
| 115 | void simulate(float deltaTime, Transmitter* transmitter); | 115 | void simulate(float deltaTime, Transmitter* transmitter); |
| 116 | void updateThrust(float deltaTime, Transmitter * transmitter); | 116 | void updateThrust(float deltaTime, Transmitter * transmitter); |
| 117 | void follow(Avatar* leadingAvatar); | ||
| 117 | void updateFromGyrosAndOrWebcam(bool gyroLook, | 118 | void updateFromGyrosAndOrWebcam(bool gyroLook, |
| 118 | const glm::vec3& amplifyAngle, | 119 | const glm::vec3& amplifyAngle, |
| 119 | float yawFromTouch, | 120 | float yawFromTouch, |
| @@ -157,18 +158,16 @@ public: · 37 unmodified lines | |||
| 157 | float getElapsedTimeMoving () const { return _elapsedTimeMoving;} | 158 | float getElapsedTimeMoving () const { return _elapsedTimeMoving;} |
| 158 | float getElapsedTimeSinceCollision() const { return _elapsedTimeSinceCollision;} | 159 | float getElapsedTimeSinceCollision() const { return _elapsedTimeSinceCollision;} |
| 159 | const glm::vec3& getLastCollisionPosition () const { return _lastCollisionPosition;} | 160 | const glm::vec3& getLastCollisionPosition () const { return _lastCollisionPosition;} |
| 160 | float getAbsoluteHeadYaw () const; | 161 | float getAbsoluteHeadYaw () const; |
| 161 | float getAbsoluteHeadPitch () const; | 162 | float getAbsoluteHeadPitch () const; |
| 162 | Head& getHead () {return _head; } | 163 | Head& getHead () {return _head; } |
| 163 | Hand& getHand () {return _hand; } | 164 | Hand& getHand () {return _hand; } |
| 164 | glm::quat getOrientation () const; | 165 | glm::quat getOrientation () const; |
| 165 | glm::quat getWorldAlignedOrientation() const; | 166 | glm::quat getWorldAlignedOrientation() const; |
| 166 | 167 | const glm::vec3& getMouseRayOrigin () const { return _mouseRayOrigin; } | |
| 167 | const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; } | 168 | const glm::vec3& getMouseRayDirection () const { return _mouseRayDirection; } |
| 168 | const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; } | 169 | Avatar* getLeadingAvatar () const { return _leadingAvatar; } |
| 169 | 170 | glm::vec3 getGravity () const { return _gravity; } | |
| 170 | |||
| 171 | glm::vec3 getGravity () const { return _gravity; } | ||
| 172 | 171 | ||
| 173 | glm::vec3 getUprightHeadPosition() const; | 172 | glm::vec3 getUprightHeadPosition() const; |
| 174 | glm::vec3 getUprightEyeLevelPosition() const; | 173 | glm::vec3 getUprightEyeLevelPosition() const; |
| @@ -255,7 +254,10 @@ private: · 80 unmodified lines | |||
| 255 | glm::vec3 _lastCollisionPosition; | 254 | glm::vec3 _lastCollisionPosition; |
| 256 | bool _speedBrakes; | 255 | bool _speedBrakes; |
| 257 | bool _isThrustOn; | 256 | bool _isThrustOn; |
| 258 | 257 | ||
| 258 | Avatar* _leadingAvatar; | ||
| 259 | float _stringLength; | ||
| 260 | |||
| 259 | AvatarVoxelSystem _voxels; | 261 | AvatarVoxelSystem _voxels; |
| 260 | 262 | ||
| 261 | // private methods... | 263 | // private methods... |
| @@ -250,7 +250,8 @@ void AvatarVoxelSystem::handleVoxelDownloadProgress(qint64 bytesReceived, qint64 · 249 unmodified lines | |||
| 250 | _voxelReply->deleteLater(); | 250 | _voxelReply->deleteLater(); |
| 251 | _voxelReply = 0; | 251 | _voxelReply = 0; |
| 252 | 252 | ||
| 253 | _tree->readBitstreamToTree((unsigned char*)entirety.data(), entirety.size(), WANT_COLOR, NO_EXISTS_BITS); | 253 | ReadBitstreamToTreeParams args(WANT_COLOR, NO_EXISTS_BITS); |
| 254 | _tree->readBitstreamToTree((unsigned char*)entirety.data(), entirety.size(), args); | ||
| 254 | setupNewVoxelsForDrawing(); | 255 | setupNewVoxelsForDrawing(); |
| 255 | } | 256 | } |
| 256 | 257 | ||
| @@ -14,7 +14,7 @@ · 13 unmodified lines | |||
| 14 | #include "Util.h" | 14 | #include "Util.h" |
| 15 | #include "renderer/ProgramObject.h" | 15 | #include "renderer/ProgramObject.h" |
| 16 | 16 | ||
| 17 | const bool SHOW_LEAP_HAND = true; | 17 | const bool SHOW_LEAP_HAND = false; |
| 18 | 18 | ||
| 19 | using namespace std; | 19 | using namespace std; |
| 20 | 20 | ||
| @@ -51,6 +51,7 @@ void Hand::reset() { · 30 unmodified lines | |||
| 51 | 51 | ||
| 52 | 52 | ||
| 53 | void Hand::simulate(float deltaTime, bool isMine) { | 53 | void Hand::simulate(float deltaTime, bool isMine) { |
| 54 | |||
| 54 | if (_isRaveGloveActive) { | 55 | if (_isRaveGloveActive) { |
| 55 | updateRaveGloveParticles(deltaTime); | 56 | updateRaveGloveParticles(deltaTime); |
| 56 | } | 57 | } |
| @@ -63,7 +64,8 @@ void Hand::calculateGeometry() { · 6 unmodified lines | |||
| 63 | _basePosition = head.getPosition() + head.getOrientation() * offset; | 64 | _basePosition = head.getPosition() + head.getOrientation() * offset; |
| 64 | _baseOrientation = head.getOrientation(); | 65 | _baseOrientation = head.getOrientation(); |
| 65 | 66 | ||
| 66 | _leapBalls.clear(); | 67 | // generate finger tip balls.... |
| 68 | _leapFingerTipBalls.clear(); | ||
| 67 | for (size_t i = 0; i < getNumPalms(); ++i) { | 69 | for (size_t i = 0; i < getNumPalms(); ++i) { |
| 68 | PalmData& palm = getPalms()[i]; | 70 | PalmData& palm = getPalms()[i]; |
| 69 | if (palm.isActive()) { | 71 | if (palm.isActive()) { |
| @@ -71,8 +73,8 @@ void Hand::calculateGeometry() { · 1 unmodified line | |||
| 71 | FingerData& finger = palm.getFingers()[f]; | 73 | FingerData& finger = palm.getFingers()[f]; |
| 72 | if (finger.isActive()) { | 74 | if (finger.isActive()) { |
| 73 | const float standardBallRadius = 0.01f; | 75 | const float standardBallRadius = 0.01f; |
| 74 | _leapBalls.resize(_leapBalls.size() + 1); | 76 | _leapFingerTipBalls.resize(_leapFingerTipBalls.size() + 1); |
| 75 | HandBall& ball = _leapBalls.back(); | 77 | HandBall& ball = _leapFingerTipBalls.back(); |
| 76 | ball.rotation = _baseOrientation; | 78 | ball.rotation = _baseOrientation; |
| 77 | ball.position = finger.getTipPosition(); | 79 | ball.position = finger.getTipPosition(); |
| 78 | ball.radius = standardBallRadius; | 80 | ball.radius = standardBallRadius; |
| @@ -82,6 +84,27 @@ void Hand::calculateGeometry() { · 3 unmodified lines | |||
| 82 | } | 84 | } |
| 83 | } | 85 | } |
| 84 | } | 86 | } |
| 87 | |||
| 88 | // generate finger rot balls.... | ||
| 89 | _leapFingerRootBalls.clear(); | ||
| 90 | for (size_t i = 0; i < getNumPalms(); ++i) { | ||
| 91 | PalmData& palm = getPalms()[i]; | ||
| 92 | if (palm.isActive()) { | ||
| 93 | for (size_t f = 0; f < palm.getNumFingers(); ++f) { | ||
| 94 | FingerData& finger = palm.getFingers()[f]; | ||
| 95 | if (finger.isActive()) { | ||
| 96 | const float standardBallRadius = 0.01f; | ||
| 97 | _leapFingerRootBalls.resize(_leapFingerRootBalls.size() + 1); | ||
| 98 | HandBall& ball = _leapFingerRootBalls.back(); | ||
| 99 | ball.rotation = _baseOrientation; | ||
| 100 | ball.position = finger.getRootPosition(); | ||
| 101 | ball.radius = standardBallRadius; | ||
| 102 | ball.touchForce = 0.0; | ||
| 103 | ball.isCollidable = true; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | } | ||
| 85 | } | 108 | } |
| 86 | 109 | ||
| 87 | void Hand::setRaveGloveEffectsMode(QKeyEvent* event) { | 110 | void Hand::setRaveGloveEffectsMode(QKeyEvent* event) { |
| @@ -120,8 +143,9 @@ void Hand::render(bool lookingInMirror) { · 32 unmodified lines | |||
| 120 | glEnable(GL_RESCALE_NORMAL); | 143 | glEnable(GL_RESCALE_NORMAL); |
| 121 | 144 | ||
| 122 | if ( SHOW_LEAP_HAND ) { | 145 | if ( SHOW_LEAP_HAND ) { |
| 123 | renderFingerTrails(); | 146 | //renderLeapHands(); |
| 124 | renderHandSpheres(); | 147 | renderLeapFingerTrails(); |
| 148 | renderLeapHandSpheres(); | ||
| 125 | } | 149 | } |
| 126 | } | 150 | } |
| 127 | 151 | ||
| @@ -153,18 +177,64 @@ void Hand::renderRaveGloveStage() { · 25 unmodified lines | |||
| 153 | } | 177 | } |
| 154 | } | 178 | } |
| 155 | 179 | ||
| 156 | void Hand::renderHandSpheres() { | 180 | |
| 181 | void Hand::renderLeapHands() { | ||
| 182 | for (size_t i = 0; i < getNumPalms(); ++i) { | ||
| 183 | PalmData& hand = getPalms()[i]; | ||
| 184 | if (hand.isActive()) { | ||
| 185 | renderLeapHand(hand); | ||
| 186 | } | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | void Hand::renderLeapHand(PalmData& hand) { | ||
| 191 | |||
| 192 | glPushMatrix(); | ||
| 193 | const float palmThickness = 0.002f; | ||
| 194 | glColor4f(0.5f, 0.5f, 0.5f, 1.0); | ||
| 195 | glm::vec3 tip = hand.getPosition(); | ||
| 196 | glm::vec3 root = hand.getPosition() + hand.getNormal() * palmThickness; | ||
| 197 | Avatar::renderJointConnectingCone(root, tip, 0.05, 0.03); | ||
| 198 | |||
| 199 | for (size_t f = 0; f < hand.getNumFingers(); ++f) { | ||
| 200 | FingerData& finger = hand.getFingers()[f]; | ||
| 201 | if (finger.isActive()) { | ||
| 202 | glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, 0.5); | ||
| 203 | glm::vec3 tip = finger.getTipPosition(); | ||
| 204 | glm::vec3 root = finger.getRootPosition(); | ||
| 205 | Avatar::renderJointConnectingCone(root, tip, 0.001, 0.003); | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | glPopMatrix(); | ||
| 210 | } | ||
| 211 | |||
| 212 | |||
| 213 | void Hand::renderLeapHandSpheres() { | ||
| 157 | glPushMatrix(); | 214 | glPushMatrix(); |
| 158 | // Draw the leap balls | 215 | // Draw the leap balls |
| 159 | for (size_t i = 0; i < _leapBalls.size(); i++) { | 216 | for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) { |
| 160 | float alpha = 1.0f; | 217 | float alpha = 1.0f; |
| 161 | 218 | ||
| 162 | if (alpha > 0.0f) { | 219 | if (alpha > 0.0f) { |
| 163 | glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, alpha); | 220 | glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, alpha); |
| 164 | 221 | ||
| 165 | glPushMatrix(); | 222 | glPushMatrix(); |
| 166 | glTranslatef(_leapBalls[i].position.x, _leapBalls[i].position.y, _leapBalls[i].position.z); | 223 | glTranslatef(_leapFingerTipBalls[i].position.x, _leapFingerTipBalls[i].position.y, _leapFingerTipBalls[i].position.z); |
| 167 | glutSolidSphere(_leapBalls[i].radius, 20.0f, 20.0f); | 224 | glutSolidSphere(_leapFingerTipBalls[i].radius, 20.0f, 20.0f); |
| 225 | glPopMatrix(); | ||
| 226 | } | ||
| 227 | } | ||
| 228 | |||
| 229 | for (size_t i = 0; i < _leapFingerRootBalls.size(); i++) { | ||
| 230 | float alpha = 1.0f; | ||
| 231 | |||
| 232 | if (alpha > 0.0f) { | ||
| 233 | glColor4f(0.3f, 0.4f, 0.6f, alpha); | ||
| 234 | |||
| 235 | glPushMatrix(); | ||
| 236 | glTranslatef(_leapFingerRootBalls[i].position.x, _leapFingerRootBalls[i].position.y, _leapFingerRootBalls[i].position.z); | ||
| 237 | glutSolidSphere(_leapFingerRootBalls[i].radius, 20.0f, 20.0f); | ||
| 168 | glPopMatrix(); | 238 | glPopMatrix(); |
| 169 | } | 239 | } |
| 170 | } | 240 | } |
| @@ -200,7 +270,7 @@ void Hand::renderHandSpheres() { · 29 unmodified lines | |||
| 200 | glPopMatrix(); | 270 | glPopMatrix(); |
| 201 | } | 271 | } |
| 202 | 272 | ||
| 203 | void Hand::renderFingerTrails() { | 273 | void Hand::renderLeapFingerTrails() { |
| 204 | // Draw the finger root cones | 274 | // Draw the finger root cones |
| 205 | for (size_t i = 0; i < getNumPalms(); ++i) { | 275 | for (size_t i = 0; i < getNumPalms(); ++i) { |
| 206 | PalmData& palm = getPalms()[i]; | 276 | PalmData& palm = getPalms()[i]; |
| @@ -229,6 +299,7 @@ void Hand::renderFingerTrails() { · 22 unmodified lines | |||
| 229 | } | 299 | } |
| 230 | } | 300 | } |
| 231 | 301 | ||
| 302 | |||
| 232 | void Hand::setLeapHands(const std::vector<glm::vec3>& handPositions, | 303 | void Hand::setLeapHands(const std::vector<glm::vec3>& handPositions, |
| 233 | const std::vector<glm::vec3>& handNormals) { | 304 | const std::vector<glm::vec3>& handNormals) { |
| 234 | for (size_t i = 0; i < getNumPalms(); ++i) { | 305 | for (size_t i = 0; i < getNumPalms(); ++i) { |
| @@ -244,69 +315,28 @@ void Hand::setLeapHands(const std::vector<glm::vec3>& handPositions, · 9 unmodified lines | |||
| 244 | } | 315 | } |
| 245 | } | 316 | } |
| 246 | 317 | ||
| 247 | // call this right after the geometry of the leap hands are set | ||
| 248 | void Hand::updateRaveGloveEmitters() { | ||
| 249 | 318 | ||
| 250 | bool debug = false; | 319 | // call this soon after the geometry of the leap hands are set |
| 320 | void Hand::updateRaveGloveEmitters() { | ||
| 251 | 321 | ||
| 252 | if (_raveGloveInitialized) { | 322 | for (size_t i = 0; i < NUM_FINGERS; i++) { |
| 253 | 323 | _raveGloveParticleSystem.setEmitterActive(_raveGloveEmitter[i], false); | |
| 254 | if(debug) printf( "\n" ); | 324 | } |
| 255 | if(debug) printf( "------------------------------------\n" ); | ||
| 256 | if(debug) printf( "updating rave glove emitters:\n" ); | ||
| 257 | if(debug) printf( "------------------------------------\n" ); | ||
| 258 | |||
| 259 | int emitterIndex = 0; | ||
| 260 | 325 | ||
| 261 | for (size_t i = 0; i < getNumPalms(); ++i) { | 326 | for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) { |
| 262 | PalmData& palm = getPalms()[i]; | 327 | if (i < NUM_FINGERS) { |
| 263 | 328 | glm::vec3 fingerDirection = _leapFingerTipBalls[i].position - _leapFingerRootBalls[i].position; | |
| 264 | if(debug) printf( "\n" ); | 329 | float fingerLength = glm::length(fingerDirection); |
| 265 | if(debug) printf( "palm %d ", (int)i ); | ||
| 266 | |||
| 267 | if (palm.isActive()) { | ||
| 268 | 330 | ||
| 269 | if(debug) printf( "is active\n" ); | 331 | if (fingerLength > 0.0f) { |
| 270 | 332 | fingerDirection /= fingerLength; | |
| 271 | for (size_t f = 0; f < palm.getNumFingers(); ++f) { | ||
| 272 | FingerData& finger = palm.getFingers()[f]; | ||
| 273 | |||
| 274 | if(debug) printf( "emitterIndex %d: ", emitterIndex ); | ||
| 275 | |||
| 276 | if (finger.isActive()) { | ||
| 277 | |||
| 278 | if ((emitterIndex >=0) | ||
| 279 | && (emitterIndex < NUM_FINGERS)) { | ||
| 280 | |||
| 281 | assert(emitterIndex >=0 ); | ||
| 282 | assert(emitterIndex < NUM_FINGERS ); | ||
| 283 | |||
| 284 | if(debug) printf( "_raveGloveEmitter[%d] = %d\n", emitterIndex, _raveGloveEmitter[emitterIndex] ); | ||
| 285 | |||
| 286 | glm::vec3 fingerDirection = finger.getTipPosition() - finger.getRootPosition(); | ||
| 287 | float fingerLength = glm::length(fingerDirection); | ||
| 288 | |||
| 289 | if (fingerLength > 0.0f) { | ||
| 290 | fingerDirection /= fingerLength; | ||
| 291 | } else { | ||
| 292 | fingerDirection = IDENTITY_UP; | ||
| 293 | } | ||
| 294 | |||
| 295 | assert(_raveGloveEmitter[emitterIndex] >=0 ); | ||
| 296 | assert(_raveGloveEmitter[emitterIndex] < NUM_FINGERS ); | ||
| 297 | |||
| 298 | _raveGloveParticleSystem.setEmitterPosition (_raveGloveEmitter[emitterIndex], finger.getTipPosition()); | ||
| 299 | _raveGloveParticleSystem.setEmitterDirection(_raveGloveEmitter[emitterIndex], fingerDirection); | ||
| 300 | } | ||
| 301 | } else { | ||
| 302 | if(debug) printf( "BOGUS finger\n" ); | ||
| 303 | } | ||
| 304 | |||
| 305 | emitterIndex ++; | ||
| 306 | } | ||
| 307 | } else { | 333 | } else { |
| 308 | if(debug) printf( "is NOT active\n" ); | 334 | fingerDirection = IDENTITY_UP; |
| 309 | } | 335 | } |
| 336 | |||
| 337 | _raveGloveParticleSystem.setEmitterActive (_raveGloveEmitter[i], true); | ||
| 338 | _raveGloveParticleSystem.setEmitterPosition (_raveGloveEmitter[i], _leapFingerTipBalls[i].position); | ||
| 339 | _raveGloveParticleSystem.setEmitterDirection(_raveGloveEmitter[i], fingerDirection); | ||
| 310 | } | 340 | } |
| 311 | } | 341 | } |
| 312 | } | 342 | } |
| @@ -317,16 +347,11 @@ void Hand::updateRaveGloveParticles(float deltaTime) { · 4 unmodified lines | |||
| 317 | 347 | ||
| 318 | if (!_raveGloveInitialized) { | 348 | if (!_raveGloveInitialized) { |
| 319 | 349 | ||
| 320 | //printf( "Initializing rave glove emitters:\n" ); | ||
| 321 | //printf( "The indices of the emitters are:\n" ); | ||
| 322 | |||
| 323 | // start up the rave glove finger particles... | 350 | // start up the rave glove finger particles... |
| 324 | for ( int f = 0; f< NUM_FINGERS; f ++ ) { | 351 | for ( int f = 0; f< NUM_FINGERS; f ++ ) { |
| 325 | _raveGloveEmitter[f] = _raveGloveParticleSystem.addEmitter(); | 352 | _raveGloveEmitter[f] = _raveGloveParticleSystem.addEmitter(); |
| 326 | assert( _raveGloveEmitter[f] >= 0 ); | 353 | assert( _raveGloveEmitter[f] >= 0 ); |
| 327 | assert( _raveGloveEmitter[f] != NULL_EMITTER ); | 354 | assert( _raveGloveEmitter[f] != NULL_EMITTER ); |
| 328 | |||
| 329 | //printf( "%d\n", _raveGloveEmitter[f] ); | ||
| 330 | } | 355 | } |
| 331 | 356 | ||
| 332 | setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_FIRE); | 357 | setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_FIRE); |
| @@ -339,13 +364,13 @@ void Hand::updateRaveGloveParticles(float deltaTime) { · 6 unmodified lines | |||
| 339 | // this rave glove effect oscillates though various colors and radii that are meant to show off some effects | 364 | // this rave glove effect oscillates though various colors and radii that are meant to show off some effects |
| 340 | if (_raveGloveMode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) { | 365 | if (_raveGloveMode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) { |
| 341 | ParticleSystem::ParticleAttributes attributes; | 366 | ParticleSystem::ParticleAttributes attributes; |
| 342 | float red = 0.5f + 0.5f * sinf(_raveGloveClock * 1.4f); | 367 | float red = 0.5f + 0.5f * sinf(_raveGloveClock * 2.4f); |
| 343 | float green = 0.5f + 0.5f * cosf(_raveGloveClock * 1.7f); | 368 | float green = 0.5f + 0.5f * cosf(_raveGloveClock * 2.7f); |
| 344 | float blue = 0.5f + 0.5f * sinf(_raveGloveClock * 2.0f); | 369 | float blue = 0.5f + 0.5f * sinf(_raveGloveClock * 3.0f); |
| 345 | float alpha = 1.0f; | 370 | float alpha = 1.0f; |
| 346 | 371 | ||
| 347 | attributes.color = glm::vec4(red, green, blue, alpha); | 372 | attributes.color = glm::vec4(red, green, blue, alpha); |
| 348 | attributes.radius = 0.01f + 0.005f * sinf(_raveGloveClock * 2.2f); | 373 | attributes.radius = 0.01f + 0.003f * sinf(_raveGloveClock * 50.0f); |
| 349 | attributes.modulationAmplitude = 0.0f; | 374 | attributes.modulationAmplitude = 0.0f; |
| 350 | 375 | ||
| 351 | for ( int f = 0; f< NUM_FINGERS; f ++ ) { | 376 | for ( int f = 0; f< NUM_FINGERS; f ++ ) { |
| @@ -360,6 +385,8 @@ void Hand::updateRaveGloveParticles(float deltaTime) { · 8 unmodified lines | |||
| 360 | } | 385 | } |
| 361 | } | 386 | } |
| 362 | 387 | ||
| 388 | |||
| 389 | |||
| 363 | void Hand::setRaveGloveMode(int mode) { | 390 | void Hand::setRaveGloveMode(int mode) { |
| 364 | 391 | ||
| 365 | _raveGloveMode = mode; | 392 | _raveGloveMode = mode; |
| @@ -376,7 +403,7 @@ void Hand::setRaveGloveMode(int mode) { · 10 unmodified lines | |||
| 376 | if (mode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) { | 403 | if (mode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) { |
| 377 | _raveGloveParticleSystem.setParticleRenderStyle (_raveGloveEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); | 404 | _raveGloveParticleSystem.setParticleRenderStyle (_raveGloveEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); |
| 378 | _raveGloveParticleSystem.setShowingEmitterBaseParticle(_raveGloveEmitter[f], true ); | 405 | _raveGloveParticleSystem.setShowingEmitterBaseParticle(_raveGloveEmitter[f], true ); |
| 379 | _raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.0f ); | 406 | _raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.03f ); |
| 380 | _raveGloveParticleSystem.setEmitterThrust (_raveGloveEmitter[f], 0.0f ); | 407 | _raveGloveParticleSystem.setEmitterThrust (_raveGloveEmitter[f], 0.0f ); |
| 381 | _raveGloveParticleSystem.setEmitterRate (_raveGloveEmitter[f], 30.0f ); | 408 | _raveGloveParticleSystem.setEmitterRate (_raveGloveEmitter[f], 30.0f ); |
| 382 | _raveGloveParticleSystem.setEmitterParticleResolution (_raveGloveEmitter[f], 20 ); | 409 | _raveGloveParticleSystem.setEmitterParticleResolution (_raveGloveEmitter[f], 20 ); |
| @@ -650,7 +677,7 @@ void Hand::setRaveGloveMode(int mode) { · 267 unmodified lines | |||
| 650 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes); | 677 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes); |
| 651 | 678 | ||
| 652 | //----------------------------------------- | 679 | //----------------------------------------- |
| 653 | // throb | 680 | // long sparkler |
| 654 | //----------------------------------------- | 681 | //----------------------------------------- |
| 655 | } else if (mode == RAVE_GLOVE_EFFECTS_MODE_LONG_SPARKLER) { | 682 | } else if (mode == RAVE_GLOVE_EFFECTS_MODE_LONG_SPARKLER) { |
| 656 | 683 | ||
| @@ -672,6 +699,30 @@ void Hand::setRaveGloveMode(int mode) { · 15 unmodified lines | |||
| 672 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_1, attributes); | 699 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_1, attributes); |
| 673 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_2, attributes); | 700 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_2, attributes); |
| 674 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes); | 701 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes); |
| 702 | |||
| 703 | //----------------------------------------- | ||
| 704 | // throb | ||
| 705 | //----------------------------------------- | ||
| 706 | } else if (mode == RAVE_GLOVE_EFFECTS_MODE_THROB) { | ||
| 707 | |||
| 708 | _raveGloveParticleSystem.setParticleRenderStyle (_raveGloveEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); | ||
| 709 | _raveGloveParticleSystem.setShowingEmitterBaseParticle(_raveGloveEmitter[f], true ); | ||
| 710 | _raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.03 ); | ||
| 711 | _raveGloveParticleSystem.setEmitterThrust (_raveGloveEmitter[f], 0.0f ); | ||
| 712 | _raveGloveParticleSystem.setEmitterRate (_raveGloveEmitter[f], 30.0 ); | ||
| 713 | _raveGloveParticleSystem.setEmitterParticleResolution (_raveGloveEmitter[f], 20 ); | ||
| 714 | |||
| 715 | _raveGloveParticleSystem.setParticleAttributesToDefault(&attributes); | ||
| 716 | |||
| 717 | attributes.radius = 0.01f; | ||
| 718 | attributes.color = glm::vec4( 0.1f, 0.2f, 0.4f, 0.5f); | ||
| 719 | attributes.modulationAmplitude = 0.5; | ||
| 720 | attributes.modulationRate = 3.0; | ||
| 721 | attributes.modulationStyle = COLOR_MODULATION_STYLE_LIGHTNESS_WAVE; | ||
| 722 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_0, attributes); | ||
| 723 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_1, attributes); | ||
| 724 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_2, attributes); | ||
| 725 | _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes); | ||
| 675 | } | 726 | } |
| 676 | } | 727 | } |
| 677 | } | 728 | } |
| @@ -65,8 +65,9 @@ public: · 64 unmodified lines | |||
| 65 | void setRaveGloveEffectsMode(QKeyEvent* event); | 65 | void setRaveGloveEffectsMode(QKeyEvent* event); |
| 66 | 66 | ||
| 67 | // getters | 67 | // getters |
| 68 | const glm::vec3& getLeapBallPosition (int ball) const { return _leapBalls[ball].position;} | 68 | const glm::vec3& getLeapFingerTipBallPosition (int ball) const { return _leapFingerTipBalls [ball].position;} |
| 69 | bool isRaveGloveActive () const { return _isRaveGloveActive; } | 69 | const glm::vec3& getLeapFingerRootBallPosition(int ball) const { return _leapFingerRootBalls[ball].position;} |
| 70 | bool isRaveGloveActive() const { return _isRaveGloveActive; } | ||
| 70 | 71 | ||
| 71 | private: | 72 | private: |
| 72 | // disallow copies of the Hand, copy of owning Avatar is disallowed too | 73 | // disallow copies of the Hand, copy of owning Avatar is disallowed too |
| @@ -84,7 +85,8 @@ private: · 11 unmodified lines | |||
| 84 | float _renderAlpha; | 85 | float _renderAlpha; |
| 85 | bool _lookingInMirror; | 86 | bool _lookingInMirror; |
| 86 | glm::vec3 _ballColor; | 87 | glm::vec3 _ballColor; |
| 87 | std::vector<HandBall> _leapBalls; | 88 | std::vector<HandBall> _leapFingerTipBalls; |
| 89 | std::vector<HandBall> _leapFingerRootBalls; | ||
| 88 | 90 | ||
| 89 | // private methods | 91 | // private methods |
| 90 | void setLeapHands(const std::vector<glm::vec3>& handPositions, | 92 | void setLeapHands(const std::vector<glm::vec3>& handPositions, |
| @@ -92,8 +94,10 @@ private: · 1 unmodified line | |||
| 92 | 94 | ||
| 93 | void renderRaveGloveStage(); | 95 | void renderRaveGloveStage(); |
| 94 | void setRaveGloveMode(int mode); | 96 | void setRaveGloveMode(int mode); |
| 95 | void renderHandSpheres(); | 97 | void renderLeapHandSpheres(); |
| 96 | void renderFingerTrails(); | 98 | void renderLeapHands(); |
| 99 | void renderLeapHand(PalmData& hand); | ||
| 100 | void renderLeapFingerTrails(); | ||
| 97 | void calculateGeometry(); | 101 | void calculateGeometry(); |
| 98 | }; | 102 | }; |
| 99 | 103 | ||
| @@ -130,6 +130,8 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { · 129 unmodified lines | |||
| 130 | 130 | ||
| 131 | // leap hand data | 131 | // leap hand data |
| 132 | std::vector<glm::vec3> fingerVectors; | 132 | std::vector<glm::vec3> fingerVectors; |
| 133 | |||
| 134 | //printf("about to call _handData->encodeRemoteData(fingerVectors);\n"); | ||
| 133 | _handData->encodeRemoteData(fingerVectors); | 135 | _handData->encodeRemoteData(fingerVectors); |
| 134 | 136 | ||
| 135 | if (fingerVectors.size() > 255) | 137 | if (fingerVectors.size() > 255) |
| @@ -244,17 +246,32 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { · 108 unmodified lines | |||
| 244 | // hand state, stored as a semi-nibble in the bitItems | 246 | // hand state, stored as a semi-nibble in the bitItems |
| 245 | _handState = getSemiNibbleAt(bitItems,HAND_STATE_START_BIT); | 247 | _handState = getSemiNibbleAt(bitItems,HAND_STATE_START_BIT); |
| 246 | 248 | ||
| 249 | //printf("about to call leap hand data code in AvatarData::parseData...\n"); | ||
| 250 | |||
| 247 | // leap hand data | 251 | // leap hand data |
| 248 | if (sourceBuffer - startPosition < numBytes) { | 252 | if (sourceBuffer - startPosition < numBytes) { |
| 253 | |||
| 254 | //printf("got inside of 'if (sourceBuffer - startPosition < numBytes)'\n"); | ||
| 255 | |||
| 256 | |||
| 249 | // check passed, bytes match | 257 | // check passed, bytes match |
| 250 | unsigned int numFingerVectors = *sourceBuffer++; | 258 | unsigned int numFingerVectors = *sourceBuffer++; |
| 259 | |||
| 260 | //printf("numFingerVectors = %d\n", numFingerVectors); | ||
| 261 | |||
| 262 | |||
| 251 | if (numFingerVectors > 0) { | 263 | if (numFingerVectors > 0) { |
| 264 | |||
| 265 | //printf("ok, we got fingers in AvatarData::parseData\n"); | ||
| 266 | |||
| 252 | std::vector<glm::vec3> fingerVectors(numFingerVectors); | 267 | std::vector<glm::vec3> fingerVectors(numFingerVectors); |
| 253 | for (size_t i = 0; i < numFingerVectors; ++i) { | 268 | for (size_t i = 0; i < numFingerVectors; ++i) { |
| 254 | sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].x), fingerVectorRadix); | 269 | sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].x), fingerVectorRadix); |
| 255 | sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].y), fingerVectorRadix); | 270 | sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].y), fingerVectorRadix); |
| 256 | sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].z), fingerVectorRadix); | 271 | sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].z), fingerVectorRadix); |
| 257 | } | 272 | } |
| 273 | |||
| 274 | //printf("about to call _handData->decodeRemoteData(fingerVectors);\n"); | ||
| 258 | _handData->decodeRemoteData(fingerVectors); | 275 | _handData->decodeRemoteData(fingerVectors); |
| 259 | } | 276 | } |
| 260 | } | 277 | } |
| @@ -51,7 +51,9 @@ _owningHandData(owningHandData) · 50 unmodified lines | |||
| 51 | 51 | ||
| 52 | void HandData::encodeRemoteData(std::vector<glm::vec3>& fingerVectors) { | 52 | void HandData::encodeRemoteData(std::vector<glm::vec3>& fingerVectors) { |
| 53 | fingerVectors.clear(); | 53 | fingerVectors.clear(); |
| 54 | |||
| 54 | for (size_t i = 0; i < getNumPalms(); ++i) { | 55 | for (size_t i = 0; i < getNumPalms(); ++i) { |
| 56 | |||
| 55 | PalmData& palm = getPalms()[i]; | 57 | PalmData& palm = getPalms()[i]; |
| 56 | if (!palm.isActive()) { | 58 | if (!palm.isActive()) { |
| 57 | continue; | 59 | continue; |
| @@ -60,6 +62,7 @@ void HandData::encodeRemoteData(std::vector<glm::vec3>& fingerVectors) { · 2 unmodified lines | |||
| 60 | fingerVectors.push_back(palm.getRawNormal()); | 62 | fingerVectors.push_back(palm.getRawNormal()); |
| 61 | for (size_t f = 0; f < palm.getNumFingers(); ++f) { | 63 | for (size_t f = 0; f < palm.getNumFingers(); ++f) { |
| 62 | FingerData& finger = palm.getFingers()[f]; | 64 | FingerData& finger = palm.getFingers()[f]; |
| 65 | |||
| 63 | if (finger.isActive()) { | 66 | if (finger.isActive()) { |
| 64 | fingerVectors.push_back(finger.getTipRawPosition()); | 67 | fingerVectors.push_back(finger.getTipRawPosition()); |
| 65 | fingerVectors.push_back(finger.getRootRawPosition()); | 68 | fingerVectors.push_back(finger.getRootRawPosition()); |
| @@ -24,10 +24,9 @@ · 23 unmodified lines | |||
| 24 | #include <arpa/inet.h> | 24 | #include <arpa/inet.h> |
| 25 | #endif | 25 | #endif |
| 26 | 26 | ||
| 27 | const char SOLO_NODE_TYPES[3] = { | 27 | const char SOLO_NODE_TYPES[2] = { |
| 28 | NODE_TYPE_AVATAR_MIXER, | 28 | NODE_TYPE_AVATAR_MIXER, |
| 29 | NODE_TYPE_AUDIO_MIXER, | 29 | NODE_TYPE_AUDIO_MIXER |
| 30 | NODE_TYPE_VOXEL_SERVER | ||
| 31 | }; | 30 | }; |
| 32 | 31 | ||
| 33 | const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES] = "root.highfidelity.io"; | 32 | const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES] = "root.highfidelity.io"; |
| @@ -32,7 +32,7 @@ const unsigned int NODE_SOCKET_LISTEN_PORT = 40103; · 31 unmodified lines | |||
| 32 | const int NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000; | 32 | const int NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000; |
| 33 | const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000; | 33 | const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000; |
| 34 | 34 | ||
| 35 | extern const char SOLO_NODE_TYPES[3]; | 35 | extern const char SOLO_NODE_TYPES[2]; |
| 36 | 36 | ||
| 37 | const int MAX_HOSTNAME_BYTES = 256; | 37 | const int MAX_HOSTNAME_BYTES = 256; |
| 38 | 38 | ||
| @@ -257,3 +257,42 @@ unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* · 256 unmodified lines | |||
| 257 | return newCode; | 257 | return newCode; |
| 258 | } | 258 | } |
| 259 | 259 | ||
| 260 | bool isAncestorOf(unsigned char* possibleAncestor, unsigned char* possibleDescendent, int descendentsChild) { | ||
| 261 | if (!possibleAncestor || !possibleDescendent) { | ||
| 262 | return false; | ||
| 263 | } | ||
| 264 | |||
| 265 | int ancestorCodeLength = numberOfThreeBitSectionsInCode(possibleAncestor); | ||
| 266 | if (ancestorCodeLength == 0) { | ||
| 267 | return true; // this is the root, it's the anscestor of all | ||
| 268 | } | ||
| 269 | |||
| 270 | int descendentCodeLength = numberOfThreeBitSectionsInCode(possibleDescendent); | ||
| 271 | |||
| 272 | // if the caller also include a child, then our descendent length is actually one extra! | ||
| 273 | if (descendentsChild != CHECK_NODE_ONLY) { | ||
| 274 | descendentCodeLength++; | ||
| 275 | } | ||
| 276 | |||
| 277 | if (ancestorCodeLength > descendentCodeLength) { | ||
| 278 | return false; // if the descendent is shorter, it can't be a descendent | ||
| 279 | } | ||
| 280 | |||
| 281 | // compare the sections for the ancestor to the descendent | ||
| 282 | for (int section = 0; section < ancestorCodeLength; section++) { | ||
| 283 | char sectionValueAncestor = getOctalCodeSectionValue(possibleAncestor, section); | ||
| 284 | char sectionValueDescendent; | ||
| 285 | if (ancestorCodeLength <= descendentCodeLength) { | ||
| 286 | sectionValueDescendent = getOctalCodeSectionValue(possibleDescendent, section); | ||
| 287 | } else { | ||
| 288 | assert(descendentsChild != CHECK_NODE_ONLY); | ||
| 289 | sectionValueDescendent = descendentsChild; | ||
| 290 | } | ||
| 291 | if (sectionValueAncestor != sectionValueDescendent) { | ||
| 292 | return false; // first non-match, means they don't match | ||
| 293 | } | ||
| 294 | } | ||
| 295 | |||
| 296 | // they all match, so we are an ancestor | ||
| 297 | return true; | ||
| 298 | } | ||
| @@ -21,7 +21,6 @@ const int BLUE_INDEX = 2; · 20 unmodified lines | |||
| 21 | 21 | ||
| 22 | void printOctalCode(unsigned char * octalCode); | 22 | void printOctalCode(unsigned char * octalCode); |
| 23 | int bytesRequiredForCodeLength(unsigned char threeBitCodes); | 23 | int bytesRequiredForCodeLength(unsigned char threeBitCodes); |
| 24 | bool isDirectParentOfChild(unsigned char *parentOctalCode, unsigned char * childOctalCode); | ||
| 25 | int branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode); | 24 | int branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode); |
| 26 | unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber); | 25 | unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber); |
| 27 | int numberOfThreeBitSectionsInCode(unsigned char * octalCode); | 26 | int numberOfThreeBitSectionsInCode(unsigned char * octalCode); |
| @@ -29,6 +28,9 @@ unsigned char* chopOctalCode(unsigned char* originalOctalCode, int chopLevels); · 1 unmodified line | |||
| 29 | unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* newParentOctalCode, | 28 | unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* newParentOctalCode, |
| 30 | bool includeColorSpace = false); | 29 | bool includeColorSpace = false); |
| 31 | 30 | ||
| 31 | const int CHECK_NODE_ONLY = -1; | ||
| 32 | bool isAncestorOf(unsigned char* possibleAncestor, unsigned char* possibleDescendent, int descendentsChild = CHECK_NODE_ONLY); | ||
| 33 | |||
| 32 | // Note: copyFirstVertexForCode() is preferred because it doesn't allocate memory for the return | 34 | // Note: copyFirstVertexForCode() is preferred because it doesn't allocate memory for the return |
| 33 | // but other than that these do the same thing. | 35 | // but other than that these do the same thing. |
| 34 | float * firstVertexForCode(unsigned char * octalCode); | 36 | float * firstVertexForCode(unsigned char * octalCode); |
| @@ -0,0 +1,178 @@ | |||
| 1 | // | ||
| 2 | // JurisdictionMap.cpp | ||
| 3 | // hifi | ||
| 4 | // | ||
| 5 | // Created by Brad Hefta-Gaub on 8/1/13. | ||
| 6 | // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #include <QSettings> | ||
| 10 | #include <QString> | ||
| 11 | #include <QStringList> | ||
| 12 | |||
| 13 | #include "JurisdictionMap.h" | ||
| 14 | #include "VoxelNode.h" | ||
| 15 | |||
| 16 | JurisdictionMap::~JurisdictionMap() { | ||
| 17 | clear(); | ||
| 18 | } | ||
| 19 | |||
| 20 | void JurisdictionMap::clear() { | ||
| 21 | if (_rootOctalCode) { | ||
| 22 | delete[] _rootOctalCode; | ||
| 23 | _rootOctalCode = NULL; | ||
| 24 | } | ||
| 25 | |||
| 26 | for (int i = 0; i < _endNodes.size(); i++) { | ||
| 27 | if (_endNodes[i]) { | ||
| 28 | delete[] _endNodes[i]; | ||
| 29 | } | ||
| 30 | } | ||
| 31 | _endNodes.clear(); | ||
| 32 | } | ||
| 33 | |||
| 34 | JurisdictionMap::JurisdictionMap() : _rootOctalCode(NULL) { | ||
| 35 | unsigned char* rootCode = new unsigned char[1]; | ||
| 36 | *rootCode = 0; | ||
| 37 | |||
| 38 | std::vector<unsigned char*> emptyEndNodes; | ||
| 39 | init(rootCode, emptyEndNodes); | ||
| 40 | } | ||
| 41 | |||
| 42 | JurisdictionMap::JurisdictionMap(const char* filename) : _rootOctalCode(NULL) { | ||
| 43 | clear(); // clean up our own memory | ||
| 44 | readFromFile(filename); | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | JurisdictionMap::JurisdictionMap(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes) | ||
| 49 | : _rootOctalCode(NULL) { | ||
| 50 | init(rootOctalCode, endNodes); | ||
| 51 | } | ||
| 52 | |||
| 53 | void JurisdictionMap::init(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes) { | ||
| 54 | clear(); // clean up our own memory | ||
| 55 | _rootOctalCode = rootOctalCode; | ||
| 56 | _endNodes = endNodes; | ||
| 57 | } | ||
| 58 | |||
| 59 | JurisdictionMap::Area JurisdictionMap::isMyJurisdiction(unsigned char* nodeOctalCode, int childIndex) const { | ||
| 60 | // to be in our jurisdiction, we must be under the root... | ||
| 61 | |||
| 62 | // if the node is an ancestor of my root, then we return ABOVE | ||
| 63 | if (isAncestorOf(nodeOctalCode, _rootOctalCode)) { | ||
| 64 | return ABOVE; | ||
| 65 | } | ||
| 66 | |||
| 67 | // otherwise... | ||
| 68 | bool isInJurisdiction = isAncestorOf(_rootOctalCode, nodeOctalCode, childIndex); | ||
| 69 | |||
| 70 | //printf("isInJurisdiction=%s rootOctalCode=",debug::valueOf(isInJurisdiction)); | ||
| 71 | //printOctalCode(_rootOctalCode); | ||
| 72 | //printf("nodeOctalCode="); | ||
| 73 | //printOctalCode(nodeOctalCode); | ||
| 74 | |||
| 75 | // if we're under the root, then we can't be under any of the endpoints | ||
| 76 | if (isInJurisdiction) { | ||
| 77 | for (int i = 0; i < _endNodes.size(); i++) { | ||
| 78 | bool isUnderEndNode = isAncestorOf(_endNodes[i], nodeOctalCode); | ||
| 79 | if (isUnderEndNode) { | ||
| 80 | isInJurisdiction = false; | ||
| 81 | break; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | return isInJurisdiction ? WITHIN : BELOW; | ||
| 87 | } | ||
| 88 | |||
| 89 | |||
| 90 | bool JurisdictionMap::readFromFile(const char* filename) { | ||
| 91 | QString settingsFile(filename); | ||
| 92 | QSettings settings(settingsFile, QSettings::IniFormat); | ||
| 93 | QString rootCode = settings.value("root","00").toString(); | ||
| 94 | qDebug() << "rootCode=" << rootCode << "\n"; | ||
| 95 | |||
| 96 | _rootOctalCode = hexStringToOctalCode(rootCode); | ||
| 97 | printOctalCode(_rootOctalCode); | ||
| 98 | |||
| 99 | settings.beginGroup("endNodes"); | ||
| 100 | const QStringList childKeys = settings.childKeys(); | ||
| 101 | QHash<QString, QString> values; | ||
| 102 | foreach (const QString &childKey, childKeys) { | ||
| 103 | QString childValue = settings.value(childKey).toString(); | ||
| 104 | values.insert(childKey, childValue); | ||
| 105 | qDebug() << childKey << "=" << childValue << "\n"; | ||
| 106 | |||
| 107 | unsigned char* octcode = hexStringToOctalCode(childValue); | ||
| 108 | printOctalCode(octcode); | ||
| 109 | |||
| 110 | _endNodes.push_back(octcode); | ||
| 111 | } | ||
| 112 | settings.endGroup(); | ||
| 113 | return true; | ||
| 114 | } | ||
| 115 | |||
| 116 | bool JurisdictionMap::writeToFile(const char* filename) { | ||
| 117 | QString settingsFile(filename); | ||
| 118 | QSettings settings(settingsFile, QSettings::IniFormat); | ||
| 119 | |||
| 120 | |||
| 121 | QString rootNodeValue = octalCodeToHexString(_rootOctalCode); | ||
| 122 | |||
| 123 | settings.setValue("root", rootNodeValue); | ||
| 124 | |||
| 125 | settings.beginGroup("endNodes"); | ||
| 126 | for (int i = 0; i < _endNodes.size(); i++) { | ||
| 127 | QString key = QString("endnode%1").arg(i); | ||
| 128 | QString value = octalCodeToHexString(_endNodes[i]); | ||
| 129 | settings.setValue(key, value); | ||
| 130 | } | ||
| 131 | settings.endGroup(); | ||
| 132 | return true; | ||
| 133 | } | ||
| 134 | |||
| 135 | |||
| 136 | unsigned char* JurisdictionMap::hexStringToOctalCode(const QString& input) const { | ||
| 137 | const int HEX_NUMBER_BASE = 16; | ||
| 138 | const int HEX_BYTE_SIZE = 2; | ||
| 139 | int stringIndex = 0; | ||
| 140 | int byteArrayIndex = 0; | ||
| 141 | |||
| 142 | // allocate byte array based on half of string length | ||
| 143 | unsigned char* bytes = new unsigned char[(input.length()) / HEX_BYTE_SIZE]; | ||
| 144 | |||
| 145 | // loop through the string - 2 bytes at a time converting | ||
| 146 | // it to decimal equivalent and store in byte array | ||
| 147 | bool ok; | ||
| 148 | while (stringIndex < input.length()) { | ||
| 149 | uint value = input.mid(stringIndex, HEX_BYTE_SIZE).toUInt(&ok, HEX_NUMBER_BASE); | ||
| 150 | if (!ok) { | ||
| 151 | break; | ||
| 152 | } | ||
| 153 | bytes[byteArrayIndex] = (unsigned char)value; | ||
| 154 | stringIndex += HEX_BYTE_SIZE; | ||
| 155 | byteArrayIndex++; | ||
| 156 | } | ||
| 157 | |||
| 158 | // something went wrong | ||
| 159 | if (!ok) { | ||
| 160 | delete[] bytes; | ||
| 161 | return NULL; | ||
| 162 | } | ||
| 163 | return bytes; | ||
| 164 | } | ||
| 165 | |||
| 166 | QString JurisdictionMap::octalCodeToHexString(unsigned char* octalCode) const { | ||
| 167 | const int HEX_NUMBER_BASE = 16; | ||
| 168 | const int HEX_BYTE_SIZE = 2; | ||
| 169 | QString output; | ||
| 170 | if (!octalCode) { | ||
| 171 | output = "00"; | ||
| 172 | } else { | ||
| 173 | for (int i = 0; i < bytesRequiredForCodeLength(*octalCode); i++) { | ||
| 174 | output.append(QString("%1").arg(octalCode[i], HEX_BYTE_SIZE, HEX_NUMBER_BASE, QChar('0')).toUpper()); | ||
| 175 | } | ||
| 176 | } | ||
| 177 | return output; | ||
| 178 | } | ||
| @@ -0,0 +1,46 @@ | |||
| 1 | // | ||
| 2 | // JurisdictionMap.h | ||
| 3 | // hifi | ||
| 4 | // | ||
| 5 | // Created by Brad Hefta-Gaub on 8/1/13. | ||
| 6 | // Copyright (c) 2013 High Fidelity, Inc. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #ifndef __hifi__JurisdictionMap__ | ||
| 10 | #define __hifi__JurisdictionMap__ | ||
| 11 | |||
| 12 | #include <vector> | ||
| 13 | #include <QString> | ||
| 14 | |||
| 15 | class JurisdictionMap { | ||
| 16 | public: | ||
| 17 | enum Area { | ||
| 18 | ABOVE, | ||
| 19 | WITHIN, | ||
| 20 | BELOW | ||
| 21 | }; | ||
| 22 | |||
| 23 | JurisdictionMap(); | ||
| 24 | JurisdictionMap(const char* filename); | ||
| 25 | JurisdictionMap(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes); | ||
| 26 | ~JurisdictionMap(); | ||
| 27 | |||
| 28 | Area isMyJurisdiction(unsigned char* nodeOctalCode, int childIndex) const; | ||
| 29 | |||
| 30 | bool writeToFile(const char* filename); | ||
| 31 | bool readFromFile(const char* filename); | ||
| 32 | |||
| 33 | private: | ||
| 34 | void clear(); | ||
| 35 | void init(unsigned char* rootOctalCode, const std::vector<unsigned char*>& endNodes); | ||
| 36 | |||
| 37 | unsigned char* hexStringToOctalCode(const QString& input) const; | ||
| 38 | QString octalCodeToHexString(unsigned char* octalCode) const; | ||
| 39 | |||
| 40 | unsigned char* _rootOctalCode; | ||
| 41 | std::vector<unsigned char*> _endNodes; | ||
| 42 | }; | ||
| 43 | |||
| 44 | #endif /* defined(__hifi__JurisdictionMap__) */ | ||
| 45 | |||
| 46 | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | // | 1 | // |
| 2 | // Tags.h | 2 | // Tags.cpp |
| 3 | // hifi | 3 | // hifi |
| 4 | // | 4 | // |
| 5 | // Created by Clement Brisset on 7/3/13. | 5 | // Created by Clement Brisset on 7/3/13. |
| @@ -12,6 +12,8 @@ · 11 unmodified lines | |||
| 12 | 12 | ||
| 13 | #include <QDebug> | 13 | #include <QDebug> |
| 14 | 14 | ||
| 15 | #include <NodeList.h> | ||
| 16 | |||
| 15 | #include "AABox.h" | 17 | #include "AABox.h" |
| 16 | #include "OctalCode.h" | 18 | #include "OctalCode.h" |
| 17 | #include "SharedUtil.h" | 19 | #include "SharedUtil.h" |
| @@ -51,6 +53,7 @@ void VoxelNode::init(unsigned char * octalCode) { · 33 unmodified lines | |||
| 51 | _voxelSystem = NULL; | 53 | _voxelSystem = NULL; |
| 52 | _isDirty = true; | 54 | _isDirty = true; |
| 53 | _shouldRender = false; | 55 | _shouldRender = false; |
| 56 | _sourceID = UNKNOWN_NODE_ID; | ||
| 54 | markWithChangedTime(); | 57 | markWithChangedTime(); |
| 55 | calculateAABox(); | 58 | calculateAABox(); |
| 56 | } | 59 | } |
| @@ -93,8 +93,6 @@ public: · 92 unmodified lines | |||
| 93 | void setColor(const nodeColor& color); | 93 | void setColor(const nodeColor& color); |
| 94 | const nodeColor& getTrueColor() const { return _trueColor; }; | 94 | const nodeColor& getTrueColor() const { return _trueColor; }; |
| 95 | const nodeColor& getColor() const { return _currentColor; }; | 95 | const nodeColor& getColor() const { return _currentColor; }; |
| 96 | void setDensity(float density) { _density = density; }; | ||
| 97 | float getDensity() const { return _density; }; | ||
| 98 | #else | 96 | #else |
| 99 | void setFalseColor(colorPart red, colorPart green, colorPart blue) { /* no op */ }; | 97 | void setFalseColor(colorPart red, colorPart green, colorPart blue) { /* no op */ }; |
| 100 | void setFalseColored(bool isFalseColored) { /* no op */ }; | 98 | void setFalseColored(bool isFalseColored) { /* no op */ }; |
| @@ -105,6 +103,11 @@ public: · 4 unmodified lines | |||
| 105 | const nodeColor& getColor() const { return _trueColor; }; | 103 | const nodeColor& getColor() const { return _trueColor; }; |
| 106 | #endif | 104 | #endif |
| 107 | 105 | ||
| 106 | void setDensity(float density) { _density = density; }; | ||
| 107 | float getDensity() const { return _density; }; | ||
| 108 | void setSourceID(uint16_t sourceID) { _sourceID = sourceID; }; | ||
| 109 | uint16_t getSourceID() const { return _sourceID; }; | ||
| 110 | |||
| 108 | static void addDeleteHook(VoxelNodeDeleteHook* hook); | 111 | static void addDeleteHook(VoxelNodeDeleteHook* hook); |
| 109 | static void removeDeleteHook(VoxelNodeDeleteHook* hook); | 112 | static void removeDeleteHook(VoxelNodeDeleteHook* hook); |
| 110 | 113 | ||
| @@ -135,6 +138,7 @@ private: · 24 unmodified lines | |||
| 135 | unsigned long _subtreeNodeCount; | 138 | unsigned long _subtreeNodeCount; |
| 136 | unsigned long _subtreeLeafNodeCount; | 139 | unsigned long _subtreeLeafNodeCount; |
| 137 | float _density; // If leaf: density = 1, if internal node: 0-1 density of voxels inside | 140 | float _density; // If leaf: density = 1, if internal node: 0-1 density of voxels inside |
| 141 | uint16_t _sourceID; | ||
| 138 | 142 | ||
| 139 | static std::vector<VoxelNodeDeleteHook*> _hooks; | 143 | static std::vector<VoxelNodeDeleteHook*> _hooks; |
| 140 | }; | 144 | }; |
| @@ -231,7 +231,7 @@ VoxelNode* VoxelTree::createMissingNode(VoxelNode* lastParentNode, unsigned char · 230 unmodified lines | |||
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, int bytesLeftToRead, | 233 | int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, int bytesLeftToRead, |
| 234 | bool includeColor, bool includeExistsBits) { | 234 | ReadBitstreamToTreeParams& args) { |
| 235 | // give this destination node the child mask from the packet | 235 | // give this destination node the child mask from the packet |
| 236 | const unsigned char ALL_CHILDREN_ASSUMED_TO_EXIST = 0xFF; | 236 | const unsigned char ALL_CHILDREN_ASSUMED_TO_EXIST = 0xFF; |
| 237 | unsigned char colorInPacketMask = *nodeData; | 237 | unsigned char colorInPacketMask = *nodeData; |
| @@ -254,12 +254,13 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, · 16 unmodified lines | |||
| 254 | 254 | ||
| 255 | // pull the color for this child | 255 | // pull the color for this child |
| 256 | nodeColor newColor = { 128, 128, 128, 1}; | 256 | nodeColor newColor = { 128, 128, 128, 1}; |
| 257 | if (includeColor) { | 257 | if (args.includeColor) { |
| 258 | memcpy(newColor, nodeData + bytesRead, 3); | 258 | memcpy(newColor, nodeData + bytesRead, 3); |
| 259 | bytesRead += 3; | 259 | bytesRead += 3; |
| 260 | } | 260 | } |
| 261 | bool nodeWasDirty = destinationNode->getChildAtIndex(i)->isDirty(); | 261 | bool nodeWasDirty = destinationNode->getChildAtIndex(i)->isDirty(); |
| 262 | destinationNode->getChildAtIndex(i)->setColor(newColor); | 262 | destinationNode->getChildAtIndex(i)->setColor(newColor); |
| 263 | destinationNode->getChildAtIndex(i)->setSourceID(args.sourceID); | ||
| 263 | bool nodeIsDirty = destinationNode->getChildAtIndex(i)->isDirty(); | 264 | bool nodeIsDirty = destinationNode->getChildAtIndex(i)->isDirty(); |
| 264 | if (nodeIsDirty) { | 265 | if (nodeIsDirty) { |
| 265 | _isDirty = true; | 266 | _isDirty = true; |
| @@ -273,11 +274,11 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, · 7 unmodified lines | |||
| 273 | } | 274 | } |
| 274 | 275 | ||
| 275 | // give this destination node the child mask from the packet | 276 | // give this destination node the child mask from the packet |
| 276 | unsigned char childrenInTreeMask = includeExistsBits ? *(nodeData + bytesRead) : ALL_CHILDREN_ASSUMED_TO_EXIST; | 277 | unsigned char childrenInTreeMask = args.includeExistsBits ? *(nodeData + bytesRead) : ALL_CHILDREN_ASSUMED_TO_EXIST; |
| 277 | unsigned char childMask = *(nodeData + bytesRead + (includeExistsBits ? sizeof(childrenInTreeMask) : 0)); | 278 | unsigned char childMask = *(nodeData + bytesRead + (args.includeExistsBits ? sizeof(childrenInTreeMask) : 0)); |
| 278 | 279 | ||
| 279 | int childIndex = 0; | 280 | int childIndex = 0; |
| 280 | bytesRead += includeExistsBits ? sizeof(childrenInTreeMask) + sizeof(childMask) : sizeof(childMask); | 281 | bytesRead += args.includeExistsBits ? sizeof(childrenInTreeMask) + sizeof(childMask) : sizeof(childMask); |
| 281 | 282 | ||
| 282 | while (bytesLeftToRead - bytesRead > 0 && childIndex < NUMBER_OF_CHILDREN) { | 283 | while (bytesLeftToRead - bytesRead > 0 && childIndex < NUMBER_OF_CHILDREN) { |
| 283 | // check the exists mask to see if we have a child to traverse into | 284 | // check the exists mask to see if we have a child to traverse into |
| @@ -300,13 +301,12 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, · 16 unmodified lines | |||
| 300 | 301 | ||
| 301 | // tell the child to read the subsequent data | 302 | // tell the child to read the subsequent data |
| 302 | bytesRead += readNodeData(destinationNode->getChildAtIndex(childIndex), | 303 | bytesRead += readNodeData(destinationNode->getChildAtIndex(childIndex), |
| 303 | nodeData + bytesRead, bytesLeftToRead - bytesRead, includeColor, includeExistsBits); | 304 | nodeData + bytesRead, bytesLeftToRead - bytesRead, args); |
| 304 | } | 305 | } |
| 305 | childIndex++; | 306 | childIndex++; |
| 306 | } | 307 | } |
| 307 | 308 | ||
| 308 | 309 | if (args.includeExistsBits) { | |
| 309 | if (includeExistsBits) { | ||
| 310 | for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { | 310 | for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { |
| 311 | // now also check the childrenInTreeMask, if the mask is missing the bit, then it means we need to delete this child | 311 | // now also check the childrenInTreeMask, if the mask is missing the bit, then it means we need to delete this child |
| 312 | // subtree/node, because it shouldn't actually exist in the tree. | 312 | // subtree/node, because it shouldn't actually exist in the tree. |
| @@ -319,14 +319,14 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, · 6 unmodified lines | |||
| 319 | return bytesRead; | 319 | return bytesRead; |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int bufferSizeBytes, | 322 | void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int bufferSizeBytes, |
| 323 | bool includeColor, bool includeExistsBits, VoxelNode* destinationNode) { | 323 | ReadBitstreamToTreeParams& args) { |
| 324 | int bytesRead = 0; | 324 | int bytesRead = 0; |
| 325 | unsigned char* bitstreamAt = bitstream; | 325 | unsigned char* bitstreamAt = bitstream; |
| 326 | 326 | ||
| 327 | // If destination node is not included, set it to root | 327 | // If destination node is not included, set it to root |
| 328 | if (!destinationNode) { | 328 | if (!args.destinationNode) { |
| 329 | destinationNode = rootNode; | 329 | args.destinationNode = rootNode; |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | _nodesChangedFromBitstream = 0; | 332 | _nodesChangedFromBitstream = 0; |
| @@ -336,14 +336,14 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int · 3 unmodified lines | |||
| 336 | // if there are more bytes after that, it's assumed to be another root relative tree | 336 | // if there are more bytes after that, it's assumed to be another root relative tree |
| 337 | 337 | ||
| 338 | while (bitstreamAt < bitstream + bufferSizeBytes) { | 338 | while (bitstreamAt < bitstream + bufferSizeBytes) { |
| 339 | VoxelNode* bitstreamRootNode = nodeForOctalCode(destinationNode, (unsigned char *)bitstreamAt, NULL); | 339 | VoxelNode* bitstreamRootNode = nodeForOctalCode(args.destinationNode, (unsigned char *)bitstreamAt, NULL); |
| 340 | if (*bitstreamAt != *bitstreamRootNode->getOctalCode()) { | 340 | if (*bitstreamAt != *bitstreamRootNode->getOctalCode()) { |
| 341 | // if the octal code returned is not on the same level as | 341 | // if the octal code returned is not on the same level as |
| 342 | // the code being searched for, we have VoxelNodes to create | 342 | // the code being searched for, we have VoxelNodes to create |
| 343 | 343 | ||
| 344 | // Note: we need to create this node relative to root, because we're assuming that the bitstream for the initial | 344 | // Note: we need to create this node relative to root, because we're assuming that the bitstream for the initial |
| 345 | // octal code is always relative to root! | 345 | // octal code is always relative to root! |
| 346 | bitstreamRootNode = createMissingNode(destinationNode, (unsigned char*) bitstreamAt); | 346 | bitstreamRootNode = createMissingNode(args.destinationNode, (unsigned char*) bitstreamAt); |
| 347 | if (bitstreamRootNode->isDirty()) { | 347 | if (bitstreamRootNode->isDirty()) { |
| 348 | _isDirty = true; | 348 | _isDirty = true; |
| 349 | _nodesChangedFromBitstream++; | 349 | _nodesChangedFromBitstream++; |
| @@ -353,8 +353,8 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int · 3 unmodified lines | |||
| 353 | int octalCodeBytes = bytesRequiredForCodeLength(*bitstreamAt); | 353 | int octalCodeBytes = bytesRequiredForCodeLength(*bitstreamAt); |
| 354 | int theseBytesRead = 0; | 354 | int theseBytesRead = 0; |
| 355 | theseBytesRead += octalCodeBytes; | 355 | theseBytesRead += octalCodeBytes; |
| 356 | theseBytesRead += readNodeData(bitstreamRootNode, bitstreamAt + octalCodeBytes, | 356 | theseBytesRead += readNodeData(bitstreamRootNode, bitstreamAt + octalCodeBytes, |
| 357 | bufferSizeBytes - (bytesRead + octalCodeBytes), includeColor, includeExistsBits); | 357 | bufferSizeBytes - (bytesRead + octalCodeBytes), args); |
| 358 | 358 | ||
| 359 | // skip bitstream to new startPoint | 359 | // skip bitstream to new startPoint |
| 360 | bitstreamAt += theseBytesRead; | 360 | bitstreamAt += theseBytesRead; |
| @@ -1078,6 +1078,15 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp · 717 unmodified lines | |||
| 1078 | if (currentEncodeLevel >= params.maxEncodeLevel) { | 1078 | if (currentEncodeLevel >= params.maxEncodeLevel) { |
| 1079 | return bytesAtThisLevel; | 1079 | return bytesAtThisLevel; |
| 1080 | } | 1080 | } |
| 1081 | |||
| 1082 | // If we've been provided a jurisdiction map, then we need to honor it. | ||
| 1083 | if (params.jurisdictionMap) { | ||
| 1084 | // here's how it works... if we're currently above our root jurisdiction, then we proceed normally. | ||
| 1085 | // but once we're in our own jurisdiction, then we need to make sure we're not below it. | ||
| 1086 | if (JurisdictionMap::BELOW == params.jurisdictionMap->isMyJurisdiction(node->getOctalCode(), CHECK_NODE_ONLY)) { | ||
| 1087 | return bytesAtThisLevel; | ||
| 1088 | } | ||
| 1089 | } | ||
| 1081 | 1090 | ||
| 1082 | // caller can pass NULL as viewFrustum if they want everything | 1091 | // caller can pass NULL as viewFrustum if they want everything |
| 1083 | if (params.viewFrustum) { | 1092 | if (params.viewFrustum) { |
| @@ -1197,9 +1206,18 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp · 113 unmodified lines | |||
| 1197 | for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { | 1206 | for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { |
| 1198 | VoxelNode* childNode = node->getChildAtIndex(i); | 1207 | VoxelNode* childNode = node->getChildAtIndex(i); |
| 1199 | 1208 | ||
| 1200 | // if the caller wants to include childExistsBits, then include them even if not in view | 1209 | // if the caller wants to include childExistsBits, then include them even if not in view, if however, |
| 1201 | if (params.includeExistsBits && childNode) { | 1210 | // we're in a portion of the tree that's not our responsibility, then we assume the child nodes exist |
| 1202 | childrenExistInTreeBits += (1 << (7 - i)); | 1211 | // even if they don't in our local tree |
| 1212 | bool notMyJurisdiction = false; | ||
| 1213 | if (params.jurisdictionMap) { | ||
| 1214 | notMyJurisdiction = (JurisdictionMap::BELOW == params.jurisdictionMap->isMyJurisdiction(node->getOctalCode(), i)); | ||
| 1215 | } | ||
| 1216 | if (params.includeExistsBits) { | ||
| 1217 | // If the child is known to exist, OR, it's not my jurisdiction, then we mark the bit as existing | ||
| 1218 | if (childNode || notMyJurisdiction) { | ||
| 1219 | childrenExistInTreeBits += (1 << (7 - i)); | ||
| 1220 | } | ||
| 1203 | } | 1221 | } |
| 1204 | 1222 | ||
| 1205 | if (params.wantOcclusionCulling) { | 1223 | if (params.wantOcclusionCulling) { |
| @@ -1548,7 +1566,8 @@ bool VoxelTree::readFromSVOFile(const char* fileName) { · 342 unmodified lines | |||
| 1548 | // read the entire file into a buffer, WHAT!? Why not. | 1566 | // read the entire file into a buffer, WHAT!? Why not. |
| 1549 | unsigned char* entireFile = new unsigned char[fileLength]; | 1567 | unsigned char* entireFile = new unsigned char[fileLength]; |
| 1550 | file.read((char*)entireFile, fileLength); | 1568 | file.read((char*)entireFile, fileLength); |
| 1551 | readBitstreamToTree(entireFile, fileLength, WANT_COLOR, NO_EXISTS_BITS); | 1569 | ReadBitstreamToTreeParams args(WANT_COLOR, NO_EXISTS_BITS); |
| 1570 | readBitstreamToTree(entireFile, fileLength, args); | ||
| 1552 | delete[] entireFile; | 1571 | delete[] entireFile; |
| 1553 | 1572 | ||
| 1554 | file.close(); | 1573 | file.close(); |
| @@ -1702,7 +1721,8 @@ void VoxelTree::copySubTreeIntoNewTree(VoxelNode* startNode, VoxelTree* destinat · 147 unmodified lines | |||
| 1702 | bytesWritten = encodeTreeBitstream(subTree, &outputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, nodeBag, params); | 1721 | bytesWritten = encodeTreeBitstream(subTree, &outputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, nodeBag, params); |
| 1703 | 1722 | ||
| 1704 | // ask destination tree to read the bitstream | 1723 | // ask destination tree to read the bitstream |
| 1705 | destinationTree->readBitstreamToTree(&outputBuffer[0], bytesWritten, WANT_COLOR, NO_EXISTS_BITS); | 1724 | ReadBitstreamToTreeParams args(WANT_COLOR, NO_EXISTS_BITS); |
| 1725 | destinationTree->readBitstreamToTree(&outputBuffer[0], bytesWritten, args); | ||
| 1706 | } | 1726 | } |
| 1707 | } | 1727 | } |
| 1708 | 1728 | ||
| @@ -1722,7 +1742,8 @@ void VoxelTree::copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelNode* destin · 13 unmodified lines | |||
| 1722 | bytesWritten = sourceTree->encodeTreeBitstream(subTree, &outputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, nodeBag, params); | 1742 | bytesWritten = sourceTree->encodeTreeBitstream(subTree, &outputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, nodeBag, params); |
| 1723 | 1743 | ||
| 1724 | // ask destination tree to read the bitstream | 1744 | // ask destination tree to read the bitstream |
| 1725 | readBitstreamToTree(&outputBuffer[0], bytesWritten, WANT_COLOR, NO_EXISTS_BITS, destinationNode); | 1745 | ReadBitstreamToTreeParams args(WANT_COLOR, NO_EXISTS_BITS, destinationNode); |
| 1746 | readBitstreamToTree(&outputBuffer[0], bytesWritten, args); | ||
| 1726 | } | 1747 | } |
| 1727 | } | 1748 | } |
| 1728 | 1749 | ||
| @@ -1877,4 +1898,4 @@ void VoxelTree::computeBlockColor(int id, int data, int& red, int& green, int& b · 148 unmodified lines | |||
| 1877 | create = 0; | 1898 | create = 0; |
| 1878 | break; | 1899 | break; |
| 1879 | } | 1900 | } |
| 1880 | } | 1901 | } |
| @@ -13,6 +13,7 @@ · 12 unmodified lines | |||
| 13 | #include <SimpleMovingAverage.h> | 13 | #include <SimpleMovingAverage.h> |
| 14 | 14 | ||
| 15 | #include "CoverageMap.h" | 15 | #include "CoverageMap.h" |
| 16 | #include "JurisdictionMap.h" | ||
| 16 | #include "ViewFrustum.h" | 17 | #include "ViewFrustum.h" |
| 17 | #include "VoxelNode.h" | 18 | #include "VoxelNode.h" |
| 18 | #include "VoxelNodeBag.h" | 19 | #include "VoxelNodeBag.h" |
| @@ -36,9 +37,10 @@ const int NO_BOUNDARY_ADJUST = 0; · 17 unmodified lines | |||
| 36 | const int LOW_RES_MOVING_ADJUST = 1; | 37 | const int LOW_RES_MOVING_ADJUST = 1; |
| 37 | const uint64_t IGNORE_LAST_SENT = 0; | 38 | const uint64_t IGNORE_LAST_SENT = 0; |
| 38 | 39 | ||
| 39 | #define IGNORE_SCENE_STATS NULL | 40 | #define IGNORE_SCENE_STATS NULL |
| 40 | #define IGNORE_VIEW_FRUSTUM NULL | 41 | #define IGNORE_VIEW_FRUSTUM NULL |
| 41 | #define IGNORE_COVERAGE_MAP NULL | 42 | #define IGNORE_COVERAGE_MAP NULL |
| 43 | #define IGNORE_JURISDICTION_MAP NULL | ||
| 42 | 44 | ||
| 43 | class EncodeBitstreamParams { | 45 | class EncodeBitstreamParams { |
| 44 | public: | 46 | public: |
| @@ -56,6 +58,7 @@ public: · 11 unmodified lines | |||
| 56 | bool forceSendScene; | 58 | bool forceSendScene; |
| 57 | VoxelSceneStats* stats; | 59 | VoxelSceneStats* stats; |
| 58 | CoverageMap* map; | 60 | CoverageMap* map; |
| 61 | JurisdictionMap* jurisdictionMap; | ||
| 59 | 62 | ||
| 60 | EncodeBitstreamParams( | 63 | EncodeBitstreamParams( |
| 61 | int maxEncodeLevel = INT_MAX, | 64 | int maxEncodeLevel = INT_MAX, |
| @@ -70,7 +73,8 @@ public: · 8 unmodified lines | |||
| 70 | int boundaryLevelAdjust = NO_BOUNDARY_ADJUST, | 73 | int boundaryLevelAdjust = NO_BOUNDARY_ADJUST, |
| 71 | uint64_t lastViewFrustumSent = IGNORE_LAST_SENT, | 74 | uint64_t lastViewFrustumSent = IGNORE_LAST_SENT, |
| 72 | bool forceSendScene = true, | 75 | bool forceSendScene = true, |
| 73 | VoxelSceneStats* stats = IGNORE_SCENE_STATS) : | 76 | VoxelSceneStats* stats = IGNORE_SCENE_STATS, |
| 77 | JurisdictionMap* jurisdictionMap = IGNORE_JURISDICTION_MAP) : | ||
| 74 | maxEncodeLevel (maxEncodeLevel), | 78 | maxEncodeLevel (maxEncodeLevel), |
| 75 | maxLevelReached (0), | 79 | maxLevelReached (0), |
| 76 | viewFrustum (viewFrustum), | 80 | viewFrustum (viewFrustum), |
| @@ -84,7 +88,27 @@ public: · 7 unmodified lines | |||
| 84 | lastViewFrustumSent (lastViewFrustumSent), | 88 | lastViewFrustumSent (lastViewFrustumSent), |
| 85 | forceSendScene (forceSendScene), | 89 | forceSendScene (forceSendScene), |
| 86 | stats (stats), | 90 | stats (stats), |
| 87 | map (map) | 91 | map (map), |
| 92 | jurisdictionMap (jurisdictionMap) | ||
| 93 | {} | ||
| 94 | }; | ||
| 95 | |||
| 96 | class ReadBitstreamToTreeParams { | ||
| 97 | public: | ||
| 98 | bool includeColor; | ||
| 99 | bool includeExistsBits; | ||
| 100 | VoxelNode* destinationNode; | ||
| 101 | uint16_t sourceID; | ||
| 102 | |||
| 103 | ReadBitstreamToTreeParams( | ||
| 104 | bool includeColor = WANT_COLOR, | ||
| 105 | bool includeExistsBits = WANT_EXISTS_BITS, | ||
| 106 | VoxelNode* destinationNode = NULL, | ||
| 107 | uint16_t sourceID = UNKNOWN_NODE_ID) : | ||
| 108 | includeColor (includeColor), | ||
| 109 | includeExistsBits (includeExistsBits), | ||
| 110 | destinationNode (destinationNode), | ||
| 111 | sourceID (sourceID) | ||
| 88 | {} | 112 | {} |
| 89 | }; | 113 | }; |
| 90 | 114 | ||
| @@ -109,9 +133,7 @@ public: · 18 unmodified lines | |||
| 109 | void eraseAllVoxels(); | 133 | void eraseAllVoxels(); |
| 110 | 134 | ||
| 111 | void processRemoveVoxelBitstream(unsigned char* bitstream, int bufferSizeBytes); | 135 | void processRemoveVoxelBitstream(unsigned char* bitstream, int bufferSizeBytes); |
| 112 | void readBitstreamToTree(unsigned char* bitstream, unsigned long int bufferSizeBytes, | 136 | void readBitstreamToTree(unsigned char* bitstream, unsigned long int bufferSizeBytes, ReadBitstreamToTreeParams& args); |
| 113 | bool includeColor = WANT_COLOR, bool includeExistsBits = WANT_EXISTS_BITS, | ||
| 114 | VoxelNode* destinationNode = NULL); | ||
| 115 | void readCodeColorBufferToTree(unsigned char* codeColorBuffer, bool destructive = false); | 137 | void readCodeColorBufferToTree(unsigned char* codeColorBuffer, bool destructive = false); |
| 116 | void deleteVoxelCodeFromTree(unsigned char* codeBuffer, bool collapseEmptyTrees = DONT_COLLAPSE); | 138 | void deleteVoxelCodeFromTree(unsigned char* codeBuffer, bool collapseEmptyTrees = DONT_COLLAPSE); |
| 117 | void printTreeForDebugging(VoxelNode* startNode); | 139 | void printTreeForDebugging(VoxelNode* startNode); |
| @@ -169,7 +191,8 @@ public: · 51 unmodified lines | |||
| 169 | void recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime, | 191 | void recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime, |
| 170 | RecurseVoxelTreeOperation operation, | 192 | RecurseVoxelTreeOperation operation, |
| 171 | const glm::vec3& point, void* extraData); | 193 | const glm::vec3& point, void* extraData); |
| 172 | 194 | ||
| 195 | |||
| 173 | private: | 196 | private: |
| 174 | void deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraData); | 197 | void deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraData); |
| 175 | void readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraData); | 198 | void readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraData); |
| @@ -181,8 +204,7 @@ private: · 5 unmodified lines | |||
| 181 | 204 | ||
| 182 | VoxelNode* nodeForOctalCode(VoxelNode* ancestorNode, unsigned char* needleCode, VoxelNode** parentOfFoundNode) const; | 205 | VoxelNode* nodeForOctalCode(VoxelNode* ancestorNode, unsigned char* needleCode, VoxelNode** parentOfFoundNode) const; |
| 183 | VoxelNode* createMissingNode(VoxelNode* lastParentNode, unsigned char* deepestCodeToCreate); | 206 | VoxelNode* createMissingNode(VoxelNode* lastParentNode, unsigned char* deepestCodeToCreate); |
| 184 | int readNodeData(VoxelNode *destinationNode, unsigned char* nodeData, int bufferSizeBytes, | 207 | int readNodeData(VoxelNode *destinationNode, unsigned char* nodeData, int bufferSizeBytes, ReadBitstreamToTreeParams& args); |
| 185 | bool includeColor = WANT_COLOR, bool includeExistsBits = WANT_EXISTS_BITS); | ||
| 186 | 208 | ||
| 187 | bool _isDirty; | 209 | bool _isDirty; |
| 188 | unsigned long int _nodesChangedFromBitstream; | 210 | unsigned long int _nodesChangedFromBitstream; |
| @@ -0,0 +1,80 @@ | |||
| 1 | NAME | ||
| 2 | voxel-server - the High Fidelity Voxel Server | ||
| 3 | |||
| 4 | SYNOPSIS | ||
| 5 | voxel-server [--local] [--jurisdictionFile <filename>] [--port <port>] [--voxelsPersistFilename <filename>] | ||
| 6 | [--displayVoxelStats] [--debugVoxelSending] [--debugVoxelReceiving] [--shouldShowAnimationDebug] | ||
| 7 | [--wantColorRandomizer] [--NoVoxelPersist] [--packetsPerSecond <value>] | ||
| 8 | [--AddRandomVoxels] [--AddScene] [--NoAddScene] | ||
| 9 | |||
| 10 | DESCRIPTION | ||
| 11 | voxel-server is a compact, portable, scalable, distributed sparse voxel octree server | ||
| 12 | |||
| 13 | OPTIONS | ||
| 14 | |||
| 15 | --local | ||
| 16 | This will run the voxel server in "local domain mode" and will look for a domain-server running on the same IP | ||
| 17 | address as the voxel server | ||
| 18 | |||
| 19 | --jurisdictionFile [filename] | ||
| 20 | Tells the server to load it's jurisdiction from the specified file. When a voxel server is running with a limited | ||
| 21 | "jurisdiction" it will only server voxels from that portion of the voxel tree. The jurisdiction file is a ".ini" style | ||
| 22 | file with the following options: [General/root] specifies the octal code for the node in the tree that this server will | ||
| 23 | use as it's "root". It will only server voxels under this root. [endNodes/...] a list or group of additional octalcodes | ||
| 24 | under the root, which will not be served. | ||
| 25 | |||
| 26 | The following example jurisdiction file will server all voxels from the root and below, and exclude voxels from the | ||
| 27 | voxel of scale 0.25 and 0,0,0. | ||
| 28 | |||
| 29 | ****** example jurisdiction.ini ********************************************************************** | ||
| 30 | [General] | ||
| 31 | root=00 | ||
| 32 | |||
| 33 | [endNodes] | ||
| 34 | endnode0=0200 | ||
| 35 | |||
| 36 | ****************************************************************************************************** | ||
| 37 | |||
| 38 | |||
| 39 | --port [port] | ||
| 40 | Specify the port the voxel-server will listen on. You must specify different ports to enable multiple voxel servers | ||
| 41 | running on a single machine. | ||
| 42 | |||
| 43 | --voxelsPersistFilename [filename] | ||
| 44 | Specify and alternate file that the voxel server will read and write persistant voxels to. By default the voxel server | ||
| 45 | will use one of the following files: | ||
| 46 | |||
| 47 | default: /etc/highfidelity/voxel-server/resources/voxels.svo | ||
| 48 | in local mode: ./resources/voxels.svo | ||
| 49 | |||
| 50 | --displayVoxelStats | ||
| 51 | Displays additional voxel stats debugging | ||
| 52 | |||
| 53 | --debugVoxelSending | ||
| 54 | Displays additional voxel sending debugging | ||
| 55 | |||
| 56 | --debugVoxelReceiving | ||
| 57 | Displays additional voxel receiving debugging | ||
| 58 | |||
| 59 | --shouldShowAnimationDebug | ||
| 60 | Displays additional verbose animation debugging | ||
| 61 | |||
| 62 | --wantColorRandomizer | ||
| 63 | Adds color randomization to inserts into the local voxel tree | ||
| 64 | |||
| 65 | --NoVoxelPersist | ||
| 66 | Disables voxel persisting | ||
| 67 | |||
| 68 | --packetsPerSecond [value] | ||
| 69 | Specifies the packets per second that this voxel server will send to attached clients | ||
| 70 | |||
| 71 | --AddRandomVoxels | ||
| 72 | Add random voxels to the surface on startup | ||
| 73 | |||
| 74 | --AddScene | ||
| 75 | OBSOLETE: Adds an arbitrary scene with several "planet" spheres | ||
| 76 | |||
| 77 | --NoAddScene | ||
| 78 | OBSOLETE: disables adding of scene | ||
| 79 | |||
| 80 | |||
| @@ -32,6 +32,8 @@ · 31 unmodified lines | |||
| 32 | 32 | ||
| 33 | const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.svo"; | 33 | const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.svo"; |
| 34 | const char* VOXELS_PERSIST_FILE = "/etc/highfidelity/voxel-server/resources/voxels.svo"; | 34 | const char* VOXELS_PERSIST_FILE = "/etc/highfidelity/voxel-server/resources/voxels.svo"; |
| 35 | const int MAX_FILENAME_LENGTH = 1024; | ||
| 36 | char voxelPersistFilename[MAX_FILENAME_LENGTH]; | ||
| 35 | const int VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds | 37 | const int VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds |
| 36 | 38 | ||
| 37 | const int VOXEL_LISTEN_PORT = 40106; | 39 | const int VOXEL_LISTEN_PORT = 40106; |
| @@ -65,6 +67,8 @@ bool debugVoxelReceiving = false; · 27 unmodified lines | |||
| 65 | 67 | ||
| 66 | EnvironmentData environmentData[3]; | 68 | EnvironmentData environmentData[3]; |
| 67 | 69 | ||
| 70 | int receivedPacketCount = 0; | ||
| 71 | JurisdictionMap* jurisdiction = NULL; | ||
| 68 | 72 | ||
| 69 | void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) { | 73 | void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) { |
| 70 | // randomly generate children for this node | 74 | // randomly generate children for this node |
| @@ -292,7 +296,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, · 221 unmodified lines | |||
| 292 | WANT_EXISTS_BITS, DONT_CHOP, wantDelta, lastViewFrustum, | 296 | WANT_EXISTS_BITS, DONT_CHOP, wantDelta, lastViewFrustum, |
| 293 | wantOcclusionCulling, coverageMap, boundaryLevelAdjust, | 297 | wantOcclusionCulling, coverageMap, boundaryLevelAdjust, |
| 294 | nodeData->getLastTimeBagEmpty(), | 298 | nodeData->getLastTimeBagEmpty(), |
| 295 | isFullScene, &nodeData->stats); | 299 | isFullScene, &nodeData->stats, ::jurisdiction); |
| 296 | 300 | ||
| 297 | nodeData->stats.encodeStarted(); | 301 | nodeData->stats.encodeStarted(); |
| 298 | bytesWritten = serverTree.encodeTreeBitstream(subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, | 302 | bytesWritten = serverTree.encodeTreeBitstream(subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, |
| @@ -376,7 +380,7 @@ void persistVoxelsWhenDirty() { · 77 unmodified lines | |||
| 376 | "persistVoxelsWhenDirty() - writeToSVOFile()", ::shouldShowAnimationDebug); | 380 | "persistVoxelsWhenDirty() - writeToSVOFile()", ::shouldShowAnimationDebug); |
| 377 | 381 | ||
| 378 | printf("saving voxels to file...\n"); | 382 | printf("saving voxels to file...\n"); |
| 379 | serverTree.writeToSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); | 383 | serverTree.writeToSVOFile(::voxelPersistFilename); |
| 380 | serverTree.clearDirtyBit(); // tree is clean after saving | 384 | serverTree.clearDirtyBit(); // tree is clean after saving |
| 381 | printf("DONE saving voxels to file...\n"); | 385 | printf("DONE saving voxels to file...\n"); |
| 382 | } | 386 | } |
| @@ -427,14 +431,39 @@ void attachVoxelNodeDataToNode(Node* newNode) { · 44 unmodified lines | |||
| 427 | } | 431 | } |
| 428 | } | 432 | } |
| 429 | 433 | ||
| 430 | int receivedPacketCount = 0; | ||
| 431 | |||
| 432 | int main(int argc, const char * argv[]) { | 434 | int main(int argc, const char * argv[]) { |
| 433 | pthread_mutex_init(&::treeLock, NULL); | 435 | pthread_mutex_init(&::treeLock, NULL); |
| 434 | 436 | ||
| 435 | qInstallMessageHandler(sharedMessageHandler); | 437 | qInstallMessageHandler(sharedMessageHandler); |
| 436 | 438 | ||
| 437 | NodeList* nodeList = NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, VOXEL_LISTEN_PORT); | 439 | int listenPort = VOXEL_LISTEN_PORT; |
| 440 | // Check to see if the user passed in a command line option for setting listen port | ||
| 441 | const char* PORT_PARAMETER = "--port"; | ||
| 442 | const char* portParameter = getCmdOption(argc, argv, PORT_PARAMETER); | ||
| 443 | if (portParameter) { | ||
| 444 | listenPort = atoi(portParameter); | ||
| 445 | if (listenPort < 1) { | ||
| 446 | listenPort = VOXEL_LISTEN_PORT; | ||
| 447 | } | ||
| 448 | printf("portParameter=%s listenPort=%d\n", portParameter, listenPort); | ||
| 449 | } | ||
| 450 | |||
| 451 | const char* JURISDICTION_FILE = "--jurisdictionFile"; | ||
| 452 | const char* jurisdictionFile = getCmdOption(argc, argv, JURISDICTION_FILE); | ||
| 453 | if (jurisdictionFile) { | ||
| 454 | printf("jurisdictionFile=%s\n", jurisdictionFile); | ||
| 455 | |||
| 456 | printf("about to readFromFile().... jurisdictionFile=%s\n", jurisdictionFile); | ||
| 457 | jurisdiction = new JurisdictionMap(jurisdictionFile); | ||
| 458 | printf("after readFromFile().... jurisdictionFile=%s\n", jurisdictionFile); | ||
| 459 | |||
| 460 | // test writing the file... | ||
| 461 | printf("about to writeToFile().... jurisdictionFile=%s\n", jurisdictionFile); | ||
| 462 | jurisdiction->writeToFile(jurisdictionFile); | ||
| 463 | printf("after writeToFile().... jurisdictionFile=%s\n", jurisdictionFile); | ||
| 464 | } | ||
| 465 | |||
| 466 | NodeList* nodeList = NodeList::createInstance(NODE_TYPE_VOXEL_SERVER, listenPort); | ||
| 438 | setvbuf(stdout, NULL, _IOLBF, 0); | 467 | setvbuf(stdout, NULL, _IOLBF, 0); |
| 439 | 468 | ||
| 440 | // Handle Local Domain testing with the --local command line | 469 | // Handle Local Domain testing with the --local command line |
| @@ -480,8 +509,19 @@ int main(int argc, const char * argv[]) { · 39 unmodified lines | |||
| 480 | // if we want Voxel Persistance, load the local file now... | 509 | // if we want Voxel Persistance, load the local file now... |
| 481 | bool persistantFileRead = false; | 510 | bool persistantFileRead = false; |
| 482 | if (::wantVoxelPersist) { | 511 | if (::wantVoxelPersist) { |
| 483 | printf("loading voxels from file...\n"); | 512 | |
| 484 | persistantFileRead = ::serverTree.readFromSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); | 513 | // Check to see if the user passed in a command line option for setting packet send rate |
| 514 | const char* VOXELS_PERSIST_FILENAME = "--voxelsPersistFilename"; | ||
| 515 | const char* voxelsPersistFilenameParameter = getCmdOption(argc, argv, VOXELS_PERSIST_FILENAME); | ||
| 516 | if (voxelsPersistFilenameParameter) { | ||
| 517 | strcpy(voxelPersistFilename, voxelsPersistFilenameParameter); | ||
| 518 | } else { | ||
| 519 | strcpy(voxelPersistFilename, ::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE); | ||
| 520 | } | ||
| 521 | |||
| 522 | printf("loading voxels from file: %s...\n", voxelPersistFilename); | ||
| 523 | |||
| 524 | persistantFileRead = ::serverTree.readFromSVOFile(::voxelPersistFilename); | ||
| 485 | if (persistantFileRead) { | 525 | if (persistantFileRead) { |
| 486 | PerformanceWarning warn(::shouldShowAnimationDebug, | 526 | PerformanceWarning warn(::shouldShowAnimationDebug, |
| 487 | "persistVoxelsWhenDirty() - reaverageVoxelColors()", ::shouldShowAnimationDebug); | 527 | "persistVoxelsWhenDirty() - reaverageVoxelColors()", ::shouldShowAnimationDebug); |
| @@ -707,6 +747,10 @@ int main(int argc, const char * argv[]) { · 219 unmodified lines | |||
| 707 | 747 | ||
| 708 | pthread_join(sendVoxelThread, NULL); | 748 | pthread_join(sendVoxelThread, NULL); |
| 709 | pthread_mutex_destroy(&::treeLock); | 749 | pthread_mutex_destroy(&::treeLock); |
| 750 | |||
| 751 | if (jurisdiction) { | ||
| 752 | delete jurisdiction; | ||
| 753 | } | ||
| 710 | 754 | ||
| 711 | return 0; | 755 | return 0; |
| 712 | } | 756 | } |