mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 22:17:57 +02:00
More transform rejiggery.
This commit is contained in:
parent
d393bdcea6
commit
1f8bed9d9c
6 changed files with 61 additions and 71 deletions
|
@ -44,42 +44,21 @@ void FaceModel::simulate(float deltaTime) {
|
||||||
Model::simulate(deltaTime);
|
Model::simulate(deltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FaceModel::updateJointState(int index) {
|
void FaceModel::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
|
||||||
JointState& state = _jointStates[index];
|
// get the rotation axes in joint space and use them to adjust the rotation
|
||||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
glm::mat3 axes = glm::mat3_cast(_rotation);
|
||||||
const FBXJoint& joint = geometry.joints.at(index);
|
glm::quat inverse = parentState.combinedRotation * joint.preRotation * joint.rotation;
|
||||||
|
state.rotation = glm::angleAxis(_owningHead->getRoll(), glm::normalize(inverse * axes[2])) *
|
||||||
glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation;
|
glm::angleAxis(_owningHead->getYaw(), glm::normalize(inverse * axes[1])) *
|
||||||
if (joint.parentIndex == -1) {
|
glm::angleAxis(_owningHead->getPitch(), glm::normalize(inverse * axes[0])) * joint.rotation;
|
||||||
glm::mat4 baseTransform = glm::translate(_translation) * glm::mat4_cast(_rotation) *
|
}
|
||||||
glm::scale(_scale) * glm::translate(_offset);
|
|
||||||
|
void FaceModel::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
|
||||||
state.transform = baseTransform * geometry.offset * joint.preTransform *
|
// likewise with the eye joints
|
||||||
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
glm::mat4 inverse = glm::inverse(parentState.transform *
|
||||||
state.combinedRotation = _rotation * combinedRotation;
|
joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation));
|
||||||
|
glm::vec3 front = glm::vec3(inverse * glm::vec4(_owningHead->getOrientation() * IDENTITY_FRONT, 0.0f));
|
||||||
} else {
|
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(_owningHead->getLookAtPosition() +
|
||||||
const JointState& parentState = _jointStates.at(joint.parentIndex);
|
_owningHead->getSaccade(), 1.0f));
|
||||||
if (index == geometry.neckJointIndex) {
|
state.rotation = rotationBetween(front, lookAt) * joint.rotation;
|
||||||
// get the rotation axes in joint space and use them to adjust the rotation
|
|
||||||
glm::mat3 axes = glm::mat3_cast(getRotation());
|
|
||||||
glm::mat3 inverse = glm::inverse(glm::mat3(parentState.transform *
|
|
||||||
joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation)));
|
|
||||||
state.rotation = glm::angleAxis(_owningHead->getRoll(), glm::normalize(inverse * axes[2])) *
|
|
||||||
glm::angleAxis(_owningHead->getYaw(), glm::normalize(inverse * axes[1])) *
|
|
||||||
glm::angleAxis(_owningHead->getPitch(), glm::normalize(inverse * axes[0])) * joint.rotation;
|
|
||||||
|
|
||||||
} else if (index == geometry.leftEyeJointIndex || index == geometry.rightEyeJointIndex) {
|
|
||||||
// likewise with the eye joints
|
|
||||||
glm::mat4 inverse = glm::inverse(parentState.transform *
|
|
||||||
joint.preTransform * glm::mat4_cast(joint.preRotation * joint.rotation));
|
|
||||||
glm::vec3 front = glm::vec3(inverse * glm::vec4(_owningHead->getOrientation() * IDENTITY_FRONT, 0.0f));
|
|
||||||
glm::vec3 lookAt = glm::vec3(inverse * glm::vec4(_owningHead->getLookAtPosition() +
|
|
||||||
_owningHead->getSaccade(), 1.0f));
|
|
||||||
state.rotation = rotationBetween(front, lookAt) * joint.rotation;
|
|
||||||
}
|
|
||||||
state.transform = parentState.transform * joint.preTransform *
|
|
||||||
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
|
||||||
state.combinedRotation = parentState.combinedRotation * combinedRotation;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/// Updates the state of the joint at the specified index.
|
virtual void maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state);
|
||||||
virtual void updateJointState(int index);
|
virtual void maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -58,38 +58,21 @@ bool SkeletonModel::render(float alpha) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonModel::updateJointState(int index) {
|
void SkeletonModel::updateJointState(int index) {
|
||||||
JointState& state = _jointStates[index];
|
Model::updateJointState(index);
|
||||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
|
||||||
const FBXJoint& joint = geometry.joints.at(index);
|
|
||||||
|
|
||||||
glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation;
|
if (index == _geometry->getFBXGeometry().rootJointIndex) {
|
||||||
if (joint.parentIndex == -1) {
|
JointState& state = _jointStates[index];
|
||||||
glm::mat4 baseTransform = glm::translate(_translation) * glm::mat4_cast(_rotation) *
|
|
||||||
glm::scale(_scale) * glm::translate(_offset);
|
|
||||||
|
|
||||||
state.transform = baseTransform * geometry.offset * joint.preTransform *
|
|
||||||
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
|
||||||
state.combinedRotation = _rotation * combinedRotation;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
const JointState& parentState = _jointStates.at(joint.parentIndex);
|
|
||||||
if (index == geometry.leanJointIndex) {
|
|
||||||
// get the rotation axes in joint space and use them to adjust the rotation
|
|
||||||
state.combinedRotation = _rotation * glm::quat(glm::radians(glm::vec3(_owningAvatar->getHead().getLeanForward(),
|
|
||||||
0.0f, _owningAvatar->getHead().getLeanSideways()))) * glm::inverse(_rotation) * parentState.combinedRotation *
|
|
||||||
joint.preRotation * joint.rotation;
|
|
||||||
state.rotation = glm::inverse(joint.postRotation * glm::inverse(state.combinedRotation) *
|
|
||||||
parentState.combinedRotation * joint.preRotation);
|
|
||||||
combinedRotation = joint.preRotation * state.rotation * joint.postRotation;
|
|
||||||
}
|
|
||||||
state.transform = parentState.transform * joint.preTransform *
|
|
||||||
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
|
||||||
state.combinedRotation = parentState.combinedRotation * combinedRotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (index == geometry.rootJointIndex) {
|
|
||||||
state.transform[3][0] = _translation.x;
|
state.transform[3][0] = _translation.x;
|
||||||
state.transform[3][1] = _translation.y;
|
state.transform[3][1] = _translation.y;
|
||||||
state.transform[3][2] = _translation.z;
|
state.transform[3][2] = _translation.z;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SkeletonModel::maybeUpdateLeanRotation(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::quat inverse = parentState.combinedRotation * joint.preRotation * joint.rotation;
|
||||||
|
state.rotation = glm::angleAxis(-_owningAvatar->getHead().getLeanSideways(), glm::normalize(inverse * axes[2])) *
|
||||||
|
glm::angleAxis(-_owningAvatar->getHead().getLeanForward(), glm::normalize(inverse * axes[0])) * joint.rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@ protected:
|
||||||
/// Updates the state of the joint at the specified index.
|
/// Updates the state of the joint at the specified index.
|
||||||
virtual void updateJointState(int index);
|
virtual void updateJointState(int index);
|
||||||
|
|
||||||
|
virtual void maybeUpdateLeanRotation(const JointState& parentState, const FBXJoint& joint, JointState& state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Avatar* _owningAvatar;
|
Avatar* _owningAvatar;
|
||||||
|
|
|
@ -387,23 +387,45 @@ void Model::updateJointState(int index) {
|
||||||
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
const FBXGeometry& geometry = _geometry->getFBXGeometry();
|
||||||
const FBXJoint& joint = geometry.joints.at(index);
|
const FBXJoint& joint = geometry.joints.at(index);
|
||||||
|
|
||||||
glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation;
|
|
||||||
if (joint.parentIndex == -1) {
|
if (joint.parentIndex == -1) {
|
||||||
glm::mat4 baseTransform = glm::translate(_translation) * glm::mat4_cast(_rotation) *
|
glm::mat4 baseTransform = glm::translate(_translation) * glm::mat4_cast(_rotation) *
|
||||||
glm::scale(_scale) * glm::translate(_offset);
|
glm::scale(_scale) * glm::translate(_offset);
|
||||||
|
|
||||||
|
glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation;
|
||||||
state.transform = baseTransform * geometry.offset * joint.preTransform *
|
state.transform = baseTransform * geometry.offset * joint.preTransform *
|
||||||
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
||||||
state.combinedRotation = _rotation * combinedRotation;
|
state.combinedRotation = _rotation * combinedRotation;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const JointState& parentState = _jointStates.at(joint.parentIndex);
|
const JointState& parentState = _jointStates.at(joint.parentIndex);
|
||||||
|
if (index == geometry.leanJointIndex) {
|
||||||
|
maybeUpdateLeanRotation(parentState, joint, state);
|
||||||
|
|
||||||
|
} else if (index == geometry.neckJointIndex) {
|
||||||
|
maybeUpdateNeckRotation(parentState, joint, state);
|
||||||
|
|
||||||
|
} else if (index == geometry.leftEyeJointIndex || index == geometry.rightEyeJointIndex) {
|
||||||
|
maybeUpdateEyeRotation(parentState, joint, state);
|
||||||
|
}
|
||||||
|
glm::quat combinedRotation = joint.preRotation * state.rotation * joint.postRotation;
|
||||||
state.transform = parentState.transform * joint.preTransform *
|
state.transform = parentState.transform * joint.preTransform *
|
||||||
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
glm::mat4_cast(combinedRotation) * joint.postTransform;
|
||||||
state.combinedRotation = parentState.combinedRotation * combinedRotation;
|
state.combinedRotation = parentState.combinedRotation * combinedRotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Model::maybeUpdateLeanRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
|
||||||
|
// nothing by default
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
|
||||||
|
// nothing by default
|
||||||
|
}
|
||||||
|
|
||||||
|
void Model::maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state) {
|
||||||
|
// nothing by default
|
||||||
|
}
|
||||||
|
|
||||||
bool Model::getJointPosition(int jointIndex, glm::vec3& position) const {
|
bool Model::getJointPosition(int jointIndex, glm::vec3& position) const {
|
||||||
if (jointIndex == -1 || _jointStates.isEmpty()) {
|
if (jointIndex == -1 || _jointStates.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -94,6 +94,10 @@ protected:
|
||||||
/// Updates the state of the joint at the specified index.
|
/// Updates the state of the joint at the specified index.
|
||||||
virtual void updateJointState(int index);
|
virtual void updateJointState(int index);
|
||||||
|
|
||||||
|
virtual void maybeUpdateLeanRotation(const JointState& parentState, const FBXJoint& joint, JointState& state);
|
||||||
|
virtual void maybeUpdateNeckRotation(const JointState& parentState, const FBXJoint& joint, JointState& state);
|
||||||
|
virtual void maybeUpdateEyeRotation(const JointState& parentState, const FBXJoint& joint, JointState& state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool getJointPosition(int jointIndex, glm::vec3& position) const;
|
bool getJointPosition(int jointIndex, glm::vec3& position) const;
|
||||||
|
|
Loading…
Reference in a new issue