mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 22:56:29 +02:00
Merge branch 'cleanup-jointstate' of github.com:howard-stearns/hifi into polyvox
This commit is contained in:
commit
44ee13a185
9 changed files with 131 additions and 84 deletions
|
@ -56,12 +56,12 @@ void FaceModel::simulate(float deltaTime, bool fullUpdate) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, int index) {
|
void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const JointState& state, int index) {
|
||||||
// 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(glm::quat());
|
glm::mat3 axes = glm::mat3_cast(glm::quat());
|
||||||
glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransform() *
|
glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransform() *
|
||||||
glm::translate(_rig->getJointDefaultTranslationInConstrainedFrame(index)) *
|
glm::translate(_rig->getJointDefaultTranslationInConstrainedFrame(index)) *
|
||||||
joint.preTransform * glm::mat4_cast(joint.preRotation)));
|
state.getPreTransform() * glm::mat4_cast(state.getPreRotation())));
|
||||||
glm::vec3 pitchYawRoll = safeEulerAngles(_owningHead->getFinalOrientationInLocalFrame());
|
glm::vec3 pitchYawRoll = safeEulerAngles(_owningHead->getFinalOrientationInLocalFrame());
|
||||||
glm::vec3 lean = glm::radians(glm::vec3(_owningHead->getFinalLeanForward(),
|
glm::vec3 lean = glm::radians(glm::vec3(_owningHead->getFinalLeanForward(),
|
||||||
_owningHead->getTorsoTwist(),
|
_owningHead->getTorsoTwist(),
|
||||||
|
@ -71,15 +71,15 @@ void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBX
|
||||||
glm::angleAxis(-pitchYawRoll.z, glm::normalize(inverse * axes[2]))
|
glm::angleAxis(-pitchYawRoll.z, glm::normalize(inverse * axes[2]))
|
||||||
* glm::angleAxis(pitchYawRoll.y, glm::normalize(inverse * axes[1]))
|
* glm::angleAxis(pitchYawRoll.y, glm::normalize(inverse * axes[1]))
|
||||||
* glm::angleAxis(-pitchYawRoll.x, glm::normalize(inverse * axes[0]))
|
* glm::angleAxis(-pitchYawRoll.x, glm::normalize(inverse * axes[0]))
|
||||||
* joint.rotation, DEFAULT_PRIORITY);
|
* state.getOriginalRotation(), DEFAULT_PRIORITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FaceModel::maybeUpdateEyeRotation(Model* model, const JointState& parentState, const FBXJoint& joint, int index) {
|
void FaceModel::maybeUpdateEyeRotation(Model* model, const JointState& parentState, const JointState& state, int index) {
|
||||||
// likewise with the eye joints
|
// likewise with the eye joints
|
||||||
// NOTE: at the moment we do the math in the world-frame, hence the inverse transform is more complex than usual.
|
// NOTE: at the moment we do the math in the world-frame, hence the inverse transform is more complex than usual.
|
||||||
glm::mat4 inverse = glm::inverse(glm::mat4_cast(model->getRotation()) * parentState.getTransform() *
|
glm::mat4 inverse = glm::inverse(glm::mat4_cast(model->getRotation()) * parentState.getTransform() *
|
||||||
glm::translate(_rig->getJointDefaultTranslationInConstrainedFrame(index)) *
|
glm::translate(_rig->getJointDefaultTranslationInConstrainedFrame(index)) *
|
||||||
joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation));
|
state.getPreTransform() * glm::mat4_cast(state.getPreRotation() * state.getOriginalRotation()));
|
||||||
glm::vec3 front = glm::vec3(inverse * glm::vec4(_owningHead->getFinalOrientationInWorldFrame() * IDENTITY_FRONT, 0.0f));
|
glm::vec3 front = glm::vec3(inverse * glm::vec4(_owningHead->getFinalOrientationInWorldFrame() * IDENTITY_FRONT, 0.0f));
|
||||||
glm::vec3 lookAtDelta = _owningHead->getCorrectedLookAtPosition() - model->getTranslation();
|
glm::vec3 lookAtDelta = _owningHead->getCorrectedLookAtPosition() - model->getTranslation();
|
||||||
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(lookAtDelta + glm::length(lookAtDelta) * _owningHead->getSaccade(), 1.0f));
|
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(lookAtDelta + glm::length(lookAtDelta) * _owningHead->getSaccade(), 1.0f));
|
||||||
|
@ -87,22 +87,22 @@ void FaceModel::maybeUpdateEyeRotation(Model* model, const JointState& parentSta
|
||||||
const float MAX_ANGLE = 30.0f * RADIANS_PER_DEGREE;
|
const float MAX_ANGLE = 30.0f * RADIANS_PER_DEGREE;
|
||||||
_rig->setJointRotationInConstrainedFrame(index, glm::angleAxis(glm::clamp(glm::angle(between),
|
_rig->setJointRotationInConstrainedFrame(index, glm::angleAxis(glm::clamp(glm::angle(between),
|
||||||
-MAX_ANGLE, MAX_ANGLE), glm::axis(between)) *
|
-MAX_ANGLE, MAX_ANGLE), glm::axis(between)) *
|
||||||
joint.rotation, DEFAULT_PRIORITY);
|
state.getOriginalRotation(), DEFAULT_PRIORITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FaceModel::maybeUpdateNeckAndEyeRotation(int index) {
|
void FaceModel::maybeUpdateNeckAndEyeRotation(int index) {
|
||||||
const JointState& state = _rig->getJointState(index);
|
const JointState& state = _rig->getJointState(index);
|
||||||
const FBXJoint& joint = state.getFBXJoint();
|
|
||||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||||
|
const int parentIndex = state.getParentIndex();
|
||||||
|
|
||||||
// guard against out-of-bounds access to _jointStates
|
// guard against out-of-bounds access to _jointStates
|
||||||
if (joint.parentIndex != -1 && joint.parentIndex >= 0 && joint.parentIndex < _rig->getJointStateCount()) {
|
if (parentIndex != -1 && parentIndex >= 0 && parentIndex < _rig->getJointStateCount()) {
|
||||||
const JointState& parentState = _rig->getJointState(joint.parentIndex);
|
const JointState& parentState = _rig->getJointState(parentIndex);
|
||||||
if (index == geometry.neckJointIndex) {
|
if (index == geometry.neckJointIndex) {
|
||||||
maybeUpdateNeckRotation(parentState, joint, index);
|
maybeUpdateNeckRotation(parentState, state, index);
|
||||||
|
|
||||||
} else if (index == geometry.leftEyeJointIndex || index == geometry.rightEyeJointIndex) {
|
} else if (index == geometry.leftEyeJointIndex || index == geometry.rightEyeJointIndex) {
|
||||||
maybeUpdateEyeRotation(this, parentState, joint, index);
|
maybeUpdateEyeRotation(this, parentState, state, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,8 +26,8 @@ public:
|
||||||
|
|
||||||
virtual void simulate(float deltaTime, bool fullUpdate = true);
|
virtual void simulate(float deltaTime, bool fullUpdate = true);
|
||||||
|
|
||||||
void maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, int index);
|
void maybeUpdateNeckRotation(const JointState& parentState, const JointState& state, int index);
|
||||||
void maybeUpdateEyeRotation(Model* model, const JointState& parentState, const FBXJoint& joint, int index);
|
void maybeUpdateEyeRotation(Model* model, const JointState& parentState, const JointState& state, int index);
|
||||||
void maybeUpdateNeckAndEyeRotation(int index);
|
void maybeUpdateNeckAndEyeRotation(int index);
|
||||||
|
|
||||||
/// Retrieve the positions of up to two eye meshes.
|
/// Retrieve the positions of up to two eye meshes.
|
||||||
|
|
|
@ -402,7 +402,7 @@ bool SkeletonModel::getNeckParentRotationFromDefaultOrientation(glm::quat& neckP
|
||||||
glm::quat worldFrameRotation;
|
glm::quat worldFrameRotation;
|
||||||
bool success = getJointRotationInWorldFrame(parentIndex, worldFrameRotation);
|
bool success = getJointRotationInWorldFrame(parentIndex, worldFrameRotation);
|
||||||
if (success) {
|
if (success) {
|
||||||
neckParentRotation = worldFrameRotation * _rig->getJointState(parentIndex).getFBXJoint().inverseDefaultRotation;
|
neckParentRotation = worldFrameRotation * _rig->getJointState(parentIndex).getInverseDefaultRotation();
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -478,18 +478,17 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) {
|
||||||
for (int i = 0; i < numStates; i++) {
|
for (int i = 0; i < numStates; i++) {
|
||||||
// compute the default transform of this joint
|
// compute the default transform of this joint
|
||||||
const JointState& state = _rig->getJointState(i);
|
const JointState& state = _rig->getJointState(i);
|
||||||
const FBXJoint& joint = state.getFBXJoint();
|
int parentIndex = state.getParentIndex();
|
||||||
int parentIndex = joint.parentIndex;
|
|
||||||
if (parentIndex == -1) {
|
if (parentIndex == -1) {
|
||||||
transforms[i] = _rig->getJointTransform(i);
|
transforms[i] = _rig->getJointTransform(i);
|
||||||
} else {
|
} else {
|
||||||
glm::quat modifiedRotation = joint.preRotation * joint.rotation * joint.postRotation;
|
glm::quat modifiedRotation = state.getPreRotation() * state.getOriginalRotation() * state.getPostRotation();
|
||||||
transforms[i] = transforms[parentIndex] * glm::translate(joint.translation)
|
transforms[i] = transforms[parentIndex] * glm::translate(state.getTranslation())
|
||||||
* joint.preTransform * glm::mat4_cast(modifiedRotation) * joint.postTransform;
|
* state.getPreTransform() * glm::mat4_cast(modifiedRotation) * state.getPostTransform();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Each joint contributes a sphere at its position
|
// Each joint contributes a sphere at its position
|
||||||
glm::vec3 axis(joint.boneRadius);
|
glm::vec3 axis(state.getBoneRadius());
|
||||||
glm::vec3 jointPosition = extractTranslation(transforms[i]);
|
glm::vec3 jointPosition = extractTranslation(transforms[i]);
|
||||||
totalExtents.addPoint(jointPosition + axis);
|
totalExtents.addPoint(jointPosition + axis);
|
||||||
totalExtents.addPoint(jointPosition - axis);
|
totalExtents.addPoint(jointPosition - axis);
|
||||||
|
|
|
@ -17,7 +17,6 @@ void AvatarRig::updateJointState(int index, glm::mat4 parentTransform) {
|
||||||
return; // bail
|
return; // bail
|
||||||
}
|
}
|
||||||
JointState& state = _jointStates[index];
|
JointState& state = _jointStates[index];
|
||||||
const FBXJoint& joint = state.getFBXJoint();
|
|
||||||
|
|
||||||
// compute model transforms
|
// compute model transforms
|
||||||
if (index == _rootJointIndex) {
|
if (index == _rootJointIndex) {
|
||||||
|
@ -26,7 +25,7 @@ void AvatarRig::updateJointState(int index, glm::mat4 parentTransform) {
|
||||||
clearJointTransformTranslation(index);
|
clearJointTransformTranslation(index);
|
||||||
} else {
|
} else {
|
||||||
// guard against out-of-bounds access to _jointStates
|
// guard against out-of-bounds access to _jointStates
|
||||||
int parentIndex = joint.parentIndex;
|
int parentIndex = state.getParentIndex();
|
||||||
if (parentIndex >= 0 && parentIndex < _jointStates.size()) {
|
if (parentIndex >= 0 && parentIndex < _jointStates.size()) {
|
||||||
const JointState& parentState = _jointStates.at(parentIndex);
|
const JointState& parentState = _jointStates.at(parentIndex);
|
||||||
state.computeTransform(parentState.getTransform(), parentState.getTransformChanged());
|
state.computeTransform(parentState.getTransform(), parentState.getTransformChanged());
|
||||||
|
@ -53,8 +52,8 @@ void AvatarRig::setHandPosition(int jointIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
// precomputed lengths
|
// precomputed lengths
|
||||||
float upperArmLength = _jointStates[elbowJointIndex].getFBXJoint().distanceToParent * scale;
|
float upperArmLength = _jointStates[elbowJointIndex].getDistanceToParent() * scale;
|
||||||
float lowerArmLength = _jointStates[jointIndex].getFBXJoint().distanceToParent * scale;
|
float lowerArmLength = _jointStates[jointIndex].getDistanceToParent() * scale;
|
||||||
|
|
||||||
// first set wrist position
|
// first set wrist position
|
||||||
glm::vec3 wristPosition = position;
|
glm::vec3 wristPosition = position;
|
||||||
|
|
|
@ -14,15 +14,14 @@
|
||||||
/// Updates the state of the joint at the specified index.
|
/// Updates the state of the joint at the specified index.
|
||||||
void EntityRig::updateJointState(int index, glm::mat4 parentTransform) {
|
void EntityRig::updateJointState(int index, glm::mat4 parentTransform) {
|
||||||
JointState& state = _jointStates[index];
|
JointState& state = _jointStates[index];
|
||||||
const FBXJoint& joint = state.getFBXJoint();
|
|
||||||
|
|
||||||
// compute model transforms
|
// compute model transforms
|
||||||
int parentIndex = joint.parentIndex;
|
int parentIndex = state.getParentIndex();
|
||||||
if (parentIndex == -1) {
|
if (parentIndex == -1) {
|
||||||
state.computeTransform(parentTransform);
|
state.computeTransform(parentTransform);
|
||||||
} else {
|
} else {
|
||||||
// guard against out-of-bounds access to _jointStates
|
// guard against out-of-bounds access to _jointStates
|
||||||
if (joint.parentIndex >= 0 && joint.parentIndex < _jointStates.size()) {
|
if (parentIndex >= 0 && parentIndex < _jointStates.size()) {
|
||||||
const JointState& parentState = _jointStates.at(parentIndex);
|
const JointState& parentState = _jointStates.at(parentIndex);
|
||||||
state.computeTransform(parentState.getTransform(), parentState.getTransformChanged());
|
state.computeTransform(parentState.getTransform(), parentState.getTransformChanged());
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ JointState::JointState() :
|
||||||
_rotationIsValid(false),
|
_rotationIsValid(false),
|
||||||
_positionInParentFrame(0.0f),
|
_positionInParentFrame(0.0f),
|
||||||
_distanceToParent(0.0f),
|
_distanceToParent(0.0f),
|
||||||
_fbxJoint(NULL),
|
|
||||||
_constraint(NULL) {
|
_constraint(NULL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +36,21 @@ JointState::JointState(const JointState& other) : _constraint(NULL) {
|
||||||
_positionInParentFrame = other._positionInParentFrame;
|
_positionInParentFrame = other._positionInParentFrame;
|
||||||
_distanceToParent = other._distanceToParent;
|
_distanceToParent = other._distanceToParent;
|
||||||
_animationPriority = other._animationPriority;
|
_animationPriority = other._animationPriority;
|
||||||
_fbxJoint = other._fbxJoint;
|
|
||||||
// DO NOT copy _constraint
|
// DO NOT copy _constraint
|
||||||
|
_name = other._name;
|
||||||
|
_isFree = other._isFree;
|
||||||
|
_boneRadius = other._boneRadius;
|
||||||
|
_parentIndex = other._parentIndex;
|
||||||
|
_translation = other._translation;
|
||||||
|
_originalRotation = other._originalRotation;
|
||||||
|
_inverseDefaultRotation = other._inverseDefaultRotation;
|
||||||
|
_rotationMin = other._rotationMin;
|
||||||
|
_rotationMax = other._rotationMax;
|
||||||
|
_preRotation = other._preRotation;
|
||||||
|
_postRotation = other._postRotation;
|
||||||
|
_preTransform = other._preTransform;
|
||||||
|
_postTransform = other._postTransform;
|
||||||
|
_inverseBindRotation = other._inverseBindRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
JointState::~JointState() {
|
JointState::~JointState() {
|
||||||
|
@ -65,8 +77,20 @@ void JointState::setFBXJoint(const FBXJoint* joint) {
|
||||||
_transformChanged = true;
|
_transformChanged = true;
|
||||||
_rotationIsValid = false;
|
_rotationIsValid = false;
|
||||||
|
|
||||||
// NOTE: JointState does not own the FBXJoint to which it points.
|
_name = joint->name;
|
||||||
_fbxJoint = joint;
|
_isFree = joint->isFree;
|
||||||
|
_boneRadius = joint->boneRadius;
|
||||||
|
_parentIndex = joint->parentIndex;
|
||||||
|
_translation = joint->translation;
|
||||||
|
_originalRotation = joint->rotation;
|
||||||
|
_inverseDefaultRotation = joint->inverseDefaultRotation;
|
||||||
|
_rotationMin = joint->rotationMin;
|
||||||
|
_rotationMax = joint->rotationMax;
|
||||||
|
_preRotation = joint->preRotation;
|
||||||
|
_postRotation = joint->postRotation;
|
||||||
|
_preTransform = joint->preTransform;
|
||||||
|
_postTransform = joint->postTransform;
|
||||||
|
_inverseBindRotation = joint->inverseBindRotation;
|
||||||
if (_constraint) {
|
if (_constraint) {
|
||||||
delete _constraint;
|
delete _constraint;
|
||||||
_constraint = NULL;
|
_constraint = NULL;
|
||||||
|
@ -78,10 +102,10 @@ void JointState::buildConstraint() {
|
||||||
delete _constraint;
|
delete _constraint;
|
||||||
_constraint = NULL;
|
_constraint = NULL;
|
||||||
}
|
}
|
||||||
if (glm::distance2(glm::vec3(-PI), _fbxJoint->rotationMin) > EPSILON ||
|
if (glm::distance2(glm::vec3(-PI), _rotationMin) > EPSILON ||
|
||||||
glm::distance2(glm::vec3(PI), _fbxJoint->rotationMax) > EPSILON ) {
|
glm::distance2(glm::vec3(PI), _rotationMax) > EPSILON ) {
|
||||||
// this joint has rotation constraints
|
// this joint has rotation constraints
|
||||||
_constraint = AngularConstraint::newAngularConstraint(_fbxJoint->rotationMin, _fbxJoint->rotationMax);
|
_constraint = AngularConstraint::newAngularConstraint(_rotationMin, _rotationMax);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +122,21 @@ void JointState::copyState(const JointState& state) {
|
||||||
_visibleTransform = state._visibleTransform;
|
_visibleTransform = state._visibleTransform;
|
||||||
_visibleRotation = extractRotation(_visibleTransform);
|
_visibleRotation = extractRotation(_visibleTransform);
|
||||||
_visibleRotationInConstrainedFrame = state._visibleRotationInConstrainedFrame;
|
_visibleRotationInConstrainedFrame = state._visibleRotationInConstrainedFrame;
|
||||||
// DO NOT copy _fbxJoint or _constraint
|
// DO NOT copy _constraint
|
||||||
|
_name = state._name;
|
||||||
|
_isFree = state._isFree;
|
||||||
|
_boneRadius = state._boneRadius;
|
||||||
|
_parentIndex = state._parentIndex;
|
||||||
|
_originalRotation = state._originalRotation;
|
||||||
|
_inverseDefaultRotation = state._inverseDefaultRotation;
|
||||||
|
_translation = state._translation;
|
||||||
|
_rotationMin = state._rotationMin;
|
||||||
|
_rotationMax = state._rotationMax;
|
||||||
|
_preRotation = state._preRotation;
|
||||||
|
_postRotation = state._postRotation;
|
||||||
|
_preTransform = state._preTransform;
|
||||||
|
_postTransform = state._postTransform;
|
||||||
|
_inverseBindRotation = state._inverseBindRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointState::initTransform(const glm::mat4& parentTransform) {
|
void JointState::initTransform(const glm::mat4& parentTransform) {
|
||||||
|
@ -112,9 +150,9 @@ void JointState::computeTransform(const glm::mat4& parentTransform, bool parentT
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat rotationInParentFrame = _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation;
|
glm::quat rotationInParentFrame = _preRotation * _rotationInConstrainedFrame * _postRotation;
|
||||||
glm::mat4 transformInParentFrame = _fbxJoint->preTransform * glm::mat4_cast(rotationInParentFrame) * _fbxJoint->postTransform;
|
glm::mat4 transformInParentFrame = _preTransform * glm::mat4_cast(rotationInParentFrame) * _postTransform;
|
||||||
glm::mat4 newTransform = parentTransform * glm::translate(_fbxJoint->translation) * transformInParentFrame;
|
glm::mat4 newTransform = parentTransform * glm::translate(_translation) * transformInParentFrame;
|
||||||
|
|
||||||
if (newTransform != _transform) {
|
if (newTransform != _transform) {
|
||||||
_transform = newTransform;
|
_transform = newTransform;
|
||||||
|
@ -124,37 +162,35 @@ void JointState::computeTransform(const glm::mat4& parentTransform, bool parentT
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointState::computeVisibleTransform(const glm::mat4& parentTransform) {
|
void JointState::computeVisibleTransform(const glm::mat4& parentTransform) {
|
||||||
glm::quat rotationInParentFrame = _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation;
|
glm::quat rotationInParentFrame = _preRotation * _visibleRotationInConstrainedFrame * _postRotation;
|
||||||
glm::mat4 transformInParentFrame = _fbxJoint->preTransform * glm::mat4_cast(rotationInParentFrame) * _fbxJoint->postTransform;
|
glm::mat4 transformInParentFrame = _preTransform * glm::mat4_cast(rotationInParentFrame) * _postTransform;
|
||||||
_visibleTransform = parentTransform * glm::translate(_fbxJoint->translation) * transformInParentFrame;
|
_visibleTransform = parentTransform * glm::translate(_translation) * transformInParentFrame;
|
||||||
_visibleRotation = extractRotation(_visibleTransform);
|
_visibleRotation = extractRotation(_visibleTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat JointState::getRotationInBindFrame() const {
|
glm::quat JointState::getRotationInBindFrame() const {
|
||||||
return getRotation() * _fbxJoint->inverseBindRotation;
|
return getRotation() * _inverseBindRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat JointState::getRotationInParentFrame() const {
|
glm::quat JointState::getRotationInParentFrame() const {
|
||||||
return _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation;
|
return _preRotation * _rotationInConstrainedFrame * _postRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat JointState::getVisibleRotationInParentFrame() const {
|
glm::quat JointState::getVisibleRotationInParentFrame() const {
|
||||||
return _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation;
|
return _preRotation * _visibleRotationInConstrainedFrame * _postRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointState::restoreRotation(float fraction, float priority) {
|
void JointState::restoreRotation(float fraction, float priority) {
|
||||||
assert(_fbxJoint != NULL);
|
|
||||||
if (priority == _animationPriority || _animationPriority == 0.0f) {
|
if (priority == _animationPriority || _animationPriority == 0.0f) {
|
||||||
setRotationInConstrainedFrameInternal(safeMix(_rotationInConstrainedFrame, _fbxJoint->rotation, fraction));
|
setRotationInConstrainedFrameInternal(safeMix(_rotationInConstrainedFrame, _originalRotation, fraction));
|
||||||
_animationPriority = 0.0f;
|
_animationPriority = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointState::setRotationInBindFrame(const glm::quat& rotation, float priority, bool constrain) {
|
void JointState::setRotationInBindFrame(const glm::quat& rotation, float priority, bool constrain) {
|
||||||
// rotation is from bind- to model-frame
|
// rotation is from bind- to model-frame
|
||||||
assert(_fbxJoint != NULL);
|
|
||||||
if (priority >= _animationPriority) {
|
if (priority >= _animationPriority) {
|
||||||
glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * rotation * glm::inverse(_fbxJoint->inverseBindRotation);
|
glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * rotation * glm::inverse(_inverseBindRotation);
|
||||||
if (constrain && _constraint) {
|
if (constrain && _constraint) {
|
||||||
_constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f);
|
_constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f);
|
||||||
}
|
}
|
||||||
|
@ -175,7 +211,6 @@ void JointState::clearTransformTranslation() {
|
||||||
|
|
||||||
void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, float priority) {
|
void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, float priority) {
|
||||||
// NOTE: delta is in model-frame
|
// NOTE: delta is in model-frame
|
||||||
assert(_fbxJoint != NULL);
|
|
||||||
if (priority < _animationPriority || delta == glm::quat()) {
|
if (priority < _animationPriority || delta == glm::quat()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -196,14 +231,13 @@ void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, floa
|
||||||
/// This helps keep an IK solution stable.
|
/// This helps keep an IK solution stable.
|
||||||
void JointState::mixRotationDelta(const glm::quat& delta, float mixFactor, float priority) {
|
void JointState::mixRotationDelta(const glm::quat& delta, float mixFactor, float priority) {
|
||||||
// NOTE: delta is in model-frame
|
// NOTE: delta is in model-frame
|
||||||
assert(_fbxJoint != NULL);
|
|
||||||
if (priority < _animationPriority) {
|
if (priority < _animationPriority) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_animationPriority = priority;
|
_animationPriority = priority;
|
||||||
glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * delta * getRotation();
|
glm::quat targetRotation = _rotationInConstrainedFrame * glm::inverse(getRotation()) * delta * getRotation();
|
||||||
if (mixFactor > 0.0f && mixFactor <= 1.0f) {
|
if (mixFactor > 0.0f && mixFactor <= 1.0f) {
|
||||||
targetRotation = safeMix(targetRotation, _fbxJoint->rotation, mixFactor);
|
targetRotation = safeMix(targetRotation, _originalRotation, mixFactor);
|
||||||
}
|
}
|
||||||
if (_constraint) {
|
if (_constraint) {
|
||||||
_constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f);
|
_constraint->softClamp(targetRotation, _rotationInConstrainedFrame, 0.5f);
|
||||||
|
@ -213,10 +247,8 @@ void JointState::mixRotationDelta(const glm::quat& delta, float mixFactor, float
|
||||||
|
|
||||||
void JointState::mixVisibleRotationDelta(const glm::quat& delta, float mixFactor) {
|
void JointState::mixVisibleRotationDelta(const glm::quat& delta, float mixFactor) {
|
||||||
// NOTE: delta is in model-frame
|
// NOTE: delta is in model-frame
|
||||||
assert(_fbxJoint != NULL);
|
|
||||||
glm::quat targetRotation = _visibleRotationInConstrainedFrame * glm::inverse(_visibleRotation) * delta * _visibleRotation;
|
glm::quat targetRotation = _visibleRotationInConstrainedFrame * glm::inverse(_visibleRotation) * delta * _visibleRotation;
|
||||||
if (mixFactor > 0.0f && mixFactor <= 1.0f) {
|
if (mixFactor > 0.0f && mixFactor <= 1.0f) {
|
||||||
//targetRotation = safeMix(targetRotation, _fbxJoint->rotation, mixFactor);
|
|
||||||
targetRotation = safeMix(targetRotation, _rotationInConstrainedFrame, mixFactor);
|
targetRotation = safeMix(targetRotation, _rotationInConstrainedFrame, mixFactor);
|
||||||
}
|
}
|
||||||
setVisibleRotationInConstrainedFrame(targetRotation);
|
setVisibleRotationInConstrainedFrame(targetRotation);
|
||||||
|
@ -225,11 +257,11 @@ void JointState::mixVisibleRotationDelta(const glm::quat& delta, float mixFactor
|
||||||
glm::quat JointState::computeParentRotation() const {
|
glm::quat JointState::computeParentRotation() const {
|
||||||
// R = Rp * Rpre * r * Rpost
|
// R = Rp * Rpre * r * Rpost
|
||||||
// Rp = R * (Rpre * r * Rpost)^
|
// Rp = R * (Rpre * r * Rpost)^
|
||||||
return getRotation() * glm::inverse(_fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation);
|
return getRotation() * glm::inverse(_preRotation * _rotationInConstrainedFrame * _postRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat JointState::computeVisibleParentRotation() const {
|
glm::quat JointState::computeVisibleParentRotation() const {
|
||||||
return _visibleRotation * glm::inverse(_fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation);
|
return _visibleRotation * glm::inverse(_preRotation * _visibleRotationInConstrainedFrame * _postRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointState::setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain, float mix) {
|
void JointState::setRotationInConstrainedFrame(glm::quat targetRotation, float priority, bool constrain, float mix) {
|
||||||
|
@ -248,17 +280,17 @@ void JointState::setRotationInConstrainedFrameInternal(const glm::quat& targetRo
|
||||||
_rotationInConstrainedFrame = targetRotation;
|
_rotationInConstrainedFrame = targetRotation;
|
||||||
_transformChanged = true;
|
_transformChanged = true;
|
||||||
// R' = Rp * Rpre * r' * Rpost
|
// R' = Rp * Rpre * r' * Rpost
|
||||||
_rotation = parentRotation * _fbxJoint->preRotation * _rotationInConstrainedFrame * _fbxJoint->postRotation;
|
_rotation = parentRotation * _preRotation * _rotationInConstrainedFrame * _postRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointState::setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation) {
|
void JointState::setVisibleRotationInConstrainedFrame(const glm::quat& targetRotation) {
|
||||||
glm::quat parentRotation = computeVisibleParentRotation();
|
glm::quat parentRotation = computeVisibleParentRotation();
|
||||||
_visibleRotationInConstrainedFrame = targetRotation;
|
_visibleRotationInConstrainedFrame = targetRotation;
|
||||||
_visibleRotation = parentRotation * _fbxJoint->preRotation * _visibleRotationInConstrainedFrame * _fbxJoint->postRotation;
|
_visibleRotation = parentRotation * _preRotation * _visibleRotationInConstrainedFrame * _postRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JointState::rotationIsDefault(const glm::quat& rotation, float tolerance) const {
|
bool JointState::rotationIsDefault(const glm::quat& rotation, float tolerance) const {
|
||||||
glm::quat defaultRotation = _fbxJoint->rotation;
|
glm::quat defaultRotation = _originalRotation;
|
||||||
return glm::abs(rotation.x - defaultRotation.x) < tolerance &&
|
return glm::abs(rotation.x - defaultRotation.x) < tolerance &&
|
||||||
glm::abs(rotation.y - defaultRotation.y) < tolerance &&
|
glm::abs(rotation.y - defaultRotation.y) < tolerance &&
|
||||||
glm::abs(rotation.z - defaultRotation.z) < tolerance &&
|
glm::abs(rotation.z - defaultRotation.z) < tolerance &&
|
||||||
|
@ -266,13 +298,12 @@ bool JointState::rotationIsDefault(const glm::quat& rotation, float tolerance) c
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::quat JointState::getDefaultRotationInParentFrame() const {
|
glm::quat JointState::getDefaultRotationInParentFrame() const {
|
||||||
// NOTE: the result is constant and could be cached in the FBXJoint
|
// NOTE: the result is constant and could be cached
|
||||||
return _fbxJoint->preRotation * _fbxJoint->rotation * _fbxJoint->postRotation;
|
return _preRotation * _originalRotation * _postRotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
const glm::vec3& JointState::getDefaultTranslationInConstrainedFrame() const {
|
const glm::vec3& JointState::getDefaultTranslationInConstrainedFrame() const {
|
||||||
assert(_fbxJoint != NULL);
|
return _translation;
|
||||||
return _fbxJoint->translation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JointState::slaveVisibleTransform() {
|
void JointState::slaveVisibleTransform() {
|
||||||
|
|
|
@ -31,7 +31,6 @@ public:
|
||||||
~JointState();
|
~JointState();
|
||||||
|
|
||||||
void setFBXJoint(const FBXJoint* joint);
|
void setFBXJoint(const FBXJoint* joint);
|
||||||
const FBXJoint& getFBXJoint() const { return *_fbxJoint; }
|
|
||||||
|
|
||||||
void buildConstraint();
|
void buildConstraint();
|
||||||
void copyState(const JointState& state);
|
void copyState(const JointState& state);
|
||||||
|
@ -61,7 +60,7 @@ public:
|
||||||
const glm::vec3& getPositionInParentFrame() const { return _positionInParentFrame; }
|
const glm::vec3& getPositionInParentFrame() const { return _positionInParentFrame; }
|
||||||
float getDistanceToParent() const { return _distanceToParent; }
|
float getDistanceToParent() const { return _distanceToParent; }
|
||||||
|
|
||||||
int getParentIndex() const { return _fbxJoint->parentIndex; }
|
int getParentIndex() const { return _parentIndex; }
|
||||||
|
|
||||||
/// \param delta is in the model-frame
|
/// \param delta is in the model-frame
|
||||||
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);
|
||||||
|
@ -109,6 +108,17 @@ public:
|
||||||
void setTransform(const glm::mat4& transform) { _transform = transform; }
|
void setTransform(const glm::mat4& transform) { _transform = transform; }
|
||||||
void setVisibleTransform(const glm::mat4& transform) { _visibleTransform = transform; }
|
void setVisibleTransform(const glm::mat4& transform) { _visibleTransform = transform; }
|
||||||
|
|
||||||
|
const glm::vec3& getTranslation() const { return _translation; }
|
||||||
|
const glm::mat4& getPreTransform() const { return _preTransform; }
|
||||||
|
const glm::mat4& getPostTransform() const { return _postTransform; }
|
||||||
|
const glm::quat& getPreRotation() const { return _preRotation; }
|
||||||
|
const glm::quat& getPostRotation() const { return _postRotation; }
|
||||||
|
const glm::quat& getOriginalRotation() const { return _originalRotation; }
|
||||||
|
const glm::quat& getInverseDefaultRotation() const { return _inverseDefaultRotation; }
|
||||||
|
const QString& getName() const { return _name; }
|
||||||
|
float getBoneRadius() const { return _boneRadius; }
|
||||||
|
bool getIsFree() const { return _isFree; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setRotationInConstrainedFrameInternal(const glm::quat& targetRotation);
|
void setRotationInConstrainedFrameInternal(const glm::quat& targetRotation);
|
||||||
/// debug helper function
|
/// debug helper function
|
||||||
|
@ -126,7 +136,20 @@ private:
|
||||||
glm::quat _visibleRotation;
|
glm::quat _visibleRotation;
|
||||||
glm::quat _visibleRotationInConstrainedFrame;
|
glm::quat _visibleRotationInConstrainedFrame;
|
||||||
|
|
||||||
const FBXJoint* _fbxJoint; // JointState does NOT own its FBXJoint
|
glm::quat _originalRotation; // Not necessarilly bind rotation. See FBXJoint transform/bindTransform
|
||||||
|
glm::quat _inverseDefaultRotation;
|
||||||
|
glm::vec3 _translation;
|
||||||
|
float _boneRadius;
|
||||||
|
bool _isFree;
|
||||||
|
glm::vec3 _rotationMin;
|
||||||
|
glm::vec3 _rotationMax;
|
||||||
|
glm::quat _preRotation;
|
||||||
|
glm::quat _postRotation;
|
||||||
|
glm::mat4 _preTransform;
|
||||||
|
glm::mat4 _postTransform;
|
||||||
|
glm::quat _inverseBindRotation;
|
||||||
|
int _parentIndex;
|
||||||
|
QString _name;
|
||||||
AngularConstraint* _constraint; // JointState owns its AngularConstraint
|
AngularConstraint* _constraint; // JointState owns its AngularConstraint
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,7 @@ float Rig::initJointStates(QVector<JointState> states, glm::mat4 parentTransform
|
||||||
// Should we be using .fst mapping instead/also?
|
// Should we be using .fst mapping instead/also?
|
||||||
int Rig::indexOfJoint(const QString& jointName) {
|
int Rig::indexOfJoint(const QString& jointName) {
|
||||||
for (int i = 0; i < _jointStates.count(); i++) {
|
for (int i = 0; i < _jointStates.count(); i++) {
|
||||||
if (_jointStates[i].getFBXJoint().name == jointName) {
|
if (_jointStates[i].getName() == jointName) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,8 +237,7 @@ void Rig::initJointTransforms(glm::mat4 parentTransform) {
|
||||||
int numStates = _jointStates.size();
|
int numStates = _jointStates.size();
|
||||||
for (int i = 0; i < numStates; ++i) {
|
for (int i = 0; i < numStates; ++i) {
|
||||||
JointState& state = _jointStates[i];
|
JointState& state = _jointStates[i];
|
||||||
const FBXJoint& joint = state.getFBXJoint();
|
int parentIndex = state.getParentIndex();
|
||||||
int parentIndex = joint.parentIndex;
|
|
||||||
if (parentIndex == -1) {
|
if (parentIndex == -1) {
|
||||||
state.initTransform(parentTransform);
|
state.initTransform(parentTransform);
|
||||||
} else {
|
} else {
|
||||||
|
@ -532,8 +531,7 @@ bool Rig::setJointPosition(int jointIndex, const glm::vec3& position, const glm:
|
||||||
for (int j = 1; freeLineage.at(j - 1) != lastFreeIndex; j++) {
|
for (int j = 1; freeLineage.at(j - 1) != lastFreeIndex; j++) {
|
||||||
int index = freeLineage.at(j);
|
int index = freeLineage.at(j);
|
||||||
JointState& state = _jointStates[index];
|
JointState& state = _jointStates[index];
|
||||||
const FBXJoint& joint = state.getFBXJoint();
|
if (!(state.getIsFree() || allIntermediatesFree)) {
|
||||||
if (!(joint.isFree || allIntermediatesFree)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
glm::vec3 jointPosition = extractTranslation(state.getTransform());
|
glm::vec3 jointPosition = extractTranslation(state.getTransform());
|
||||||
|
@ -602,8 +600,7 @@ void Rig::inverseKinematics(int endIndex, glm::vec3 targetPosition, const glm::q
|
||||||
{
|
{
|
||||||
int index = freeLineage.last();
|
int index = freeLineage.last();
|
||||||
const JointState& state = _jointStates.at(index);
|
const JointState& state = _jointStates.at(index);
|
||||||
const FBXJoint& joint = state.getFBXJoint();
|
int parentIndex = state.getParentIndex();
|
||||||
int parentIndex = joint.parentIndex;
|
|
||||||
if (parentIndex == -1) {
|
if (parentIndex == -1) {
|
||||||
topParentTransform = parentTransform;
|
topParentTransform = parentTransform;
|
||||||
} else {
|
} else {
|
||||||
|
@ -628,8 +625,7 @@ void Rig::inverseKinematics(int endIndex, glm::vec3 targetPosition, const glm::q
|
||||||
for (int j = 1; j < numFree; j++) {
|
for (int j = 1; j < numFree; j++) {
|
||||||
int nextIndex = freeLineage.at(j);
|
int nextIndex = freeLineage.at(j);
|
||||||
JointState& nextState = _jointStates[nextIndex];
|
JointState& nextState = _jointStates[nextIndex];
|
||||||
FBXJoint nextJoint = nextState.getFBXJoint();
|
if (! nextState.getIsFree()) {
|
||||||
if (! nextJoint.isFree) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -803,20 +799,20 @@ void Rig::updateLeanJoint(int index, float leanSideways, float leanForward, floa
|
||||||
glm::angleAxis(- RADIANS_PER_DEGREE * leanSideways, inverse * zAxis) *
|
glm::angleAxis(- RADIANS_PER_DEGREE * leanSideways, inverse * zAxis) *
|
||||||
glm::angleAxis(- RADIANS_PER_DEGREE * leanForward, inverse * xAxis) *
|
glm::angleAxis(- RADIANS_PER_DEGREE * leanForward, inverse * xAxis) *
|
||||||
glm::angleAxis(RADIANS_PER_DEGREE * torsoTwist, inverse * yAxis) *
|
glm::angleAxis(RADIANS_PER_DEGREE * torsoTwist, inverse * yAxis) *
|
||||||
getJointState(index).getFBXJoint().rotation, DEFAULT_PRIORITY);
|
getJointState(index).getOriginalRotation(), DEFAULT_PRIORITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rig::updateNeckJoint(int index, const glm::quat& localHeadOrientation, float leanSideways, float leanForward, float torsoTwist) {
|
void Rig::updateNeckJoint(int index, const glm::quat& localHeadOrientation, float leanSideways, float leanForward, float torsoTwist) {
|
||||||
if (index >= 0 && _jointStates[index].getParentIndex() >= 0) {
|
if (index >= 0 && _jointStates[index].getParentIndex() >= 0) {
|
||||||
auto& parentState = _jointStates[_jointStates[index].getParentIndex()];
|
auto& state = _jointStates[index];
|
||||||
auto joint = _jointStates[index].getFBXJoint();
|
auto& parentState = _jointStates[state.getParentIndex()];
|
||||||
|
|
||||||
// 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(glm::quat());
|
glm::mat3 axes = glm::mat3_cast(glm::quat());
|
||||||
glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransform() *
|
glm::mat3 inverse = glm::mat3(glm::inverse(parentState.getTransform() *
|
||||||
glm::translate(getJointDefaultTranslationInConstrainedFrame(index)) *
|
glm::translate(getJointDefaultTranslationInConstrainedFrame(index)) *
|
||||||
joint.preTransform * glm::mat4_cast(joint.preRotation)));
|
state.getPreTransform() * glm::mat4_cast(state.getPreRotation())));
|
||||||
glm::vec3 pitchYawRoll = safeEulerAngles(localHeadOrientation);
|
glm::vec3 pitchYawRoll = safeEulerAngles(localHeadOrientation);
|
||||||
glm::vec3 lean = glm::radians(glm::vec3(leanForward, torsoTwist, leanSideways));
|
glm::vec3 lean = glm::radians(glm::vec3(leanForward, torsoTwist, leanSideways));
|
||||||
pitchYawRoll -= lean;
|
pitchYawRoll -= lean;
|
||||||
|
@ -824,19 +820,19 @@ void Rig::updateNeckJoint(int index, const glm::quat& localHeadOrientation, floa
|
||||||
glm::angleAxis(-pitchYawRoll.z, glm::normalize(inverse * axes[2])) *
|
glm::angleAxis(-pitchYawRoll.z, glm::normalize(inverse * axes[2])) *
|
||||||
glm::angleAxis(pitchYawRoll.y, glm::normalize(inverse * axes[1])) *
|
glm::angleAxis(pitchYawRoll.y, glm::normalize(inverse * axes[1])) *
|
||||||
glm::angleAxis(-pitchYawRoll.x, glm::normalize(inverse * axes[0])) *
|
glm::angleAxis(-pitchYawRoll.x, glm::normalize(inverse * axes[0])) *
|
||||||
joint.rotation, DEFAULT_PRIORITY);
|
state.getOriginalRotation(), DEFAULT_PRIORITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rig::updateEyeJoint(int index, const glm::quat& worldHeadOrientation, const glm::vec3& lookAt, const glm::vec3& saccade) {
|
void Rig::updateEyeJoint(int index, const glm::quat& worldHeadOrientation, const glm::vec3& lookAt, const glm::vec3& saccade) {
|
||||||
if (index >= 0 && _jointStates[index].getParentIndex() >= 0) {
|
if (index >= 0 && _jointStates[index].getParentIndex() >= 0) {
|
||||||
auto& parentState = _jointStates[_jointStates[index].getParentIndex()];
|
auto& state = _jointStates[index];
|
||||||
auto joint = _jointStates[index].getFBXJoint();
|
auto& parentState = _jointStates[state.getParentIndex()];
|
||||||
|
|
||||||
// NOTE: at the moment we do the math in the world-frame, hence the inverse transform is more complex than usual.
|
// NOTE: at the moment we do the math in the world-frame, hence the inverse transform is more complex than usual.
|
||||||
glm::mat4 inverse = glm::inverse(parentState.getTransform() *
|
glm::mat4 inverse = glm::inverse(parentState.getTransform() *
|
||||||
glm::translate(getJointDefaultTranslationInConstrainedFrame(index)) *
|
glm::translate(getJointDefaultTranslationInConstrainedFrame(index)) *
|
||||||
joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation));
|
state.getPreTransform() * glm::mat4_cast(state.getPreRotation() * state.getOriginalRotation()));
|
||||||
glm::vec3 front = glm::vec3(inverse * glm::vec4(worldHeadOrientation * IDENTITY_FRONT, 0.0f));
|
glm::vec3 front = glm::vec3(inverse * glm::vec4(worldHeadOrientation * IDENTITY_FRONT, 0.0f));
|
||||||
glm::vec3 lookAtDelta = lookAt;
|
glm::vec3 lookAtDelta = lookAt;
|
||||||
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(lookAtDelta + glm::length(lookAtDelta) * saccade, 1.0f));
|
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(lookAtDelta + glm::length(lookAtDelta) * saccade, 1.0f));
|
||||||
|
@ -844,6 +840,6 @@ void Rig::updateEyeJoint(int index, const glm::quat& worldHeadOrientation, const
|
||||||
const float MAX_ANGLE = 30.0f * RADIANS_PER_DEGREE;
|
const float MAX_ANGLE = 30.0f * RADIANS_PER_DEGREE;
|
||||||
float angle = glm::clamp(glm::angle(between), -MAX_ANGLE, MAX_ANGLE);
|
float angle = glm::clamp(glm::angle(between), -MAX_ANGLE, MAX_ANGLE);
|
||||||
glm::quat rot = glm::angleAxis(angle, glm::axis(between));
|
glm::quat rot = glm::angleAxis(angle, glm::axis(between));
|
||||||
setJointRotationInConstrainedFrame(index, rot * joint.rotation, DEFAULT_PRIORITY);
|
setJointRotationInConstrainedFrame(index, rot * state.getOriginalRotation(), DEFAULT_PRIORITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ void RigTests::initTestCase() {
|
||||||
|
|
||||||
static void reportJoint(int index, JointState joint) { // Handy for debugging
|
static void reportJoint(int index, JointState joint) { // Handy for debugging
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
std::cout << index << " " << joint.getFBXJoint().name.toUtf8().data() << "\n";
|
std::cout << index << " " << joint.getName.toUtf8().data() << "\n";
|
||||||
std::cout << " pos:" << joint.getPosition() << "/" << joint.getPositionInParentFrame() << " from " << joint.getParentIndex() << "\n";
|
std::cout << " pos:" << joint.getPosition() << "/" << joint.getPositionInParentFrame() << " from " << joint.getParentIndex() << "\n";
|
||||||
std::cout << " rot:" << safeEulerAngles(joint.getRotation()) << "/" << safeEulerAngles(joint.getRotationInParentFrame()) << "/" << safeEulerAngles(joint.getRotationInBindFrame()) << "\n";
|
std::cout << " rot:" << safeEulerAngles(joint.getRotation()) << "/" << safeEulerAngles(joint.getRotationInParentFrame()) << "/" << safeEulerAngles(joint.getRotationInBindFrame()) << "\n";
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
|
|
Loading…
Reference in a new issue