renames of JointState data members

This commit is contained in:
Andrew Meadows 2014-06-04 13:27:28 -07:00
parent b1b7f6bdc4
commit d32e14ca04
4 changed files with 37 additions and 37 deletions

View file

@ -51,7 +51,7 @@ void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBX
glm::mat3 axes = glm::mat3_cast(glm::quat()); glm::mat3 axes = glm::mat3_cast(glm::quat());
glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransformInModelFrame() * glm::translate(state.getDefaultTranslationInParentFrame()) * glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransformInModelFrame() * 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._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->getFinalYaw(), glm::normalize(inverse * axes[1]))
* glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getFinalPitch(), glm::normalize(inverse * axes[0])) * glm::angleAxis(- RADIANS_PER_DEGREE * _owningHead->getFinalPitch(), glm::normalize(inverse * axes[0]))
* joint.rotation; * joint.rotation;
@ -68,7 +68,7 @@ void FaceModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJ
_owningHead->getSaccade() - _translation, 1.0f)); _owningHead->getSaccade() - _translation, 1.0f));
glm::quat between = rotationBetween(front, lookAt); glm::quat between = rotationBetween(front, lookAt);
const float MAX_ANGLE = 30.0f * RADIANS_PER_DEGREE; 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; joint.rotation;
} }

View file

@ -200,7 +200,7 @@ void SkeletonModel::applyPalmDataInModelFrame(int jointIndex, PalmData& palm) {
JointState& parentState = _jointStates[parentJointIndex]; JointState& parentState = _jointStates[parentJointIndex];
parentState.setRotationInModelFrame(palmRotation, PALM_PRIORITY); parentState.setRotationInModelFrame(palmRotation, PALM_PRIORITY);
// lock hand to forearm by slamming its rotation (in parent-frame) to identity // lock hand to forearm by slamming its rotation (in parent-frame) to identity
_jointStates[jointIndex]._rotation = glm::quat(); _jointStates[jointIndex]._rotationInParentFrame = glm::quat();
} else { } else {
setJointPositionInModelFrame(jointIndex, palmPosition, palmRotation, setJointPositionInModelFrame(jointIndex, palmPosition, palmRotation,
true, -1, false, glm::vec3(0.0f, -1.0f, 0.0f), PALM_PRIORITY); 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 axes = glm::mat3_cast(glm::quat());
glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransformInModelFrame() * glm::translate(state.getDefaultTranslationInParentFrame()) * glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransformInModelFrame() * 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._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[2])) * glm::angleAxis(- RADIANS_PER_DEGREE * _owningAvatar->getHead()->getFinalLeanForward(),
glm::normalize(inverse * axes[0])) * joint.rotation; glm::normalize(inverse * axes[0])) * joint.rotation;
} }

View file

@ -459,7 +459,7 @@ void Model::reset() {
} }
const FBXGeometry& geometry = _geometry->getFBXGeometry(); const FBXGeometry& geometry = _geometry->getFBXGeometry();
for (int i = 0; i < _jointStates.size(); i++) { 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()) { if (index == -1 || index >= _jointStates.size()) {
return false; return false;
} }
rotation = _jointStates.at(index)._rotation; rotation = _jointStates.at(index)._rotationInParentFrame;
const glm::quat& defaultRotation = _geometry->getFBXGeometry().joints.at(index).rotation; const glm::quat& defaultRotation = _geometry->getFBXGeometry().joints.at(index).rotation;
return glm::abs(rotation.x - defaultRotation.x) >= EPSILON || return glm::abs(rotation.x - defaultRotation.x) >= EPSILON ||
glm::abs(rotation.y - defaultRotation.y) >= 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]; JointState& state = _jointStates[index];
if (priority >= state._animationPriority) { if (priority >= state._animationPriority) {
if (valid) { if (valid) {
state._rotation = rotation; state._rotationInParentFrame = rotation;
state._animationPriority = priority; state._animationPriority = priority;
} else { } else {
state.restoreRotation(1.0f, priority); state.restoreRotation(1.0f, priority);
@ -1932,7 +1932,7 @@ void AnimationHandle::simulate(float deltaTime) {
if (mapping != -1) { if (mapping != -1) {
JointState& state = _model->_jointStates[mapping]; JointState& state = _model->_jointStates[mapping];
if (_priority >= state._animationPriority) { if (_priority >= state._animationPriority) {
state._rotation = frame.rotations.at(i); state._rotationInParentFrame = frame.rotations.at(i);
state._animationPriority = _priority; state._animationPriority = _priority;
} }
} }
@ -1956,7 +1956,7 @@ void AnimationHandle::simulate(float deltaTime) {
if (mapping != -1) { if (mapping != -1) {
JointState& state = _model->_jointStates[mapping]; JointState& state = _model->_jointStates[mapping];
if (_priority >= state._animationPriority) { 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; state._animationPriority = _priority;
} }
} }
@ -1985,34 +1985,34 @@ JointState::JointState() :
void JointState::setFBXJoint(const FBXJoint* joint) { void JointState::setFBXJoint(const FBXJoint* joint) {
assert(joint != NULL); assert(joint != NULL);
_rotation = joint->rotation; _rotationInParentFrame = 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) {
_rotation = state._rotation; _rotationInParentFrame = state._rotationInParentFrame;
_transformInModelFrame = state._transformInModelFrame; _transform = state._transform;
_rotationInModelFrame = extractRotation(_transformInModelFrame); _rotation = extractRotation(_transform);
_animationPriority = state._animationPriority; _animationPriority = state._animationPriority;
// DO NOT copy _fbxJoint // DO NOT copy _fbxJoint
} }
void JointState::computeTransformInModelFrame(const glm::mat4& parentTransform) { 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; glm::mat4 modifiedTransform = _fbxJoint->preTransform * glm::mat4_cast(modifiedRotation) * _fbxJoint->postTransform;
_transformInModelFrame = parentTransform * glm::translate(_fbxJoint->translation) * modifiedTransform; _transform = parentTransform * glm::translate(_fbxJoint->translation) * modifiedTransform;
_rotationInModelFrame = extractRotation(_transformInModelFrame); _rotation = extractRotation(_transform);
} }
glm::quat JointState::getRotationFromBindToModelFrame() const { glm::quat JointState::getRotationFromBindToModelFrame() const {
return _rotationInModelFrame * _fbxJoint->inverseBindRotation; return _rotation * _fbxJoint->inverseBindRotation;
} }
void JointState::restoreRotation(float fraction, float priority) { void JointState::restoreRotation(float fraction, float priority) {
assert(_fbxJoint != NULL); assert(_fbxJoint != NULL);
if (priority == _animationPriority) { if (priority == _animationPriority) {
_rotation = safeMix(_rotation, _fbxJoint->rotation, fraction); _rotationInParentFrame = safeMix(_rotationInParentFrame, _fbxJoint->rotation, fraction);
_animationPriority = 0.0f; _animationPriority = 0.0f;
} }
} }
@ -2020,15 +2020,15 @@ void JointState::restoreRotation(float fraction, float priority) {
void JointState::setRotationInModelFrame(const glm::quat& rotation, float priority) { void JointState::setRotationInModelFrame(const glm::quat& rotation, float priority) {
assert(_fbxJoint != NULL); assert(_fbxJoint != NULL);
if (priority >= _animationPriority) { 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; _animationPriority = priority;
} }
} }
void JointState::clearTransformTranslation() { void JointState::clearTransformTranslation() {
_transformInModelFrame[3][0] = 0.0f; _transform[3][0] = 0.0f;
_transformInModelFrame[3][1] = 0.0f; _transform[3][1] = 0.0f;
_transformInModelFrame[3][2] = 0.0f; _transform[3][2] = 0.0f;
} }
void JointState::applyRotationDeltaInModelFrame(const glm::quat& delta, bool constrain, float priority) { 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) && if (!constrain || (_fbxJoint->rotationMin == glm::vec3(-PI, -PI, -PI) &&
_fbxJoint->rotationMax == glm::vec3(PI, PI, PI))) { _fbxJoint->rotationMax == glm::vec3(PI, PI, PI))) {
// no constraints // no constraints
_rotation = _rotation * glm::inverse(_rotationInModelFrame) * delta * _rotationInModelFrame; _rotationInParentFrame = _rotationInParentFrame * glm::inverse(_rotation) * delta * _rotation;
_rotationInModelFrame = delta * _rotationInModelFrame; _rotation = delta * _rotation;
return; return;
} }
glm::quat targetRotation = delta * _rotationInModelFrame; glm::quat targetRotation = delta * _rotation;
glm::vec3 eulers = safeEulerAngles(_rotation * glm::inverse(_rotationInModelFrame) * targetRotation); glm::vec3 eulers = safeEulerAngles(_rotationInParentFrame * glm::inverse(_rotation) * targetRotation);
glm::quat newRotation = glm::quat(glm::clamp(eulers, _fbxJoint->rotationMin, _fbxJoint->rotationMax)); glm::quat newRotation = glm::quat(glm::clamp(eulers, _fbxJoint->rotationMin, _fbxJoint->rotationMax));
_rotationInModelFrame = _rotationInModelFrame * glm::inverse(_rotation) * newRotation; _rotation = _rotation * glm::inverse(_rotationInParentFrame) * newRotation;
_rotation = newRotation; _rotationInParentFrame = newRotation;
} }
const glm::vec3& JointState::getDefaultTranslationInParentFrame() const { const glm::vec3& JointState::getDefaultTranslationInParentFrame() const {

View file

@ -41,10 +41,10 @@ public:
void copyState(const JointState& state); void copyState(const JointState& state);
void computeTransformInModelFrame(const glm::mat4& parentTransform); 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::quat getRotationInModelFrame() const { return _rotation; }
glm::vec3 getPositionInModelFrame() const { return extractTranslation(_transformInModelFrame); } glm::vec3 getPositionInModelFrame() const { return extractTranslation(_transform); }
/// \return rotation from bind to model frame /// \return rotation from bind to model frame
glm::quat getRotationFromBindToModelFrame() const; glm::quat getRotationFromBindToModelFrame() const;
@ -55,19 +55,19 @@ public:
void restoreRotation(float fraction, float priority); void restoreRotation(float fraction, float priority);
/// \param rotation is from bind-frame to model-frame /// \param rotation is from bind- to model-frame
/// computes parent relative _rotation and sets that /// computes and sets new _rotationInParentFrame
/// \warning no combined transforms are updated! /// NOTE: the JointState's model-frame transform/rotation are NOT updated!
void setRotationInModelFrame(const glm::quat& rotation, float priority); void setRotationInModelFrame(const glm::quat& rotation, float priority);
void clearTransformTranslation(); 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 float _animationPriority; // the priority of the animation affecting this joint
private: private:
glm::mat4 _transformInModelFrame; glm::mat4 _transform; // joint- to model-frame
glm::quat _rotationInModelFrame; glm::quat _rotation; // joint- to model-frame
const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint
}; };