diff --git a/interface/src/avatar/FaceModel.cpp b/interface/src/avatar/FaceModel.cpp index 93cd93b71c..652ecdec32 100644 --- a/interface/src/avatar/FaceModel.cpp +++ b/interface/src/avatar/FaceModel.cpp @@ -51,7 +51,7 @@ void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBX glm::mat3 axes = glm::mat3_cast(glm::quat()); glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransformInModelFrame() * glm::translate(state.getDefaultTranslationInParentFrame()) * joint.preTransform * glm::mat4_cast(joint.preRotation))); - state._rotation = glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getFinalRoll(), glm::normalize(inverse * axes[2])) + state._rotationInParentFrame = glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getFinalRoll(), glm::normalize(inverse * axes[2])) * glm::angleAxis(RADIANS_PER_DEGREE * _owningHead->getFinalYaw(), glm::normalize(inverse * axes[1])) * glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getFinalPitch(), glm::normalize(inverse * axes[0])) * joint.rotation; @@ -68,7 +68,7 @@ void FaceModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJ _owningHead->getSaccade() - _translation, 1.0f)); glm::quat between = rotationBetween(front, lookAt); const float MAX_ANGLE = 30.0f * RADIANS_PER_DEGREE; - state._rotation = glm::angleAxis(glm::clamp(glm::angle(between), -MAX_ANGLE, MAX_ANGLE), glm::axis(between)) * + state._rotationInParentFrame = glm::angleAxis(glm::clamp(glm::angle(between), -MAX_ANGLE, MAX_ANGLE), glm::axis(between)) * joint.rotation; } diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 93374ef3d0..cf9b96cbd1 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -200,7 +200,7 @@ void SkeletonModel::applyPalmDataInModelFrame(int jointIndex, PalmData& palm) { JointState& parentState = _jointStates[parentJointIndex]; parentState.setRotationInModelFrame(palmRotation, PALM_PRIORITY); // lock hand to forearm by slamming its rotation (in parent-frame) to identity - _jointStates[jointIndex]._rotation = glm::quat(); + _jointStates[jointIndex]._rotationInParentFrame = glm::quat(); } else { setJointPositionInModelFrame(jointIndex, palmPosition, palmRotation, true, -1, false, glm::vec3(0.0f, -1.0f, 0.0f), PALM_PRIORITY); @@ -239,7 +239,7 @@ void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, const glm::mat3 axes = glm::mat3_cast(glm::quat()); glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransformInModelFrame() * glm::translate(state.getDefaultTranslationInParentFrame()) * joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation))); - state._rotation = glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanSideways(), + state._rotationInParentFrame = glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanSideways(), glm::normalize(inverse * axes[2])) * glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanForward(), glm::normalize(inverse * axes[0])) * joint.rotation; } diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index df6381d447..d1a8587a5c 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -459,7 +459,7 @@ void Model::reset() { } const FBXGeometry& geometry = _geometry->getFBXGeometry(); for (int i = 0; i < _jointStates.size(); i++) { - _jointStates[i]._rotation = geometry.joints.at(i).rotation; + _jointStates[i]._rotationInParentFrame = geometry.joints.at(i).rotation; } } @@ -669,7 +669,7 @@ bool Model::getJointState(int index, glm::quat& rotation) const { if (index == -1 || index >= _jointStates.size()) { return false; } - rotation = _jointStates.at(index)._rotation; + rotation = _jointStates.at(index)._rotationInParentFrame; const glm::quat& defaultRotation = _geometry->getFBXGeometry().joints.at(index).rotation; return glm::abs(rotation.x - defaultRotation.x) >= EPSILON || glm::abs(rotation.y - defaultRotation.y) >= EPSILON || @@ -682,7 +682,7 @@ void Model::setJointState(int index, bool valid, const glm::quat& rotation, floa JointState& state = _jointStates[index]; if (priority >= state._animationPriority) { if (valid) { - state._rotation = rotation; + state._rotationInParentFrame = rotation; state._animationPriority = priority; } else { state.restoreRotation(1.0f, priority); @@ -1932,7 +1932,7 @@ void AnimationHandle::simulate(float deltaTime) { if (mapping != -1) { JointState& state = _model->_jointStates[mapping]; if (_priority >= state._animationPriority) { - state._rotation = frame.rotations.at(i); + state._rotationInParentFrame = frame.rotations.at(i); state._animationPriority = _priority; } } @@ -1956,7 +1956,7 @@ void AnimationHandle::simulate(float deltaTime) { if (mapping != -1) { JointState& state = _model->_jointStates[mapping]; if (_priority >= state._animationPriority) { - state._rotation = safeMix(floorFrame.rotations.at(i), ceilFrame.rotations.at(i), frameFraction); + state._rotationInParentFrame = safeMix(floorFrame.rotations.at(i), ceilFrame.rotations.at(i), frameFraction); state._animationPriority = _priority; } } @@ -1985,34 +1985,34 @@ JointState::JointState() : void JointState::setFBXJoint(const FBXJoint* joint) { assert(joint != NULL); - _rotation = joint->rotation; + _rotationInParentFrame = joint->rotation; // NOTE: JointState does not own the FBXJoint to which it points. _fbxJoint = joint; } void JointState::copyState(const JointState& state) { - _rotation = state._rotation; - _transformInModelFrame = state._transformInModelFrame; - _rotationInModelFrame = extractRotation(_transformInModelFrame); + _rotationInParentFrame = state._rotationInParentFrame; + _transform = state._transform; + _rotation = extractRotation(_transform); _animationPriority = state._animationPriority; // DO NOT copy _fbxJoint } void JointState::computeTransformInModelFrame(const glm::mat4& parentTransform) { - glm::quat modifiedRotation = _fbxJoint->preRotation * _rotation * _fbxJoint->postRotation; + glm::quat modifiedRotation = _fbxJoint->preRotation * _rotationInParentFrame * _fbxJoint->postRotation; glm::mat4 modifiedTransform = _fbxJoint->preTransform * glm::mat4_cast(modifiedRotation) * _fbxJoint->postTransform; - _transformInModelFrame = parentTransform * glm::translate(_fbxJoint->translation) * modifiedTransform; - _rotationInModelFrame = extractRotation(_transformInModelFrame); + _transform = parentTransform * glm::translate(_fbxJoint->translation) * modifiedTransform; + _rotation = extractRotation(_transform); } glm::quat JointState::getRotationFromBindToModelFrame() const { - return _rotationInModelFrame * _fbxJoint->inverseBindRotation; + return _rotation * _fbxJoint->inverseBindRotation; } void JointState::restoreRotation(float fraction, float priority) { assert(_fbxJoint != NULL); if (priority == _animationPriority) { - _rotation = safeMix(_rotation, _fbxJoint->rotation, fraction); + _rotationInParentFrame = safeMix(_rotationInParentFrame, _fbxJoint->rotation, fraction); _animationPriority = 0.0f; } } @@ -2020,15 +2020,15 @@ void JointState::restoreRotation(float fraction, float priority) { void JointState::setRotationInModelFrame(const glm::quat& rotation, float priority) { assert(_fbxJoint != NULL); if (priority >= _animationPriority) { - _rotation = _rotation * glm::inverse(_rotationInModelFrame) * rotation * glm::inverse(_fbxJoint->inverseBindRotation); + _rotationInParentFrame = _rotationInParentFrame * glm::inverse(_rotation) * rotation * glm::inverse(_fbxJoint->inverseBindRotation); _animationPriority = priority; } } void JointState::clearTransformTranslation() { - _transformInModelFrame[3][0] = 0.0f; - _transformInModelFrame[3][1] = 0.0f; - _transformInModelFrame[3][2] = 0.0f; + _transform[3][0] = 0.0f; + _transform[3][1] = 0.0f; + _transform[3][2] = 0.0f; } void JointState::applyRotationDeltaInModelFrame(const glm::quat& delta, bool constrain, float priority) { @@ -2040,15 +2040,15 @@ void JointState::applyRotationDeltaInModelFrame(const glm::quat& delta, bool con if (!constrain || (_fbxJoint->rotationMin == glm::vec3(-PI, -PI, -PI) && _fbxJoint->rotationMax == glm::vec3(PI, PI, PI))) { // no constraints - _rotation = _rotation * glm::inverse(_rotationInModelFrame) * delta * _rotationInModelFrame; - _rotationInModelFrame = delta * _rotationInModelFrame; + _rotationInParentFrame = _rotationInParentFrame * glm::inverse(_rotation) * delta * _rotation; + _rotation = delta * _rotation; return; } - glm::quat targetRotation = delta * _rotationInModelFrame; - glm::vec3 eulers = safeEulerAngles(_rotation * glm::inverse(_rotationInModelFrame) * targetRotation); + glm::quat targetRotation = delta * _rotation; + glm::vec3 eulers = safeEulerAngles(_rotationInParentFrame * glm::inverse(_rotation) * targetRotation); glm::quat newRotation = glm::quat(glm::clamp(eulers, _fbxJoint->rotationMin, _fbxJoint->rotationMax)); - _rotationInModelFrame = _rotationInModelFrame * glm::inverse(_rotation) * newRotation; - _rotation = newRotation; + _rotation = _rotation * glm::inverse(_rotationInParentFrame) * newRotation; + _rotationInParentFrame = newRotation; } const glm::vec3& JointState::getDefaultTranslationInParentFrame() const { diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index 9aeb6f68ba..955207445b 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -41,10 +41,10 @@ public: void copyState(const JointState& state); void computeTransformInModelFrame(const glm::mat4& parentTransform); - const glm::mat4& getTransformInModelFrame() const { return _transformInModelFrame; } + const glm::mat4& getTransformInModelFrame() const { return _transform; } - glm::quat getRotationInModelFrame() const { return _rotationInModelFrame; } - glm::vec3 getPositionInModelFrame() const { return extractTranslation(_transformInModelFrame); } + glm::quat getRotationInModelFrame() const { return _rotation; } + glm::vec3 getPositionInModelFrame() const { return extractTranslation(_transform); } /// \return rotation from bind to model frame glm::quat getRotationFromBindToModelFrame() const; @@ -55,19 +55,19 @@ public: void restoreRotation(float fraction, float priority); - /// \param rotation is from bind-frame to model-frame - /// computes parent relative _rotation and sets that - /// \warning no combined transforms are updated! + /// \param rotation is from bind- to model-frame + /// computes and sets new _rotationInParentFrame + /// NOTE: the JointState's model-frame transform/rotation are NOT updated! void setRotationInModelFrame(const glm::quat& rotation, float priority); void clearTransformTranslation(); - glm::quat _rotation; // rotation relative to parent + glm::quat _rotationInParentFrame; // joint- to parentJoint-frame float _animationPriority; // the priority of the animation affecting this joint private: - glm::mat4 _transformInModelFrame; - glm::quat _rotationInModelFrame; + glm::mat4 _transform; // joint- to model-frame + glm::quat _rotation; // joint- to model-frame const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint };