From 09bce076cc950e836ad79f6120ad2b95c069749a Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 15 Jan 2014 14:06:31 -0800 Subject: [PATCH] All avatars now have disk collision proxies at their hands. --- .../particles/src/ParticleCollisionSystem.cpp | 47 ++++++------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index 7d199d3c38..417c1e0667 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -137,15 +137,14 @@ void ParticleCollisionSystem::updateCollisionWithParticles(Particle* particleA) void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { - // particles that are in hand, don't collide with other avatar parts + // particles that are in hand, don't collide with avatars if (particle->getInHand()) { return; } - //printf("updateCollisionWithAvatars()...\n"); glm::vec3 center = particle->getPosition() * (float)(TREE_SCALE); float radius = particle->getRadius() * (float)(TREE_SCALE); - const float ELASTICITY = 0.4f; + const float ELASTICITY = 0.95f; const float DAMPING = 0.0f; const float COLLISION_FREQUENCY = 0.5f; glm::vec3 penetration; @@ -157,55 +156,37 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { CollisionInfo collision; if (avatar->findSphereCollision(center, radius, collision)) { if (glm::dot(particle->getVelocity(), collision._addedVelocity) < 0.f) { + // only collide when particle and collision point are moving toward each other collision._penetration /= (float)(TREE_SCALE); collision._addedVelocity /= (float)(TREE_SCALE); - glm::vec3 pv = particle->getVelocity(); updateCollisionSound(particle, collision._penetration, COLLISION_FREQUENCY); applyHardCollision(particle, collision._penetration, ELASTICITY, DAMPING, collision._addedVelocity); } } } - // TODO: convert other avatars to collide like _selfAvatar - // loop through all the other avatars for potential interactions... - foreach (const SharedNodePointer& node, NodeList::getInstance()->getNodeHash()) { //qDebug() << "updateCollisionWithAvatars()... node:" << *node << "\n"; if (node->getLinkedData() && node->getType() == NODE_TYPE_AGENT) { - // TODO: dot collidingPalm and hand velocities and skip collision when they are moving apart. AvatarData* avatar = static_cast(node->getLinkedData()); - //printf("updateCollisionWithAvatars()...avatar=%p\n", avatar); - - // check hands... - const HandData* handData = avatar->getHandData(); - - if (handData->findSpherePenetration(center, radius, penetration, collidingPalm)) { - // apply a hard collision when ball collides with hand - penetration /= (float)(TREE_SCALE); - updateCollisionSound(particle, penetration, COLLISION_FREQUENCY); - - // determine if the palm that collided was moving, if so, then we add that palm velocity as well... - glm::vec3 addedVelocity = NO_ADDED_VELOCITY; - if (collidingPalm) { - glm::vec3 palmVelocity = collidingPalm->getVelocity() / (float)(TREE_SCALE); - //printf("collidingPalm Velocity=%f,%f,%f\n", palmVelocity.x, palmVelocity.y, palmVelocity.z); - addedVelocity = palmVelocity; + + CollisionInfo collision; + if (avatar->findSphereCollision(center, radius, collision)) { + if (glm::dot(particle->getVelocity(), collision._addedVelocity) < 0.f) { + // only collide when particle and collision point are moving toward each other + collision._penetration /= (float)(TREE_SCALE); + collision._addedVelocity /= (float)(TREE_SCALE); + updateCollisionSound(particle, collision._penetration, COLLISION_FREQUENCY); + applyHardCollision(particle, collision._penetration, ELASTICITY, DAMPING, collision._addedVelocity); } - - applyHardCollision(particle, penetration, ELASTICITY, DAMPING, addedVelocity); - - } else if (avatar->findSpherePenetration(center, radius, penetration)) { - penetration /= (float)(TREE_SCALE); - updateCollisionSound(particle, penetration, COLLISION_FREQUENCY); - glm::vec3 addedVelocity = avatar->getVelocity(); - applyHardCollision(particle, penetration, ELASTICITY, DAMPING, addedVelocity); } } } } +// TODO: convert applyHardCollision() to take a CollisionInfo& instead of penetration + addedVelocity void ParticleCollisionSystem::applyHardCollision(Particle* particle, const glm::vec3& penetration, float elasticity, float damping, const glm::vec3& addedVelocity) { // @@ -221,7 +202,7 @@ void ParticleCollisionSystem::applyHardCollision(Particle* particle, const glm:: const float EPSILON = 0.0f; float velocityDotPenetration = glm::dot(velocity, penetration); if (velocityDotPenetration > EPSILON) { - position -= penetration; + //position -= penetration; static float HALTING_VELOCITY = 0.2f / (float)(TREE_SCALE); // cancel out the velocity component in the direction of penetration