First pass at particle-hand collisions using hacked hand capsules.

This commit is contained in:
Andrew Meadows 2014-01-14 16:25:31 -08:00
parent 9847ab3bfd
commit b51699bb2f
2 changed files with 12 additions and 30 deletions

View file

@ -10,6 +10,7 @@
#include <AbstractAudioInterface.h> #include <AbstractAudioInterface.h>
#include <VoxelTree.h> #include <VoxelTree.h>
#include <AvatarData.h> #include <AvatarData.h>
#include <CollisionInfo.h>
#include <HeadData.h> #include <HeadData.h>
#include <HandData.h> #include <HandData.h>
@ -153,39 +154,20 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) {
// first check the selfAvatar if set... // first check the selfAvatar if set...
if (_selfAvatar) { if (_selfAvatar) {
AvatarData* avatar = (AvatarData*)_selfAvatar; AvatarData* avatar = (AvatarData*)_selfAvatar;
//printf("updateCollisionWithAvatars()..._selfAvatar=%p\n", avatar); CollisionInfo collision;
if (avatar->findSphereCollision(center, radius, collision)) {
// check hands... if (glm::dot(particle->getVelocity(), collision._addedVelocity) < 0.f) {
const HandData* handData = avatar->getHandData(); collision._penetration /= (float)(TREE_SCALE);
collision._addedVelocity /= (float)(TREE_SCALE);
// TODO: combine hand and collision check into one. Note: would need to supply glm::vec3 pv = particle->getVelocity();
// CollisionInfo class rather than just vec3 (penetration) so we can get back updateCollisionSound(particle, collision._penetration, COLLISION_FREQUENCY);
// added velocity. applyHardCollision(particle, collision._penetration, ELASTICITY, DAMPING, collision._addedVelocity);
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, 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;
} }
applyHardCollision(particle, penetration, ELASTICITY, DAMPING, addedVelocity);
} else if (avatar->findSpherePenetration(center, radius, penetration)) {
// apply hard collision when particle collides with avatar
penetration /= (float)(TREE_SCALE);
updateCollisionSound(particle, penetration, COLLISION_FREQUENCY);
glm::vec3 addedVelocity = avatar->getVelocity();
applyHardCollision(particle, penetration, ELASTICITY, DAMPING, addedVelocity);
} }
} }
// TODO: convert other avatars to collide like _selfAvatar
// loop through all the other avatars for potential interactions... // loop through all the other avatars for potential interactions...
NodeList* nodeList = NodeList::getInstance(); NodeList* nodeList = NodeList::getInstance();
for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) { for (NodeList::iterator node = nodeList->begin(); node != nodeList->end(); node++) {

View file

@ -61,4 +61,4 @@ private:
AvatarData* _selfAvatar; AvatarData* _selfAvatar;
}; };
#endif /* defined(__hifi__ParticleCollisionSystem__) */ #endif /* defined(__hifi__ParticleCollisionSystem__) */