History

Merge branch 'master' of https://github.com/worklist/hifi into Remove-body

Philip Rosedale committed 13 years ago

Commit 639b6be2 parents 8aa8b5d f24cf1931 files · +1165 −199Browse files

Unified · Split

31 files
  1. interface/resources/images/hifi-interface-tools-v2-pie.svg +22 −0
  2. interface/src/Application.cpp +80 −15
  3. interface/src/Application.h +10 −2
  4. interface/src/ParticleSystem.cpp +31 −24
  5. interface/src/ParticleSystem.h +4 −1
  6. interface/src/PieMenu.cpp +138 −0
  7. interface/src/PieMenu.h +59 −0
  8. interface/src/VoxelSystem.cpp +89 −2
  9. interface/src/VoxelSystem.h +10 −2
  10. interface/src/Webcam.cpp +2 −2
  11. interface/src/Webcam.h +5 −1
  12. interface/src/avatar/Avatar.cpp +51 −2
  13. interface/src/avatar/Avatar.h +15 −13
  14. interface/src/avatar/AvatarVoxelSystem.cpp +2 −1
  15. interface/src/avatar/Hand.cpp +131 −80
  16. interface/src/avatar/Hand.h +9 −5
  17. libraries/avatars/src/AvatarData.cpp +17 −0
  18. libraries/avatars/src/HandData.cpp +3 −0
  19. libraries/shared/src/NodeList.cpp +2 −3
  20. libraries/shared/src/NodeList.h +1 −1
  21. libraries/shared/src/OctalCode.cpp +39 −0
  22. libraries/shared/src/OctalCode.h +3 −1
  23. libraries/voxels/src/JurisdictionMap.cpp +178 −0
  24. libraries/voxels/src/JurisdictionMap.h +46 −0
  25. libraries/voxels/src/Tags.cpp +1 −1
  26. libraries/voxels/src/VoxelNode.cpp +3 −0
  27. libraries/voxels/src/VoxelNode.h +6 −2
  28. libraries/voxels/src/VoxelTree.cpp +44 −23
  29. libraries/voxels/src/VoxelTree.h +33 −11
  30. voxel-server/src/README +80 −0
  31. voxel-server/src/main.cpp +51 −7
interface/resources/images/hifi-interface-tools-v2-pie.svg+22−0
@@ -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>
interface/src/Application.cpp+80−15
@@ -852,6 +852,8 @@ void Application::mouseMoveEvent(QMouseEvent* event) { · 851 unmodified lines
852852 deleteVoxelUnderCursor();
853853 }
854854 }
855+
856+ _pieMenu.mouseMoveEvent(_mouseX, _mouseY);
855857 }
856858 }
857859
@@ -869,7 +871,12 @@ void Application::mousePressEvent(QMouseEvent* event) { · 11 unmodified lines
869871 _mouseDragStartedY = _mouseY;
870872 _mouseVoxelDragging = _mouseVoxel;
871873 _mousePressed = true;
872− maybeEditVoxelUnderCursor();
874+
875+
876+ if (!maybeEditVoxelUnderCursor()) {
877+ _pieMenu.mousePressEvent(_mouseX, _mouseY);
878+ }
879+
873880 if (MAKE_SOUND_ON_VOXEL_CLICK && _isHoverVoxel && !_isHoverVoxelSounding) {
874881 _hoverVoxelOriginalColor[0] = _hoverVoxel.red;
875882 _hoverVoxelOriginalColor[1] = _hoverVoxel.green;
@@ -892,6 +899,8 @@ void Application::mouseReleaseEvent(QMouseEvent* event) { · 16 unmodified lines
892899 _mouseY = event->y();
893900 _mousePressed = false;
894901 checkBandwidthMeterClick();
902+
903+ _pieMenu.mouseReleaseEvent(_mouseX, _mouseY);
895904 }
896905 }
897906 }
@@ -1383,6 +1392,10 @@ void Application::doFalseColorizeOccludedV2() { · 485 unmodified lines
13831392 _voxels.falseColorizeOccludedV2();
13841393 }
13851394
1395+void Application::doFalseColorizeBySource() {
1396+ _voxels.falseColorizeBySource();
1397+}
1398+
13861399 void Application::doTrueVoxelColors() {
13871400 _voxels.trueColorize();
13881401 }
@@ -1804,6 +1817,7 @@ void Application::initMenu() { · 415 unmodified lines
18041817 _testPing->setChecked(true);
18051818 (_fullScreenMode = optionsMenu->addAction("Fullscreen", this, SLOT(setFullscreen(bool)), Qt::Key_F))->setCheckable(true);
18061819 optionsMenu->addAction("Webcam", &_webcam, SLOT(setEnabled(bool)))->setCheckable(true);
1820+ optionsMenu->addAction("Toggle Skeleton Tracking", &_webcam, SLOT(setSkeletonTrackingOn(bool)))->setCheckable(true);
18071821 optionsMenu->addAction("Cycle Webcam Send Mode", _webcam.getGrabber(), SLOT(cycleVideoSendMode()));
18081822 optionsMenu->addAction("Go Home", this, SLOT(goHome()));
18091823
@@ -1832,7 +1846,6 @@ void Application::initMenu() { · 22 unmodified lines
18321846 (_renderLookatIndicatorOn = renderMenu->addAction("Lookat Indicator"))->setCheckable(true);
18331847 _renderLookatIndicatorOn->setChecked(true);
18341848 (_renderParticleSystemOn = renderMenu->addAction("Particle System"))->setCheckable(true);
1835− _renderParticleSystemOn->setChecked(true);
18361849 (_manualFirstPerson = renderMenu->addAction(
18371850 "First Person", this, SLOT(setRenderFirstPerson(bool)), Qt::Key_P))->setCheckable(true);
18381851 (_manualThirdPerson = renderMenu->addAction(
@@ -1919,6 +1932,7 @@ void Application::initMenu() { · 80 unmodified lines
19191932 renderDebugMenu->addAction("FALSE Color Voxel Out of View", this, SLOT(doFalseColorizeInView()));
19201933 renderDebugMenu->addAction("FALSE Color Occluded Voxels", this, SLOT(doFalseColorizeOccluded()), Qt::CTRL | Qt::Key_O);
19211934 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);
19221936 renderDebugMenu->addAction("Show TRUE Colors", this, SLOT(doTrueVoxelColors()), Qt::CTRL | Qt::Key_T);
19231937
19241938 (_shouldLowPassFilter = debugMenu->addAction("Test: LowPass filter"))->setCheckable(true);
@@ -2057,7 +2071,15 @@ void Application::init() { · 132 unmodified lines
20572071 _palette.addTool(&_swatch);
20582072 _palette.addAction(_colorVoxelMode, 0, 2);
20592073 _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);
20612083 }
20622084
20632085
@@ -2069,7 +2091,7 @@ const float HEAD_SPHERE_RADIUS = 0.07; · 5 unmodified lines
20692091 static uint16_t DEFAULT_NODE_ID_REF = 1;
20702092
20712093
2072−bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
2094+Avatar* Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
20732095 glm::vec3& eyePosition, uint16_t& nodeID = DEFAULT_NODE_ID_REF) {
20742096
20752097 NodeList* nodeList = NodeList::getInstance();
@@ -2082,11 +2104,11 @@ bool Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& m · 6 unmodified lines
20822104 _lookatIndicatorScale = avatar->getScale();
20832105 _lookatOtherPosition = headPosition;
20842106 nodeID = avatar->getOwningNode()->getNodeID();
2085− return true;
2107+ return avatar;
20862108 }
20872109 }
20882110 }
2089− return false;
2111+ return NULL;
20902112 }
20912113
20922114 void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera) {
@@ -2101,6 +2123,7 @@ void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& which · 8 unmodified lines
21012123 }
21022124
21032125 void Application::update(float deltaTime) {
2126+
21042127 // Use Transmitter Hand to move hand if connected, else use mouse
21052128 if (_myTransmitter.isConnected()) {
21062129 const float HAND_FORCE_SCALING = 0.01f;
@@ -2997,6 +3020,10 @@ void Application::displayOverlay() { · 890 unmodified lines
29973020 _swatch.checkColor();
29983021 }
29993022
3023+ if (_pieMenu.isDisplayed()) {
3024+ _pieMenu.render();
3025+ }
3026+
30003027 glPopMatrix();
30013028 }
30023029
@@ -3009,19 +3036,35 @@ void Application::displayStats() { · 6 unmodified lines
30093036 drawtext(10, statsVerticalOffset + 15, 0.10f, 0, 1.0, 0, stats);
30103037
30113038 if (_testPing->isChecked()) {
3012− int pingAudio = 0, pingAvatar = 0, pingVoxel = 0;
3039+ int pingAudio = 0, pingAvatar = 0, pingVoxel = 0, pingVoxelMax = 0;
30133040
3014− NodeList *nodeList = NodeList::getInstance();
3015− Node *audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);
3016− Node *avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
3017− Node *voxelServerNode = nodeList->soloNodeOfType(NODE_TYPE_VOXEL_SERVER);
3041+ NodeList* nodeList = NodeList::getInstance();
3042+ Node* audioMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER);
3043+ Node* avatarMixerNode = nodeList->soloNodeOfType(NODE_TYPE_AVATAR_MIXER);
30183044
30193045 pingAudio = audioMixerNode ? audioMixerNode->getPingMs() : 0;
30203046 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+
30223065
30233066 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);
30253068 drawtext(10, statsVerticalOffset + 35, 0.10f, 0, 1.0, 0, pingStats);
30263069 }
30273070
@@ -3396,7 +3439,7 @@ void Application::shiftPaintingColor() { · 368 unmodified lines
33963439 }
33973440
33983441
3399−void Application::maybeEditVoxelUnderCursor() {
3442+bool Application::maybeEditVoxelUnderCursor() {
34003443 if (_addVoxelMode->isChecked() || _colorVoxelMode->isChecked()) {
34013444 if (_mouseVoxel.s != 0) {
34023445 PACKET_TYPE message = (_destructiveAddVoxel->isChecked() ?
@@ -3467,7 +3510,11 @@ void Application::maybeEditVoxelUnderCursor() { · 64 unmodified lines
34673510 deleteVoxelUnderCursor();
34683511 } else if (_eyedropperMode->isChecked()) {
34693512 eyedropperVoxelUnderCursor();
3513+ } else {
3514+ return false;
34703515 }
3516+
3517+ return true;
34713518 }
34723519
34733520 void Application::deleteVoxelUnderCursor() {
@@ -3510,6 +3557,22 @@ void Application::goHome() { · 36 unmodified lines
35103557 _myAvatar.setPosition(START_LOCATION);
35113558 }
35123559
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+
35133576 void Application::resetSensors() {
35143577 _headMouseX = _mouseX = _glWidget->width() / 2;
35153578 _headMouseY = _mouseY = _glWidget->height() / 2;
@@ -3622,13 +3685,15 @@ void* Application::networkReceive(void* args) { · 106 unmodified lines
36223685 } // fall through to piggyback message
36233686
36243687 if (app->_renderVoxels->isChecked()) {
3625− Node* voxelServer = NodeList::getInstance()->soloNodeOfType(NODE_TYPE_VOXEL_SERVER);
3688+ Node* voxelServer = NodeList::getInstance()->nodeWithAddress(&senderAddress);
36263689 if (voxelServer && socketMatch(voxelServer->getActiveSocket(), &senderAddress)) {
36273690 voxelServer->lock();
36283691 if (messageData[0] == PACKET_TYPE_ENVIRONMENT_DATA) {
36293692 app->_environment.parseData(&senderAddress, messageData, messageLength);
36303693 } else {
3694+ app->_voxels.setDataSourceID(voxelServer->getNodeID());
36313695 app->_voxels.parseData(messageData, messageLength);
3696+ app->_voxels.setDataSourceID(UNKNOWN_NODE_ID);
36323697 }
36333698 voxelServer->unlock();
36343699 }
interface/src/Application.h+10−2
@@ -39,6 +39,7 @@ · 38 unmodified lines
3939 #include "ViewFrustum.h"
4040 #include "VoxelSystem.h"
4141 #include "Webcam.h"
42+#include "PieMenu.h"
4243 #include "avatar/Avatar.h"
4344 #include "avatar/HandControl.h"
4445 #include "ui/BandwidthDialog.h"
@@ -149,6 +150,7 @@ private slots: · 104 unmodified lines
149150 void doFalseColorizeByDistance();
150151 void doFalseColorizeOccluded();
151152 void doFalseColorizeOccludedV2();
153+ void doFalseColorizeBySource();
152154 void doFalseColorizeInView();
153155 void doTrueVoxelColors();
154156 void doTreeStats();
@@ -186,6 +188,8 @@ private slots: · 31 unmodified lines
186188 glm::vec2 getScaledScreenPoint(glm::vec2 projectedPoint);
187189 void goHome();
188190
191+ void toggleFollowMode();
192+
189193 private:
190194
191195 static void controlledBroadcastToNodes(unsigned char* broadcastData, size_t dataBytes,
@@ -205,7 +209,7 @@ private: · 13 unmodified lines
205209 void init();
206210
207211 void update(float deltaTime);
208− bool isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
212+ Avatar* isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection,
209213 glm::vec3& eyePosition, uint16_t& nodeID);
210214
211215 void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera);
@@ -222,7 +226,7 @@ private: · 10 unmodified lines
222226
223227 void setupPaintingVoxel();
224228 void shiftPaintingColor();
225− void maybeEditVoxelUnderCursor();
229+ bool maybeEditVoxelUnderCursor();
226230 void deleteVoxelUnderCursor();
227231 void eyedropperVoxelUnderCursor();
228232 void resetSensors();
@@ -290,6 +294,8 @@ private: · 61 unmodified lines
290294
291295 QAction* _simulateLeapHand; // When there's no Leap, use this to pretend there is one and feed fake hand data
292296 QAction* _testRaveGlove; // Test fancy sparkle-rave-glove mode
297+
298+ QAction* _followMode;
293299
294300 BandwidthMeter _bandwidthMeter;
295301 BandwidthDialog* _bandwidthDialog;
@@ -429,6 +435,8 @@ private: · 133 unmodified lines
429435
430436 ToolsPalette _palette;
431437 Swatch _swatch;
438+
439+ PieMenu _pieMenu;
432440
433441 VoxelSceneStats _voxelSceneStats;
434442 };
interface/src/ParticleSystem.cpp+31−24
@@ -27,6 +27,7 @@ ParticleSystem::ParticleSystem() { · 26 unmodified lines
2727 for (unsigned int emitterIndex = 0; emitterIndex < MAX_EMITTERS; emitterIndex++) {
2828
2929 Emitter * e = &_emitter[emitterIndex];
30+ e->active = false;
3031 e->position = glm::vec3(0.0f, 0.0f, 0.0f);
3132 e->previousPosition = glm::vec3(0.0f, 0.0f, 0.0f);
3233 e->direction = glm::vec3(0.0f, 1.0f, 0.0f);
@@ -72,25 +73,16 @@ void ParticleSystem::simulate(float deltaTime) { · 39 unmodified lines
7273
7374 _timer += deltaTime;
7475
75− // emit particles
76− for (int e = 0; e < _numEmitters; e++) {
77−
78− assert(e >= 0);
79− assert(e <= MAX_EMITTERS);
80− assert(_emitter[e].rate >= 0);
76+ // update emitters
77+ for (int emitterIndex = 0; emitterIndex < _numEmitters; emitterIndex++) {
78+ assert(emitterIndex <= MAX_EMITTERS);
8179
82− _emitter[e].emitReserve += _emitter[e].rate * deltaTime;
83− _emitter[e].numParticlesEmittedThisTime = (int)_emitter[e].emitReserve;
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);
80+ if (_emitter[emitterIndex].active) {
81+ updateEmitter(emitterIndex, deltaTime);
8982 }
9083 }
91−
92− // update particles
9384
85+ // update particles
9486 for (int p = 0; p < MAX_PARTICLES; p++) {
9587 if (_particle[p].alive) {
9688 if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) {
@@ -102,6 +94,20 @@ void ParticleSystem::simulate(float deltaTime) { · 5 unmodified lines
10294 }
10395 }
10496
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+
105111 void ParticleSystem::createParticle(int e, float timeFraction) {
106112
107113 for (unsigned int p = 0; p < MAX_PARTICLES; p++) {
@@ -212,7 +218,6 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleLifeStage l · 104 unmodified lines
212218 }
213219
214220
215−
216221 void ParticleSystem::updateParticle(int p, float deltaTime) {
217222
218223 Emitter myEmitter = _emitter[_particle[p].emitterIndex];
@@ -363,14 +368,16 @@ void ParticleSystem::killAllParticles() { · 144 unmodified lines
363368 void ParticleSystem::render() {
364369
365370 // render the emitters
366− for (int e = 0; e < _numEmitters; e++) {
367−
368− if (_emitter[e].showingBaseParticle) {
369− glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a);
370− glPushMatrix();
371− glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z);
372− glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution);
373− glPopMatrix();
371+ for (int e = 0; e < MAX_EMITTERS; e++) {
372+
373+ if (_emitter[e].active) {
374+ if (_emitter[e].showingBaseParticle) {
375+ glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a);
376+ glPushMatrix();
377+ glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z);
378+ glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution);
379+ glPopMatrix();
380+ }
374381 }
375382
376383 if (_emitter[e].visible) {
interface/src/ParticleSystem.h+4−1
@@ -10,10 +10,10 @@ · 9 unmodified lines
1010
1111 #include <glm/gtc/quaternion.hpp>
1212
13−const int MAX_PARTICLES = 5000;
1413 const int NULL_EMITTER = -1;
1514 const int NULL_PARTICLE = -1;
1615 const int MAX_EMITTERS = 100;
16+const int MAX_PARTICLES = 5000;
1717
1818 enum ParticleRenderStyle
1919 {
@@ -78,6 +78,7 @@ public: · 58 unmodified lines
7878 void setParticleAttributes (int emitterIndex, ParticleAttributes attributes); // set attributes for whole life of particles
7979 void setParticleAttributes (int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes); // set attributes for this life stage
8080 void setEmitterPosition (int emitterIndex, glm::vec3 position );
81+ void setEmitterActive (int emitterIndex, bool active ) {_emitter[emitterIndex].active = active; }
8182 void setEmitterParticleResolution (int emitterIndex, int resolution ) {_emitter[emitterIndex].particleResolution = resolution; }
8283 void setEmitterDirection (int emitterIndex, glm::vec3 direction ) {_emitter[emitterIndex].direction = direction; }
8384 void setShowingEmitter (int emitterIndex, bool showing ) {_emitter[emitterIndex].visible = showing; }
@@ -101,6 +102,7 @@ private: · 17 unmodified lines
101102 };
102103
103104 struct Emitter {
105+ bool active; // if false, the emitter is disabled - allows for easy switching on and off
104106 glm::vec3 position; // the position of the emitter in world coordinates
105107 glm::vec3 previousPosition; // the position of the emitter in the previous time step
106108 glm::vec3 direction; // a normalized vector used as an axis for particle emission and other effects
@@ -124,6 +126,7 @@ private: · 17 unmodified lines
124126 float _timer;
125127
126128 // private methods
129+ void updateEmitter(int emitterIndex, float deltaTime);
127130 void updateParticle(int index, float deltaTime);
128131 void createParticle(int e, float timeFraction);
129132 void killParticle(int p);
interface/src/PieMenu.cpp+138−0
@@ -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+}
interface/src/PieMenu.h+59−0
@@ -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__) */
interface/src/VoxelSystem.cpp+89−2
@@ -23,6 +23,8 @@ · 22 unmodified lines
2323 #include <PacketHeaders.h>
2424 #include <PerfStat.h>
2525 #include <SharedUtil.h>
26+#include <NodeList.h>
27+#include <NodeTypes.h>
2628
2729 #include "Application.h"
2830 #include "CoverageMap.h"
@@ -61,6 +63,8 @@ VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) : · 32 unmodified lines
6163
6264 VoxelNode::addDeleteHook(this);
6365 _abandonedVBOSlots = 0;
66+ _falseColorizeBySource = false;
67+ _dataSourceID = UNKNOWN_NODE_ID;
6468 }
6569
6670 void VoxelSystem::nodeDeleted(VoxelNode* node) {
@@ -153,13 +157,15 @@ int VoxelSystem::parseData(unsigned char* sourceBuffer, int numBytes) { · 86 unmodified lines
153157 case PACKET_TYPE_VOXEL_DATA: {
154158 PerformanceWarning warn(_renderWarningsOn, "readBitstreamToTree()");
155159 // 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);
157162 }
158163 break;
159164 case PACKET_TYPE_VOXEL_DATA_MONOCHROME: {
160165 PerformanceWarning warn(_renderWarningsOn, "readBitstreamToTree()");
161166 // 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);
163169 }
164170 break;
165171 case PACKET_TYPE_Z_COMMAND:
@@ -747,6 +753,7 @@ void VoxelSystem::randomizeVoxelColors() { · 581 unmodified lines
747753 _nodeCount = 0;
748754 _tree->recurseTreeWithOperation(randomColorOperation);
749755 qDebug("setting randomized true color for %d nodes\n", _nodeCount);
756+ _tree->setDirtyBit();
750757 setupNewVoxelsForDrawing();
751758 }
752759
@@ -761,6 +768,7 @@ void VoxelSystem::falseColorizeRandom() { · 8 unmodified lines
761768 _nodeCount = 0;
762769 _tree->recurseTreeWithOperation(falseColorizeRandomOperation);
763770 qDebug("setting randomized false color for %d nodes\n", _nodeCount);
771+ _tree->setDirtyBit();
764772 setupNewVoxelsForDrawing();
765773 }
766774
@@ -775,6 +783,7 @@ void VoxelSystem::trueColorize() { · 8 unmodified lines
775783 _nodeCount = 0;
776784 _tree->recurseTreeWithOperation(trueColorizeOperation);
777785 qDebug("setting true color for %d nodes\n", _nodeCount);
786+ _tree->setDirtyBit();
778787 setupNewVoxelsForDrawing();
779788 }
780789
@@ -795,6 +804,80 @@ void VoxelSystem::falseColorizeInView(ViewFrustum* viewFrustum) { · 14 unmodified lines
795804 _nodeCount = 0;
796805 _tree->recurseTreeWithOperation(falseColorizeInViewOperation,(void*)viewFrustum);
797806 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();
798881 setupNewVoxelsForDrawing();
799882 }
800883
@@ -848,6 +931,7 @@ void VoxelSystem::falseColorizeDistanceFromView(ViewFrustum* viewFrustum) { · 47 unmodified lines
848931 _nodeCount = 0;
849932 _tree->recurseTreeWithOperation(falseColorizeDistanceFromViewOperation,(void*)viewFrustum);
850933 qDebug("setting in distance false color for %d nodes\n", _nodeCount);
934+ _tree->setDirtyBit();
851935 setupNewVoxelsForDrawing();
852936 }
853937
@@ -1027,6 +1111,7 @@ void VoxelSystem::falseColorizeRandomEveryOther() { · 173 unmodified lines
10271111 _tree->recurseTreeWithOperation(falseColorizeRandomEveryOtherOperation,&args);
10281112 qDebug("randomized false color for every other node: total %ld, colorable %ld, colored %ld\n",
10291113 args.totalNodes, args.colorableNodes, args.coloredNodes);
1114+ _tree->setDirtyBit();
10301115 setupNewVoxelsForDrawing();
10311116 }
10321117
@@ -1331,6 +1416,7 @@ void VoxelSystem::falseColorizeOccluded() { · 298 unmodified lines
13311416
13321417 //myCoverageMap.erase();
13331418
1419+ _tree->setDirtyBit();
13341420 setupNewVoxelsForDrawing();
13351421 }
13361422
@@ -1447,6 +1533,7 @@ void VoxelSystem::falseColorizeOccludedV2() { · 110 unmodified lines
14471533 //myCoverageMapV2.erase();
14481534
14491535
1536+ _tree->setDirtyBit();
14501537 setupNewVoxelsForDrawing();
14511538 }
14521539
interface/src/VoxelSystem.h+10−2
@@ -33,6 +33,9 @@ public: · 32 unmodified lines
3333 VoxelSystem(float treeScale = TREE_SCALE, int maxVoxels = MAX_VOXELS_PER_SYSTEM);
3434 ~VoxelSystem();
3535
36+ void setDataSourceID(int dataSourceID) { _dataSourceID = dataSourceID; };
37+ int getDataSourceID() const { return _dataSourceID; };
38+
3639 int parseData(unsigned char* sourceBuffer, int numBytes);
3740
3841 virtual void init();
@@ -62,6 +65,8 @@ public: · 23 unmodified lines
6265 void falseColorizeRandomEveryOther();
6366 void falseColorizeOccluded();
6467 void falseColorizeOccludedV2();
68+ void falseColorizeBySource();
69+
6570
6671 void killLocalVoxels();
6772 void setRenderPipelineWarnings(bool on) { _renderWarningsOn = on; };
@@ -94,7 +99,7 @@ public: · 26 unmodified lines
9499 CoverageMap myCoverageMap;
95100
96101 virtual void nodeDeleted(VoxelNode* node);
97−
102+
98103 protected:
99104 float _treeScale;
100105 int _maxVoxels;
@@ -134,7 +139,7 @@ private: · 33 unmodified lines
134139 static bool falseColorizeOccludedOperation(VoxelNode* node, void* extraData);
135140 static bool falseColorizeSubTreeOperation(VoxelNode* node, void* extraData);
136141 static bool falseColorizeOccludedV2Operation(VoxelNode* node, void* extraData);
137−
142+ static bool falseColorizeBySourceOperation(VoxelNode* node, void* extraData);
138143
139144 int updateNodeInArraysAsFullVBO(VoxelNode* node);
140145 int updateNodeInArraysAsPartialVBO(VoxelNode* node);
@@ -195,6 +200,9 @@ private: · 54 unmodified lines
195200
196201 void freeBufferIndex(glBufferIndex index);
197202 void clearFreeBufferIndexes();
203+
204+ bool _falseColorizeBySource;
205+ int _dataSourceID;
198206 };
199207
200208 #endif
interface/src/Webcam.cpp+2−2
@@ -33,7 +33,7 @@ int jointVectorMetaType = qRegisterMetaType<JointVector>("JointVector"); · 32 unmodified lines
3333 int matMetaType = qRegisterMetaType<Mat>("cv::Mat");
3434 int rotatedRectMetaType = qRegisterMetaType<RotatedRect>("cv::RotatedRect");
3535
36−Webcam::Webcam() : _enabled(false), _active(false), _colorTextureID(0), _depthTextureID(0) {
36+Webcam::Webcam() : _enabled(false), _active(false), _colorTextureID(0), _depthTextureID(0), _skeletonTrackingOn(false) {
3737 // the grabber simply runs as fast as possible
3838 _grabber = new FrameGrabber();
3939 _grabber->moveToThread(&_grabberThread);
@@ -197,7 +197,7 @@ void Webcam::setFrame(const Mat& color, int format, const Mat& depth, float midF · 157 unmodified lines
197197 _aspectRatio = aspectRatio;
198198 _faceRect = faceRect;
199199 _sending = sending;
200− _joints = joints;
200+ _joints = _skeletonTrackingOn ? joints : JointVector();
201201 _frameCount++;
202202
203203 const int MAX_FPS = 60;
interface/src/Webcam.h+5−1
@@ -47,6 +47,7 @@ public: · 46 unmodified lines
4747 FrameGrabber* getGrabber() { return _grabber; }
4848
4949 bool isActive() const { return _active; }
50+
5051 bool isSending() const { return _sending; }
5152
5253 GLuint getColorTextureID() const { return _colorTextureID; }
@@ -62,13 +63,14 @@ public: · 9 unmodified lines
6263 const JointVector& getEstimatedJoints() const { return _estimatedJoints; }
6364
6465 void reset();
65− void renderPreview(int screenWidth, int screenHeight);
66+ void renderPreview(int screenWidth, int screenHeight);
6667
6768 public slots:
6869
6970 void setEnabled(bool enabled);
7071 void setFrame(const cv::Mat& color, int format, const cv::Mat& depth, float midFaceDepth,
7172 float aspectRatio, const cv::RotatedRect& faceRect, bool sending, const JointVector& joints);
73+ void setSkeletonTrackingOn(bool toggle) { _skeletonTrackingOn = toggle; };
7274
7375 private:
7476
@@ -95,6 +97,8 @@ private: · 20 unmodified lines
9597 glm::vec3 _estimatedPosition;
9698 glm::vec3 _estimatedRotation;
9799 JointVector _estimatedJoints;
100+
101+ bool _skeletonTrackingOn;
98102 };
99103
100104 class FrameGrabber : public QObject {
interface/src/avatar/Avatar.cpp+51−2
@@ -101,7 +101,8 @@ Avatar::Avatar(Node* owningNode) : · 100 unmodified lines
101101 _lastCollisionPosition(0, 0, 0),
102102 _speedBrakes(false),
103103 _isThrustOn(false),
104− _voxels(this)
104+ _voxels(this),
105+ _leadingAvatar(NULL)
105106 {
106107 // give the pointer to our head to inherited _headData variable from AvatarData
107108 _headData = &_head;
@@ -404,6 +405,33 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { · 296 unmodified lines
404405 _thrust += _scale * THRUST_JUMP * up;
405406 _shouldJump = false;
406407 }
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+ }
407435
408436 // Add thrusts from Transmitter
409437 if (transmitter) {
@@ -447,6 +475,18 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { · 37 unmodified lines
447475 _isThrustOn = (glm::length(_thrust) > EPSILON);
448476 }
449477
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+
450490 void Avatar::simulate(float deltaTime, Transmitter* transmitter) {
451491
452492 glm::quat orientation = getOrientation();
@@ -475,6 +515,13 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { · 22 unmodified lines
475515 if (isMyAvatar()) {
476516 updateThrust(deltaTime, transmitter);
477517 }
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+ }
478525
479526 // copy velocity so we can use it later for acceleration
480527 glm::vec3 oldVelocity = getVelocity();
@@ -681,7 +728,9 @@ void Avatar::simulate(float deltaTime, Transmitter* transmitter) { · 200 unmodified lines
681728 _head.setScale(_scale);
682729 _head.setSkinColor(glm::vec3(SKIN_COLOR[0], SKIN_COLOR[1], SKIN_COLOR[2]));
683730 _head.simulate(deltaTime, isMyAvatar());
684−
731+
732+
733+
685734 // use speed and angular velocity to determine walking vs. standing
686735 if (_speed + fabs(_bodyYawDelta) > 0.2) {
687736 _mode = AVATAR_MODE_WALKING;
interface/src/avatar/Avatar.h+15−13
@@ -114,6 +114,7 @@ public: · 113 unmodified lines
114114 void reset();
115115 void simulate(float deltaTime, Transmitter* transmitter);
116116 void updateThrust(float deltaTime, Transmitter * transmitter);
117+ void follow(Avatar* leadingAvatar);
117118 void updateFromGyrosAndOrWebcam(bool gyroLook,
118119 const glm::vec3& amplifyAngle,
119120 float yawFromTouch,
@@ -157,18 +158,16 @@ public: · 37 unmodified lines
157158 float getElapsedTimeMoving () const { return _elapsedTimeMoving;}
158159 float getElapsedTimeSinceCollision() const { return _elapsedTimeSinceCollision;}
159160 const glm::vec3& getLastCollisionPosition () const { return _lastCollisionPosition;}
160− float getAbsoluteHeadYaw () const;
161− float getAbsoluteHeadPitch () const;
162− Head& getHead () {return _head; }
163− Hand& getHand () {return _hand; }
164− glm::quat getOrientation () const;
165− glm::quat getWorldAlignedOrientation() const;
166−
167− const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; }
168− const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; }
169−
170−
171− glm::vec3 getGravity () const { return _gravity; }
161+ float getAbsoluteHeadYaw () const;
162+ float getAbsoluteHeadPitch () const;
163+ Head& getHead () {return _head; }
164+ Hand& getHand () {return _hand; }
165+ glm::quat getOrientation () const;
166+ glm::quat getWorldAlignedOrientation() const;
167+ const glm::vec3& getMouseRayOrigin () const { return _mouseRayOrigin; }
168+ const glm::vec3& getMouseRayDirection () const { return _mouseRayDirection; }
169+ Avatar* getLeadingAvatar () const { return _leadingAvatar; }
170+ glm::vec3 getGravity () const { return _gravity; }
172171
173172 glm::vec3 getUprightHeadPosition() const;
174173 glm::vec3 getUprightEyeLevelPosition() const;
@@ -255,7 +254,10 @@ private: · 80 unmodified lines
255254 glm::vec3 _lastCollisionPosition;
256255 bool _speedBrakes;
257256 bool _isThrustOn;
258−
257+
258+ Avatar* _leadingAvatar;
259+ float _stringLength;
260+
259261 AvatarVoxelSystem _voxels;
260262
261263 // private methods...
interface/src/avatar/AvatarVoxelSystem.cpp+2−1
@@ -250,7 +250,8 @@ void AvatarVoxelSystem::handleVoxelDownloadProgress(qint64 bytesReceived, qint64 · 249 unmodified lines
250250 _voxelReply->deleteLater();
251251 _voxelReply = 0;
252252
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);
254255 setupNewVoxelsForDrawing();
255256 }
256257
interface/src/avatar/Hand.cpp+131−80
@@ -14,7 +14,7 @@ · 13 unmodified lines
1414 #include "Util.h"
1515 #include "renderer/ProgramObject.h"
1616
17−const bool SHOW_LEAP_HAND = true;
17+const bool SHOW_LEAP_HAND = false;
1818
1919 using namespace std;
2020
@@ -51,6 +51,7 @@ void Hand::reset() { · 30 unmodified lines
5151
5252
5353 void Hand::simulate(float deltaTime, bool isMine) {
54+
5455 if (_isRaveGloveActive) {
5556 updateRaveGloveParticles(deltaTime);
5657 }
@@ -63,7 +64,8 @@ void Hand::calculateGeometry() { · 6 unmodified lines
6364 _basePosition = head.getPosition() + head.getOrientation() * offset;
6465 _baseOrientation = head.getOrientation();
6566
66− _leapBalls.clear();
67+ // generate finger tip balls....
68+ _leapFingerTipBalls.clear();
6769 for (size_t i = 0; i < getNumPalms(); ++i) {
6870 PalmData& palm = getPalms()[i];
6971 if (palm.isActive()) {
@@ -71,8 +73,8 @@ void Hand::calculateGeometry() { · 1 unmodified line
7173 FingerData& finger = palm.getFingers()[f];
7274 if (finger.isActive()) {
7375 const float standardBallRadius = 0.01f;
74− _leapBalls.resize(_leapBalls.size() + 1);
75− HandBall& ball = _leapBalls.back();
76+ _leapFingerTipBalls.resize(_leapFingerTipBalls.size() + 1);
77+ HandBall& ball = _leapFingerTipBalls.back();
7678 ball.rotation = _baseOrientation;
7779 ball.position = finger.getTipPosition();
7880 ball.radius = standardBallRadius;
@@ -82,6 +84,27 @@ void Hand::calculateGeometry() { · 3 unmodified lines
8284 }
8385 }
8486 }
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+ }
85108 }
86109
87110 void Hand::setRaveGloveEffectsMode(QKeyEvent* event) {
@@ -120,8 +143,9 @@ void Hand::render(bool lookingInMirror) { · 32 unmodified lines
120143 glEnable(GL_RESCALE_NORMAL);
121144
122145 if ( SHOW_LEAP_HAND ) {
123− renderFingerTrails();
124− renderHandSpheres();
146+ //renderLeapHands();
147+ renderLeapFingerTrails();
148+ renderLeapHandSpheres();
125149 }
126150 }
127151
@@ -153,18 +177,64 @@ void Hand::renderRaveGloveStage() { · 25 unmodified lines
153177 }
154178 }
155179
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() {
157214 glPushMatrix();
158215 // Draw the leap balls
159− for (size_t i = 0; i < _leapBalls.size(); i++) {
216+ for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) {
160217 float alpha = 1.0f;
161218
162219 if (alpha > 0.0f) {
163220 glColor4f(_ballColor.r, _ballColor.g, _ballColor.b, alpha);
164221
165222 glPushMatrix();
166− glTranslatef(_leapBalls[i].position.x, _leapBalls[i].position.y, _leapBalls[i].position.z);
167− glutSolidSphere(_leapBalls[i].radius, 20.0f, 20.0f);
223+ glTranslatef(_leapFingerTipBalls[i].position.x, _leapFingerTipBalls[i].position.y, _leapFingerTipBalls[i].position.z);
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);
168238 glPopMatrix();
169239 }
170240 }
@@ -200,7 +270,7 @@ void Hand::renderHandSpheres() { · 29 unmodified lines
200270 glPopMatrix();
201271 }
202272
203−void Hand::renderFingerTrails() {
273+void Hand::renderLeapFingerTrails() {
204274 // Draw the finger root cones
205275 for (size_t i = 0; i < getNumPalms(); ++i) {
206276 PalmData& palm = getPalms()[i];
@@ -229,6 +299,7 @@ void Hand::renderFingerTrails() { · 22 unmodified lines
229299 }
230300 }
231301
302+
232303 void Hand::setLeapHands(const std::vector<glm::vec3>& handPositions,
233304 const std::vector<glm::vec3>& handNormals) {
234305 for (size_t i = 0; i < getNumPalms(); ++i) {
@@ -244,69 +315,28 @@ void Hand::setLeapHands(const std::vector<glm::vec3>& handPositions, · 9 unmodified lines
244315 }
245316 }
246317
247−// call this right after the geometry of the leap hands are set
248−void Hand::updateRaveGloveEmitters() {
249318
250− bool debug = false;
319+// call this soon after the geometry of the leap hands are set
320+void Hand::updateRaveGloveEmitters() {
251321
252− if (_raveGloveInitialized) {
253−
254− if(debug) printf( "\n" );
255− if(debug) printf( "------------------------------------\n" );
256− if(debug) printf( "updating rave glove emitters:\n" );
257− if(debug) printf( "------------------------------------\n" );
258−
259− int emitterIndex = 0;
322+ for (size_t i = 0; i < NUM_FINGERS; i++) {
323+ _raveGloveParticleSystem.setEmitterActive(_raveGloveEmitter[i], false);
324+ }
260325
261− for (size_t i = 0; i < getNumPalms(); ++i) {
262− PalmData& palm = getPalms()[i];
263−
264− if(debug) printf( "\n" );
265− if(debug) printf( "palm %d ", (int)i );
266−
267− if (palm.isActive()) {
326+ for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) {
327+ if (i < NUM_FINGERS) {
328+ glm::vec3 fingerDirection = _leapFingerTipBalls[i].position - _leapFingerRootBalls[i].position;
329+ float fingerLength = glm::length(fingerDirection);
268330
269− if(debug) printf( "is active\n" );
270−
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− }
331+ if (fingerLength > 0.0f) {
332+ fingerDirection /= fingerLength;
307333 } else {
308− if(debug) printf( "is NOT active\n" );
334+ fingerDirection = IDENTITY_UP;
309335 }
336+
337+ _raveGloveParticleSystem.setEmitterActive (_raveGloveEmitter[i], true);
338+ _raveGloveParticleSystem.setEmitterPosition (_raveGloveEmitter[i], _leapFingerTipBalls[i].position);
339+ _raveGloveParticleSystem.setEmitterDirection(_raveGloveEmitter[i], fingerDirection);
310340 }
311341 }
312342 }
@@ -317,16 +347,11 @@ void Hand::updateRaveGloveParticles(float deltaTime) { · 4 unmodified lines
317347
318348 if (!_raveGloveInitialized) {
319349
320− //printf( "Initializing rave glove emitters:\n" );
321− //printf( "The indices of the emitters are:\n" );
322−
323350 // start up the rave glove finger particles...
324351 for ( int f = 0; f< NUM_FINGERS; f ++ ) {
325− _raveGloveEmitter[f] = _raveGloveParticleSystem.addEmitter();
352+ _raveGloveEmitter[f] = _raveGloveParticleSystem.addEmitter();
326353 assert( _raveGloveEmitter[f] >= 0 );
327354 assert( _raveGloveEmitter[f] != NULL_EMITTER );
328−
329− //printf( "%d\n", _raveGloveEmitter[f] );
330355 }
331356
332357 setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_FIRE);
@@ -339,13 +364,13 @@ void Hand::updateRaveGloveParticles(float deltaTime) { · 6 unmodified lines
339364 // this rave glove effect oscillates though various colors and radii that are meant to show off some effects
340365 if (_raveGloveMode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) {
341366 ParticleSystem::ParticleAttributes attributes;
342− float red = 0.5f + 0.5f * sinf(_raveGloveClock * 1.4f);
343− float green = 0.5f + 0.5f * cosf(_raveGloveClock * 1.7f);
344− float blue = 0.5f + 0.5f * sinf(_raveGloveClock * 2.0f);
367+ float red = 0.5f + 0.5f * sinf(_raveGloveClock * 2.4f);
368+ float green = 0.5f + 0.5f * cosf(_raveGloveClock * 2.7f);
369+ float blue = 0.5f + 0.5f * sinf(_raveGloveClock * 3.0f);
345370 float alpha = 1.0f;
346371
347372 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);
349374 attributes.modulationAmplitude = 0.0f;
350375
351376 for ( int f = 0; f< NUM_FINGERS; f ++ ) {
@@ -360,6 +385,8 @@ void Hand::updateRaveGloveParticles(float deltaTime) { · 8 unmodified lines
360385 }
361386 }
362387
388+
389+
363390 void Hand::setRaveGloveMode(int mode) {
364391
365392 _raveGloveMode = mode;
@@ -376,7 +403,7 @@ void Hand::setRaveGloveMode(int mode) { · 10 unmodified lines
376403 if (mode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) {
377404 _raveGloveParticleSystem.setParticleRenderStyle (_raveGloveEmitter[f], PARTICLE_RENDER_STYLE_SPHERE );
378405 _raveGloveParticleSystem.setShowingEmitterBaseParticle(_raveGloveEmitter[f], true );
379− _raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.0f );
406+ _raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.03f );
380407 _raveGloveParticleSystem.setEmitterThrust (_raveGloveEmitter[f], 0.0f );
381408 _raveGloveParticleSystem.setEmitterRate (_raveGloveEmitter[f], 30.0f );
382409 _raveGloveParticleSystem.setEmitterParticleResolution (_raveGloveEmitter[f], 20 );
@@ -650,7 +677,7 @@ void Hand::setRaveGloveMode(int mode) { · 267 unmodified lines
650677 _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes);
651678
652679 //-----------------------------------------
653− // throb
680+ // long sparkler
654681 //-----------------------------------------
655682 } else if (mode == RAVE_GLOVE_EFFECTS_MODE_LONG_SPARKLER) {
656683
@@ -672,6 +699,30 @@ void Hand::setRaveGloveMode(int mode) { · 15 unmodified lines
672699 _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_1, attributes);
673700 _raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_2, attributes);
674701 _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);
675726 }
676727 }
677728 }
interface/src/avatar/Hand.h+9−5
@@ -65,8 +65,9 @@ public: · 64 unmodified lines
6565 void setRaveGloveEffectsMode(QKeyEvent* event);
6666
6767 // getters
68− const glm::vec3& getLeapBallPosition (int ball) const { return _leapBalls[ball].position;}
69− bool isRaveGloveActive () const { return _isRaveGloveActive; }
68+ const glm::vec3& getLeapFingerTipBallPosition (int ball) const { return _leapFingerTipBalls [ball].position;}
69+ const glm::vec3& getLeapFingerRootBallPosition(int ball) const { return _leapFingerRootBalls[ball].position;}
70+ bool isRaveGloveActive() const { return _isRaveGloveActive; }
7071
7172 private:
7273 // disallow copies of the Hand, copy of owning Avatar is disallowed too
@@ -84,7 +85,8 @@ private: · 11 unmodified lines
8485 float _renderAlpha;
8586 bool _lookingInMirror;
8687 glm::vec3 _ballColor;
87− std::vector<HandBall> _leapBalls;
88+ std::vector<HandBall> _leapFingerTipBalls;
89+ std::vector<HandBall> _leapFingerRootBalls;
8890
8991 // private methods
9092 void setLeapHands(const std::vector<glm::vec3>& handPositions,
@@ -92,8 +94,10 @@ private: · 1 unmodified line
9294
9395 void renderRaveGloveStage();
9496 void setRaveGloveMode(int mode);
95− void renderHandSpheres();
96− void renderFingerTrails();
97+ void renderLeapHandSpheres();
98+ void renderLeapHands();
99+ void renderLeapHand(PalmData& hand);
100+ void renderLeapFingerTrails();
97101 void calculateGeometry();
98102 };
99103
libraries/avatars/src/AvatarData.cpp+17−0
@@ -130,6 +130,8 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { · 129 unmodified lines
130130
131131 // leap hand data
132132 std::vector<glm::vec3> fingerVectors;
133+
134+//printf("about to call _handData->encodeRemoteData(fingerVectors);\n");
133135 _handData->encodeRemoteData(fingerVectors);
134136
135137 if (fingerVectors.size() > 255)
@@ -244,17 +246,32 @@ int AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { · 108 unmodified lines
244246 // hand state, stored as a semi-nibble in the bitItems
245247 _handState = getSemiNibbleAt(bitItems,HAND_STATE_START_BIT);
246248
249+//printf("about to call leap hand data code in AvatarData::parseData...\n");
250+
247251 // leap hand data
248252 if (sourceBuffer - startPosition < numBytes) {
253+
254+//printf("got inside of 'if (sourceBuffer - startPosition < numBytes)'\n");
255+
256+
249257 // check passed, bytes match
250258 unsigned int numFingerVectors = *sourceBuffer++;
259+
260+//printf("numFingerVectors = %d\n", numFingerVectors);
261+
262+
251263 if (numFingerVectors > 0) {
264+
265+//printf("ok, we got fingers in AvatarData::parseData\n");
266+
252267 std::vector<glm::vec3> fingerVectors(numFingerVectors);
253268 for (size_t i = 0; i < numFingerVectors; ++i) {
254269 sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].x), fingerVectorRadix);
255270 sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].y), fingerVectorRadix);
256271 sourceBuffer += unpackFloatScalarFromSignedTwoByteFixed((int16_t*) sourceBuffer, &(fingerVectors[i].z), fingerVectorRadix);
257272 }
273+
274+//printf("about to call _handData->decodeRemoteData(fingerVectors);\n");
258275 _handData->decodeRemoteData(fingerVectors);
259276 }
260277 }
libraries/avatars/src/HandData.cpp+3−0
@@ -51,7 +51,9 @@ _owningHandData(owningHandData) · 50 unmodified lines
5151
5252 void HandData::encodeRemoteData(std::vector<glm::vec3>& fingerVectors) {
5353 fingerVectors.clear();
54+
5455 for (size_t i = 0; i < getNumPalms(); ++i) {
56+
5557 PalmData& palm = getPalms()[i];
5658 if (!palm.isActive()) {
5759 continue;
@@ -60,6 +62,7 @@ void HandData::encodeRemoteData(std::vector<glm::vec3>& fingerVectors) { · 2 unmodified lines
6062 fingerVectors.push_back(palm.getRawNormal());
6163 for (size_t f = 0; f < palm.getNumFingers(); ++f) {
6264 FingerData& finger = palm.getFingers()[f];
65+
6366 if (finger.isActive()) {
6467 fingerVectors.push_back(finger.getTipRawPosition());
6568 fingerVectors.push_back(finger.getRootRawPosition());
libraries/shared/src/NodeList.cpp+2−3
@@ -24,10 +24,9 @@ · 23 unmodified lines
2424 #include <arpa/inet.h>
2525 #endif
2626
27−const char SOLO_NODE_TYPES[3] = {
27+const char SOLO_NODE_TYPES[2] = {
2828 NODE_TYPE_AVATAR_MIXER,
29− NODE_TYPE_AUDIO_MIXER,
30− NODE_TYPE_VOXEL_SERVER
29+ NODE_TYPE_AUDIO_MIXER
3130 };
3231
3332 const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES] = "root.highfidelity.io";
libraries/shared/src/NodeList.h+1−1
@@ -32,7 +32,7 @@ const unsigned int NODE_SOCKET_LISTEN_PORT = 40103; · 31 unmodified lines
3232 const int NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000;
3333 const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
3434
35−extern const char SOLO_NODE_TYPES[3];
35+extern const char SOLO_NODE_TYPES[2];
3636
3737 const int MAX_HOSTNAME_BYTES = 256;
3838
libraries/shared/src/OctalCode.cpp+39−0
@@ -257,3 +257,42 @@ unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* · 256 unmodified lines
257257 return newCode;
258258 }
259259
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+}
libraries/shared/src/OctalCode.h+3−1
@@ -21,7 +21,6 @@ const int BLUE_INDEX = 2; · 20 unmodified lines
2121
2222 void printOctalCode(unsigned char * octalCode);
2323 int bytesRequiredForCodeLength(unsigned char threeBitCodes);
24−bool isDirectParentOfChild(unsigned char *parentOctalCode, unsigned char * childOctalCode);
2524 int branchIndexWithDescendant(unsigned char * ancestorOctalCode, unsigned char * descendantOctalCode);
2625 unsigned char * childOctalCode(unsigned char * parentOctalCode, char childNumber);
2726 int numberOfThreeBitSectionsInCode(unsigned char * octalCode);
@@ -29,6 +28,9 @@ unsigned char* chopOctalCode(unsigned char* originalOctalCode, int chopLevels); · 1 unmodified line
2928 unsigned char* rebaseOctalCode(unsigned char* originalOctalCode, unsigned char* newParentOctalCode,
3029 bool includeColorSpace = false);
3130
31+const int CHECK_NODE_ONLY = -1;
32+bool isAncestorOf(unsigned char* possibleAncestor, unsigned char* possibleDescendent, int descendentsChild = CHECK_NODE_ONLY);
33+
3234 // Note: copyFirstVertexForCode() is preferred because it doesn't allocate memory for the return
3335 // but other than that these do the same thing.
3436 float * firstVertexForCode(unsigned char * octalCode);
libraries/voxels/src/JurisdictionMap.cpp+178−0
@@ -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+}
libraries/voxels/src/JurisdictionMap.h+46−0
@@ -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+
libraries/voxels/src/Tags.cpp+1−1
@@ -1,5 +1,5 @@
11 //
2−// Tags.h
2+// Tags.cpp
33 // hifi
44 //
55 // Created by Clement Brisset on 7/3/13.
libraries/voxels/src/VoxelNode.cpp+3−0
@@ -12,6 +12,8 @@ · 11 unmodified lines
1212
1313 #include <QDebug>
1414
15+#include <NodeList.h>
16+
1517 #include "AABox.h"
1618 #include "OctalCode.h"
1719 #include "SharedUtil.h"
@@ -51,6 +53,7 @@ void VoxelNode::init(unsigned char * octalCode) { · 33 unmodified lines
5153 _voxelSystem = NULL;
5254 _isDirty = true;
5355 _shouldRender = false;
56+ _sourceID = UNKNOWN_NODE_ID;
5457 markWithChangedTime();
5558 calculateAABox();
5659 }
libraries/voxels/src/VoxelNode.h+6−2
@@ -93,8 +93,6 @@ public: · 92 unmodified lines
9393 void setColor(const nodeColor& color);
9494 const nodeColor& getTrueColor() const { return _trueColor; };
9595 const nodeColor& getColor() const { return _currentColor; };
96− void setDensity(float density) { _density = density; };
97− float getDensity() const { return _density; };
9896 #else
9997 void setFalseColor(colorPart red, colorPart green, colorPart blue) { /* no op */ };
10098 void setFalseColored(bool isFalseColored) { /* no op */ };
@@ -105,6 +103,11 @@ public: · 4 unmodified lines
105103 const nodeColor& getColor() const { return _trueColor; };
106104 #endif
107105
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+
108111 static void addDeleteHook(VoxelNodeDeleteHook* hook);
109112 static void removeDeleteHook(VoxelNodeDeleteHook* hook);
110113
@@ -135,6 +138,7 @@ private: · 24 unmodified lines
135138 unsigned long _subtreeNodeCount;
136139 unsigned long _subtreeLeafNodeCount;
137140 float _density; // If leaf: density = 1, if internal node: 0-1 density of voxels inside
141+ uint16_t _sourceID;
138142
139143 static std::vector<VoxelNodeDeleteHook*> _hooks;
140144 };
libraries/voxels/src/VoxelTree.cpp+44−23
@@ -231,7 +231,7 @@ VoxelNode* VoxelTree::createMissingNode(VoxelNode* lastParentNode, unsigned char · 230 unmodified lines
231231 }
232232
233233 int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, int bytesLeftToRead,
234− bool includeColor, bool includeExistsBits) {
234+ ReadBitstreamToTreeParams& args) {
235235 // give this destination node the child mask from the packet
236236 const unsigned char ALL_CHILDREN_ASSUMED_TO_EXIST = 0xFF;
237237 unsigned char colorInPacketMask = *nodeData;
@@ -254,12 +254,13 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, · 16 unmodified lines
254254
255255 // pull the color for this child
256256 nodeColor newColor = { 128, 128, 128, 1};
257− if (includeColor) {
257+ if (args.includeColor) {
258258 memcpy(newColor, nodeData + bytesRead, 3);
259259 bytesRead += 3;
260260 }
261261 bool nodeWasDirty = destinationNode->getChildAtIndex(i)->isDirty();
262262 destinationNode->getChildAtIndex(i)->setColor(newColor);
263+ destinationNode->getChildAtIndex(i)->setSourceID(args.sourceID);
263264 bool nodeIsDirty = destinationNode->getChildAtIndex(i)->isDirty();
264265 if (nodeIsDirty) {
265266 _isDirty = true;
@@ -273,11 +274,11 @@ int VoxelTree::readNodeData(VoxelNode* destinationNode, unsigned char* nodeData, · 7 unmodified lines
273274 }
274275
275276 // 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 childMask = *(nodeData + bytesRead + (includeExistsBits ? sizeof(childrenInTreeMask) : 0));
277+ unsigned char childrenInTreeMask = args.includeExistsBits ? *(nodeData + bytesRead) : ALL_CHILDREN_ASSUMED_TO_EXIST;
278+ unsigned char childMask = *(nodeData + bytesRead + (args.includeExistsBits ? sizeof(childrenInTreeMask) : 0));
278279
279280 int childIndex = 0;
280− bytesRead += includeExistsBits ? sizeof(childrenInTreeMask) + sizeof(childMask) : sizeof(childMask);
281+ bytesRead += args.includeExistsBits ? sizeof(childrenInTreeMask) + sizeof(childMask) : sizeof(childMask);
281282
282283 while (bytesLeftToRead - bytesRead > 0 && childIndex < NUMBER_OF_CHILDREN) {
283284 // 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
300301
301302 // tell the child to read the subsequent data
302303 bytesRead += readNodeData(destinationNode->getChildAtIndex(childIndex),
303− nodeData + bytesRead, bytesLeftToRead - bytesRead, includeColor, includeExistsBits);
304+ nodeData + bytesRead, bytesLeftToRead - bytesRead, args);
304305 }
305306 childIndex++;
306307 }
307308
308−
309− if (includeExistsBits) {
309+ if (args.includeExistsBits) {
310310 for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
311311 // now also check the childrenInTreeMask, if the mask is missing the bit, then it means we need to delete this child
312312 // 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
319319 return bytesRead;
320320 }
321321
322−void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int bufferSizeBytes,
323− bool includeColor, bool includeExistsBits, VoxelNode* destinationNode) {
322+void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int bufferSizeBytes,
323+ ReadBitstreamToTreeParams& args) {
324324 int bytesRead = 0;
325325 unsigned char* bitstreamAt = bitstream;
326326
327327 // If destination node is not included, set it to root
328− if (!destinationNode) {
329− destinationNode = rootNode;
328+ if (!args.destinationNode) {
329+ args.destinationNode = rootNode;
330330 }
331331
332332 _nodesChangedFromBitstream = 0;
@@ -336,14 +336,14 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int · 3 unmodified lines
336336 // if there are more bytes after that, it's assumed to be another root relative tree
337337
338338 while (bitstreamAt < bitstream + bufferSizeBytes) {
339− VoxelNode* bitstreamRootNode = nodeForOctalCode(destinationNode, (unsigned char *)bitstreamAt, NULL);
339+ VoxelNode* bitstreamRootNode = nodeForOctalCode(args.destinationNode, (unsigned char *)bitstreamAt, NULL);
340340 if (*bitstreamAt != *bitstreamRootNode->getOctalCode()) {
341341 // if the octal code returned is not on the same level as
342342 // the code being searched for, we have VoxelNodes to create
343343
344344 // Note: we need to create this node relative to root, because we're assuming that the bitstream for the initial
345345 // octal code is always relative to root!
346− bitstreamRootNode = createMissingNode(destinationNode, (unsigned char*) bitstreamAt);
346+ bitstreamRootNode = createMissingNode(args.destinationNode, (unsigned char*) bitstreamAt);
347347 if (bitstreamRootNode->isDirty()) {
348348 _isDirty = true;
349349 _nodesChangedFromBitstream++;
@@ -353,8 +353,8 @@ void VoxelTree::readBitstreamToTree(unsigned char * bitstream, unsigned long int · 3 unmodified lines
353353 int octalCodeBytes = bytesRequiredForCodeLength(*bitstreamAt);
354354 int theseBytesRead = 0;
355355 theseBytesRead += octalCodeBytes;
356− theseBytesRead += readNodeData(bitstreamRootNode, bitstreamAt + octalCodeBytes,
357− bufferSizeBytes - (bytesRead + octalCodeBytes), includeColor, includeExistsBits);
356+ theseBytesRead += readNodeData(bitstreamRootNode, bitstreamAt + octalCodeBytes,
357+ bufferSizeBytes - (bytesRead + octalCodeBytes), args);
358358
359359 // skip bitstream to new startPoint
360360 bitstreamAt += theseBytesRead;
@@ -1078,6 +1078,15 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp · 717 unmodified lines
10781078 if (currentEncodeLevel >= params.maxEncodeLevel) {
10791079 return bytesAtThisLevel;
10801080 }
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+ }
10811090
10821091 // caller can pass NULL as viewFrustum if they want everything
10831092 if (params.viewFrustum) {
@@ -1197,9 +1206,18 @@ int VoxelTree::encodeTreeBitstreamRecursion(VoxelNode* node, unsigned char* outp · 113 unmodified lines
11971206 for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
11981207 VoxelNode* childNode = node->getChildAtIndex(i);
11991208
1200− // if the caller wants to include childExistsBits, then include them even if not in view
1201− if (params.includeExistsBits && childNode) {
1202− childrenExistInTreeBits += (1 << (7 - i));
1209+ // if the caller wants to include childExistsBits, then include them even if not in view, if however,
1210+ // we're in a portion of the tree that's not our responsibility, then we assume the child nodes exist
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+ }
12031221 }
12041222
12051223 if (params.wantOcclusionCulling) {
@@ -1548,7 +1566,8 @@ bool VoxelTree::readFromSVOFile(const char* fileName) { · 342 unmodified lines
15481566 // read the entire file into a buffer, WHAT!? Why not.
15491567 unsigned char* entireFile = new unsigned char[fileLength];
15501568 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);
15521571 delete[] entireFile;
15531572
15541573 file.close();
@@ -1702,7 +1721,8 @@ void VoxelTree::copySubTreeIntoNewTree(VoxelNode* startNode, VoxelTree* destinat · 147 unmodified lines
17021721 bytesWritten = encodeTreeBitstream(subTree, &outputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, nodeBag, params);
17031722
17041723 // 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);
17061726 }
17071727 }
17081728
@@ -1722,7 +1742,8 @@ void VoxelTree::copyFromTreeIntoSubTree(VoxelTree* sourceTree, VoxelNode* destin · 13 unmodified lines
17221742 bytesWritten = sourceTree->encodeTreeBitstream(subTree, &outputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1, nodeBag, params);
17231743
17241744 // 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);
17261747 }
17271748 }
17281749
@@ -1877,4 +1898,4 @@ void VoxelTree::computeBlockColor(int id, int data, int& red, int& green, int& b · 148 unmodified lines
18771898 create = 0;
18781899 break;
18791900 }
1880−}
1901+}
libraries/voxels/src/VoxelTree.h+33−11
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <SimpleMovingAverage.h>
1414
1515 #include "CoverageMap.h"
16+#include "JurisdictionMap.h"
1617 #include "ViewFrustum.h"
1718 #include "VoxelNode.h"
1819 #include "VoxelNodeBag.h"
@@ -36,9 +37,10 @@ const int NO_BOUNDARY_ADJUST = 0; · 17 unmodified lines
3637 const int LOW_RES_MOVING_ADJUST = 1;
3738 const uint64_t IGNORE_LAST_SENT = 0;
3839
39−#define IGNORE_SCENE_STATS NULL
40−#define IGNORE_VIEW_FRUSTUM NULL
41−#define IGNORE_COVERAGE_MAP NULL
40+#define IGNORE_SCENE_STATS NULL
41+#define IGNORE_VIEW_FRUSTUM NULL
42+#define IGNORE_COVERAGE_MAP NULL
43+#define IGNORE_JURISDICTION_MAP NULL
4244
4345 class EncodeBitstreamParams {
4446 public:
@@ -56,6 +58,7 @@ public: · 11 unmodified lines
5658 bool forceSendScene;
5759 VoxelSceneStats* stats;
5860 CoverageMap* map;
61+ JurisdictionMap* jurisdictionMap;
5962
6063 EncodeBitstreamParams(
6164 int maxEncodeLevel = INT_MAX,
@@ -70,7 +73,8 @@ public: · 8 unmodified lines
7073 int boundaryLevelAdjust = NO_BOUNDARY_ADJUST,
7174 uint64_t lastViewFrustumSent = IGNORE_LAST_SENT,
7275 bool forceSendScene = true,
73− VoxelSceneStats* stats = IGNORE_SCENE_STATS) :
76+ VoxelSceneStats* stats = IGNORE_SCENE_STATS,
77+ JurisdictionMap* jurisdictionMap = IGNORE_JURISDICTION_MAP) :
7478 maxEncodeLevel (maxEncodeLevel),
7579 maxLevelReached (0),
7680 viewFrustum (viewFrustum),
@@ -84,7 +88,27 @@ public: · 7 unmodified lines
8488 lastViewFrustumSent (lastViewFrustumSent),
8589 forceSendScene (forceSendScene),
8690 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)
88112 {}
89113 };
90114
@@ -109,9 +133,7 @@ public: · 18 unmodified lines
109133 void eraseAllVoxels();
110134
111135 void processRemoveVoxelBitstream(unsigned char* bitstream, int bufferSizeBytes);
112− void readBitstreamToTree(unsigned char* bitstream, unsigned long int bufferSizeBytes,
113− bool includeColor = WANT_COLOR, bool includeExistsBits = WANT_EXISTS_BITS,
114− VoxelNode* destinationNode = NULL);
136+ void readBitstreamToTree(unsigned char* bitstream, unsigned long int bufferSizeBytes, ReadBitstreamToTreeParams& args);
115137 void readCodeColorBufferToTree(unsigned char* codeColorBuffer, bool destructive = false);
116138 void deleteVoxelCodeFromTree(unsigned char* codeBuffer, bool collapseEmptyTrees = DONT_COLLAPSE);
117139 void printTreeForDebugging(VoxelNode* startNode);
@@ -169,7 +191,8 @@ public: · 51 unmodified lines
169191 void recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime,
170192 RecurseVoxelTreeOperation operation,
171193 const glm::vec3& point, void* extraData);
172−
194+
195+
173196 private:
174197 void deleteVoxelCodeFromTreeRecursion(VoxelNode* node, void* extraData);
175198 void readCodeColorBufferToTreeRecursion(VoxelNode* node, void* extraData);
@@ -181,8 +204,7 @@ private: · 5 unmodified lines
181204
182205 VoxelNode* nodeForOctalCode(VoxelNode* ancestorNode, unsigned char* needleCode, VoxelNode** parentOfFoundNode) const;
183206 VoxelNode* createMissingNode(VoxelNode* lastParentNode, unsigned char* deepestCodeToCreate);
184− int readNodeData(VoxelNode *destinationNode, unsigned char* nodeData, int bufferSizeBytes,
185− bool includeColor = WANT_COLOR, bool includeExistsBits = WANT_EXISTS_BITS);
207+ int readNodeData(VoxelNode *destinationNode, unsigned char* nodeData, int bufferSizeBytes, ReadBitstreamToTreeParams& args);
186208
187209 bool _isDirty;
188210 unsigned long int _nodesChangedFromBitstream;
voxel-server/src/README+80−0
@@ -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+
voxel-server/src/main.cpp+51−7
@@ -32,6 +32,8 @@ · 31 unmodified lines
3232
3333 const char* LOCAL_VOXELS_PERSIST_FILE = "resources/voxels.svo";
3434 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];
3537 const int VOXEL_PERSIST_INTERVAL = 1000 * 30; // every 30 seconds
3638
3739 const int VOXEL_LISTEN_PORT = 40106;
@@ -65,6 +67,8 @@ bool debugVoxelReceiving = false; · 27 unmodified lines
6567
6668 EnvironmentData environmentData[3];
6769
70+int receivedPacketCount = 0;
71+JurisdictionMap* jurisdiction = NULL;
6872
6973 void randomlyFillVoxelTree(int levelsToGo, VoxelNode *currentRootNode) {
7074 // randomly generate children for this node
@@ -292,7 +296,7 @@ void deepestLevelVoxelDistributor(NodeList* nodeList, · 221 unmodified lines
292296 WANT_EXISTS_BITS, DONT_CHOP, wantDelta, lastViewFrustum,
293297 wantOcclusionCulling, coverageMap, boundaryLevelAdjust,
294298 nodeData->getLastTimeBagEmpty(),
295− isFullScene, &nodeData->stats);
299+ isFullScene, &nodeData->stats, ::jurisdiction);
296300
297301 nodeData->stats.encodeStarted();
298302 bytesWritten = serverTree.encodeTreeBitstream(subTree, &tempOutputBuffer[0], MAX_VOXEL_PACKET_SIZE - 1,
@@ -376,7 +380,7 @@ void persistVoxelsWhenDirty() { · 77 unmodified lines
376380 "persistVoxelsWhenDirty() - writeToSVOFile()", ::shouldShowAnimationDebug);
377381
378382 printf("saving voxels to file...\n");
379− serverTree.writeToSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE);
383+ serverTree.writeToSVOFile(::voxelPersistFilename);
380384 serverTree.clearDirtyBit(); // tree is clean after saving
381385 printf("DONE saving voxels to file...\n");
382386 }
@@ -427,14 +431,39 @@ void attachVoxelNodeDataToNode(Node* newNode) { · 44 unmodified lines
427431 }
428432 }
429433
430−int receivedPacketCount = 0;
431−
432434 int main(int argc, const char * argv[]) {
433435 pthread_mutex_init(&::treeLock, NULL);
434436
435437 qInstallMessageHandler(sharedMessageHandler);
436438
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);
438467 setvbuf(stdout, NULL, _IOLBF, 0);
439468
440469 // Handle Local Domain testing with the --local command line
@@ -480,8 +509,19 @@ int main(int argc, const char * argv[]) { · 39 unmodified lines
480509 // if we want Voxel Persistance, load the local file now...
481510 bool persistantFileRead = false;
482511 if (::wantVoxelPersist) {
483− printf("loading voxels from file...\n");
484− persistantFileRead = ::serverTree.readFromSVOFile(::wantLocalDomain ? LOCAL_VOXELS_PERSIST_FILE : VOXELS_PERSIST_FILE);
512+
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);
485525 if (persistantFileRead) {
486526 PerformanceWarning warn(::shouldShowAnimationDebug,
487527 "persistVoxelsWhenDirty() - reaverageVoxelColors()", ::shouldShowAnimationDebug);
@@ -707,6 +747,10 @@ int main(int argc, const char * argv[]) { · 219 unmodified lines
707747
708748 pthread_join(sendVoxelThread, NULL);
709749 pthread_mutex_destroy(&::treeLock);
750+
751+ if (jurisdiction) {
752+ delete jurisdiction;
753+ }
710754
711755 return 0;
712756 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t