From 934b0f619bc065550fa73ee1ec991aad9233eced Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 2 Jan 2014 09:36:21 -0800 Subject: [PATCH] Particles now collide with avatars, but avatars don't react yet. --- .../particles/src/ParticleCollisionSystem.cpp | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index 0c36022c75..68898087d7 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -133,12 +133,17 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { if (_selfAvatar) { AvatarData* avatar = (AvatarData*)_selfAvatar; //printf("updateCollisionWithAvatars()..._selfAvatar=%p\n", avatar); - + // check hands... const HandData* handData = avatar->getHandData(); - // if the particle penetrates the hand, then apply a hard collision + // TODO: combine hand and collision check into one. Note: would need to supply + // CollisionInfo class rather than just vec3 (penetration) so we can get back + // added velocity. + if (handData->findSpherePenetration(center, radius, penetration, collidingPalm)) { + // TODO: dot collidingPalm and hand velocities and skip collision when they are moving apart. + // apply a hard collision when ball collides with hand penetration /= (float)TREE_SCALE; updateCollisionSound(particle, penetration, VOXEL_COLLISION_FREQUENCY); @@ -150,6 +155,12 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { addedVelocity = palmVelocity; } + applyHardCollision(particle, penetration, VOXEL_ELASTICITY, VOXEL_DAMPING, addedVelocity); + } else if (avatar->findSpherePenetration(center, radius, penetration)) { + // apply hard collision when particle collides with avatar + penetration /= (float)TREE_SCALE; + updateCollisionSound(particle, penetration, VOXEL_COLLISION_FREQUENCY); + glm::vec3 addedVelocity = avatar->getVelocity(); applyHardCollision(particle, penetration, VOXEL_ELASTICITY, VOXEL_DAMPING, addedVelocity); } } @@ -159,14 +170,15 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { //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 the particle penetrates the hand, then apply a hard collision if (handData->findSpherePenetration(center, radius, penetration, collidingPalm)) { + // apply a hard collision when ball collides with hand penetration /= (float)TREE_SCALE; updateCollisionSound(particle, penetration, VOXEL_COLLISION_FREQUENCY); @@ -180,6 +192,11 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { applyHardCollision(particle, penetration, VOXEL_ELASTICITY, VOXEL_DAMPING, addedVelocity); + } else if (avatar->findSpherePenetration(center, radius, penetration)) { + penetration /= (float)TREE_SCALE; + updateCollisionSound(particle, penetration, VOXEL_COLLISION_FREQUENCY); + glm::vec3 addedVelocity = avatar->getVelocity(); + applyHardCollision(particle, penetration, VOXEL_ELASTICITY, VOXEL_DAMPING, addedVelocity); } } }