Showing the changes to interface/src/avatar/SkeletonModel.cpp (1 of 7 files). Show all
Unified · Split
| @@ -22,12 +22,6 @@ · 21 unmodified lines | |||
| 22 | #include "Util.h" | 22 | #include "Util.h" |
| 23 | #include "InterfaceLogging.h" | 23 | #include "InterfaceLogging.h" |
| 24 | 24 | ||
| 25 | enum StandingFootState { | ||
| 26 | LEFT_FOOT, | ||
| 27 | RIGHT_FOOT, | ||
| 28 | NO_FOOT | ||
| 29 | }; | ||
| 30 | |||
| 31 | SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer rig) : | 25 | SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer rig) : |
| 32 | Model(rig, parent), | 26 | Model(rig, parent), |
| 33 | _triangleFanID(DependencyManager::get<GeometryCache>()->allocateID()), | 27 | _triangleFanID(DependencyManager::get<GeometryCache>()->allocateID()), |
| @@ -36,9 +30,6 @@ SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent, RigPointer r · 2 unmodified lines | |||
| 36 | _boundingCapsuleRadius(0.0f), | 30 | _boundingCapsuleRadius(0.0f), |
| 37 | _boundingCapsuleHeight(0.0f), | 31 | _boundingCapsuleHeight(0.0f), |
| 38 | _defaultEyeModelPosition(glm::vec3(0.0f, 0.0f, 0.0f)), | 32 | _defaultEyeModelPosition(glm::vec3(0.0f, 0.0f, 0.0f)), |
| 39 | _standingFoot(NO_FOOT), | ||
| 40 | _standingOffset(0.0f), | ||
| 41 | _clampedFootPosition(0.0f), | ||
| 42 | _headClipDistance(DEFAULT_NEAR_CLIP) | 33 | _headClipDistance(DEFAULT_NEAR_CLIP) |
| 43 | { | 34 | { |
| 44 | assert(_rig); | 35 | assert(_rig); |
| @@ -534,65 +525,6 @@ glm::vec3 SkeletonModel::getDefaultEyeModelPosition() const { · 489 unmodified lines | |||
| 534 | return _owningAvatar->getScale() * _defaultEyeModelPosition; | 525 | return _owningAvatar->getScale() * _defaultEyeModelPosition; |
| 535 | } | 526 | } |
| 536 | 527 | ||
| 537 | /// \return offset of hips after foot animation | ||
| 538 | void SkeletonModel::updateStandingFoot() { | ||
| 539 | if (_geometry == NULL) { | ||
| 540 | return; | ||
| 541 | } | ||
| 542 | glm::vec3 offset(0.0f); | ||
| 543 | int leftFootIndex = _geometry->getFBXGeometry().leftToeJointIndex; | ||
| 544 | int rightFootIndex = _geometry->getFBXGeometry().rightToeJointIndex; | ||
| 545 | |||
| 546 | if (leftFootIndex != -1 && rightFootIndex != -1) { | ||
| 547 | glm::vec3 leftPosition, rightPosition; | ||
| 548 | getJointPosition(leftFootIndex, leftPosition); | ||
| 549 | getJointPosition(rightFootIndex, rightPosition); | ||
| 550 | |||
| 551 | int lowestFoot = (leftPosition.y < rightPosition.y) ? LEFT_FOOT : RIGHT_FOOT; | ||
| 552 | const float MIN_STEP_HEIGHT_THRESHOLD = 0.05f; | ||
| 553 | bool oneFoot = fabsf(leftPosition.y - rightPosition.y) > MIN_STEP_HEIGHT_THRESHOLD; | ||
| 554 | int currentFoot = oneFoot ? lowestFoot : _standingFoot; | ||
| 555 | |||
| 556 | if (_standingFoot == NO_FOOT) { | ||
| 557 | currentFoot = lowestFoot; | ||
| 558 | } | ||
| 559 | if (currentFoot != _standingFoot) { | ||
| 560 | if (_standingFoot == NO_FOOT) { | ||
| 561 | // pick the lowest foot | ||
| 562 | glm::vec3 lowestPosition = (currentFoot == LEFT_FOOT) ? leftPosition : rightPosition; | ||
| 563 | // we ignore zero length positions which can happen for a few frames until skeleton is fully loaded | ||
| 564 | if (glm::length(lowestPosition) > 0.0f) { | ||
| 565 | _standingFoot = currentFoot; | ||
| 566 | _clampedFootPosition = lowestPosition; | ||
| 567 | } | ||
| 568 | } else { | ||
| 569 | // swap feet | ||
| 570 | _standingFoot = currentFoot; | ||
| 571 | glm::vec3 nextPosition = leftPosition; | ||
| 572 | glm::vec3 prevPosition = rightPosition; | ||
| 573 | if (_standingFoot == RIGHT_FOOT) { | ||
| 574 | nextPosition = rightPosition; | ||
| 575 | prevPosition = leftPosition; | ||
| 576 | } | ||
| 577 | glm::vec3 oldOffset = _clampedFootPosition - prevPosition; | ||
| 578 | _clampedFootPosition = oldOffset + nextPosition; | ||
| 579 | offset = _clampedFootPosition - nextPosition; | ||
| 580 | } | ||
| 581 | } else { | ||
| 582 | glm::vec3 nextPosition = (_standingFoot == LEFT_FOOT) ? leftPosition : rightPosition; | ||
| 583 | offset = _clampedFootPosition - nextPosition; | ||
| 584 | } | ||
| 585 | |||
| 586 | // clamp the offset to not exceed some max distance | ||
| 587 | const float MAX_STEP_OFFSET = 1.0f; | ||
| 588 | float stepDistance = glm::length(offset); | ||
| 589 | if (stepDistance > MAX_STEP_OFFSET) { | ||
| 590 | offset *= (MAX_STEP_OFFSET / stepDistance); | ||
| 591 | } | ||
| 592 | } | ||
| 593 | _standingOffset = offset; | ||
| 594 | } | ||
| 595 | |||
| 596 | float DENSITY_OF_WATER = 1000.0f; // kg/m^3 | 528 | float DENSITY_OF_WATER = 1000.0f; // kg/m^3 |
| 597 | float MIN_JOINT_MASS = 1.0f; | 529 | float MIN_JOINT_MASS = 1.0f; |
| 598 | float VERY_BIG_MASS = 1.0e6f; | 530 | float VERY_BIG_MASS = 1.0e6f; |