added basic support for hit particles with the palm of the hand

This commit is contained in:
ZappoMan 2013-12-13 19:02:45 -08:00
parent aaf4ff7dfc
commit 02d3d384ca
4 changed files with 67 additions and 19 deletions

View file

@ -72,22 +72,47 @@ void Hand::reset() {
} }
void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) { void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, float deltaTime) {
int handID = palm.getSixenseID();
glm::vec3 targetPosition = fingerTipPosition / (float)TREE_SCALE; glm::vec3 targetPosition = palm.getPosition() / (float)TREE_SCALE;
float targetRadius = (TOY_BALL_RADIUS * 2.0f) / (float)TREE_SCALE; float targetRadius = 0.25f / (float)TREE_SCALE; // (TOY_BALL_RADIUS * 4.0f) / (float)TREE_SCALE;
const Particle* closestParticle = Application::getInstance()->getParticles() const Particle* closestParticle = Application::getInstance()->getParticles()
->getTree()->findClosestParticle(targetPosition, targetRadius); ->getTree()->findClosestParticle(targetPosition, targetRadius);
if (closestParticle) { if (closestParticle) {
//printf("potentially caught... particle ID:%d\n", closestParticle->getID()); //printf("potentially caught... particle ID:%d\n", closestParticle->getID());
if (!_toyBallInHand[handID]) {
printf("particle ID:%d NOT IN HAND\n", closestParticle->getID());
// you can create a ParticleEditHandle by doing this... // you can create a ParticleEditHandle by doing this...
ParticleEditHandle* caughtParticle = Application::getInstance()->newParticleEditHandle(closestParticle->getID()); ParticleEditHandle* caughtParticle = Application::getInstance()->newParticleEditHandle(closestParticle->getID());
// 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 // but make sure you clean it up, when you're done
delete caughtParticle; 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 // 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(); 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 // create the ball, call MakeParticle, and use the resulting ParticleEditHandle to
// manage the newly created particle. // manage the newly created particle.
// Create a particle on the particle server // Create a particle on the particle server
glm::vec3 ballPosition = palm.getPosition();
_ballParticleEditHandles[handID] = Application::getInstance()->makeParticle( _ballParticleEditHandles[handID] = Application::getInstance()->makeParticle(
fingerTipPosition / (float)TREE_SCALE, ballPosition / (float)TREE_SCALE,
TOY_BALL_RADIUS / (float) TREE_SCALE, TOY_BALL_RADIUS / (float) TREE_SCALE,
TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]],
NO_VELOCITY / (float)TREE_SCALE, NO_VELOCITY / (float)TREE_SCALE,
@ -129,7 +155,8 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
} }
} else { } else {
// Ball is in hand // 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_RADIUS / (float) TREE_SCALE,
TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]],
NO_VELOCITY / (float)TREE_SCALE, NO_VELOCITY / (float)TREE_SCALE,
@ -142,13 +169,14 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
if (_toyBallInHand[handID]) { if (_toyBallInHand[handID]) {
_toyBallInHand[handID] = false; _toyBallInHand[handID] = false;
glm::vec3 ballPosition = palm.getPosition();
glm::vec3 handVelocity = palm.getRawVelocity(); glm::vec3 handVelocity = palm.getRawVelocity();
glm::vec3 fingerTipVelocity = palm.getTipVelocity(); glm::vec3 fingerTipVelocity = palm.getTipVelocity();
glm::quat avatarRotation = _owningAvatar->getOrientation(); glm::quat avatarRotation = _owningAvatar->getOrientation();
glm::vec3 toyBallVelocity = avatarRotation * fingerTipVelocity; glm::vec3 toyBallVelocity = avatarRotation * fingerTipVelocity;
// ball is no longer in hand... // 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_RADIUS / (float) TREE_SCALE,
TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]], TOY_BALL_ON_SERVER_COLOR[_whichBallColor[handID]],
toyBallVelocity / (float)TREE_SCALE, toyBallVelocity / (float)TREE_SCALE,
@ -406,8 +434,25 @@ void Hand::renderLeapHands() {
//const glm::vec3 handColor = _ballColor; //const glm::vec3 handColor = _ballColor;
const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE); 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(); glPushMatrix();
// Draw the leap balls // Draw the leap balls
for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) { for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) {
@ -444,11 +489,14 @@ void Hand::renderLeapHands() {
for (size_t i = 0; i < getNumPalms(); ++i) { for (size_t i = 0; i < getNumPalms(); ++i) {
PalmData& palm = getPalms()[i]; PalmData& palm = getPalms()[i];
if (palm.isActive()) { if (palm.isActive()) {
const float palmThickness = 0.02f; const float palmThickness = 0.05f; //0.02f;
glColor4f(handColor.r, handColor.g, handColor.b, 0.25); //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 tip = palm.getPosition();
glm::vec3 root = palm.getPosition() + palm.getNormal() * palmThickness; 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); glDepthMask(GL_TRUE);

View file

@ -140,7 +140,7 @@ public:
void setSixenseID(int id) { _sixenseID = id; } void setSixenseID(int id) { _sixenseID = id; }
void setRawRotation(const glm::quat rawRotation) { _rawRotation = rawRotation; }; 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 setRawPosition(const glm::vec3& pos) { _rawPosition = pos; }
void setRawNormal(const glm::vec3& normal) { _rawNormal = normal; } void setRawNormal(const glm::vec3& normal) { _rawNormal = normal; }
void setRawVelocity(const glm::vec3& velocity) { _rawVelocity = velocity; } void setRawVelocity(const glm::vec3& velocity) { _rawVelocity = velocity; }

View file

@ -57,7 +57,7 @@ public:
const glm::vec3& getPosition() const { return _position; } const glm::vec3& getPosition() const { return _position; }
const rgbColor& getColor() const { return _color; } 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; } float getRadius() const { return _radius; }
const glm::vec3& getVelocity() const { return _velocity; } const glm::vec3& getVelocity() const { return _velocity; }
const glm::vec3& getGravity() const { return _gravity; } const glm::vec3& getGravity() const { return _gravity; }
@ -129,7 +129,7 @@ public:
public slots: public slots:
glm::vec3 getPosition() const { return _particle->getPosition(); } glm::vec3 getPosition() const { return _particle->getPosition(); }
glm::vec3 getVelocity() const { return _particle->getVelocity(); } 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(); } glm::vec3 getGravity() const { return _particle->getGravity(); }
float getDamping() const { return _particle->getDamping(); } float getDamping() const { return _particle->getDamping(); }
float getRadius() const { return _particle->getRadius(); } float getRadius() const { return _particle->getRadius(); }

View file

@ -119,7 +119,7 @@ void ParticleCollisionSystem::applyHardCollision(Particle* particle, const glm::
} }
} }
ParticleEditHandle particleEditHandle(_packetSender, _particles, particle->getID()); 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()); particle->getGravity(), particle->getDamping(), particle->getUpdateScript());
} }