From 5c3da41067a292f87ecdde17fb71c01babee2e3a Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 15 Sep 2016 14:51:05 -0700 Subject: [PATCH 1/8] fix windows build --- libraries/physics/src/CharacterRayResult.cpp | 0 libraries/physics/src/CharacterSweepResult.cpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 libraries/physics/src/CharacterRayResult.cpp mode change 100644 => 100755 libraries/physics/src/CharacterSweepResult.cpp diff --git a/libraries/physics/src/CharacterRayResult.cpp b/libraries/physics/src/CharacterRayResult.cpp old mode 100644 new mode 100755 diff --git a/libraries/physics/src/CharacterSweepResult.cpp b/libraries/physics/src/CharacterSweepResult.cpp old mode 100644 new mode 100755 From 83157b573a9002b31d82bb0f7b15bda60531918d Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 15 Sep 2016 14:51:21 -0700 Subject: [PATCH 2/8] measure max hips offset and clamp it in IK --- interface/src/avatar/MyAvatar.cpp | 10 ++++- .../animation/src/AnimInverseKinematics.cpp | 10 +++++ .../animation/src/AnimInverseKinematics.h | 3 ++ libraries/animation/src/Rig.cpp | 13 +++++++ libraries/animation/src/Rig.h | 1 + libraries/physics/src/CharacterController.cpp | 31 ++++++++++++++- libraries/physics/src/CharacterController.h | 3 +- .../physics/src/CharacterGhostObject.cpp | 38 ++++++++++--------- libraries/physics/src/CharacterGhostObject.h | 9 +++-- 9 files changed, 92 insertions(+), 26 deletions(-) mode change 100644 => 100755 interface/src/avatar/MyAvatar.cpp mode change 100644 => 100755 libraries/physics/src/CharacterController.cpp mode change 100644 => 100755 libraries/physics/src/CharacterGhostObject.cpp mode change 100644 => 100755 libraries/physics/src/CharacterGhostObject.h diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp old mode 100644 new mode 100755 index 9978d915fd..1ace282023 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1354,7 +1354,15 @@ void MyAvatar::prepareForPhysicsSimulation() { } void MyAvatar::harvestResultsFromPhysicsSimulation(float deltaTime) { - // ANDREW TODO -- measure maxHipOffsetRadius here and transmit that to Rig + // figoure out how far the hips can move before they hit something + int hipsJoint = getJointIndex("Hips"); + glm::vec3 hipsPosition; // rig-frame + // OUTOFBODY_HACK -- hardcoded maxHipsOffsetRadius (ultimately must exceed FollowHelper lateral/forward/back walk thresholds) + float maxHipsOffsetRadius = 3.0f * _characterController.getCapsuleRadius(); + if (_rig->getJointPosition(hipsJoint, hipsPosition)) { + maxHipsOffsetRadius = _characterController.measureMaxHipsOffsetRadius(hipsPosition, maxHipsOffsetRadius); + } + _rig->setMaxHipsOffsetLength(maxHipsOffsetRadius); glm::vec3 position = getPosition(); glm::quat orientation = getOrientation(); diff --git a/libraries/animation/src/AnimInverseKinematics.cpp b/libraries/animation/src/AnimInverseKinematics.cpp index 27300699c4..48e3fdb978 100644 --- a/libraries/animation/src/AnimInverseKinematics.cpp +++ b/libraries/animation/src/AnimInverseKinematics.cpp @@ -535,6 +535,11 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars // smooth transitions by relaxing _hipsOffset toward the new value const float HIPS_OFFSET_SLAVE_TIMESCALE = 0.15f; float tau = dt < HIPS_OFFSET_SLAVE_TIMESCALE ? dt / HIPS_OFFSET_SLAVE_TIMESCALE : 1.0f; + float newOffsetLength = glm::length(newHipsOffset); + if (newOffsetLength > _maxHipsOffsetLength) { + // clamp the hips offset + newHipsOffset *= _maxHipsOffsetLength / newOffsetLength; + } _hipsOffset += (newHipsOffset - _hipsOffset) * tau; } } @@ -548,6 +553,11 @@ void AnimInverseKinematics::clearIKJointLimitHistory() { } } +void AnimInverseKinematics::setMaxHipsOffsetLength(float maxLength) { + assert(maxLength > 0.0f); + _maxHipsOffsetLength = maxLength; +} + RotationConstraint* AnimInverseKinematics::getConstraint(int index) { RotationConstraint* constraint = nullptr; std::map::iterator constraintItr = _constraints.find(index); diff --git a/libraries/animation/src/AnimInverseKinematics.h b/libraries/animation/src/AnimInverseKinematics.h index c9560c7383..7e4a7e5473 100644 --- a/libraries/animation/src/AnimInverseKinematics.h +++ b/libraries/animation/src/AnimInverseKinematics.h @@ -39,6 +39,8 @@ public: void clearIKJointLimitHistory(); + void setMaxHipsOffsetLength(float maxLength); + protected: void computeTargets(const AnimVariantMap& animVars, std::vector& targets, const AnimPoseVec& underPoses); void solveWithCyclicCoordinateDescent(const std::vector& targets); @@ -83,6 +85,7 @@ protected: // experimental data for moving hips during IK glm::vec3 _hipsOffset { Vectors::ZERO }; + float _maxHipsOffsetLength { 1.0f }; int _headIndex { -1 }; int _hipsIndex { -1 }; int _hipsParentIndex { -1 }; diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 2d11a1e17f..240190ae2c 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -310,6 +310,19 @@ void Rig::clearIKJointLimitHistory() { } } +void Rig::setMaxHipsOffsetLength(float maxLength) { + if (_animNode) { + _animNode->traverse([&](AnimNode::Pointer node) { + // only report clip nodes as valid roles. + auto ikNode = std::dynamic_pointer_cast(node); + if (ikNode) { + ikNode->setMaxHipsOffsetLength(maxLength); + } + return true; + }); + } +} + void Rig::setJointTranslation(int index, bool valid, const glm::vec3& translation, float priority) { if (isIndexValid(index)) { if (valid) { diff --git a/libraries/animation/src/Rig.h b/libraries/animation/src/Rig.h index 7eb0316889..f0cc68a828 100644 --- a/libraries/animation/src/Rig.h +++ b/libraries/animation/src/Rig.h @@ -104,6 +104,7 @@ public: void clearJointAnimationPriority(int index); void clearIKJointLimitHistory(); + void setMaxHipsOffsetLength(float maxLength); // geometry space void setJointState(int index, bool valid, const glm::quat& rotation, const glm::vec3& translation, float priority); diff --git a/libraries/physics/src/CharacterController.cpp b/libraries/physics/src/CharacterController.cpp old mode 100644 new mode 100755 index d3a38ed533..256b64421b --- a/libraries/physics/src/CharacterController.cpp +++ b/libraries/physics/src/CharacterController.cpp @@ -323,7 +323,7 @@ void CharacterController::setState(State desiredState) { } } -void CharacterController::setLocalBoundingBox(const glm::vec3& corner, const glm::vec3& scale) { +void CharacterController::setLocalBoundingBox(const glm::vec3& minCorner, const glm::vec3& scale) { _boxScale = scale; float x = _boxScale.x; @@ -350,7 +350,7 @@ void CharacterController::setLocalBoundingBox(const glm::vec3& corner, const glm } // it's ok to change offset immediately -- there are no thread safety issues here - _shapeLocalOffset = corner + 0.5f * _boxScale; + _shapeLocalOffset = minCorner + 0.5f * _boxScale; } void CharacterController::setCollisionGroup(int16_t group) { @@ -724,6 +724,33 @@ void CharacterController::setFlyingAllowed(bool value) { } } +float CharacterController::measureMaxHipsOffsetRadius(const glm::vec3& currentHipsOffset, float maxSweepDistance) { + btVector3 hipsOffset = glmToBullet(currentHipsOffset); // rig-frame + btScalar hipsOffsetLength = hipsOffset.length(); + if (hipsOffsetLength > FLT_EPSILON) { + const btTransform& transform = _rigidBody->getWorldTransform(); + + // rotate into world-frame + btTransform rotation = transform; + rotation.setOrigin(btVector3(0.0f, 0.0f, 0.0f)); + btVector3 startPos = transform.getOrigin() - rotation * glmToBullet(_shapeLocalOffset); + btVector3 endPos = startPos + rotation * ((maxSweepDistance / hipsOffsetLength) * hipsOffset); + + // sweep test a sphere + btSphereShape sphere(_radius); + CharacterSweepResult result(&_ghost); + btTransform endTransform = transform; + endTransform.setOrigin(endPos); + _ghost.sweepTest(&sphere, transform, endTransform, result); + + // measure sweep success + if (result.hasHit()) { + maxSweepDistance *= result.m_closestHitFraction; + } + } + return maxSweepDistance; +} + void CharacterController::setMoveKinematically(bool kinematic) { if (kinematic != _moveKinematically) { _moveKinematically = kinematic; diff --git a/libraries/physics/src/CharacterController.h b/libraries/physics/src/CharacterController.h index 3b1ec6e945..2a3a81b416 100644 --- a/libraries/physics/src/CharacterController.h +++ b/libraries/physics/src/CharacterController.h @@ -110,7 +110,7 @@ public: State getState() const { return _state; } - void setLocalBoundingBox(const glm::vec3& corner, const glm::vec3& scale); + void setLocalBoundingBox(const glm::vec3& minCorner, const glm::vec3& scale); bool isEnabledAndReady() const { return _dynamicsWorld; } @@ -122,6 +122,7 @@ public: void setFlyingAllowed(bool value); + float measureMaxHipsOffsetRadius(const glm::vec3& currentHipsOffset, float maxSweepDistance); void setMoveKinematically(bool kinematic); // KINEMATIC_CONTROLLER_HACK protected: diff --git a/libraries/physics/src/CharacterGhostObject.cpp b/libraries/physics/src/CharacterGhostObject.cpp old mode 100644 new mode 100755 index c503f8a927..903d84c646 --- a/libraries/physics/src/CharacterGhostObject.cpp +++ b/libraries/physics/src/CharacterGhostObject.cpp @@ -29,6 +29,8 @@ CharacterGhostObject::~CharacterGhostObject() { } } +const int16_t wtf = 9; // adebug wtf? + void CharacterGhostObject::setCollisionGroupAndMask(int16_t group, int16_t mask) { _collisionFilterGroup = group; _collisionFilterMask = mask; @@ -199,6 +201,24 @@ void CharacterGhostObject::move(btScalar dt, btScalar overshoot) { updateTraction(); } +bool CharacterGhostObject::sweepTest( + const btConvexShape* shape, + const btTransform& start, + const btTransform& end, + CharacterSweepResult& result) const { + if (_world && _inWorld) { + assert(shape); + + btScalar allowedPenetration = _world->getDispatchInfo().m_allowedCcdPenetration; + convexSweepTest(shape, start, end, result, allowedPenetration); + + if (result.hasHit()) { + return true; + } + } + return false; +} + void CharacterGhostObject::removeFromWorld() { if (_world && _inWorld) { _world->removeCollisionObject(this); @@ -218,24 +238,6 @@ void CharacterGhostObject::addToWorld() { } } -bool CharacterGhostObject::sweepTest( - const btConvexShape* shape, - const btTransform& start, - const btTransform& end, - CharacterSweepResult& result) const { - if (_world && _inWorld) { - assert(shape); - - btScalar allowedPenetration = _world->getDispatchInfo().m_allowedCcdPenetration; - convexSweepTest(shape, start, end, result, allowedPenetration); - - if (result.hasHit()) { - return true; - } - } - return false; -} - bool CharacterGhostObject::rayTest(const btVector3& start, const btVector3& end, CharacterRayResult& result) const { diff --git a/libraries/physics/src/CharacterGhostObject.h b/libraries/physics/src/CharacterGhostObject.h old mode 100644 new mode 100755 index 8faf429542..dd2f694a59 --- a/libraries/physics/src/CharacterGhostObject.h +++ b/libraries/physics/src/CharacterGhostObject.h @@ -16,6 +16,7 @@ #include #include +#include #include "CharacterSweepResult.h" #include "CharacterRayResult.h" @@ -45,14 +46,14 @@ public: void move(btScalar dt, btScalar overshoot); -protected: - void removeFromWorld(); - void addToWorld(); - bool sweepTest(const btConvexShape* shape, const btTransform& start, const btTransform& end, CharacterSweepResult& result) const; +protected: + void removeFromWorld(); + void addToWorld(); + bool rayTest(const btVector3& start, const btVector3& end, CharacterRayResult& result) const; From 7f381ac4c4045b113bde0fce913cbe2becb1e986 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 15 Sep 2016 15:33:04 -0700 Subject: [PATCH 3/8] remove unused variables --- libraries/physics/src/CharacterGhostObject.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libraries/physics/src/CharacterGhostObject.cpp b/libraries/physics/src/CharacterGhostObject.cpp index 903d84c646..bdd147fb74 100755 --- a/libraries/physics/src/CharacterGhostObject.cpp +++ b/libraries/physics/src/CharacterGhostObject.cpp @@ -17,8 +17,6 @@ #include "CharacterGhostShape.h" #include "CharacterRayResult.h" -const btScalar DEFAULT_STEP_UP_HEIGHT = 0.5f; - CharacterGhostObject::~CharacterGhostObject() { removeFromWorld(); @@ -29,8 +27,6 @@ CharacterGhostObject::~CharacterGhostObject() { } } -const int16_t wtf = 9; // adebug wtf? - void CharacterGhostObject::setCollisionGroupAndMask(int16_t group, int16_t mask) { _collisionFilterGroup = group; _collisionFilterMask = mask; From 20418d5f58c49a5565ec599232342445408a74d4 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 15 Sep 2016 18:39:57 -0700 Subject: [PATCH 4/8] fix hips sweep test --- interface/src/avatar/MyAvatar.cpp | 5 +++- .../animation/src/AnimInverseKinematics.cpp | 25 ++++++++++++++++--- libraries/physics/src/CharacterController.cpp | 6 +++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 1ace282023..d3acc15be6 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1354,12 +1354,15 @@ void MyAvatar::prepareForPhysicsSimulation() { } void MyAvatar::harvestResultsFromPhysicsSimulation(float deltaTime) { - // figoure out how far the hips can move before they hit something + // figure out how far the hips can move before they hit something int hipsJoint = getJointIndex("Hips"); glm::vec3 hipsPosition; // rig-frame // OUTOFBODY_HACK -- hardcoded maxHipsOffsetRadius (ultimately must exceed FollowHelper lateral/forward/back walk thresholds) float maxHipsOffsetRadius = 3.0f * _characterController.getCapsuleRadius(); if (_rig->getJointPosition(hipsJoint, hipsPosition)) { + // OUTOFBODY_HACK -- flip PI about yAxis + hipsPosition.x *= -1.0f; + hipsPosition.z *= -1.0f; maxHipsOffsetRadius = _characterController.measureMaxHipsOffsetRadius(hipsPosition, maxHipsOffsetRadius); } _rig->setMaxHipsOffsetLength(maxHipsOffsetRadius); diff --git a/libraries/animation/src/AnimInverseKinematics.cpp b/libraries/animation/src/AnimInverseKinematics.cpp index 48e3fdb978..68fc0b45dc 100644 --- a/libraries/animation/src/AnimInverseKinematics.cpp +++ b/libraries/animation/src/AnimInverseKinematics.cpp @@ -505,6 +505,12 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars // measure new _hipsOffset for next frame // by looking for discrepancies between where a targeted endEffector is // and where it wants to be (after IK solutions are done) + + // OUTOFBODY_HACK:use weighted average between HMD and other targets + // ANDREW TODO: change how HMD IK target is handled to allow torso to lean over + float HMD_WEIGHT = 10.0f; + float OTHER_WEIGHT = 1.0f; + float totalWeight = 0.0f; glm::vec3 newHipsOffset = Vectors::ZERO; for (auto& target: targets) { int targetIndex = target.getIndex(); @@ -516,21 +522,32 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars glm::vec3 under = _skeleton->getAbsolutePose(_headIndex, underPoses).trans; glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans; const float HEAD_OFFSET_SLAVE_FACTOR = 0.65f; - newHipsOffset += HEAD_OFFSET_SLAVE_FACTOR * (actual - under); + newHipsOffset += (OTHER_WEIGHT * HEAD_OFFSET_SLAVE_FACTOR) * (actual - under); + totalWeight += OTHER_WEIGHT; } else if (target.getType() == IKTarget::Type::HmdHead) { + /* OUTOFBODY_HACK: keep this old code to remind us of what changed // we want to shift the hips to bring the head to its designated position glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans; _hipsOffset += target.getTranslation() - actual; // and ignore all other targets newHipsOffset = _hipsOffset; break; + */ + glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans; + newHipsOffset += HMD_WEIGHT * (target.getTranslation() - actual); + totalWeight += HMD_WEIGHT; } } else if (target.getType() == IKTarget::Type::RotationAndPosition) { glm::vec3 actualPosition = _skeleton->getAbsolutePose(targetIndex, _relativePoses).trans; glm::vec3 targetPosition = target.getTranslation(); - newHipsOffset += targetPosition - actualPosition; + newHipsOffset += OTHER_WEIGHT * (targetPosition - actualPosition); + totalWeight += OTHER_WEIGHT; } } + if (totalWeight == 0.0f) { + totalWeight = 1.0f; + } + newHipsOffset /= totalWeight; // smooth transitions by relaxing _hipsOffset toward the new value const float HIPS_OFFSET_SLAVE_TIMESCALE = 0.15f; @@ -555,7 +572,9 @@ void AnimInverseKinematics::clearIKJointLimitHistory() { void AnimInverseKinematics::setMaxHipsOffsetLength(float maxLength) { assert(maxLength > 0.0f); - _maxHipsOffsetLength = maxLength; + // OUTOFBODY_HACK: manually adjust scale here + const float METERS_TO_CENTIMETERS = 100.0f; + _maxHipsOffsetLength = METERS_TO_CENTIMETERS * maxLength; } RotationConstraint* AnimInverseKinematics::getConstraint(int index) { diff --git a/libraries/physics/src/CharacterController.cpp b/libraries/physics/src/CharacterController.cpp index 256b64421b..9f5a88847f 100755 --- a/libraries/physics/src/CharacterController.cpp +++ b/libraries/physics/src/CharacterController.cpp @@ -734,14 +734,16 @@ float CharacterController::measureMaxHipsOffsetRadius(const glm::vec3& currentHi btTransform rotation = transform; rotation.setOrigin(btVector3(0.0f, 0.0f, 0.0f)); btVector3 startPos = transform.getOrigin() - rotation * glmToBullet(_shapeLocalOffset); + btTransform startTransform = transform; + startTransform.setOrigin(startPos); btVector3 endPos = startPos + rotation * ((maxSweepDistance / hipsOffsetLength) * hipsOffset); // sweep test a sphere btSphereShape sphere(_radius); CharacterSweepResult result(&_ghost); - btTransform endTransform = transform; + btTransform endTransform = startTransform; endTransform.setOrigin(endPos); - _ghost.sweepTest(&sphere, transform, endTransform, result); + _ghost.sweepTest(&sphere, startTransform, endTransform, result); // measure sweep success if (result.hasHit()) { From 61a05eb4d103e7d318f60e9b3f36d892b7d01198 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 16 Sep 2016 10:16:18 -0700 Subject: [PATCH 5/8] failed experiment for getting hip lean over table --- .../animation/src/AnimInverseKinematics.cpp | 41 ++++++++++++------- .../animation/src/AnimInverseKinematics.h | 1 + 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/libraries/animation/src/AnimInverseKinematics.cpp b/libraries/animation/src/AnimInverseKinematics.cpp index 68fc0b45dc..059f192f3c 100644 --- a/libraries/animation/src/AnimInverseKinematics.cpp +++ b/libraries/animation/src/AnimInverseKinematics.cpp @@ -244,6 +244,11 @@ int AnimInverseKinematics::solveTargetWithCCD(const IKTarget& target, AnimPoseVe // the tip's parent-relative as we proceed up the chain glm::quat tipParentOrientation = absolutePoses[pivotIndex].rot; + /* OUTOFBODY_HACK -- experimental override target type when HmdHead pushes outside hipsOffset limit + if (targetType == IKTarget::Type::HmdHead && _hipsAreOver) { + targetType = IKTarget::Type::RotationAndPosition; + } + */ if (targetType == IKTarget::Type::HmdHead) { // rotate tip directly to target orientation tipOrientation = target.getRotation(); @@ -525,17 +530,19 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars newHipsOffset += (OTHER_WEIGHT * HEAD_OFFSET_SLAVE_FACTOR) * (actual - under); totalWeight += OTHER_WEIGHT; } else if (target.getType() == IKTarget::Type::HmdHead) { - /* OUTOFBODY_HACK: keep this old code to remind us of what changed - // we want to shift the hips to bring the head to its designated position glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans; - _hipsOffset += target.getTranslation() - actual; - // and ignore all other targets - newHipsOffset = _hipsOffset; - break; - */ - glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans; - newHipsOffset += HMD_WEIGHT * (target.getTranslation() - actual); - totalWeight += HMD_WEIGHT; + glm::vec3 thisOffset = target.getTranslation() - actual; + glm::vec3 futureHipsOffset = _hipsOffset + thisOffset; + if (glm::length(futureHipsOffset) < _maxHipsOffsetLength) { + // it is imperative to shift the hips and bring the head to its designated position + // so we slam newHipsOffset here and ignore all other targets + newHipsOffset = futureHipsOffset; + totalWeight = 0.0f; + break; + } else { + newHipsOffset += HMD_WEIGHT * (target.getTranslation() - actual); + totalWeight += HMD_WEIGHT; + } } } else if (target.getType() == IKTarget::Type::RotationAndPosition) { glm::vec3 actualPosition = _skeleton->getAbsolutePose(targetIndex, _relativePoses).trans; @@ -544,13 +551,12 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars totalWeight += OTHER_WEIGHT; } } - if (totalWeight == 0.0f) { - totalWeight = 1.0f; + if (totalWeight > 1.0f) { + newHipsOffset /= totalWeight; } - newHipsOffset /= totalWeight; // smooth transitions by relaxing _hipsOffset toward the new value - const float HIPS_OFFSET_SLAVE_TIMESCALE = 0.15f; + const float HIPS_OFFSET_SLAVE_TIMESCALE = 0.10f; float tau = dt < HIPS_OFFSET_SLAVE_TIMESCALE ? dt / HIPS_OFFSET_SLAVE_TIMESCALE : 1.0f; float newOffsetLength = glm::length(newHipsOffset); if (newOffsetLength > _maxHipsOffsetLength) { @@ -558,6 +564,13 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars newHipsOffset *= _maxHipsOffsetLength / newOffsetLength; } _hipsOffset += (newHipsOffset - _hipsOffset) * tau; + /* OUTOFBODY_HACK: experimental code for disabling HmdHead IK behavior when hips over limit + if (_hipsAreOver) { + _hipsAreOver = glm::length(newHipsOffset) - _maxHipsOffsetLength > -1.0f; + } else { + _hipsAreOver = glm::length(newHipsOffset) - _maxHipsOffsetLength > 1.0f; + } + */ } } } diff --git a/libraries/animation/src/AnimInverseKinematics.h b/libraries/animation/src/AnimInverseKinematics.h index 7e4a7e5473..5b83b9734e 100644 --- a/libraries/animation/src/AnimInverseKinematics.h +++ b/libraries/animation/src/AnimInverseKinematics.h @@ -86,6 +86,7 @@ protected: // experimental data for moving hips during IK glm::vec3 _hipsOffset { Vectors::ZERO }; float _maxHipsOffsetLength { 1.0f }; + bool _hipsAreOver { false }; // OUTOFBODY_HACK: experimental int _headIndex { -1 }; int _hipsIndex { -1 }; int _hipsParentIndex { -1 }; From 49224d9698284b96d6496a08a5b565b35a56069f Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 16 Sep 2016 14:50:08 -0700 Subject: [PATCH 6/8] avoid unecessary branch --- libraries/physics/src/CharacterGhostObject.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libraries/physics/src/CharacterGhostObject.cpp b/libraries/physics/src/CharacterGhostObject.cpp index bdd147fb74..6529f2c944 100755 --- a/libraries/physics/src/CharacterGhostObject.cpp +++ b/libraries/physics/src/CharacterGhostObject.cpp @@ -204,13 +204,9 @@ bool CharacterGhostObject::sweepTest( CharacterSweepResult& result) const { if (_world && _inWorld) { assert(shape); - btScalar allowedPenetration = _world->getDispatchInfo().m_allowedCcdPenetration; convexSweepTest(shape, start, end, result, allowedPenetration); - - if (result.hasHit()) { - return true; - } + return result.hasHit(); } return false; } From a58773823d31311a99603d8df4ff6e8f7187b2ac Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 16 Sep 2016 14:50:29 -0700 Subject: [PATCH 7/8] cleanup unused cruft --- libraries/animation/src/AnimInverseKinematics.cpp | 15 +-------------- libraries/animation/src/AnimInverseKinematics.h | 1 - 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/libraries/animation/src/AnimInverseKinematics.cpp b/libraries/animation/src/AnimInverseKinematics.cpp index 059f192f3c..15774141cc 100644 --- a/libraries/animation/src/AnimInverseKinematics.cpp +++ b/libraries/animation/src/AnimInverseKinematics.cpp @@ -244,11 +244,6 @@ int AnimInverseKinematics::solveTargetWithCCD(const IKTarget& target, AnimPoseVe // the tip's parent-relative as we proceed up the chain glm::quat tipParentOrientation = absolutePoses[pivotIndex].rot; - /* OUTOFBODY_HACK -- experimental override target type when HmdHead pushes outside hipsOffset limit - if (targetType == IKTarget::Type::HmdHead && _hipsAreOver) { - targetType = IKTarget::Type::RotationAndPosition; - } - */ if (targetType == IKTarget::Type::HmdHead) { // rotate tip directly to target orientation tipOrientation = target.getRotation(); @@ -512,10 +507,10 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars // and where it wants to be (after IK solutions are done) // OUTOFBODY_HACK:use weighted average between HMD and other targets - // ANDREW TODO: change how HMD IK target is handled to allow torso to lean over float HMD_WEIGHT = 10.0f; float OTHER_WEIGHT = 1.0f; float totalWeight = 0.0f; + glm::vec3 newHipsOffset = Vectors::ZERO; for (auto& target: targets) { int targetIndex = target.getIndex(); @@ -564,13 +559,6 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars newHipsOffset *= _maxHipsOffsetLength / newOffsetLength; } _hipsOffset += (newHipsOffset - _hipsOffset) * tau; - /* OUTOFBODY_HACK: experimental code for disabling HmdHead IK behavior when hips over limit - if (_hipsAreOver) { - _hipsAreOver = glm::length(newHipsOffset) - _maxHipsOffsetLength > -1.0f; - } else { - _hipsAreOver = glm::length(newHipsOffset) - _maxHipsOffsetLength > 1.0f; - } - */ } } } @@ -584,7 +572,6 @@ void AnimInverseKinematics::clearIKJointLimitHistory() { } void AnimInverseKinematics::setMaxHipsOffsetLength(float maxLength) { - assert(maxLength > 0.0f); // OUTOFBODY_HACK: manually adjust scale here const float METERS_TO_CENTIMETERS = 100.0f; _maxHipsOffsetLength = METERS_TO_CENTIMETERS * maxLength; diff --git a/libraries/animation/src/AnimInverseKinematics.h b/libraries/animation/src/AnimInverseKinematics.h index 5b83b9734e..7e4a7e5473 100644 --- a/libraries/animation/src/AnimInverseKinematics.h +++ b/libraries/animation/src/AnimInverseKinematics.h @@ -86,7 +86,6 @@ protected: // experimental data for moving hips during IK glm::vec3 _hipsOffset { Vectors::ZERO }; float _maxHipsOffsetLength { 1.0f }; - bool _hipsAreOver { false }; // OUTOFBODY_HACK: experimental int _headIndex { -1 }; int _hipsIndex { -1 }; int _hipsParentIndex { -1 }; From 91ff9722ec25a9b7188497b0d027f0d16e4aa204 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 16 Sep 2016 15:23:41 -0700 Subject: [PATCH 8/8] remove crufty comments --- libraries/animation/src/Rig.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 240190ae2c..2d44a660a6 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -300,7 +300,6 @@ void Rig::clearJointAnimationPriority(int index) { void Rig::clearIKJointLimitHistory() { if (_animNode) { _animNode->traverse([&](AnimNode::Pointer node) { - // only report clip nodes as valid roles. auto ikNode = std::dynamic_pointer_cast(node); if (ikNode) { ikNode->clearIKJointLimitHistory(); @@ -313,7 +312,6 @@ void Rig::clearIKJointLimitHistory() { void Rig::setMaxHipsOffsetLength(float maxLength) { if (_animNode) { _animNode->traverse([&](AnimNode::Pointer node) { - // only report clip nodes as valid roles. auto ikNode = std::dynamic_pointer_cast(node); if (ikNode) { ikNode->setMaxHipsOffsetLength(maxLength);