From f3f15391118c1ac945dff0fcbf217ffcbb12c6c2 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 30 Jan 2014 09:28:21 -0800 Subject: [PATCH] Splitting avatar collision check in two: vs hands and vs skeleton. --- interface/src/avatar/Avatar.cpp | 7 ++++--- interface/src/avatar/Avatar.h | 11 +++++++++-- libraries/avatars/src/AvatarData.h | 6 +++++- libraries/particles/src/ParticleCollisionSystem.cpp | 3 ++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 68f15a3390..88c7e03011 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -285,9 +285,7 @@ bool Avatar::findSpherePenetration(const glm::vec3& penetratorCenter, float pene return false; } -bool Avatar::findSphereCollision(const glm::vec3& sphereCenter, float sphereRadius, CollisionInfo& collision) { - // TODO: provide an early exit using bounding sphere of entire avatar - +bool Avatar::findSphereCollisionWithHands(const glm::vec3& sphereCenter, float sphereRadius, CollisionInfo& collision) { const HandData* handData = getHandData(); if (handData) { for (int i = 0; i < NUM_HANDS; i++) { @@ -326,7 +324,10 @@ bool Avatar::findSphereCollision(const glm::vec3& sphereCenter, float sphereRadi } } } + return false; +} +bool Avatar::findSphereCollisionWithSkeleton(const glm::vec3& sphereCenter, float sphereRadius, CollisionInfo& collision) { if (_skeletonModel.findSpherePenetration(sphereCenter, sphereRadius, collision._penetration)) { collision._penetration /= (float)(TREE_SCALE); collision._addedVelocity = getVelocity(); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index f6ff411624..1d8d5a1604 100755 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -105,12 +105,19 @@ public: bool findSpherePenetration(const glm::vec3& penetratorCenter, float penetratorRadius, glm::vec3& penetration, int skeletonSkipIndex = -1) const; - /// Checks for collision between the a sphere and the avatar. + /// Checks for collision between the a sphere and the avatar's (paddle) hands. /// \param collisionCenter the center of the penetration test sphere /// \param collisionRadius the radius of the penetration test sphere /// \param collision[out] the details of the collision point /// \return whether or not the sphere collided - virtual bool findSphereCollision(const glm::vec3& sphereCenter, float sphereRadius, CollisionInfo& collision); + bool findSphereCollisionWithHands(const glm::vec3& sphereCenter, float sphereRadius, CollisionInfo& collision); + + /// Checks for collision between the a sphere and the avatar's skeleton (including hand capsules). + /// \param collisionCenter the center of the penetration test sphere + /// \param collisionRadius the radius of the penetration test sphere + /// \param collision[out] the details of the collision point + /// \return whether or not the sphere collided + bool findSphereCollisionWithSkeleton(const glm::vec3& sphereCenter, float sphereRadius, CollisionInfo& collision); virtual bool isMyAvatar() { return false; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 0869445090..aa21b6d9c4 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -138,7 +138,11 @@ public: virtual bool findSpherePenetration(const glm::vec3& penetratorCenter, float penetratorRadius, glm::vec3& penetration, int skeletonSkipIndex = -1) const { return false; } - virtual bool findSphereCollision(const glm::vec3& sphereCenter, float sphereRadius, CollisionInfo& collision) { + virtual bool findSphereCollisionWithHands(const glm::vec3& sphereCenter, float sphereRadius, CollisionInfo& collision) { + return false; + } + + virtual bool findSphereCollisionWithSkeleton(const glm::vec3& sphereCenter, float sphereRadius, CollisionInfo& collision) { return false; } diff --git a/libraries/particles/src/ParticleCollisionSystem.cpp b/libraries/particles/src/ParticleCollisionSystem.cpp index 65c61edaa1..a194aba6ef 100644 --- a/libraries/particles/src/ParticleCollisionSystem.cpp +++ b/libraries/particles/src/ParticleCollisionSystem.cpp @@ -170,7 +170,8 @@ void ParticleCollisionSystem::updateCollisionWithAvatars(Particle* particle) { CollisionInfo collisionInfo; collisionInfo._damping = DAMPING; collisionInfo._elasticity = ELASTICITY; - if (avatar->findSphereCollision(center, radius, collisionInfo)) { + if (avatar->findSphereCollisionWithHands(center, radius, collisionInfo) || + avatar->findSphereCollisionWithSkeleton(center, radius, collisionInfo)) { collisionInfo._addedVelocity /= (float)(TREE_SCALE); glm::vec3 relativeVelocity = collisionInfo._addedVelocity - particle->getVelocity(); if (glm::dot(relativeVelocity, collisionInfo._penetration) < 0.f) {