From ce986c367e61549c4e175b74de1807a3e56098b7 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Sun, 15 Dec 2013 19:53:24 -0800 Subject: [PATCH 1/8] palms detect collision --- interface/src/avatar/Hand.cpp | 19 ++++++++++++++++++- interface/src/avatar/Hand.h | 1 - libraries/avatars/src/HandData.cpp | 3 ++- libraries/avatars/src/HandData.h | 4 ++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index f59929b35a..164f7e9791 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -293,9 +293,22 @@ void Hand::updateCollisions() { for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { if (node->getLinkedData() && node->getType() == NODE_TYPE_AGENT) { Avatar* otherAvatar = (Avatar*)node->getLinkedData(); + // Check for palm collisions + glm::vec3 myPalmPosition = palm.getPosition(); + float palmCollisionDistance = 0.1f; + palm.setIsCollidingWithPalm(false); + for (int j = 0; j < getNumPalms(); j++) { + PalmData& otherPalm = otherAvatar->getHand().getPalms()[j]; + glm::vec3 otherPalmPosition = otherPalm.getPosition(); + if (glm::length(otherPalmPosition - myPalmPosition) < palmCollisionDistance) { + palm.setIsCollidingWithPalm(true); + + } + } glm::vec3 avatarPenetration; if (otherAvatar->findSpherePenetration(palm.getPosition(), scaledPalmRadius, avatarPenetration)) { totalPenetration = addPenetrations(totalPenetration, avatarPenetration); + // Check for collisions with the other avatar's leap palms } } } @@ -469,7 +482,11 @@ void Hand::renderLeapHands() { PalmData& palm = getPalms()[i]; if (palm.isActive()) { const float palmThickness = 0.02f; - glColor4f(handColor.r, handColor.g, handColor.b, 0.25); + if (palm.getIsCollidingWithPalm()) { + glColor4f(1, 0, 0, 0.50); + } else { + glColor4f(handColor.r, handColor.g, handColor.b, 0.25); + } glm::vec3 tip = palm.getPosition(); glm::vec3 root = palm.getPosition() + palm.getNormal() * palmThickness; Avatar::renderJointConnectingCone(root, tip, 0.05, 0.03); diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index 451da1b878..0e5355c721 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -79,7 +79,6 @@ private: std::vector _leapFingerRootBalls; glm::vec3 _lastFingerAddVoxel, _lastFingerDeleteVoxel; - bool _isCollidingWithVoxel; VoxelDetail _collidingVoxel; glm::vec3 _collisionCenter; diff --git a/libraries/avatars/src/HandData.cpp b/libraries/avatars/src/HandData.cpp index 12af614de3..6dd54bf08c 100644 --- a/libraries/avatars/src/HandData.cpp +++ b/libraries/avatars/src/HandData.cpp @@ -70,7 +70,8 @@ _leapID(LEAPID_INVALID), _sixenseID(SIXENSEID_INVALID), _numFramesWithoutData(0), _owningHandData(owningHandData), -_isCollidingWithVoxel(false) +_isCollidingWithVoxel(false), +_isCollidingWithPalm(false) { for (int i = 0; i < NUM_FINGERS_PER_HAND; ++i) { _fingers.push_back(FingerData(this, owningHandData)); diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index e299382c66..753e24d38b 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -172,6 +172,9 @@ public: bool getIsCollidingWithVoxel() { return _isCollidingWithVoxel; } void setIsCollidingWithVoxel(bool isCollidingWithVoxel) { _isCollidingWithVoxel = isCollidingWithVoxel; } + bool getIsCollidingWithPalm() { return _isCollidingWithPalm; } + void setIsCollidingWithPalm(bool isCollidingWithPalm) { _isCollidingWithPalm = isCollidingWithPalm; } + private: std::vector _fingers; glm::quat _rawRotation; @@ -195,6 +198,7 @@ private: HandData* _owningHandData; bool _isCollidingWithVoxel; /// Whether the finger of this palm is inside a leaf voxel + bool _isCollidingWithPalm; }; From 893a3900d953c736a2b6d2d0fd7fc8fe708a16ce Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Sun, 15 Dec 2013 20:55:51 -0800 Subject: [PATCH 2/8] added palm collision sounds --- interface/src/avatar/Hand.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 164f7e9791..aec55d1579 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -302,6 +302,15 @@ void Hand::updateCollisions() { glm::vec3 otherPalmPosition = otherPalm.getPosition(); if (glm::length(otherPalmPosition - myPalmPosition) < palmCollisionDistance) { palm.setIsCollidingWithPalm(true); + const float PALM_COLLIDE_VOLUME = 1.f; + const float PALM_COLLIDE_FREQUENCY = 150.f; + const float PALM_COLLIDE_DURATION_MAX = 2.f; + const float PALM_COLLIDE_DECAY_PER_SAMPLE = 0.005f; + Application::getInstance()->getAudio()->startDrumSound(PALM_COLLIDE_VOLUME, + PALM_COLLIDE_FREQUENCY, + PALM_COLLIDE_DURATION_MAX, + PALM_COLLIDE_DECAY_PER_SAMPLE); + } } From 0d76b370df7e8f9dba616f6e185645b49023869a Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 16 Dec 2013 17:01:46 -0800 Subject: [PATCH 3/8] only check palms if active --- interface/src/avatar/Hand.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index aec55d1579..bbd7527a0b 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -299,6 +299,9 @@ void Hand::updateCollisions() { palm.setIsCollidingWithPalm(false); for (int j = 0; j < getNumPalms(); j++) { PalmData& otherPalm = otherAvatar->getHand().getPalms()[j]; + if (!otherPalm.isActive()) { + continue; + } glm::vec3 otherPalmPosition = otherPalm.getPosition(); if (glm::length(otherPalmPosition - myPalmPosition) < palmCollisionDistance) { palm.setIsCollidingWithPalm(true); From 6ab4839c3b733454240033803a0afdc15d8d51c7 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 16 Dec 2013 17:14:19 -0800 Subject: [PATCH 4/8] =?UTF-8?q?it=E2=80=99s=20the=20other=20guys=20palms?= =?UTF-8?q?=20you=20want?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interface/src/avatar/Hand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index bbd7527a0b..5d4b38de63 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -297,7 +297,7 @@ void Hand::updateCollisions() { glm::vec3 myPalmPosition = palm.getPosition(); float palmCollisionDistance = 0.1f; palm.setIsCollidingWithPalm(false); - for (int j = 0; j < getNumPalms(); j++) { + for (int j = 0; j < otherAvatar->getHand().getNumPalms(); j++) { PalmData& otherPalm = otherAvatar->getHand().getPalms()[j]; if (!otherPalm.isActive()) { continue; From d4bad3421fb9fc2d1b92f3e73a54ab5bcb3b1729 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 16 Dec 2013 21:49:15 -0800 Subject: [PATCH 5/8] fix: get velocity from either hand or fingertip according to where ball is thrown from --- interface/src/avatar/Hand.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index c78b6271a4..fea593a653 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -143,6 +143,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f // create the ball, call MakeParticle, and use the resulting ParticleEditHandle to // manage the newly created particle. // Create a particle on the particle server + qDebug("Created New Ball\n"); glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition; _ballParticleEditHandles[handID] = Application::getInstance()->makeParticle( ballPosition / (float)TREE_SCALE, @@ -172,16 +173,15 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f _toyBallInHand[handID] = false; glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition; - glm::vec3 handVelocity = palm.getRawVelocity(); - glm::vec3 fingerTipVelocity = palm.getTipVelocity(); + glm::vec3 ballVelocity = ballFromHand ? palm.getRawVelocity() : palm.getTipVelocity(); glm::quat avatarRotation = _owningAvatar->getOrientation(); - glm::vec3 toyBallVelocity = avatarRotation * fingerTipVelocity; + ballVelocity = avatarRotation * ballVelocity; // ball is no longer in hand... _ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE, TOY_BALL_RADIUS / (float) TREE_SCALE, TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], - toyBallVelocity / (float)TREE_SCALE, + ballVelocity / (float)TREE_SCALE, TOY_BALL_GRAVITY / (float) TREE_SCALE, TOY_BALL_DAMPING, NOT_IN_HAND, From fc28034f3722f3933572dfd74c1d9b3ae9ac0710 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 17 Dec 2013 09:41:13 -0800 Subject: [PATCH 6/8] hydra hands hard coded to LH and RH controllers, ball debugging --- interface/src/avatar/Hand.cpp | 3 +++ libraries/avatars/src/HandData.cpp | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index fea593a653..cb2ccab1ae 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -98,6 +98,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f glm::vec3 newVelocity = NO_VELOCITY; // update the particle with it's new state... + qDebug("Update caught particle!\n"); caughtParticle->updateParticle(newPosition, closestParticle->getRadius(), closestParticle->getXColor(), @@ -157,6 +158,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f } } else { // Ball is in hand + //qDebug("Ball in hand\n"); glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition; _ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE, TOY_BALL_RADIUS / (float) TREE_SCALE, @@ -178,6 +180,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f ballVelocity = avatarRotation * ballVelocity; // ball is no longer in hand... + qDebug("Threw ball, v = %.3f\n", glm::length(ballVelocity)); _ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE, TOY_BALL_RADIUS / (float) TREE_SCALE, TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], diff --git a/libraries/avatars/src/HandData.cpp b/libraries/avatars/src/HandData.cpp index e46620398e..cf91af902a 100644 --- a/libraries/avatars/src/HandData.cpp +++ b/libraries/avatars/src/HandData.cpp @@ -38,22 +38,20 @@ PalmData& HandData::addNewPalm() { return _palms.back(); } +const int SIXENSE_CONTROLLER_ID_LEFT_HAND = 0; +const int SIXENSE_CONTROLLER_ID_RIGHT_HAND = 1; + void HandData::getLeftRightPalmIndices(int& leftPalmIndex, int& rightPalmIndex) const { leftPalmIndex = -1; - float leftPalmX = FLT_MAX; - rightPalmIndex = -1; - float rightPalmX = -FLT_MAX; + rightPalmIndex = -1; for (int i = 0; i < _palms.size(); i++) { const PalmData& palm = _palms[i]; if (palm.isActive()) { - float x = palm.getRawPosition().x; - if (x < leftPalmX) { + if (palm.getSixenseID() == SIXENSE_CONTROLLER_ID_LEFT_HAND) { leftPalmIndex = i; - leftPalmX = x; } - if (x > rightPalmX) { + if (palm.getSixenseID() == SIXENSE_CONTROLLER_ID_RIGHT_HAND) { rightPalmIndex = i; - rightPalmX = x; } } } From d6efcce28e58dd90d787f81bb575214036c182c3 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 17 Dec 2013 11:08:38 -0800 Subject: [PATCH 7/8] Debugging render call for head/hand positions, debugging for ball injection --- interface/src/avatar/Hand.cpp | 12 +++++++++- interface/src/avatar/MyAvatar.cpp | 28 ++++++++++++++++++++++++ interface/src/avatar/MyAvatar.h | 1 + interface/src/devices/SixenseManager.cpp | 6 ----- 4 files changed, 40 insertions(+), 7 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index cb2ccab1ae..d446c32469 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -17,6 +17,8 @@ #include "Util.h" #include "renderer/ProgramObject.h" +//#define DEBUG_HAND + using namespace std; const float FINGERTIP_VOXEL_SIZE = 0.05; @@ -98,7 +100,9 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f glm::vec3 newVelocity = NO_VELOCITY; // update the particle with it's new state... +#ifdef DEBUG_HAND qDebug("Update caught particle!\n"); +#endif caughtParticle->updateParticle(newPosition, closestParticle->getRadius(), closestParticle->getXColor(), @@ -144,7 +148,9 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f // create the ball, call MakeParticle, and use the resulting ParticleEditHandle to // manage the newly created particle. // Create a particle on the particle server +#ifdef DEBUG_HAND qDebug("Created New Ball\n"); +#endif glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition; _ballParticleEditHandles[handID] = Application::getInstance()->makeParticle( ballPosition / (float)TREE_SCALE, @@ -158,7 +164,9 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f } } else { // Ball is in hand - //qDebug("Ball in hand\n"); +#ifdef DEBUG_HAND + qDebug("Ball in hand\n"); +#endif glm::vec3 ballPosition = ballFromHand ? palm.getPosition() : fingerTipPosition; _ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE, TOY_BALL_RADIUS / (float) TREE_SCALE, @@ -180,7 +188,9 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f ballVelocity = avatarRotation * ballVelocity; // ball is no longer in hand... +#ifdef DEBUG_HAND qDebug("Threw ball, v = %.3f\n", glm::length(ballVelocity)); +#endif _ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE, TOY_BALL_RADIUS / (float) TREE_SCALE, TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index e462426f2e..c668eb5956 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -426,6 +426,31 @@ static TextRenderer* textRenderer() { return renderer; } +void MyAvatar::renderDebugBodyPoints() { + glm::vec3 torsoPosition(getPosition()); + glm::vec3 headPosition(getHead().getEyePosition()); + float torsoToHead = glm::length(headPosition - torsoPosition); + glm::vec3 position; + printf("head-above-torso %.2f, scale = %0.2f\n", torsoToHead, getScale()); + + // Torso Sphere + position = torsoPosition; + glPushMatrix(); + glColor4f(0, 1, 0, .5f); + glTranslatef(position.x, position.y, position.z); + glutSolidSphere(0.2, 10, 10); + glPopMatrix(); + + // Head Sphere + position = headPosition; + glPushMatrix(); + glColor4f(0, 1, 0, .5f); + glTranslatef(position.x, position.y, position.z); + glutSolidSphere(0.15, 10, 10); + glPopMatrix(); + + +} void MyAvatar::render(bool forceRenderHead) { // render body @@ -438,6 +463,9 @@ void MyAvatar::render(bool forceRenderHead) { glPopMatrix(); } + //renderDebugBodyPoints(); + + if (!_chatMessage.empty()) { int width = 0; int lastWidth = 0; diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index df8ab4aa92..508f9ce5d2 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -30,6 +30,7 @@ public: void simulate(float deltaTime, Transmitter* transmitter); void updateFromGyrosAndOrWebcam(bool turnWithHead); void render(bool forceRenderHead); + void renderDebugBodyPoints(); // setters void setMousePressed(bool mousePressed) { _mousePressed = mousePressed; } diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 3a5c2bf95c..36693000a9 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -79,12 +79,6 @@ void SixenseManager::update(float deltaTime) { palm->setTrigger(data.trigger); palm->setJoystick(data.joystick_x, data.joystick_y); - // Vibrate if needed - if (palm->getIsCollidingWithVoxel()) { - //printf("vibrate!\n"); - //vibrate(data.controller_index, 100, 1); - } - glm::vec3 position(data.pos[0], data.pos[1], data.pos[2]); // Adjust for distance between acquisition 'orb' and the user's torso // (distance to the right of body center, distance below torso, distance behind torso) From 35e7cfddbab7fe225b7aa7d0b8a91c6e7584a656 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 17 Dec 2013 11:20:26 -0800 Subject: [PATCH 8/8] =?UTF-8?q?Made=20drumming=20and=20slaps=20into=20menu?= =?UTF-8?q?=20choices=20from=20=E2=80=98Hand=20Options=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interface/src/Menu.cpp | 5 +- interface/src/Menu.h | 2 + interface/src/avatar/Hand.cpp | 100 ++++++++++++++++++---------------- 3 files changed, 59 insertions(+), 48 deletions(-) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index d79c2938f1..374efd51e2 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -373,7 +373,10 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayLeapHands, 0, true); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::LeapDrive, 0, false); addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::DisplayHandTargets, 0, false); - addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::BallFromHand, 0, false); + addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::BallFromHand, 0, false); + addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::VoxelDrumming, 0, false); + addCheckableActionToQMenuAndActionHash(handOptionsMenu, MenuOption::PlaySlaps, 0, false); + QMenu* trackingOptionsMenu = developerMenu->addMenu("Tracking Options"); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index 117a24831e..b62f49abe4 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -244,6 +244,8 @@ namespace MenuOption { const QString ShowAllLocalVoxels = "Show All Local Voxels"; const QString ShowTrueColors = "Show TRUE Colors"; const QString SimulateLeapHand = "Simulate Leap Hand"; + const QString VoxelDrumming = "Voxel Drumming"; + const QString PlaySlaps = "Play Slaps"; const QString SkeletonTracking = "Skeleton Tracking"; const QString SuppressShortTimings = "Suppress Timings Less than 10ms"; const QString LEDTracking = "LED Tracking"; diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index d446c32469..cd979a681f 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -285,32 +285,35 @@ void Hand::simulate(float deltaTime, bool isMine) { _lastFingerDeleteVoxel = fingerTipPosition; } } - // Check if the finger is intersecting with a voxel in the client voxel tree - VoxelTreeElement* fingerNode = Application::getInstance()->getVoxels()->getVoxelEnclosing( - glm::vec3(fingerTipPosition / (float)TREE_SCALE)); - if (fingerNode) { - if (!palm.getIsCollidingWithVoxel()) { - // Collision has just started - palm.setIsCollidingWithVoxel(true); - handleVoxelCollision(&palm, fingerTipPosition, fingerNode, deltaTime); - // Set highlight voxel - VoxelDetail voxel; - glm::vec3 pos = fingerNode->getCorner(); - voxel.x = pos.x; - voxel.y = pos.y; - voxel.z = pos.z; - voxel.s = fingerNode->getScale(); - voxel.red = fingerNode->getColor()[0]; - voxel.green = fingerNode->getColor()[1]; - voxel.blue = fingerNode->getColor()[2]; - Application::getInstance()->setHighlightVoxel(voxel); - Application::getInstance()->setIsHighlightVoxel(true); - } - } else { - if (palm.getIsCollidingWithVoxel()) { - // Collision has just ended - palm.setIsCollidingWithVoxel(false); - Application::getInstance()->setIsHighlightVoxel(false); + + // Voxel Drumming with fingertips if enabled + if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelDrumming)) { + VoxelTreeElement* fingerNode = Application::getInstance()->getVoxels()->getVoxelEnclosing( + glm::vec3(fingerTipPosition / (float)TREE_SCALE)); + if (fingerNode) { + if (!palm.getIsCollidingWithVoxel()) { + // Collision has just started + palm.setIsCollidingWithVoxel(true); + handleVoxelCollision(&palm, fingerTipPosition, fingerNode, deltaTime); + // Set highlight voxel + VoxelDetail voxel; + glm::vec3 pos = fingerNode->getCorner(); + voxel.x = pos.x; + voxel.y = pos.y; + voxel.z = pos.z; + voxel.s = fingerNode->getScale(); + voxel.red = fingerNode->getColor()[0]; + voxel.green = fingerNode->getColor()[1]; + voxel.blue = fingerNode->getColor()[2]; + Application::getInstance()->setHighlightVoxel(voxel); + Application::getInstance()->setIsHighlightVoxel(true); + } + } else { + if (palm.getIsCollidingWithVoxel()) { + // Collision has just ended + palm.setIsCollidingWithVoxel(false); + Application::getInstance()->setIsHighlightVoxel(false); + } } } } @@ -338,28 +341,31 @@ void Hand::updateCollisions() { for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { if (node->getLinkedData() && node->getType() == NODE_TYPE_AGENT) { Avatar* otherAvatar = (Avatar*)node->getLinkedData(); - // Check for palm collisions - glm::vec3 myPalmPosition = palm.getPosition(); - float palmCollisionDistance = 0.1f; - palm.setIsCollidingWithPalm(false); - for (int j = 0; j < otherAvatar->getHand().getNumPalms(); j++) { - PalmData& otherPalm = otherAvatar->getHand().getPalms()[j]; - if (!otherPalm.isActive()) { - continue; - } - glm::vec3 otherPalmPosition = otherPalm.getPosition(); - if (glm::length(otherPalmPosition - myPalmPosition) < palmCollisionDistance) { - palm.setIsCollidingWithPalm(true); - const float PALM_COLLIDE_VOLUME = 1.f; - const float PALM_COLLIDE_FREQUENCY = 150.f; - const float PALM_COLLIDE_DURATION_MAX = 2.f; - const float PALM_COLLIDE_DECAY_PER_SAMPLE = 0.005f; - Application::getInstance()->getAudio()->startDrumSound(PALM_COLLIDE_VOLUME, - PALM_COLLIDE_FREQUENCY, - PALM_COLLIDE_DURATION_MAX, - PALM_COLLIDE_DECAY_PER_SAMPLE); + if (Menu::getInstance()->isOptionChecked(MenuOption::PlaySlaps)) { + // Check for palm collisions + glm::vec3 myPalmPosition = palm.getPosition(); + float palmCollisionDistance = 0.1f; + palm.setIsCollidingWithPalm(false); + // If 'Play Slaps' is enabled, look for palm-to-palm collisions and make sound + for (int j = 0; j < otherAvatar->getHand().getNumPalms(); j++) { + PalmData& otherPalm = otherAvatar->getHand().getPalms()[j]; + if (!otherPalm.isActive()) { + continue; + } + glm::vec3 otherPalmPosition = otherPalm.getPosition(); + if (glm::length(otherPalmPosition - myPalmPosition) < palmCollisionDistance) { + palm.setIsCollidingWithPalm(true); + const float PALM_COLLIDE_VOLUME = 1.f; + const float PALM_COLLIDE_FREQUENCY = 150.f; + const float PALM_COLLIDE_DURATION_MAX = 2.f; + const float PALM_COLLIDE_DECAY_PER_SAMPLE = 0.005f; + Application::getInstance()->getAudio()->startDrumSound(PALM_COLLIDE_VOLUME, + PALM_COLLIDE_FREQUENCY, + PALM_COLLIDE_DURATION_MAX, + PALM_COLLIDE_DECAY_PER_SAMPLE); - + + } } } glm::vec3 avatarPenetration;