From 4e4521325d7b3c3e073f968118a7e864ba96fdf2 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Mon, 29 Apr 2013 10:38:29 -0700 Subject: [PATCH] added 'isCollidable' to avatar bone so that some bones do not collide (for handshaking) --- interface/src/Avatar.cpp | 87 ++++++++++++++++++++++------------------ interface/src/Avatar.h | 3 +- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 076d4d2c18..24af81dfdf 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -539,21 +539,23 @@ void Avatar::updateCollisionWithSphere( glm::vec3 position, float radius, float float distanceToBigSphere = glm::length(vectorFromMyBodyToBigSphere); if ( distanceToBigSphere < myBodyApproximateBoundingRadius + radius ) { for (int b = 0; b < NUM_AVATAR_BONES; b++) { - glm::vec3 vectorFromJointToBigSphereCenter(_bone[b].springyPosition - position); - float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter); - float combinedRadius = _bone[b].radius + radius; - - if ( distanceToBigSphereCenter < combinedRadius ) { - jointCollision = true; - if (distanceToBigSphereCenter > 0.0) { - glm::vec3 directionVector = vectorFromJointToBigSphereCenter / distanceToBigSphereCenter; - - float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); - glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; - - _bone[b].springyVelocity += collisionForce * 30.0f * deltaTime; - _velocity += collisionForce * 100.0f * deltaTime; - _bone[b].springyPosition = position + directionVector * combinedRadius; + if ( _bone[b].isCollidable ) { + glm::vec3 vectorFromJointToBigSphereCenter(_bone[b].springyPosition - position); + float distanceToBigSphereCenter = glm::length(vectorFromJointToBigSphereCenter); + float combinedRadius = _bone[b].radius + radius; + + if ( distanceToBigSphereCenter < combinedRadius ) { + jointCollision = true; + if (distanceToBigSphereCenter > 0.0) { + glm::vec3 directionVector = vectorFromJointToBigSphereCenter / distanceToBigSphereCenter; + + float penetration = 1.0 - (distanceToBigSphereCenter / combinedRadius); + glm::vec3 collisionForce = vectorFromJointToBigSphereCenter * penetration; + + _bone[b].springyVelocity += collisionForce * 30.0f * deltaTime; + _velocity += collisionForce * 100.0f * deltaTime; + _bone[b].springyPosition = position + directionVector * combinedRadius; + } } } } @@ -577,27 +579,32 @@ void Avatar::updateCollisionWithOtherAvatar( Avatar * otherAvatar, float deltaTi // loop through the bones of each avatar to check for every possible collision for (int b=1; b_bone[o].springyPosition); + float distanceBetweenJoints = glm::length(vectorBetweenJoints); - glm::vec3 vectorBetweenJoints(_bone[b].springyPosition - otherAvatar->_bone[o].springyPosition); - float distanceBetweenJoints = glm::length(vectorBetweenJoints); - - // to avoid divide by zero - if ( distanceBetweenJoints > 0.0 ) { - float combinedRadius = _bone[b].radius + otherAvatar->_bone[o].radius; + // to avoid divide by zero + if ( distanceBetweenJoints > 0.0 ) { + float combinedRadius = _bone[b].radius + otherAvatar->_bone[o].radius; - // check for collision - if ( distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { - glm::vec3 directionVector = vectorBetweenJoints / distanceBetweenJoints; + // check for collision + if ( distanceBetweenJoints < combinedRadius * COLLISION_RADIUS_SCALAR) { + glm::vec3 directionVector = vectorBetweenJoints / distanceBetweenJoints; - // push ball away from colliding other ball and puch avatar body (_velocity) as well - _bone[b].springyVelocity += directionVector * COLLISION_BALL_FORCE * deltaTime; - _velocity += directionVector * COLLISION_BODY_FORCE * deltaTime; - - // apply fruction to _velocity - float momentum = 1.0 - COLLISION_FRICTION * deltaTime; - if ( momentum < 0.0 ) { momentum = 0.0;} - _velocity *= momentum; + // push ball away from colliding other ball and puch avatar body (_velocity) as well + _bone[b].springyVelocity += directionVector * COLLISION_BALL_FORCE * deltaTime; + _velocity += directionVector * COLLISION_BODY_FORCE * deltaTime; + + // apply fruction to _velocity + float momentum = 1.0 - COLLISION_FRICTION * deltaTime; + if ( momentum < 0.0 ) { momentum = 0.0;} + _velocity *= momentum; + } + } } } } @@ -872,6 +879,7 @@ AvatarMode Avatar::getMode() { void Avatar::initializeSkeleton() { for (int b=0; b