From 66b6328687114ff429ac00b00f0103db316ac3ab Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 10 Apr 2014 16:58:52 -0700 Subject: [PATCH 1/2] protection against bad avatar-avatar collisions Also with logging if we encounter incorrectly large penetration depths --- interface/src/avatar/MyAvatar.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 7a05c593db..6c69fd3e3a 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -62,6 +62,7 @@ MyAvatar::MyAvatar() : _isThrustOn(false), _thrustMultiplier(1.0f), _moveTarget(0,0,0), + _lastBodyPenetration(0.0f), _moveTargetStepCounter(0), _lookAtTargetAvatar(), _shouldRender(true), @@ -681,7 +682,7 @@ void MyAvatar::updateThrust(float deltaTime) { _thrust -= _driveKeys[DOWN] * _scale * THRUST_MAG_DOWN * _thrustMultiplier * deltaTime * up; // attenuate thrust when in penetration - if (glm::dot(_thrust, _lastBodyPenetration) > 0.0f) { + if (glm::dot(_thrust, _lastBodyPenetration) > EPSILON) { const float MAX_BODY_PENETRATION_DEPTH = 0.6f * _skeletonModel.getBoundingShapeRadius(); float penetrationFactor = glm::min(1.0f, glm::length(_lastBodyPenetration) / MAX_BODY_PENETRATION_DEPTH); glm::vec3 penetrationDirection = glm::normalize(_lastBodyPenetration); @@ -932,7 +933,11 @@ void MyAvatar::updateCollisionWithAvatars(float deltaTime) { CollisionInfo collision; if (ShapeCollider::collideShapesCoarse(myShapes, theirShapes, collision)) { - if (glm::length2(collision._penetration) > EPSILON) { + float penetrationDepth = glm::length(collision._penetration); + if (penetrationDepth > myBoundingRadius) { + qDebug() << "WARNING: ignoring avatar-avatar penetration depth " << penetrationDepth; + } + else if (penetrationDepth > EPSILON) { setPosition(getPosition() - BODY_COLLISION_RESOLUTION_FACTOR * collision._penetration); _lastBodyPenetration += collision._penetration; emit collisionWithAvatar(getSessionUUID(), avatar->getSessionUUID(), collision); From f7862eb600056e6f9955af89137281c7aac95164 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 11 Apr 2014 08:58:26 -0700 Subject: [PATCH 2/2] check for bad deltaTime during avatar-avatar collisions --- interface/src/avatar/MyAvatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 6c69fd3e3a..a716d6f49a 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -910,7 +910,7 @@ void MyAvatar::updateCollisionWithAvatars(float deltaTime) { updateShapePositions(); float myBoundingRadius = getBoundingRadius(); - const float BODY_COLLISION_RESOLUTION_FACTOR = deltaTime / BODY_COLLISION_RESOLUTION_TIMESCALE; + const float BODY_COLLISION_RESOLUTION_FACTOR = glm::max(1.0f, deltaTime / BODY_COLLISION_RESOLUTION_TIMESCALE); foreach (const AvatarSharedPointer& avatarPointer, avatars) { Avatar* avatar = static_cast(avatarPointer.data());