mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
unravel rotation code by giving proper names
The goal is: eliminate dependency on JointState::_combinedRotation (which is joint-to-world) and store joint-to-model transforms instead
This commit is contained in:
parent
9b3773fa3b
commit
d7be5faa9d
3 changed files with 15 additions and 17 deletions
|
@ -147,7 +147,7 @@ void SkeletonModel::applyHandPosition(int jointIndex, const glm::vec3& position)
|
|||
return;
|
||||
}
|
||||
JointState& state = _jointStates[jointIndex];
|
||||
glm::quat handRotation = state.getJointRotation();
|
||||
glm::quat handRotation = state.getRotationFromBindToModelFrame();
|
||||
|
||||
// align hand with forearm
|
||||
float sign = (jointIndex == geometry.rightHandJointIndex) ? 1.0f : -1.0f;
|
||||
|
@ -170,10 +170,10 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) {
|
|||
if (!Menu::getInstance()->isOptionChecked(MenuOption::AlternateIK) &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) {
|
||||
JointState parentState = _jointStates[parentJointIndex];
|
||||
palmRotation = parentState.getJointRotation();
|
||||
palmRotation = parentState.getRotationFromBindToModelFrame();
|
||||
} else {
|
||||
JointState state = _jointStates[jointIndex];
|
||||
palmRotation = state.getJointRotation();
|
||||
palmRotation = state.getRotationFromBindToModelFrame();
|
||||
}
|
||||
palmRotation = rotationBetween(palmRotation * geometry.palmDirection, palm.getNormal()) * palmRotation;
|
||||
|
||||
|
@ -414,7 +414,7 @@ bool SkeletonModel::getNeckParentRotation(glm::quat& neckParentRotation) const {
|
|||
if (geometry.neckJointIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
return getJointRotationInWorldFrame(geometry.joints.at(geometry.neckJointIndex).parentIndex, neckParentRotation);
|
||||
return getJointRotationFromBindToWorldFrame(geometry.joints.at(geometry.neckJointIndex).parentIndex, neckParentRotation);
|
||||
}
|
||||
|
||||
bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const {
|
||||
|
@ -433,7 +433,7 @@ bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& seco
|
|||
const float EYE_PROPORTION = 0.6f;
|
||||
glm::vec3 baseEyePosition = glm::mix(neckPosition, headPosition, EYE_PROPORTION);
|
||||
glm::quat headRotation;
|
||||
getJointRotationInWorldFrame(geometry.headJointIndex, headRotation);
|
||||
getJointRotationFromBindToWorldFrame(geometry.headJointIndex, headRotation);
|
||||
const float EYES_FORWARD = 0.25f;
|
||||
const float EYE_SEPARATION = 0.1f;
|
||||
float headHeight = glm::distance(neckPosition, headPosition);
|
||||
|
|
|
@ -756,11 +756,11 @@ bool Model::getJointPosition(int jointIndex, glm::vec3& position) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool Model::getJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) const {
|
||||
bool Model::getJointRotationFromBindToWorldFrame(int jointIndex, glm::quat& rotation) const {
|
||||
if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
|
||||
return false;
|
||||
}
|
||||
rotation = _jointStates[jointIndex].getJointRotation();
|
||||
rotation = _rotation * _jointStates[jointIndex].getRotationFromBindToModelFrame();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1227,7 +1227,7 @@ void Model::simulateInternal(float deltaTime) {
|
|||
glm::vec3 jointTranslation = _translation;
|
||||
glm::quat jointRotation = _rotation;
|
||||
getJointPosition(attachment.jointIndex, jointTranslation);
|
||||
getJointRotationInWorldFrame(attachment.jointIndex, jointRotation);
|
||||
getJointRotationFromBindToWorldFrame(attachment.jointIndex, jointRotation);
|
||||
|
||||
model->setTranslation(jointTranslation + jointRotation * attachment.translation * _scale);
|
||||
model->setRotation(jointRotation * attachment.rotation);
|
||||
|
@ -1306,9 +1306,9 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& translation, const
|
|||
JointState& state = _jointStates[jointIndex];
|
||||
|
||||
// TODO: figure out what this is trying to do and combine it into one JointState method
|
||||
endRotation = state.getJointRotation();
|
||||
endRotation = _rotation * state.getRotationFromBindToModelFrame();
|
||||
state.applyRotationDelta(rotation * glm::inverse(endRotation), true, priority);
|
||||
endRotation = state.getJointRotation();
|
||||
endRotation = _rotation * state.getRotationFromBindToModelFrame();
|
||||
}
|
||||
|
||||
// then, we go from the joint upwards, rotating the end as close as possible to the target
|
||||
|
@ -2067,10 +2067,8 @@ void JointState::computeTransforms(const glm::mat4& parentTransform, const glm::
|
|||
_combinedRotation = baseRotation * modifiedRotation;
|
||||
}
|
||||
|
||||
glm::quat JointState::getJointRotation() const {
|
||||
assert(_fbxJoint != NULL);
|
||||
return _combinedRotation * _fbxJoint->inverseBindRotation;
|
||||
//return _rotationInModelFrame * _fbxJoint->inverseBindRotation;
|
||||
glm::quat JointState::getRotationFromBindToModelFrame() const {
|
||||
return _rotationInModelFrame * _fbxJoint->inverseBindRotation;
|
||||
}
|
||||
|
||||
void JointState::restoreRotation(float fraction, float priority) {
|
||||
|
|
|
@ -52,8 +52,8 @@ public:
|
|||
/// computes new _transform and _combinedRotation
|
||||
void computeTransforms(const glm::mat4& baseTransform, const glm::quat& baseRotation);
|
||||
|
||||
/// \return rotation from the joint's default (or bind) frame to world frame
|
||||
glm::quat getJointRotation() const;
|
||||
/// \return rotation that moves a vector given in this joint's bind-frame to the model-frame
|
||||
glm::quat getRotationFromBindToModelFrame() const;
|
||||
|
||||
void applyRotationDelta(const glm::quat& delta, bool constrain = true, float priority = 1.0f);
|
||||
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
int getLastFreeJointIndex(int jointIndex) const;
|
||||
|
||||
bool getJointPosition(int jointIndex, glm::vec3& position) const;
|
||||
bool getJointRotationInWorldFrame(int jointIndex, glm::quat& rotation) const;
|
||||
bool getJointRotationFromBindToWorldFrame(int jointIndex, glm::quat& rotation) const;
|
||||
bool getJointCombinedRotation(int jointIndex, glm::quat& rotation) const;
|
||||
|
||||
QStringList getJointNames() const;
|
||||
|
|
Loading…
Reference in a new issue