mirror of
https://github.com/overte-org/overte.git
synced 2025-04-30 00:42:46 +02:00
remove JointState::_translation
(use corresponding data in FBXJoint instead)
This commit is contained in:
parent
a898fcbf75
commit
2e99d316ac
4 changed files with 11 additions and 29 deletions
|
@ -49,7 +49,7 @@ void FaceModel::simulate(float deltaTime, bool fullUpdate) {
|
||||||
void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
|
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
|
// get the rotation axes in joint space and use them to adjust the rotation
|
||||||
glm::mat3 axes = glm::mat3_cast(_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.preTransform * glm::mat4_cast(joint.preRotation)));
|
||||||
state._rotation = glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getFinalRoll(), glm::normalize(inverse * axes[2]))
|
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]))
|
* 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) {
|
void FaceModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
|
||||||
// likewise with the eye joints
|
// 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));
|
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 front = glm::vec3(inverse * glm::vec4(_owningHead->getFinalOrientation() * IDENTITY_FRONT, 0.0f));
|
||||||
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(_owningHead->getLookAtPosition() +
|
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(_owningHead->getLookAtPosition() +
|
||||||
|
|
|
@ -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
|
// get the rotation axes in joint space and use them to adjust the rotation
|
||||||
glm::mat3 axes = glm::mat3_cast(_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)));
|
joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation)));
|
||||||
state._rotation = glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanSideways(),
|
state._rotation = 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[2])) * glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanForward(),
|
||||||
|
|
|
@ -1232,23 +1232,6 @@ bool Model::setJointRotation(int jointIndex, const glm::quat& rotation, float pr
|
||||||
return true;
|
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) {
|
bool Model::restoreJointPosition(int jointIndex, float percent, float priority) {
|
||||||
if (jointIndex == -1 || _jointStates.isEmpty()) {
|
if (jointIndex == -1 || _jointStates.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -1261,7 +1244,6 @@ bool Model::restoreJointPosition(int jointIndex, float percent, float priority)
|
||||||
if (priority == state._animationPriority) {
|
if (priority == state._animationPriority) {
|
||||||
const FBXJoint& joint = geometry.joints.at(index);
|
const FBXJoint& joint = geometry.joints.at(index);
|
||||||
state._rotation = safeMix(state._rotation, joint.rotation, percent);
|
state._rotation = safeMix(state._rotation, joint.rotation, percent);
|
||||||
state._translation = glm::mix(state._translation, joint.translation, percent);
|
|
||||||
state._animationPriority = 0.0f;
|
state._animationPriority = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1866,21 +1848,18 @@ void AnimationHandle::replaceMatchingPriorities(float newPriority) {
|
||||||
// JointState TODO: move this class to its own files
|
// JointState TODO: move this class to its own files
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
JointState::JointState() :
|
JointState::JointState() :
|
||||||
_translation(0.0f),
|
|
||||||
_animationPriority(0.0f),
|
_animationPriority(0.0f),
|
||||||
_fbxJoint(NULL) {
|
_fbxJoint(NULL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointState::setFBXJoint(const FBXJoint* joint) {
|
void JointState::setFBXJoint(const FBXJoint* joint) {
|
||||||
assert(joint != NULL);
|
assert(joint != NULL);
|
||||||
_translation = joint->translation;
|
|
||||||
_rotation = joint->rotation;
|
_rotation = joint->rotation;
|
||||||
// NOTE: JointState does not own the FBXJoint to which it points.
|
// NOTE: JointState does not own the FBXJoint to which it points.
|
||||||
_fbxJoint = joint;
|
_fbxJoint = joint;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointState::copyState(const JointState& state) {
|
void JointState::copyState(const JointState& state) {
|
||||||
_translation = state._translation;
|
|
||||||
_rotation = state._rotation;
|
_rotation = state._rotation;
|
||||||
_transform = state._transform;
|
_transform = state._transform;
|
||||||
_combinedRotation = state._combinedRotation;
|
_combinedRotation = state._combinedRotation;
|
||||||
|
@ -1891,7 +1870,7 @@ void JointState::copyState(const JointState& state) {
|
||||||
void JointState::updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation) {
|
void JointState::updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation) {
|
||||||
assert(_fbxJoint != NULL);
|
assert(_fbxJoint != NULL);
|
||||||
glm::quat combinedRotation = _fbxJoint->preRotation * _rotation * _fbxJoint->postRotation;
|
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;
|
_combinedRotation = parentRotation * combinedRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1917,3 +1896,7 @@ void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, floa
|
||||||
_combinedRotation = _combinedRotation * glm::inverse(_rotation) * newRotation;
|
_combinedRotation = _combinedRotation * glm::inverse(_rotation) * newRotation;
|
||||||
_rotation = newRotation;
|
_rotation = newRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const glm::vec3& JointState::getDefaultTranslationInParentFrame() const {
|
||||||
|
return _fbxJoint->translation;
|
||||||
|
}
|
||||||
|
|
|
@ -42,12 +42,13 @@ public:
|
||||||
|
|
||||||
void updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation);
|
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;
|
glm::quat getJointRotation(bool fromBind = false) const;
|
||||||
|
|
||||||
void applyRotationDelta(const glm::quat& delta, bool constrain = true, float priority = 1.0f);
|
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::quat _rotation; // rotation relative to parent
|
||||||
glm::mat4 _transform; // rotation to world frame + translation in model frame
|
glm::mat4 _transform; // rotation to world frame + translation in model frame
|
||||||
glm::quat _combinedRotation; // rotation from joint local to world 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);
|
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);
|
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.
|
/// 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
|
/// \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
|
/// the original position
|
||||||
|
|
Loading…
Reference in a new issue