From 9f7e79e3c142c0f361c25c214a52ad47027f53a7 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Thu, 19 Dec 2013 14:59:15 -0800 Subject: [PATCH] bigger catch radius, tweak sounds, different new ball button --- interface/src/avatar/Hand.cpp | 79 ++++++++++++++++------------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index dfe9776b64..e989cdf6fe 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -31,7 +31,7 @@ const float NO_DAMPING = 0.f; const glm::vec3 TOY_BALL_GRAVITY = glm::vec3(0,-2.0,0); const QString TOY_BALL_UPDATE_SCRIPT(""); const float PALM_COLLISION_RADIUS = 0.03f; -const float CATCH_RADIUS = 0.2f; +const float CATCH_RADIUS = 0.3f; const xColor TOY_BALL_ON_SERVER_COLOR[] = { { 255, 0, 0 }, @@ -81,14 +81,20 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f ParticleTree* particles = app->getParticles()->getTree(); bool ballFromHand = Menu::getInstance()->isOptionChecked(MenuOption::BallFromHand); int handID = palm.getSixenseID(); - - bool grabButtonPressed = (palm.getControllerButtons() & BUTTON_FWD); + + const int NEW_BALL_BUTTON = BUTTON_3; + + float trigger = palm.getTrigger(); + bool grabButtonPressed = ((palm.getControllerButtons() & BUTTON_FWD) || + (palm.getControllerButtons() & BUTTON_3) || + (trigger > 0.f)); + bool ballAlreadyInHand = _toyBallInHand[handID]; glm::vec3 targetPosition = (ballFromHand ? palm.getPosition() : fingerTipPosition) / (float)TREE_SCALE; float targetRadius = CATCH_RADIUS / (float)TREE_SCALE; - // If I don't currently have a ball in my hand, then I can catch this closest particle + // If I don't currently have a ball in my hand, then try to catch closest one if (!ballAlreadyInHand && grabButtonPressed) { const Particle* closestParticle = particles->findClosestParticle(targetPosition, targetRadius); @@ -119,7 +125,7 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f _ballParticleEditHandles[handID] = caughtParticle; caughtParticle = NULL; // Play a catch sound! - app->getAudio()->startDrumSound(1.0, 300, 0.5, 0.05); + app->getAudio()->startDrumSound(1.0, 300, 0.75, 0.015); } } @@ -133,46 +139,31 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f } } - // Is the controller button being held down.... - if (palm.getControllerButtons() & BUTTON_FWD) { + // If '3' is pressed, and not holding a ball, make a new one + if ((palm.getControllerButtons() & NEW_BALL_BUTTON) && (_toyBallInHand[handID] == false)) { + _toyBallInHand[handID] = true; + // 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] = app->makeParticle( + ballPosition / (float)TREE_SCALE, + TOY_BALL_RADIUS / (float) TREE_SCALE, + TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], + NO_VELOCITY / (float)TREE_SCALE, + TOY_BALL_GRAVITY / (float) TREE_SCALE, + TOY_BALL_DAMPING, + IN_HAND, + TOY_BALL_UPDATE_SCRIPT); + // Play a new ball sound + app->getAudio()->startDrumSound(1.0, 2000, 0.5, 0.02); + } + + if (grabButtonPressed) { // If we don't currently have a ball in hand, then create it... - if (!_toyBallInHand[handID]) { - // Test for whether close enough to catch and catch.... - - // isCaught is also used as "creating" a new ball... for now, this section is the - // create new ball portion of the code... - bool isCaught = false; - - // If we didn't catch something, then create a new ball.... - if (!isCaught) { - _toyBallInHand[handID] = true; - - // 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] = app->makeParticle( - ballPosition / (float)TREE_SCALE, - TOY_BALL_RADIUS / (float) TREE_SCALE, - TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], - NO_VELOCITY / (float)TREE_SCALE, - TOY_BALL_GRAVITY / (float) TREE_SCALE, - TOY_BALL_DAMPING, - IN_HAND, - TOY_BALL_UPDATE_SCRIPT); - // Play a new ball sound - app->getAudio()->startDrumSound(1.0, 2000, 0.5, 0.02); - - } - } else { - // Ball is in hand -#ifdef DEBUG_HAND - //qDebug("Ball in hand\n"); -#endif - + if (_toyBallInHand[handID]) { + // Update ball that is in hand uint32_t particleInHandID = _ballParticleEditHandles[handID]->getID(); const Particle* particleInHand = particles->findParticleByID(particleInHandID); xColor colorForParticleInHand = particleInHand ? particleInHand->getXColor()