From 2e99d316acf4dd899ca2bcdf1ea6211e28b90873 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 29 May 2014 12:52:05 -0700 Subject: [PATCH] remove JointState::_translation (use corresponding data in FBXJoint instead) --- interface/src/avatar/FaceModel.cpp | 4 ++-- interface/src/avatar/SkeletonModel.cpp | 2 +- interface/src/renderer/Model.cpp | 27 +++++--------------------- interface/src/renderer/Model.h | 7 +++---- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/interface/src/avatar/FaceModel.cpp b/interface/src/avatar/FaceModel.cpp index 6ecc45e1e3..acd3d2c31f 100644 --- a/interface/src/avatar/FaceModel.cpp +++ b/interface/src/avatar/FaceModel.cpp @@ -49,7 +49,7 @@ void FaceModel::simulate(float deltaTime, bool fullUpdate) { void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) { // get the rotation axes in joint space and use them to adjust the rotation glm::mat3 axes = glm::mat3_cast(_rotation); - glm::mat3 inverse = glm::mat3(glm::inverse(parentState._transform * glm::translate(state._translation) * + glm::mat3 inverse = glm::mat3(glm::inverse(parentState._transform * 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])) * glm::angleAxis(RADIANS_PER_DEGREE * _owningHead->getFinalYaw(), glm::normalize(inverse * axes[1])) @@ -59,7 +59,7 @@ void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBX void FaceModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) { // likewise with the eye joints - glm::mat4 inverse = glm::inverse(parentState._transform * glm::translate(state._translation) * + glm::mat4 inverse = glm::inverse(parentState._transform * glm::translate(state.getDefaultTranslationInParentFrame()) * joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation)); glm::vec3 front = glm::vec3(inverse * glm::vec4(_owningHead->getFinalOrientation() * IDENTITY_FRONT, 0.0f)); glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(_owningHead->getLookAtPosition() + diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 0223f390f8..d40c660c4b 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -230,7 +230,7 @@ void SkeletonModel::maybeUpdateLeanRotation(const JointState& parentState, const } // get the rotation axes in joint space and use them to adjust the rotation glm::mat3 axes = glm::mat3_cast(_rotation); - glm::mat3 inverse = glm::mat3(glm::inverse(parentState._transform * glm::translate(state._translation) * + glm::mat3 inverse = glm::mat3(glm::inverse(parentState._transform * glm::translate(state.getDefaultTranslationInParentFrame()) * joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation))); state._rotation = glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanSideways(), glm::normalize(inverse * axes[2])) * glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanForward(), diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index b77b4324db..065d4bf0f0 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -1232,23 +1232,6 @@ bool Model::setJointRotation(int jointIndex, const glm::quat& rotation, float pr return true; } -void Model::setJointTranslation(int jointIndex, const glm::vec3& translation) { - JointState& state = _jointStates[jointIndex]; - const FBXJoint& joint = state.getFBXJoint(); - - glm::mat4 parentTransform; - if (joint.parentIndex == -1) { - const FBXGeometry& geometry = _geometry->getFBXGeometry(); - parentTransform = glm::mat4_cast(_rotation) * glm::scale(_scale) * glm::translate(_offset) * geometry.offset; - - } else { - parentTransform = _jointStates.at(joint.parentIndex)._transform; - } - glm::vec3 preTranslation = extractTranslation(joint.preTransform * glm::mat4_cast(joint.preRotation * - state._rotation * joint.postRotation) * joint.postTransform); - state._translation = glm::vec3(glm::inverse(parentTransform) * glm::vec4(translation, 1.0f)) - preTranslation; -} - bool Model::restoreJointPosition(int jointIndex, float percent, float priority) { if (jointIndex == -1 || _jointStates.isEmpty()) { return false; @@ -1261,7 +1244,6 @@ bool Model::restoreJointPosition(int jointIndex, float percent, float priority) if (priority == state._animationPriority) { const FBXJoint& joint = geometry.joints.at(index); state._rotation = safeMix(state._rotation, joint.rotation, percent); - state._translation = glm::mix(state._translation, joint.translation, percent); state._animationPriority = 0.0f; } } @@ -1866,21 +1848,18 @@ void AnimationHandle::replaceMatchingPriorities(float newPriority) { // JointState TODO: move this class to its own files // ---------------------------------------------------------------------------- JointState::JointState() : - _translation(0.0f), _animationPriority(0.0f), _fbxJoint(NULL) { } void JointState::setFBXJoint(const FBXJoint* joint) { assert(joint != NULL); - _translation = joint->translation; _rotation = joint->rotation; // NOTE: JointState does not own the FBXJoint to which it points. _fbxJoint = joint; } void JointState::copyState(const JointState& state) { - _translation = state._translation; _rotation = state._rotation; _transform = state._transform; _combinedRotation = state._combinedRotation; @@ -1891,7 +1870,7 @@ void JointState::copyState(const JointState& state) { void JointState::updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation) { assert(_fbxJoint != NULL); glm::quat combinedRotation = _fbxJoint->preRotation * _rotation * _fbxJoint->postRotation; - _transform = baseTransform * glm::translate(_translation) * _fbxJoint->preTransform * glm::mat4_cast(combinedRotation) * _fbxJoint->postTransform; + _transform = baseTransform * glm::translate(_fbxJoint->translation) * _fbxJoint->preTransform * glm::mat4_cast(combinedRotation) * _fbxJoint->postTransform; _combinedRotation = parentRotation * combinedRotation; } @@ -1917,3 +1896,7 @@ void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, floa _combinedRotation = _combinedRotation * glm::inverse(_rotation) * newRotation; _rotation = newRotation; } + +const glm::vec3& JointState::getDefaultTranslationInParentFrame() const { + return _fbxJoint->translation; +} diff --git a/interface/src/renderer/Model.h b/interface/src/renderer/Model.h index f7ec181fb4..f346e5e10c 100644 --- a/interface/src/renderer/Model.h +++ b/interface/src/renderer/Model.h @@ -42,12 +42,13 @@ public: void updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation); - /// \return rotation from the joint's default (or bind) orientation + /// \return rotation from the joint's default (or bind) frame to world frame glm::quat getJointRotation(bool fromBind = false) const; void applyRotationDelta(const glm::quat& delta, bool constrain = true, float priority = 1.0f); - glm::vec3 _translation; // translation relative to parent + const glm::vec3& getDefaultTranslationInParentFrame() const; + glm::quat _rotation; // rotation relative to parent glm::mat4 _transform; // rotation to world frame + translation in model frame glm::quat _combinedRotation; // rotation from joint local to world frame @@ -240,8 +241,6 @@ protected: const glm::vec3& alignment = glm::vec3(0.0f, -1.0f, 0.0f), float priority = 1.0f); bool setJointRotation(int jointIndex, const glm::quat& rotation, float priority = 1.0f); - void setJointTranslation(int jointIndex, const glm::vec3& translation); - /// Restores the indexed joint to its default position. /// \param percent the percentage of the default position to apply (i.e., 0.25f to slerp one fourth of the way to /// the original position