From 145c6484f49c0b7879fe17f1b92b0281f04cf3e9 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 9 May 2013 13:33:23 -0700 Subject: [PATCH 01/25] Fixed issue with mouse pressed state, use mouse buttons to add/delete voxels (numbers now switch between modes). --- interface/src/main.cpp | 52 +++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 4b70f20402..80adef9e37 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -174,6 +174,10 @@ int mouseY = 0; // Mouse location at start of last down click int mousePressed = 0; // true if mouse has been pressed (clear when finished) +// The current mode for mouse interaction +enum MouseMode { ADD_VOXELS, DELETE_VOXELS }; +MouseMode mouseMode = ADD_VOXELS; + Menu menu; // main menu int menuOn = 1; // Whether to show onscreen menu @@ -1662,8 +1666,8 @@ void key(unsigned char k, int x, int y) { if (k == '^') ::shiftPaintingColor(); // shifts randomize color between R,G,B dominant if (k == '-') ::sendVoxelServerEraseAll(); // sends erase all command to voxel server if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server - if (k == '1') ::addVoxelUnderCursor(); - if (k == '2') ::deleteVoxelUnderCursor(); + if (k == '1') ::mouseMode = ADD_VOXELS; + if (k == '2') ::mouseMode = DELETE_VOXELS; if (k == 'n' || k == 'N') { noiseOn = !noiseOn; // Toggle noise @@ -1767,9 +1771,7 @@ void idle(void) { myAvatar.setHandMovementValues(handControl.getValues()); // tell my avatar if the mouse is being pressed... - if (mousePressed) { - myAvatar.setMousePressed(mousePressed); - } + myAvatar.setMousePressed(mousePressed); // walking triggers the handControl to stop if (myAvatar.getMode() == AVATAR_MODE_WALKING) { @@ -1889,17 +1891,35 @@ glm::vec3 getGravity(glm::vec3 pos) { } void mouseFunc(int button, int state, int x, int y) { - if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { - if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { - mouseX = x; - mouseY = y; - mousePressed = 1; - } else if (state == GLUT_UP) { - mouseX = x; - mouseY = y; - mousePressed = 0; - } - } + mouseX = x; + mouseY = y; + + switch (button) { + case GLUT_LEFT_BUTTON: + if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { + mousePressed = 1; + if (::mouseMode == ADD_VOXELS) { + addVoxelUnderCursor(); + + } else { // ::mouseMode == DELETE_VOXELS + deleteVoxelUnderCursor(); + } + } else { + mousePressed = 0; + } + break; + + case GLUT_RIGHT_BUTTON: + if (state == GLUT_DOWN) { + if (::mouseMode == ADD_VOXELS) { + deleteVoxelUnderCursor(); + + } else { // ::mouseMode == DELETE_VOXELS + addVoxelUnderCursor(); + } + } + break; + } } void motionFunc(int x, int y) { From c4110830576bbc4d6330ea25c4cc035a6aaa3ed4 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 9 May 2013 14:30:50 -0700 Subject: [PATCH 02/25] Working on adding an "add voxel in front of avatar" command. --- interface/src/main.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 80adef9e37..a6ffe14ad1 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1487,6 +1487,20 @@ void setupPaintingVoxel() { shiftPaintingColor(); } +void addVoxel(VoxelDetail& detail) { + unsigned char* bufferOut; + int sizeOut; + + if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){ + AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); + delete bufferOut; + } +} + +void addVoxelInFrontOfAvatar() { + +} + void addVoxelUnderCursor() { glm::vec3 origin, direction; viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction); @@ -1521,13 +1535,7 @@ void addVoxelUnderCursor() { detail.z += detail.s; break; } - unsigned char* bufferOut; - int sizeOut; - - if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){ - AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); - delete bufferOut; - } + addVoxel(detail); } } @@ -1668,6 +1676,7 @@ void key(unsigned char k, int x, int y) { if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server if (k == '1') ::mouseMode = ADD_VOXELS; if (k == '2') ::mouseMode = DELETE_VOXELS; + if (k == '3') addVoxelInFrontOfAvatar(); if (k == 'n' || k == 'N') { noiseOn = !noiseOn; // Toggle noise From ecd12e0ac4188115c723ea4b594c01b661682bab Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 9 May 2013 16:09:07 -0700 Subject: [PATCH 03/25] Show the voxels to be added/deleted as wireframe cubes. --- interface/src/main.cpp | 169 +++++++++++++++++++++++------------------ 1 file changed, 95 insertions(+), 74 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index a6ffe14ad1..5bbee6672c 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -175,8 +175,9 @@ int mouseY = 0; int mousePressed = 0; // true if mouse has been pressed (clear when finished) // The current mode for mouse interaction -enum MouseMode { ADD_VOXELS, DELETE_VOXELS }; -MouseMode mouseMode = ADD_VOXELS; +enum MouseMode { ADD_VOXEL_MODE, DELETE_VOXEL_MODE }; +MouseMode mouseMode = ADD_VOXEL_MODE; +VoxelDetail mouseVoxel; // details of the voxel under the mouse cursor Menu menu; // main menu int menuOn = 1; // Whether to show onscreen menu @@ -374,6 +375,16 @@ void reset_sensors() { } } +void sendVoxelEditMessage(PACKET_HEADER header, VoxelDetail& detail) { + unsigned char* bufferOut; + int sizeOut; + + if (createVoxelEditMessage(header, 0, 1, &detail, bufferOut, sizeOut)){ + AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); + delete bufferOut; + } +} + // // Using gyro data, update both view frustum and avatar head position // @@ -482,17 +493,11 @@ void updateAvatar(float deltaTime) { ::paintingVoxel.y = avatarPos.y / 10.0; ::paintingVoxel.z = avatarPos.z / 10.0; - unsigned char* bufferOut; - int sizeOut; - if (::paintingVoxel.x >= 0.0 && ::paintingVoxel.x <= 1.0 && ::paintingVoxel.y >= 0.0 && ::paintingVoxel.y <= 1.0 && ::paintingVoxel.z >= 0.0 && ::paintingVoxel.z <= 1.0) { - if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &::paintingVoxel, bufferOut, sizeOut)){ - AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); - delete bufferOut; - } + sendVoxelEditMessage(PACKET_HEADER_SET_VOXEL, ::paintingVoxel); } } } @@ -745,6 +750,20 @@ void displaySide(Camera& whichCamera) { voxels.render(); } + // indicate what we'll be adding/removing in mouse mode, if anything + if (::mouseVoxel.s != 0) { + glPushMatrix(); + glColor3ub(::mouseVoxel.red, ::mouseVoxel.green, ::mouseVoxel.blue); + glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE); + glTranslatef(::mouseVoxel.x + ::mouseVoxel.s*0.5f, + ::mouseVoxel.y + ::mouseVoxel.s*0.5f, + ::mouseVoxel.z + ::mouseVoxel.s*0.5f); + glLineWidth(4.0f); + glutWireCube(::mouseVoxel.s); + glLineWidth(1.0f); + glPopMatrix(); + } + if (::renderAvatarsOn) { // Render avatars of other agents AgentList* agentList = AgentList::getInstance(); @@ -1487,73 +1506,31 @@ void setupPaintingVoxel() { shiftPaintingColor(); } -void addVoxel(VoxelDetail& detail) { - unsigned char* bufferOut; - int sizeOut; - - if (createVoxelEditMessage(PACKET_HEADER_SET_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){ - AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); - delete bufferOut; - } -} - void addVoxelInFrontOfAvatar() { + VoxelDetail detail; + glm::vec3 position = (myAvatar.getPosition() + myAvatar.getCameraDirection()) * (1.0f / TREE_SCALE); + detail.s = 1.0f / 1024; + + detail.x = detail.s * floor(position.x / detail.s); + detail.y = detail.s * floor(position.y / detail.s); + detail.z = detail.s * floor(position.z / detail.s); + detail.red = 128; + detail.green = 128; + detail.blue = 128; + + sendVoxelEditMessage(PACKET_HEADER_SET_VOXEL, detail); } void addVoxelUnderCursor() { - glm::vec3 origin, direction; - viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction); - - VoxelDetail detail; - float distance; - BoxFace face; - if (voxels.findRayIntersection(origin, direction, detail, distance, face)) { - // use the face to determine the side on which to create a neighbor - switch (face) { - case MIN_X_FACE: - detail.x -= detail.s; - break; - - case MAX_X_FACE: - detail.x += detail.s; - break; - - case MIN_Y_FACE: - detail.y -= detail.s; - break; - - case MAX_Y_FACE: - detail.y += detail.s; - break; - - case MIN_Z_FACE: - detail.z -= detail.s; - break; - - case MAX_Z_FACE: - detail.z += detail.s; - break; - } - addVoxel(detail); + if (::mouseVoxel.s != 0) { + sendVoxelEditMessage(PACKET_HEADER_SET_VOXEL, ::mouseVoxel); } } void deleteVoxelUnderCursor() { - glm::vec3 origin, direction; - viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction); - - VoxelDetail detail; - float distance; - BoxFace face; - if (voxels.findRayIntersection(origin, direction, detail, distance, face)) { - unsigned char* bufferOut; - int sizeOut; - - if (createVoxelEditMessage(PACKET_HEADER_ERASE_VOXEL, 0, 1, &detail, bufferOut, sizeOut)){ - AgentList::getInstance()->broadcastToAgents(bufferOut, sizeOut, &AGENT_TYPE_VOXEL, 1); - delete bufferOut; - } + if (::mouseVoxel.s != 0) { + sendVoxelEditMessage(PACKET_HEADER_ERASE_VOXEL, ::mouseVoxel); } } @@ -1674,8 +1651,8 @@ void key(unsigned char k, int x, int y) { if (k == '^') ::shiftPaintingColor(); // shifts randomize color between R,G,B dominant if (k == '-') ::sendVoxelServerEraseAll(); // sends erase all command to voxel server if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server - if (k == '1') ::mouseMode = ADD_VOXELS; - if (k == '2') ::mouseMode = DELETE_VOXELS; + if (k == '1') ::mouseMode = ADD_VOXEL_MODE; + if (k == '2') ::mouseMode = DELETE_VOXEL_MODE; if (k == '3') addVoxelInFrontOfAvatar(); if (k == 'n' || k == 'N') { @@ -1764,6 +1741,28 @@ void* networkReceive(void* args) { return NULL; } +glm::vec3 getFaceVector(BoxFace face) { + switch (face) { + case MIN_X_FACE: + return glm::vec3(-1, 0, 0); + + case MAX_X_FACE: + return glm::vec3(1, 0, 0); + + case MIN_Y_FACE: + return glm::vec3(0, -1, 0); + + case MAX_Y_FACE: + return glm::vec3(0, 1, 0); + + case MIN_Z_FACE: + return glm::vec3(0, 0, -1); + + case MAX_Z_FACE: + return glm::vec3(0, 0, 1); + } +} + void idle(void) { timeval check; gettimeofday(&check, NULL); @@ -1781,7 +1780,29 @@ void idle(void) { // tell my avatar if the mouse is being pressed... myAvatar.setMousePressed(mousePressed); - + + // check what's under the mouse and update the mouse voxel + glm::vec3 origin, direction; + viewFrustum.computePickRay(mouseX / (float)WIDTH, mouseY / (float)HEIGHT, origin, direction); + + float distance; + BoxFace face; + ::mouseVoxel.s = 0.0f; + if (voxels.findRayIntersection(origin, direction, ::mouseVoxel, distance, face)) { + if (::mouseMode == ADD_VOXEL_MODE) { + // use the face to determine the side on which to create a neighbor + glm::vec3 offset = getFaceVector(face); + ::mouseVoxel.x += offset.x * ::mouseVoxel.s; + ::mouseVoxel.y += offset.y * ::mouseVoxel.s; + ::mouseVoxel.z += offset.z * ::mouseVoxel.s; + + } else { + // red indicates deletion + ::mouseVoxel.red = 255; + ::mouseVoxel.green = ::mouseVoxel.blue = 0; + } + } + // walking triggers the handControl to stop if (myAvatar.getMode() == AVATAR_MODE_WALKING) { handControl.stop(); @@ -1907,10 +1928,10 @@ void mouseFunc(int button, int state, int x, int y) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { mousePressed = 1; - if (::mouseMode == ADD_VOXELS) { + if (::mouseMode == ADD_VOXEL_MODE) { addVoxelUnderCursor(); - } else { // ::mouseMode == DELETE_VOXELS + } else { // ::mouseMode == DELETE_VOXEL_MODE deleteVoxelUnderCursor(); } } else { @@ -1920,10 +1941,10 @@ void mouseFunc(int button, int state, int x, int y) { case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN) { - if (::mouseMode == ADD_VOXELS) { + if (::mouseMode == ADD_VOXEL_MODE) { deleteVoxelUnderCursor(); - } else { // ::mouseMode == DELETE_VOXELS + } else { // ::mouseMode == DELETE_VOXEL_MODE addVoxelUnderCursor(); } } From 78b37fe920df08f14af3bbfa94785dfd771af930 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 9 May 2013 16:26:51 -0700 Subject: [PATCH 04/25] Starting on coloring support. --- interface/src/main.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 5bbee6672c..2eb761d65d 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -175,7 +175,7 @@ int mouseY = 0; int mousePressed = 0; // true if mouse has been pressed (clear when finished) // The current mode for mouse interaction -enum MouseMode { ADD_VOXEL_MODE, DELETE_VOXEL_MODE }; +enum MouseMode { ADD_VOXEL_MODE, DELETE_VOXEL_MODE, COLOR_VOXEL_MODE }; MouseMode mouseMode = ADD_VOXEL_MODE; VoxelDetail mouseVoxel; // details of the voxel under the mouse cursor @@ -1653,7 +1653,8 @@ void key(unsigned char k, int x, int y) { if (k == '%') ::sendVoxelServerAddScene(); // sends add scene command to voxel server if (k == '1') ::mouseMode = ADD_VOXEL_MODE; if (k == '2') ::mouseMode = DELETE_VOXEL_MODE; - if (k == '3') addVoxelInFrontOfAvatar(); + if (k == '3') ::mouseMode = COLOR_VOXEL_MODE; + if (k == '4') addVoxelInFrontOfAvatar(); if (k == 'n' || k == 'N') { noiseOn = !noiseOn; // Toggle noise @@ -1796,7 +1797,12 @@ void idle(void) { ::mouseVoxel.y += offset.y * ::mouseVoxel.s; ::mouseVoxel.z += offset.z * ::mouseVoxel.s; - } else { + } else if (::mouseMode == COLOR_VOXEL_MODE) { + ::mouseVoxel.red = 0; + ::mouseVoxel.green = 255; + ::mouseVoxel.blue = 0; + + } else { // ::mouseMode == DELETE_VOXEL_MODE // red indicates deletion ::mouseVoxel.red = 255; ::mouseVoxel.green = ::mouseVoxel.blue = 0; @@ -1928,9 +1934,9 @@ void mouseFunc(int button, int state, int x, int y) { case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { mousePressed = 1; - if (::mouseMode == ADD_VOXEL_MODE) { + if (::mouseMode == ADD_VOXEL_MODE || ::mouseMode == COLOR_VOXEL_MODE) { addVoxelUnderCursor(); - + } else { // ::mouseMode == DELETE_VOXEL_MODE deleteVoxelUnderCursor(); } @@ -1941,12 +1947,7 @@ void mouseFunc(int button, int state, int x, int y) { case GLUT_RIGHT_BUTTON: if (state == GLUT_DOWN) { - if (::mouseMode == ADD_VOXEL_MODE) { - deleteVoxelUnderCursor(); - - } else { // ::mouseMode == DELETE_VOXEL_MODE - addVoxelUnderCursor(); - } + deleteVoxelUnderCursor(); } break; } From 9dc09de75eb99107ad84b3ea549c2fa35ee5e128 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 10 May 2013 09:32:56 -0700 Subject: [PATCH 05/25] make VoxelSystem::deleteVoxelAt() work properly --- interface/src/VoxelSystem.cpp | 27 +++++++++++++++++++++++---- libraries/voxels/src/VoxelNode.cpp | 1 + libraries/voxels/src/VoxelNode.h | 7 +++++++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index b5dab29029..592a70ca26 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -232,7 +232,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { bool inChildBoundary = (distanceToNode <= childBoundary); shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary); } - node->setShouldRender(shouldRender); + node->setShouldRender(shouldRender && !node->deleteMe()); // let children figure out their renderness for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { if (node->getChildAtIndex(i)) { @@ -244,6 +244,15 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { } else { voxelsUpdated += updateNodeInArraysAsPartialVBO(node); } + + // If the node has been asked to be deleted, but we've gotten to here, after updateNodeInArraysXXX() + // then it means our VBOs are "clean" and our vertices have been removed or not added. So we can now + // safely remove the node from the tree and actually delete it. + // otherwise honor our calculated shouldRender + if (node->deleteMe()) { + _tree->deleteVoxelCodeFromTree(node->getOctalCode()); + } + node->clearDirtyBit(); // always clear the dirty bit, even if it doesn't need to be rendered return voxelsUpdated; } @@ -901,9 +910,19 @@ void VoxelSystem::collectStatsForTreesAndVBOs() { void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) { - //printLog("VoxelSystem::deleteVoxelAt(%f,%f,%f,%f)\n",x,y,z,s); - _tree->deleteVoxelAt(x, y, z, s); - setupNewVoxelsForDrawing(); + printLog("VoxelSystem::deleteVoxelAt(%f,%f,%f,%f)\n",x,y,z,s); + + VoxelNode* node = _tree->getVoxelAt(x, y, z, s); + if (node) { + // tell the node we want it deleted + node->pleaseDeleteMe(); + + // tree is now dirty + _tree->setDirtyBit(); + + // redraw! + setupNewVoxelsForDrawing(); // do we even need to do this? Or will the next network receive kick in? + } }; VoxelNode* VoxelSystem::getVoxelAt(float x, float y, float z, float s) const { diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index 5af7f09ea2..5070a6442d 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -44,6 +44,7 @@ void VoxelNode::init(unsigned char * octalCode) { _glBufferIndex = GLBUFFER_INDEX_UNKNOWN; _isDirty = true; _shouldRender = false; + _deleteMe = false; calculateAABox(); } diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index 51af8f6379..4ac083bd0f 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -27,6 +27,7 @@ private: glBufferIndex _glBufferIndex; bool _isDirty; bool _shouldRender; + bool _deleteMe; AABox _box; unsigned char* _octalCode; VoxelNode* _children[8]; @@ -66,9 +67,15 @@ public: glBufferIndex getBufferIndex() const { return _glBufferIndex; }; bool isKnownBufferIndex() const { return (_glBufferIndex != GLBUFFER_INDEX_UNKNOWN); }; void setBufferIndex(glBufferIndex index) { _glBufferIndex = index; }; + + // Used by VoxelSystem for rendering in/out of view and LOD void setShouldRender(bool shouldRender); bool getShouldRender() const { return _shouldRender; } + // Used by VoxelSystem to mark a node as to be deleted on next render pass + void pleaseDeleteMe() { _deleteMe = true; }; + bool deleteMe() const { return _deleteMe; } + #ifndef NO_FALSE_COLOR // !NO_FALSE_COLOR means, does have false color void setFalseColor(colorPart red, colorPart green, colorPart blue); void setFalseColored(bool isFalseColored); From f6fcdd78b21e3ee29eae11a6c2f4a0c3145dc70f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 10 May 2013 09:53:53 -0700 Subject: [PATCH 06/25] Adding/removing voxels at different sizes. --- interface/src/main.cpp | 21 ++++++++++++++++++++- libraries/voxels/src/VoxelTree.cpp | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 2eb761d65d..57a4b457fb 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -178,6 +178,7 @@ int mousePressed = 0; // true if mouse has been pressed (clear when finished) enum MouseMode { ADD_VOXEL_MODE, DELETE_VOXEL_MODE, COLOR_VOXEL_MODE }; MouseMode mouseMode = ADD_VOXEL_MODE; VoxelDetail mouseVoxel; // details of the voxel under the mouse cursor +float mouseVoxelScale = 1.0f / 1024.0f; // the scale for adding/removing voxels Menu menu; // main menu int menuOn = 1; // Whether to show onscreen menu @@ -1510,7 +1511,7 @@ void addVoxelInFrontOfAvatar() { VoxelDetail detail; glm::vec3 position = (myAvatar.getPosition() + myAvatar.getCameraDirection()) * (1.0f / TREE_SCALE); - detail.s = 1.0f / 1024; + detail.s = ::mouseVoxelScale; detail.x = detail.s * floor(position.x / detail.s); detail.y = detail.s * floor(position.y / detail.s); @@ -1655,6 +1656,8 @@ void key(unsigned char k, int x, int y) { if (k == '2') ::mouseMode = DELETE_VOXEL_MODE; if (k == '3') ::mouseMode = COLOR_VOXEL_MODE; if (k == '4') addVoxelInFrontOfAvatar(); + if (k == '5') ::mouseVoxelScale /= 2; + if (k == '6') ::mouseVoxelScale *= 2; if (k == 'n' || k == 'N') { noiseOn = !noiseOn; // Toggle noise @@ -1790,6 +1793,22 @@ void idle(void) { BoxFace face; ::mouseVoxel.s = 0.0f; if (voxels.findRayIntersection(origin, direction, ::mouseVoxel, distance, face)) { + // find the nearest voxel with the desired scale + if (::mouseVoxelScale > ::mouseVoxel.s) { + ::mouseVoxel.x = ::mouseVoxelScale * floorf(::mouseVoxel.x / ::mouseVoxelScale); + ::mouseVoxel.y = ::mouseVoxelScale * floorf(::mouseVoxel.y / ::mouseVoxelScale); + ::mouseVoxel.z = ::mouseVoxelScale * floorf(::mouseVoxel.z / ::mouseVoxelScale); + ::mouseVoxel.s = ::mouseVoxelScale; + + } else if (::mouseVoxelScale < ::mouseVoxel.s) { + glm::vec3 pt = (origin + direction * distance) / (float)TREE_SCALE - + getFaceVector(face) * (::mouseVoxelScale * 0.5f); + ::mouseVoxel.x = ::mouseVoxelScale * floorf(pt.x / ::mouseVoxelScale); + ::mouseVoxel.y = ::mouseVoxelScale * floorf(pt.y / ::mouseVoxelScale); + ::mouseVoxel.z = ::mouseVoxelScale * floorf(pt.z / ::mouseVoxelScale); + ::mouseVoxel.s = ::mouseVoxelScale; + } + if (::mouseMode == ADD_VOXEL_MODE) { // use the face to determine the side on which to create a neighbor glm::vec3 offset = getFaceVector(face); diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index bb55f01bc2..14cc92881e 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -620,7 +620,8 @@ bool findRayOperation(VoxelNode* node, void* extraData) { if (!node->isLeaf()) { return true; // recurse on children } - if (!args->found || distance < args->distance) { + distance *= TREE_SCALE; + if (node->getShouldRender() && (!args->found || distance < args->distance)) { args->node = node; args->distance = distance; args->face = face; From 3af8a1b8f443555093697562f4b1043bf95dba94 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 10 May 2013 10:03:28 -0700 Subject: [PATCH 07/25] code review fixes --- interface/src/VoxelSystem.cpp | 6 +++--- libraries/voxels/src/VoxelNode.cpp | 2 +- libraries/voxels/src/VoxelNode.h | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index 592a70ca26..e473961c8e 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -232,7 +232,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { bool inChildBoundary = (distanceToNode <= childBoundary); shouldRender = (node->isLeaf() && inChildBoundary) || (inBoundary && !inChildBoundary); } - node->setShouldRender(shouldRender && !node->deleteMe()); + node->setShouldRender(shouldRender && !node->isStagedForDeletion()); // let children figure out their renderness for (int i = 0; i < NUMBER_OF_CHILDREN; i++) { if (node->getChildAtIndex(i)) { @@ -249,7 +249,7 @@ int VoxelSystem::newTreeToArrays(VoxelNode* node) { // then it means our VBOs are "clean" and our vertices have been removed or not added. So we can now // safely remove the node from the tree and actually delete it. // otherwise honor our calculated shouldRender - if (node->deleteMe()) { + if (node->isStagedForDeletion()) { _tree->deleteVoxelCodeFromTree(node->getOctalCode()); } @@ -915,7 +915,7 @@ void VoxelSystem::deleteVoxelAt(float x, float y, float z, float s) { VoxelNode* node = _tree->getVoxelAt(x, y, z, s); if (node) { // tell the node we want it deleted - node->pleaseDeleteMe(); + node->stageForDeletion(); // tree is now dirty _tree->setDirtyBit(); diff --git a/libraries/voxels/src/VoxelNode.cpp b/libraries/voxels/src/VoxelNode.cpp index 5070a6442d..19e6a12aa5 100644 --- a/libraries/voxels/src/VoxelNode.cpp +++ b/libraries/voxels/src/VoxelNode.cpp @@ -44,7 +44,7 @@ void VoxelNode::init(unsigned char * octalCode) { _glBufferIndex = GLBUFFER_INDEX_UNKNOWN; _isDirty = true; _shouldRender = false; - _deleteMe = false; + _isStagedForDeletion = false; calculateAABox(); } diff --git a/libraries/voxels/src/VoxelNode.h b/libraries/voxels/src/VoxelNode.h index 4ac083bd0f..c07cb528e6 100644 --- a/libraries/voxels/src/VoxelNode.h +++ b/libraries/voxels/src/VoxelNode.h @@ -27,7 +27,7 @@ private: glBufferIndex _glBufferIndex; bool _isDirty; bool _shouldRender; - bool _deleteMe; + bool _isStagedForDeletion; AABox _box; unsigned char* _octalCode; VoxelNode* _children[8]; @@ -73,8 +73,8 @@ public: bool getShouldRender() const { return _shouldRender; } // Used by VoxelSystem to mark a node as to be deleted on next render pass - void pleaseDeleteMe() { _deleteMe = true; }; - bool deleteMe() const { return _deleteMe; } + void stageForDeletion() { _isStagedForDeletion = true; }; + bool isStagedForDeletion() const { return _isStagedForDeletion; } #ifndef NO_FALSE_COLOR // !NO_FALSE_COLOR means, does have false color void setFalseColor(colorPart red, colorPart green, colorPart blue); From 501aac39da2a9733579c25574744712d441528a6 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 10 May 2013 10:46:04 -0700 Subject: [PATCH 08/25] Use isColored, not getShouldRender. --- libraries/voxels/src/VoxelTree.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/voxels/src/VoxelTree.cpp b/libraries/voxels/src/VoxelTree.cpp index 14cc92881e..0120c7bfe1 100644 --- a/libraries/voxels/src/VoxelTree.cpp +++ b/libraries/voxels/src/VoxelTree.cpp @@ -621,7 +621,7 @@ bool findRayOperation(VoxelNode* node, void* extraData) { return true; // recurse on children } distance *= TREE_SCALE; - if (node->getShouldRender() && (!args->found || distance < args->distance)) { + if (node->isColored() && (!args->found || distance < args->distance)) { args->node = node; args->distance = distance; args->face = face; From f8701e6c0c2d4c9f5287f962162f342fdac7a7c8 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 10 May 2013 10:55:05 -0700 Subject: [PATCH 09/25] Re-added Head Mouse working correctly with invensense --- interface/src/SerialInterface.h | 2 +- interface/src/main.cpp | 46 ++++++++++++--------------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/interface/src/SerialInterface.h b/interface/src/SerialInterface.h index 8569129520..65a802d0c2 100644 --- a/interface/src/SerialInterface.h +++ b/interface/src/SerialInterface.h @@ -32,7 +32,7 @@ #define HEAD_YAW_RATE 0 #define HEAD_ROLL_RATE 2 -//const bool USING_INVENSENSE_MPU9150; +extern const bool USING_INVENSENSE_MPU9150; class SerialInterface { public: diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e82e3b5d7f..6c5218f722 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -382,13 +382,14 @@ void updateAvatar(float deltaTime) { float measuredYawRate = serialPort.getLastYawRate(); // Update gyro-based mouse (X,Y on screen) - const float MIN_MOUSE_RATE = 30.0; - const float MOUSE_SENSITIVITY = 0.1f; + const float MIN_MOUSE_RATE = 1.0; + const float HORIZONTAL_PIXELS_PER_DEGREE = 2880.f / 45.f; + const float VERTICAL_PIXELS_PER_DEGREE = 1800.f / 30.f; if (powf(measuredYawRate * measuredYawRate + measuredPitchRate * measuredPitchRate, 0.5) > MIN_MOUSE_RATE) { - headMouseX += measuredYawRate*MOUSE_SENSITIVITY; - headMouseY += measuredPitchRate*MOUSE_SENSITIVITY*(float)HEIGHT/(float)WIDTH; + headMouseX += measuredYawRate * HORIZONTAL_PIXELS_PER_DEGREE * deltaTime; + headMouseY -= measuredPitchRate * VERTICAL_PIXELS_PER_DEGREE * deltaTime; } headMouseX = max(headMouseX, 0); headMouseX = min(headMouseX, WIDTH); @@ -397,32 +398,17 @@ void updateAvatar(float deltaTime) { // Update head and body pitch and yaw based on measured gyro rates if (::gyroLook) { - // Yaw - const float MIN_YAW_RATE = 20.f; - const float YAW_MAGNIFY = 3.0; + // Render Yaw + float renderYawSpring = fabs(headMouseX - WIDTH / 2.f) / (WIDTH / 2.f); + const float RENDER_YAW_MULTIPLY = 4.f; + myAvatar.setRenderYaw((1.f - renderYawSpring * deltaTime) * myAvatar.getRenderYaw() + + renderYawSpring * deltaTime * -myAvatar.getHeadYaw() * RENDER_YAW_MULTIPLY); + // Render Pitch + float renderPitchSpring = fabs(headMouseY - HEIGHT / 2.f) / (HEIGHT / 2.f); + const float RENDER_PITCH_MULTIPLY = 4.f; + myAvatar.setRenderPitch((1.f - renderPitchSpring * deltaTime) * myAvatar.getRenderPitch() + + renderPitchSpring * deltaTime * -myAvatar.getHeadPitch() * RENDER_PITCH_MULTIPLY); - if (fabs(measuredYawRate) > MIN_YAW_RATE) { - float addToBodyYaw = (measuredYawRate > 0.f) - ? measuredYawRate - MIN_YAW_RATE : measuredYawRate + MIN_YAW_RATE; - - // If we are rotating the body (render angle), move the head reverse amount to compensate - myAvatar.addBodyYaw(-addToBodyYaw * YAW_MAGNIFY * deltaTime); - myAvatar.addHeadYaw(addToBodyYaw * YAW_MAGNIFY * deltaTime); - } - // Pitch - const float MIN_PITCH_RATE = 20.f; - const float PITCH_MAGNIFY = 2.0; - - if (fabs(measuredPitchRate) > MIN_PITCH_RATE) { - float addToBodyPitch = (measuredPitchRate > 0.f) - ? measuredPitchRate - MIN_PITCH_RATE : measuredPitchRate + MIN_PITCH_RATE; - - myAvatar.setRenderPitch(myAvatar.getRenderPitch() + addToBodyPitch * PITCH_MAGNIFY * deltaTime); - - } - // Always decay the render pitch, assuming that we are never going to want to permanently look up or down - const float RENDER_PITCH_DECAY = 1.0; - myAvatar.setRenderPitch(myAvatar.getRenderPitch() * (1.f - RENDER_PITCH_DECAY * deltaTime)); } // Get audio loudness data from audio input device @@ -925,7 +911,7 @@ void displayOverlay() { //noiseTest(WIDTH, HEIGHT); - if (displayHeadMouse && !::lookingInMirror && renderStatsOn) { + if (displayHeadMouse && !::lookingInMirror && USING_INVENSENSE_MPU9150) { // Display small target box at center or head mouse target that can also be used to measure LOD glColor3f(1.0, 1.0, 1.0); glDisable(GL_LINE_SMOOTH); From 40e7603e498c40403983e05361bd868a7dea4207 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 10 May 2013 11:27:07 -0700 Subject: [PATCH 10/25] removed print statements --- interface/src/Avatar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index fd1a775d27..962bc9040c 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -1262,7 +1262,7 @@ void Avatar::initializeSkeleton() { _joint[ AVATAR_JOINT_LEFT_HEEL ].radius + _joint[ AVATAR_JOINT_LEFT_HEEL ].length + _joint[ AVATAR_JOINT_LEFT_KNEE ].length; - printf("_pelvisStandingHeight = %f\n", _pelvisStandingHeight); + //printf("_pelvisStandingHeight = %f\n", _pelvisStandingHeight); _height = ( @@ -1277,7 +1277,7 @@ void Avatar::initializeSkeleton() { _joint[ AVATAR_JOINT_HEAD_BASE ].length + _joint[ AVATAR_JOINT_HEAD_BASE ].radius ); - printf("_height = %f\n", _height); + //printf("_height = %f\n", _height); // generate joint positions by updating the skeleton updateSkeleton(); From e84d2696f942852e954265aab99d5481cf2c5b9b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 10 May 2013 12:04:52 -0700 Subject: [PATCH 11/25] fixed menu behavior --- interface/src/main.cpp | 33 +++++++++++++++++++++++++++++---- interface/src/ui/Menu.h | 1 + 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 00e7899112..6ef1ee337e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1899,12 +1899,37 @@ glm::vec3 getGravity(glm::vec3 pos) { } } - +bool menuDisplayed = false; void mouseFunc(int button, int state, int x, int y) { - //catch mouse actions on the menu - bool menuClickedOrUnclicked = menu.mouseClick(x, y); + bool menuFound = menu.mouseClick(x, y); - if (!menuClickedOrUnclicked) { + // If we didn't previously have the menu displayed, and we did just click on the menu, then + // go into menuDisplayed mode.... + if (!::menuDisplayed && menuFound) { + ::menuDisplayed = true; + } + + // If the menu was displayed, and we're not over a menu, then leave menu mode + if (::menuDisplayed && !menuFound) { + ::menuDisplayed = false; + menu.hidePopupMenu(); + //menu.render(WIDTH,HEIGHT); // will hide the menu + } + + // In menu displayed mode use old logic + if (::menuDisplayed) { + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { + if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { + mouseX = x; + mouseY = y; + mousePressed = 1; + } else if (state == GLUT_UP) { + mouseX = x; + mouseY = y; + mousePressed = 0; + } + } + } else { if (button == GLUT_LEFT_BUTTON) { mouseX = x; mouseY = y; diff --git a/interface/src/ui/Menu.h b/interface/src/ui/Menu.h index 7ffe93bb28..5ef2a6f11b 100644 --- a/interface/src/ui/Menu.h +++ b/interface/src/ui/Menu.h @@ -24,6 +24,7 @@ public: void render(int screenwidth, int screenheight); void renderColumn(int i); MenuColumn* addColumn(const char *columnName); + void hidePopupMenu() { currentColumn = -1; }; private: std::vector columns; int currentColumn; From 5a113fd5468b37db652ebfcf83d0a20043f4ea21 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 10 May 2013 12:07:47 -0700 Subject: [PATCH 12/25] Added a stub for a Qt application class that creates a menu (which, since it's unparented, will only appear on OS X) with a test item connected to a slot. --- interface/CMakeLists.txt | 8 ++++++-- interface/src/Application.cpp | 22 ++++++++++++++++++++++ interface/src/Application.h | 26 ++++++++++++++++++++++++++ interface/src/main.cpp | 9 +++------ 4 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 interface/src/Application.cpp create mode 100644 interface/src/Application.h diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index dcef05bdf6..71f459439b 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -54,6 +54,12 @@ if (APPLE) SET(INTERFACE_SRCS ${INTERFACE_SRCS} ${INTERFACE_RSRCS}) endif (APPLE) +find_package(Qt4 REQUIRED QtCore QtGui) +include(${QT_USE_FILE}) + +# run qt moc on qt-enabled headers +qt4_wrap_cpp(INTERFACE_SRCS src/Application.h) + # create the executable, make it a bundle on OS X add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS}) @@ -77,8 +83,6 @@ include_directories( ${LODEPNG_INCLUDE_DIRS} ) -find_package(Qt4 REQUIRED QtCore QtGui) -include(${QT_USE_FILE}) target_link_libraries(${TARGET_NAME} ${QT_LIBRARIES}) if (NOT APPLE) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp new file mode 100644 index 0000000000..3080f3f3ed --- /dev/null +++ b/interface/src/Application.cpp @@ -0,0 +1,22 @@ +// +// Application.cpp +// interface +// +// Created by Andrzej Kapolka on 5/10/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. + +#include +#include + +#include "Application.h" + +Application::Application(int& argc, char** argv) : QApplication(argc, argv) { + // simple menu bar (will only appear on OS X, for now) + QMenuBar* menuBar = new QMenuBar(); + QMenu* fileMenu = menuBar->addMenu("File"); + fileMenu->addAction("Quit", this, SLOT(testSlot())); +} + +void Application::testSlot() { + qDebug() << "Hello world."; +} diff --git a/interface/src/Application.h b/interface/src/Application.h new file mode 100644 index 0000000000..c47dc3e33a --- /dev/null +++ b/interface/src/Application.h @@ -0,0 +1,26 @@ +// +// Application.h +// interface +// +// Created by Andrzej Kapolka on 5/10/13. +// Copyright (c) 2013 High Fidelity, Inc. All rights reserved. +// + +#ifndef __interface__Application__ +#define __interface__Application__ + +#include + +class Application : public QApplication { + Q_OBJECT + +public: + + Application(int& argc, char** argv); + +public slots: + + void testSlot(); +}; + +#endif /* defined(__interface__Application__) */ diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 5ff83bead9..2a2b7445e1 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -31,8 +31,6 @@ #include #endif -#include - #include #include @@ -61,6 +59,7 @@ #include "renderer/ProgramObject.h" #include "renderer/ShaderObject.h" +#include "Application.h" #include "Camera.h" #include "Avatar.h" #include @@ -86,8 +85,6 @@ void loadViewFrustum(ViewFrustum& viewFrustum); // will be defined below glm::vec3 getGravity(glm::vec3 pos); //get the local gravity vector at this location in the universe -QApplication* app; - bool enableNetworkThread = true; pthread_t networkReceiveThread; bool stopNetworkReceiveThread = false; @@ -2032,9 +2029,9 @@ int main(int argc, const char * argv[]) { #endif // we need to create a QApplication instance in order to use Qt's font rendering - app = new QApplication(argc, const_cast(argv)); + Application app(argc, const_cast(argv)); printLog( "Created QT Application.\n" ); - + // Before we render anything, let's set up our viewFrustumOffsetCamera with a sufficiently large // field of view and near and far clip to make it interesting. //viewFrustumOffsetCamera.setFieldOfView(90.0); From bfa7c91a7a3dce6e1815ffc9a5417d15665a1512 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 10 May 2013 12:08:03 -0700 Subject: [PATCH 13/25] fixed menu behavior --- interface/src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 6ef1ee337e..7a89565406 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1913,7 +1913,6 @@ void mouseFunc(int button, int state, int x, int y) { if (::menuDisplayed && !menuFound) { ::menuDisplayed = false; menu.hidePopupMenu(); - //menu.render(WIDTH,HEIGHT); // will hide the menu } // In menu displayed mode use old logic From 0888a6605f51156f78f00cccf898f62110f293f9 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 10 May 2013 12:08:43 -0700 Subject: [PATCH 14/25] CR fixes --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 7a89565406..9d5088a851 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1917,7 +1917,7 @@ void mouseFunc(int button, int state, int x, int y) { // In menu displayed mode use old logic if (::menuDisplayed) { - if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { + if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { if (state == GLUT_DOWN && !menu.mouseClick(x, y)) { mouseX = x; mouseY = y; From 012c2c9c9fc2e2109c6b012b15feed9d36719d50 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Fri, 10 May 2013 12:11:32 -0700 Subject: [PATCH 15/25] Changed "Quit" menu item to "Test" (Quit should apparently be added automatically). --- interface/src/Application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3080f3f3ed..ff6c80d456 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -14,7 +14,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) { // simple menu bar (will only appear on OS X, for now) QMenuBar* menuBar = new QMenuBar(); QMenu* fileMenu = menuBar->addMenu("File"); - fileMenu->addAction("Quit", this, SLOT(testSlot())); + fileMenu->addAction("Test", this, SLOT(testSlot())); } void Application::testSlot() { From 619c1a843fbd047ca28a962b6447c5a4120b7061 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 10 May 2013 12:18:49 -0700 Subject: [PATCH 16/25] working on hand holding algo --- interface/src/Avatar.cpp | 24 ++++++++++++++---------- interface/src/AvatarTouch.cpp | 26 +++++++++++--------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 962bc9040c..f4bbcf85c0 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -529,21 +529,25 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { //if holding hands, apply the appropriate forces if (_avatarTouch.getHoldingHands()) { + /* glm::vec3 vectorToOtherHand = _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition - _handHoldingPosition; - glm::vec3 vectorToMyHand = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _handHoldingPosition; + glm::vec3 vectorToMyHand = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition - _handHoldingPosition; - float myInfluence = 30.0f; - float yourInfluence = 30.0f; + float force = 200.0 * deltaTime; - glm::vec3 myForce = vectorToMyHand * myInfluence * deltaTime; - glm::vec3 yourForce = vectorToOtherHand * yourInfluence * deltaTime; - - if (_handState == HAND_STATE_GRASPING) {myForce *= 2.0f; } - if (_interactingOther->_handState == HAND_STATE_GRASPING) {yourForce *= 2.0f; } + force = 1.0f; + + if (force > 0.9f) { force = 0.9f; } - _handHoldingPosition += myForce + yourForce; + _handHoldingPosition += vectorToMyHand * force + vectorToOtherHand * force; - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handHoldingPosition; + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handHoldingPosition; + */ + + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + + ( _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position) * 0.5f; + } else { _handHoldingPosition = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; } diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 3c08a5f3cb..fabd30db7e 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -13,20 +13,19 @@ #include "Util.h" const float THREAD_RADIUS = 0.012; -const float HANDS_CLOSE_ENOUGH_TO_GRASP = 0.1; +const float HANDS_CLOSE_ENOUGH_TO_GRASP = 0.2; AvatarTouch::AvatarTouch() { - _myHandPosition = glm::vec3(0.0f, 0.0f, 0.0f); - _yourHandPosition = glm::vec3(0.0f, 0.0f, 0.0f); - _myBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f); - _yourBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f); - _vectorBetweenHands = glm::vec3(0.0f, 0.0f, 0.0f); - _myHandState = HAND_STATE_NULL; - _yourHandState = HAND_STATE_NULL; - _reachableRadius = 0.0f; - _weAreHoldingHands = false; - + _myHandPosition = glm::vec3(0.0f, 0.0f, 0.0f); + _yourHandPosition = glm::vec3(0.0f, 0.0f, 0.0f); + _myBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f); + _yourBodyPosition = glm::vec3(0.0f, 0.0f, 0.0f); + _vectorBetweenHands = glm::vec3(0.0f, 0.0f, 0.0f); + _myHandState = HAND_STATE_NULL; + _yourHandState = HAND_STATE_NULL; + _reachableRadius = 0.0f; + _weAreHoldingHands = false; _canReachToOtherAvatar = false; _handsCloseEnoughToGrasp = false; @@ -63,7 +62,6 @@ void AvatarTouch::setReachableRadius(float r) { _reachableRadius = r; } - void AvatarTouch::simulate (float deltaTime) { glm::vec3 vectorBetweenBodies = _yourBodyPosition - _myBodyPosition; @@ -83,9 +81,7 @@ void AvatarTouch::simulate (float deltaTime) { } else { _canReachToOtherAvatar = false; } - } - - +} void AvatarTouch::render(glm::vec3 cameraPosition) { From 685df2c65c4a467fa81d2d90fa49185e8a4ea700 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 10 May 2013 12:23:58 -0700 Subject: [PATCH 17/25] thingy --- interface/src/Avatar.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index f4bbcf85c0..df747e7480 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -544,9 +544,8 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handHoldingPosition; */ - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + - ( _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position) * 0.5f; +_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += +( _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position) * 0.9f; } else { _handHoldingPosition = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; From 87f8df7e7b6774527e1f12434e393e7f428bc6b5 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 10 May 2013 12:28:46 -0700 Subject: [PATCH 18/25] ... --- interface/src/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index df747e7480..f2ac12082d 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -545,7 +545,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { */ _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += -( _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position) * 0.9f; +( _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position) * 0.5f; } else { _handHoldingPosition = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; From 5a1d0606ce62d68e0f093073c1dbd1b508a3d0d5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 10 May 2013 12:34:31 -0700 Subject: [PATCH 19/25] add some debugging to the mixer to track down bearing issue --- audio-mixer/src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/audio-mixer/src/main.cpp b/audio-mixer/src/main.cpp index 52889cee8e..6b63075da5 100644 --- a/audio-mixer/src/main.cpp +++ b/audio-mixer/src/main.cpp @@ -144,6 +144,8 @@ int main(int argc, const char* argv[]) { float weakChannelAmplitudeRatio = 1.f; if (otherAgent != agent) { + printf("DEBUG: The bearing for this agent is %f\n", agentRingBuffer->getBearing()); + Position agentPosition = agentRingBuffer->getPosition(); Position otherAgentPosition = otherAgentBuffer->getPosition(); From 9db5d7e202e2e66be2aeb0b49f4fd814f69d1dda Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 10 May 2013 12:45:37 -0700 Subject: [PATCH 20/25] hand holding --- interface/src/Avatar.cpp | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index f2ac12082d..5e1ec951ad 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -517,39 +517,33 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } } + // if I can no longer reach the otherhand, turn off hand-holding if (!_avatarTouch.getAbleToReachOtherAvatar()) { _avatarTouch.setHoldingHands(false); } + // if neither of us are grasping, turn off hand-holding if ((_handState != HAND_STATE_GRASPING ) && (_interactingOther->_handState != HAND_STATE_GRASPING)) { _avatarTouch.setHoldingHands(false); } + + glm::vec3 v(_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); + float distance = glm::length(v); + + if (distance > _maxArmLength) { + _avatarTouch.setHoldingHands(false); + } } //if holding hands, apply the appropriate forces if (_avatarTouch.getHoldingHands()) { - - /* - glm::vec3 vectorToOtherHand = _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition - _handHoldingPosition; - glm::vec3 vectorToMyHand = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition - _handHoldingPosition; - - float force = 200.0 * deltaTime; - - force = 1.0f; - - if (force > 0.9f) { force = 0.9f; } - - _handHoldingPosition += vectorToMyHand * force + vectorToOtherHand * force; - - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position = _handHoldingPosition; - */ - -_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += -( _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position) * 0.5f; - - } else { - _handHoldingPosition = _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position; - } + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += + ( + _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + ) * 0.5f; + } + }//if (_isMine) //constrain right arm length and re-adjust elbow position as it bends From eb49a9e4f2c595a10ec5290826a240011e902474 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 10 May 2013 12:52:39 -0700 Subject: [PATCH 21/25] hand holding --- interface/src/AvatarTouch.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index fabd30db7e..5394002cc6 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -95,6 +95,18 @@ void AvatarTouch::render(glm::vec3 cameraPosition) { // show is we are golding hands... if (_weAreHoldingHands) { + renderBeamBetweenHands(); + + /* + glPushMatrix(); + glTranslatef(_yourHandPosition.x, _yourHandPosition.y, _yourHandPosition.z); + glColor4f(1.0, 0.0, 0.0, 0.7); glutSolidSphere(0.020f, 10.0f, 10.0f); + glColor4f(1.0, 0.0, 0.0, 0.7); glutSolidSphere(0.025f, 10.0f, 10.0f); + glColor4f(1.0, 0.0, 0.0, 0.7); glutSolidSphere(0.030f, 10.0f, 10.0f); + glPopMatrix(); + */ + + /* glColor4f(0.9, 0.3, 0.3, 0.5); renderSphereOutline(_myHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.3f, 20, cameraPosition); renderSphereOutline(_myHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.2f, 20, cameraPosition); @@ -103,15 +115,16 @@ void AvatarTouch::render(glm::vec3 cameraPosition) { renderSphereOutline(_yourHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.3f, 20, cameraPosition); renderSphereOutline(_yourHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.2f, 20, cameraPosition); renderSphereOutline(_yourHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP * 0.1f, 20, cameraPosition); + */ } //render the beam between our hands indicting that we can reach out and grasp hands... - renderBeamBetweenHands(); + //renderBeamBetweenHands(); //show that our hands are close enough to grasp.. if (_handsCloseEnoughToGrasp) { glColor4f(0.9, 0.3, 0.3, 0.5); - renderSphereOutline(_myHandPosition, HANDS_CLOSE_ENOUGH_TO_GRASP / 3.0f, 20, cameraPosition); + renderSphereOutline(_myHandPosition, 0.030f, 20, cameraPosition); } // if your hand is grasping, show it... @@ -143,14 +156,16 @@ void AvatarTouch::renderBeamBetweenHands() { glm::vec3 v1(_myHandPosition); glm::vec3 v2(_yourHandPosition); + /* glLineWidth(2.0); glColor4f(0.9f, 0.9f, 0.1f, 0.7); glBegin(GL_LINE_STRIP); glVertex3f(v1.x, v1.y, v1.z); glVertex3f(v2.x, v2.y, v2.z); glEnd(); + */ - glColor3f(1.0f, 1.0f, 1.0f); + glColor3f(0.0f, 0.0f, 0.0f); for (int p=0; p Date: Fri, 10 May 2013 13:04:41 -0700 Subject: [PATCH 22/25] made some improvements to handshake --- interface/src/AvatarTouch.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 5394002cc6..170693b8f9 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -12,7 +12,7 @@ #include "InterfaceConfig.h" #include "Util.h" -const float THREAD_RADIUS = 0.012; +const float THREAD_RADIUS = 0.007; const float HANDS_CLOSE_ENOUGH_TO_GRASP = 0.2; AvatarTouch::AvatarTouch() { @@ -118,22 +118,20 @@ void AvatarTouch::render(glm::vec3 cameraPosition) { */ } - //render the beam between our hands indicting that we can reach out and grasp hands... - //renderBeamBetweenHands(); - //show that our hands are close enough to grasp.. if (_handsCloseEnoughToGrasp) { glColor4f(0.9, 0.3, 0.3, 0.5); - renderSphereOutline(_myHandPosition, 0.030f, 20, cameraPosition); + renderSphereOutline(_myHandPosition, 0.03f, 20, cameraPosition); + renderSphereOutline(_yourHandPosition, 0.03f, 20, cameraPosition); } // if your hand is grasping, show it... if (_yourHandState == HAND_STATE_GRASPING) { glPushMatrix(); glTranslatef(_yourHandPosition.x, _yourHandPosition.y, _yourHandPosition.z); - glColor4f(1.0, 1.0, 0.8, 0.3); glutSolidSphere(0.020f, 10.0f, 10.0f); - glColor4f(1.0, 1.0, 0.4, 0.2); glutSolidSphere(0.025f, 10.0f, 10.0f); - glColor4f(1.0, 1.0, 0.2, 0.1); glutSolidSphere(0.030f, 10.0f, 10.0f); + glColor4f(1.0, 0.7, 0.8, 0.4); glutSolidSphere(0.020f, 10.0f, 10.0f); + glColor4f(1.0, 0.7, 0.4, 0.3); glutSolidSphere(0.025f, 10.0f, 10.0f); + glColor4f(1.0, 0.7, 0.2, 0.2); glutSolidSphere(0.030f, 10.0f, 10.0f); glPopMatrix(); } } @@ -142,9 +140,9 @@ void AvatarTouch::render(glm::vec3 cameraPosition) { if (_myHandState == HAND_STATE_GRASPING) { glPushMatrix(); glTranslatef(_myHandPosition.x, _myHandPosition.y, _myHandPosition.z); - glColor4f(1.0, 1.0, 0.8, 0.3); glutSolidSphere(0.020f, 10.0f, 10.0f); - glColor4f(1.0, 1.0, 0.4, 0.2); glutSolidSphere(0.025f, 10.0f, 10.0f); - glColor4f(1.0, 1.0, 0.2, 0.1); glutSolidSphere(0.030f, 10.0f, 10.0f); + glColor4f(1.0, 0.7, 0.8, 0.4); glutSolidSphere(0.020f, 10.0f, 10.0f); + glColor4f(1.0, 0.7, 0.4, 0.3); glutSolidSphere(0.025f, 10.0f, 10.0f); + glColor4f(1.0, 0.7, 0.2, 0.2); glutSolidSphere(0.030f, 10.0f, 10.0f); glPopMatrix(); } } @@ -156,16 +154,14 @@ void AvatarTouch::renderBeamBetweenHands() { glm::vec3 v1(_myHandPosition); glm::vec3 v2(_yourHandPosition); - /* - glLineWidth(2.0); - glColor4f(0.9f, 0.9f, 0.1f, 0.7); + glLineWidth(3.0); + glColor4f(0.9f, 0.9f, 0.1f, 0.6); glBegin(GL_LINE_STRIP); glVertex3f(v1.x, v1.y, v1.z); glVertex3f(v2.x, v2.y, v2.z); glEnd(); - */ - glColor3f(0.0f, 0.0f, 0.0f); + glColor3f(0.5f, 0.3f, 0.0f); for (int p=0; p Date: Fri, 10 May 2013 13:18:51 -0700 Subject: [PATCH 23/25] implemented partial VBOs support in copyWrittenDataToReadArrays() --- interface/src/VoxelSystem.cpp | 90 ++++++++++++++++++++++++++++++----- interface/src/VoxelSystem.h | 3 ++ 2 files changed, 82 insertions(+), 11 deletions(-) diff --git a/interface/src/VoxelSystem.cpp b/interface/src/VoxelSystem.cpp index e473961c8e..65f9718e80 100644 --- a/interface/src/VoxelSystem.cpp +++ b/interface/src/VoxelSystem.cpp @@ -205,17 +205,86 @@ void VoxelSystem::cleanupRemovedVoxels() { } } +void VoxelSystem::copyWrittenDataToReadArraysFullVBOs() { + // lock on the buffer write lock so we can't modify the data when the GPU is reading it + pthread_mutex_lock(&_bufferWriteLock); + int bytesOfVertices = (_voxelsInWriteArrays * VERTEX_POINTS_PER_VOXEL) * sizeof(GLfloat); + int bytesOfColors = (_voxelsInWriteArrays * VERTEX_POINTS_PER_VOXEL) * sizeof(GLubyte); + memcpy(_readVerticesArray, _writeVerticesArray, bytesOfVertices); + memcpy(_readColorsArray, _writeColorsArray, bytesOfColors ); + _voxelsInReadArrays = _voxelsInWriteArrays; + pthread_mutex_unlock(&_bufferWriteLock); +} + +void VoxelSystem::copyWrittenDataToReadArraysPartialVBOs() { + // lock on the buffer write lock so we can't modify the data when the GPU is reading it + pthread_mutex_lock(&_bufferWriteLock); + + glBufferIndex segmentStart = 0; + glBufferIndex segmentEnd = 0; + bool inSegment = false; + for (glBufferIndex i = 0; i < _voxelsInWriteArrays; i++) { + bool thisVoxelDirty = _voxelDirtyArray[i]; + if (!inSegment) { + if (thisVoxelDirty) { + segmentStart = i; + inSegment = true; + } + } else { + if (!thisVoxelDirty) { + // If we got here because because this voxel is NOT dirty, so the last dirty voxel was the one before + // this one and so that's where the "segment" ends + segmentEnd = i - 1; + inSegment = false; + int segmentLength = (segmentEnd - segmentStart) + 1; + + GLintptr segmentStartAt = segmentStart * VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat); + GLsizeiptr segmentSizeBytes = segmentLength * VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat); + GLfloat* readVerticesAt = _readVerticesArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); + GLfloat* writeVerticesAt = _writeVerticesArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); + memcpy(readVerticesAt, writeVerticesAt, segmentSizeBytes); + + segmentStartAt = segmentStart * VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte); + segmentSizeBytes = segmentLength * VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte); + GLubyte* readColorsAt = _readColorsArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); + GLubyte* writeColorsAt = _writeColorsArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); + memcpy(readColorsAt, writeColorsAt, segmentSizeBytes); + } + } + } + + // if we got to the end of the array, and we're in an active dirty segment... + if (inSegment) { + segmentEnd = _voxelsInWriteArrays - 1; + int segmentLength = (segmentEnd - segmentStart) + 1; + + GLintptr segmentStartAt = segmentStart * VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat); + GLsizeiptr segmentSizeBytes = segmentLength * VERTEX_POINTS_PER_VOXEL * sizeof(GLfloat); + GLfloat* readVerticesAt = _readVerticesArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); + GLfloat* writeVerticesAt = _writeVerticesArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); + memcpy(readVerticesAt, writeVerticesAt, segmentSizeBytes); + + segmentStartAt = segmentStart * VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte); + segmentSizeBytes = segmentLength * VERTEX_POINTS_PER_VOXEL * sizeof(GLubyte); + GLubyte* readColorsAt = _readColorsArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); + GLubyte* writeColorsAt = _writeColorsArray + (segmentStart * VERTEX_POINTS_PER_VOXEL); + memcpy(readColorsAt, writeColorsAt, segmentSizeBytes); + } + + // update our length + _voxelsInReadArrays = _voxelsInWriteArrays; + + pthread_mutex_unlock(&_bufferWriteLock); +} + void VoxelSystem::copyWrittenDataToReadArrays() { - PerformanceWarning warn(_renderWarningsOn, "copyWrittenDataToReadArrays()"); // would like to include _voxelsInArrays, _voxelsUpdated + PerformanceWarning warn(_renderWarningsOn, "copyWrittenDataToReadArrays()"); if (_voxelsDirty && _voxelsUpdated) { - // lock on the buffer write lock so we can't modify the data when the GPU is reading it - pthread_mutex_lock(&_bufferWriteLock); - int bytesOfVertices = (_voxelsInWriteArrays * VERTEX_POINTS_PER_VOXEL) * sizeof(GLfloat); - int bytesOfColors = (_voxelsInWriteArrays * VERTEX_POINTS_PER_VOXEL) * sizeof(GLubyte); - memcpy(_readVerticesArray, _writeVerticesArray, bytesOfVertices); - memcpy(_readColorsArray, _writeColorsArray, bytesOfColors ); - _voxelsInReadArrays = _voxelsInWriteArrays; - pthread_mutex_unlock(&_bufferWriteLock); + if (_renderFullVBO) { + copyWrittenDataToReadArraysFullVBOs(); + } else { + copyWrittenDataToReadArraysPartialVBOs(); + } } } @@ -493,11 +562,10 @@ void VoxelSystem::updateVBOs() { }; PerformanceWarning warn(_renderWarningsOn, buffer); // would like to include _callsToTreesToArrays if (_voxelsDirty) { - // updatePartialVBOs() is not yet working. For now, ALWAYS call updateFullVBOs() if (_renderFullVBO) { updateFullVBOs(); } else { - updatePartialVBOs(); // too many small segments? + updatePartialVBOs(); } _voxelsDirty = false; } diff --git a/interface/src/VoxelSystem.h b/interface/src/VoxelSystem.h index c17a9772bb..c0296376fc 100644 --- a/interface/src/VoxelSystem.h +++ b/interface/src/VoxelSystem.h @@ -97,6 +97,9 @@ private: int updateNodeInArraysAsFullVBO(VoxelNode* node); int updateNodeInArraysAsPartialVBO(VoxelNode* node); + void copyWrittenDataToReadArraysFullVBOs(); + void copyWrittenDataToReadArraysPartialVBOs(); + // these are kinda hacks, used by getDistanceFromViewRangeOperation() probably shouldn't be here static float _maxDistance; static float _minDistance; From ca5adb791c1b0f475620b3b387219f667db5d6f0 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 10 May 2013 13:25:40 -0700 Subject: [PATCH 24/25] pull avatars from handholding --- interface/src/Avatar.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 5e1ec951ad..03b868a7aa 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -527,23 +527,30 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _avatarTouch.setHoldingHands(false); } - glm::vec3 v(_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position); - float distance = glm::length(v); + glm::vec3 vectorFromMyHandToYourHand + ( + _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + ); + float distanceBetweenOurHands = glm::length(vectorFromMyHandToYourHand); - if (distance > _maxArmLength) { + if (distanceBetweenOurHands > _maxArmLength) { _avatarTouch.setHoldingHands(false); } + + //if holding hands, apply the appropriate forces + if (_avatarTouch.getHoldingHands()) { + _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += + ( + _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position + ) * 0.5f; + + if (distanceBetweenOurHands > 0.2) { + _velocity += vectorFromMyHandToYourHand * 30.0f * deltaTime; + } + } } - - //if holding hands, apply the appropriate forces - if (_avatarTouch.getHoldingHands()) { - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position += - ( - _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - ) * 0.5f; - } - }//if (_isMine) //constrain right arm length and re-adjust elbow position as it bends From 2032264e7e0040e464a50df9258f2d5f831b5718 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 10 May 2013 13:42:51 -0700 Subject: [PATCH 25/25] pull avatar from handshake --- interface/src/Avatar.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 03b868a7aa..ae99d674a5 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -516,27 +516,30 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { } } } - - // if I can no longer reach the otherhand, turn off hand-holding - if (!_avatarTouch.getAbleToReachOtherAvatar()) { - _avatarTouch.setHoldingHands(false); - } - - // if neither of us are grasping, turn off hand-holding - if ((_handState != HAND_STATE_GRASPING ) && (_interactingOther->_handState != HAND_STATE_GRASPING)) { - _avatarTouch.setHoldingHands(false); - } glm::vec3 vectorFromMyHandToYourHand ( _interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position - _joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].position ); + float distanceBetweenOurHands = glm::length(vectorFromMyHandToYourHand); + /* + // if my arm can no longer reach the other hand, turn off hand-holding + if (!_avatarTouch.getAbleToReachOtherAvatar()) { + _avatarTouch.setHoldingHands(false); + } if (distanceBetweenOurHands > _maxArmLength) { _avatarTouch.setHoldingHands(false); } + */ + + // if neither of us are grasping, turn off hand-holding + if ((_handState != HAND_STATE_GRASPING ) && (_interactingOther->_handState != HAND_STATE_GRASPING)) { + _avatarTouch.setHoldingHands(false); + } + //if holding hands, apply the appropriate forces if (_avatarTouch.getHoldingHands()) { @@ -547,7 +550,9 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { ) * 0.5f; if (distanceBetweenOurHands > 0.2) { - _velocity += vectorFromMyHandToYourHand * 30.0f * deltaTime; + float force = 700.0f * deltaTime; + if (force > 1.0f) {force = 1.0f;} + _velocity += vectorFromMyHandToYourHand * force; } } }