diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index b718729fcb..ad1c3fbf50 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -72,22 +72,47 @@ void Hand::reset() { } void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) { + int handID = palm.getSixenseID(); - glm::vec3 targetPosition = fingerTipPosition / (float)TREE_SCALE; - float targetRadius = (TOY_BALL_RADIUS * 2.0f) / (float)TREE_SCALE; + glm::vec3 targetPosition = palm.getPosition() / (float)TREE_SCALE; + float targetRadius = 0.25f / (float)TREE_SCALE; // (TOY_BALL_RADIUS * 4.0f) / (float)TREE_SCALE; const Particle* closestParticle = Application::getInstance()->getParticles() ->getTree()->findClosestParticle(targetPosition, targetRadius); if (closestParticle) { //printf("potentially caught... particle ID:%d\n", closestParticle->getID()); - // you can create a ParticleEditHandle by doing this... - ParticleEditHandle* caughtParticle = Application::getInstance()->newParticleEditHandle(closestParticle->getID()); + if (!_toyBallInHand[handID]) { + printf("particle ID:%d NOT IN HAND\n", closestParticle->getID()); + + // you can create a ParticleEditHandle by doing this... + ParticleEditHandle* caughtParticle = Application::getInstance()->newParticleEditHandle(closestParticle->getID()); - // but make sure you clean it up, when you're done - delete caughtParticle; + // reflect off the hand... + printf("particle ID:%d old velocity=%f,%f,%f\n", closestParticle->getID(), + closestParticle->getVelocity().x, closestParticle->getVelocity().y, closestParticle->getVelocity().z); + glm::vec3 newVelocity = glm::reflect(closestParticle->getVelocity(), palm.getNormal()); + + printf("particle ID:%d REFLECT velocity=%f,%f,%f\n", closestParticle->getID(), + newVelocity.x, newVelocity.y, newVelocity.z); + + newVelocity += palm.getTipVelocity() / (float)TREE_SCALE; + + printf("particle ID:%d with TIP velocity=%f,%f,%f\n", closestParticle->getID(), + newVelocity.x, newVelocity.y, newVelocity.z); + + caughtParticle->updateParticle(closestParticle->getPosition(), + closestParticle->getRadius(), + closestParticle->getXColor(), + newVelocity, + closestParticle->getGravity(), + closestParticle->getDamping(), + closestParticle->getUpdateScript()); + + // but make sure you clean it up, when you're done + delete caughtParticle; + } } - int handID = palm.getSixenseID(); // If there's a ball in hand, and the user presses the skinny button, then change the color of the ball int currentControllerButtons = palm.getControllerButtons(); @@ -118,8 +143,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 + glm::vec3 ballPosition = palm.getPosition(); _ballParticleEditHandles[handID] = Application::getInstance()->makeParticle( - fingerTipPosition / (float)TREE_SCALE, + ballPosition / (float)TREE_SCALE, TOY_BALL_RADIUS / (float) TREE_SCALE, TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], NO_VELOCITY / (float)TREE_SCALE, @@ -129,7 +155,8 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f } } else { // Ball is in hand - _ballParticleEditHandles[handID]->updateParticle(fingerTipPosition / (float)TREE_SCALE, + glm::vec3 ballPosition = palm.getPosition(); + _ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE, TOY_BALL_RADIUS / (float) TREE_SCALE, TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], NO_VELOCITY / (float)TREE_SCALE, @@ -142,13 +169,14 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f if (_toyBallInHand[handID]) { _toyBallInHand[handID] = false; + glm::vec3 ballPosition = palm.getPosition(); glm::vec3 handVelocity = palm.getRawVelocity(); glm::vec3 fingerTipVelocity = palm.getTipVelocity(); glm::quat avatarRotation = _owningAvatar->getOrientation(); glm::vec3 toyBallVelocity = avatarRotation * fingerTipVelocity; // ball is no longer in hand... - _ballParticleEditHandles[handID]->updateParticle(fingerTipPosition / (float)TREE_SCALE, + _ballParticleEditHandles[handID]->updateParticle(ballPosition / (float)TREE_SCALE, TOY_BALL_RADIUS / (float) TREE_SCALE, TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], toyBallVelocity / (float)TREE_SCALE, @@ -406,8 +434,25 @@ void Hand::renderLeapHands() { //const glm::vec3 handColor = _ballColor; const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color + + glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); + + for (size_t i = 0; i < getNumPalms(); ++i) { + PalmData& palm = getPalms()[i]; + if (!palm.isActive()) { + continue; + } + glm::vec3 targetPosition = palm.getPosition(); + float targetRadius = 0.25f; + glPushMatrix(); + glColor4f(1,1,0, alpha); + glTranslatef(targetPosition.x, targetPosition.y, targetPosition.z); + glutWireSphere(targetRadius, 20.0f, 20.0f); + glPopMatrix(); + } + glPushMatrix(); // Draw the leap balls for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) { @@ -444,11 +489,14 @@ void Hand::renderLeapHands() { for (size_t i = 0; i < getNumPalms(); ++i) { PalmData& palm = getPalms()[i]; if (palm.isActive()) { - const float palmThickness = 0.02f; - glColor4f(handColor.r, handColor.g, handColor.b, 0.25); + const float palmThickness = 0.05f; //0.02f; + //glColor4f(handColor.r, handColor.g, handColor.b, 0.25); + glColor4f(1.0, 0.0, 0.0, 0.25); glm::vec3 tip = palm.getPosition(); glm::vec3 root = palm.getPosition() + palm.getNormal() * palmThickness; - Avatar::renderJointConnectingCone(root, tip, 0.05, 0.03); + const float radiusA = 0.25f; // 0.05f; + const float radiusB = 0.23f; // 0.03f; + Avatar::renderJointConnectingCone(root, tip, radiusA, radiusB); } } glDepthMask(GL_TRUE); diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index 6fba4d5e2c..86f29cf2f1 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -122,8 +122,8 @@ private: class PalmData { public: PalmData(HandData* owningHandData); - glm::vec3 getPosition() const { return _owningHandData->leapPositionToWorldPosition(_rawPosition); } - glm::vec3 getNormal() const { return _owningHandData->leapDirectionToWorldDirection(_rawNormal); } + glm::vec3 getPosition() const { return _owningHandData->leapPositionToWorldPosition(_rawPosition); } + glm::vec3 getNormal() const { return _owningHandData->leapDirectionToWorldDirection(_rawNormal); } const glm::vec3& getRawPosition() const { return _rawPosition; } const glm::vec3& getRawNormal() const { return _rawNormal; } @@ -140,7 +140,7 @@ public: void setSixenseID(int id) { _sixenseID = id; } void setRawRotation(const glm::quat rawRotation) { _rawRotation = rawRotation; }; - const glm::quat getRawRotation() const { return _rawRotation; } + glm::quat getRawRotation() const { return _rawRotation; } void setRawPosition(const glm::vec3& pos) { _rawPosition = pos; } void setRawNormal(const glm::vec3& normal) { _rawNormal = normal; } void setRawVelocity(const glm::vec3& velocity) { _rawVelocity = velocity; } diff --git a/libraries/particles/src/Particle.h b/libraries/particles/src/Particle.h index 8e754fee39..1d80adabc6 100644 --- a/libraries/particles/src/Particle.h +++ b/libraries/particles/src/Particle.h @@ -57,7 +57,7 @@ public: const glm::vec3& getPosition() const { return _position; } const rgbColor& getColor() const { return _color; } - xColor getColor() { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; } + xColor getXColor() const { xColor color = { _color[RED_INDEX], _color[GREEN_INDEX], _color[BLUE_INDEX] }; return color; } float getRadius() const { return _radius; } const glm::vec3& getVelocity() const { return _velocity; } const glm::vec3& getGravity() const { return _gravity; } @@ -129,7 +129,7 @@ public: public slots: glm::vec3 getPosition() const { return _particle->getPosition(); } glm::vec3 getVelocity() const { return _particle->getVelocity(); } - xColor getColor() const { return _particle->getColor(); } + xColor getColor() const { return _particle->getXColor(); } glm::vec3 getGravity() const { return _particle->getGravity(); } float getDamping() const { return _particle->getDamping(); } float getRadius() const { return _particle->getRadius(); } diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index 764cbe3381..8928a3db8c 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -119,7 +119,7 @@ void ParticleCollisionSystem::applyHardCollision(Particle* particle, const glm:: } } ParticleEditHandle particleEditHandle(_packetSender, _particles, particle->getID()); - particleEditHandle.updateParticle(position, particle->getRadius(), particle->getColor(), velocity, + particleEditHandle.updateParticle(position, particle->getRadius(), particle->getXColor(), velocity, particle->getGravity(), particle->getDamping(), particle->getUpdateScript()); }