mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
move details of getJointRotation() into JointState
also: remove unused getLeft/RightHandRotation() methods
This commit is contained in:
parent
4cf5628783
commit
a898fcbf75
4 changed files with 20 additions and 27 deletions
|
@ -145,12 +145,11 @@ void SkeletonModel::applyHandPosition(int jointIndex, const glm::vec3& position)
|
|||
if (forearmLength < EPSILON) {
|
||||
return;
|
||||
}
|
||||
glm::quat handRotation;
|
||||
getJointRotation(jointIndex, handRotation, true);
|
||||
JointState& state = _jointStates[jointIndex];
|
||||
glm::quat handRotation = state.getJointRotation(true);
|
||||
|
||||
// align hand with forearm
|
||||
float sign = (jointIndex == geometry.rightHandJointIndex) ? 1.0f : -1.0f;
|
||||
JointState& state = _jointStates[jointIndex];
|
||||
state.applyRotationDelta(rotationBetween(handRotation * glm::vec3(-sign, 0.0f, 0.0f), forearmVector), true, PALM_PRIORITY);
|
||||
}
|
||||
|
||||
|
@ -169,9 +168,11 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) {
|
|||
glm::quat palmRotation;
|
||||
if (!Menu::getInstance()->isOptionChecked(MenuOption::AlternateIK) &&
|
||||
Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) {
|
||||
getJointRotation(parentJointIndex, palmRotation, true);
|
||||
JointState parentState = _jointStates[parentJointIndex];
|
||||
palmRotation = parentState.getJointRotation(true);
|
||||
} else {
|
||||
getJointRotation(jointIndex, palmRotation, true);
|
||||
JointState state = _jointStates[jointIndex];
|
||||
palmRotation = state.getJointRotation(true);
|
||||
}
|
||||
palmRotation = rotationBetween(palmRotation * geometry.palmDirection, palm.getNormal()) * palmRotation;
|
||||
|
||||
|
@ -367,18 +368,10 @@ bool SkeletonModel::getLeftHandPosition(glm::vec3& position) const {
|
|||
return getJointPosition(getLeftHandJointIndex(), position);
|
||||
}
|
||||
|
||||
bool SkeletonModel::getLeftHandRotation(glm::quat& rotation) const {
|
||||
return getJointRotation(getLeftHandJointIndex(), rotation);
|
||||
}
|
||||
|
||||
bool SkeletonModel::getRightHandPosition(glm::vec3& position) const {
|
||||
return getJointPosition(getRightHandJointIndex(), position);
|
||||
}
|
||||
|
||||
bool SkeletonModel::getRightHandRotation(glm::quat& rotation) const {
|
||||
return getJointRotation(getRightHandJointIndex(), rotation);
|
||||
}
|
||||
|
||||
bool SkeletonModel::restoreLeftHandPosition(float percent, float priority) {
|
||||
return restoreJointPosition(getLeftHandJointIndex(), percent, priority);
|
||||
}
|
||||
|
|
|
@ -45,18 +45,10 @@ public:
|
|||
/// \return true whether or not the position was found
|
||||
bool getLeftHandPosition(glm::vec3& position) const;
|
||||
|
||||
/// Retrieve the rotation of the left hand
|
||||
/// \return true whether or not the rotation was found
|
||||
bool getLeftHandRotation(glm::quat& rotation) const;
|
||||
|
||||
/// Retrieve the position of the right hand
|
||||
/// \return true whether or not the position was found
|
||||
bool getRightHandPosition(glm::vec3& position) const;
|
||||
|
||||
/// Retrieve the rotation of the right hand
|
||||
/// \return true whether or not the rotation was found
|
||||
bool getRightHandRotation(glm::quat& rotation) const;
|
||||
|
||||
/// Restores some percentage of the default position of the left hand.
|
||||
/// \param percent the percentage of the default position to restore
|
||||
/// \return whether or not the left hand joint was found
|
||||
|
|
|
@ -630,12 +630,10 @@ bool Model::getJointPosition(int jointIndex, glm::vec3& position) const {
|
|||
}
|
||||
|
||||
bool Model::getJointRotation(int jointIndex, glm::quat& rotation, bool fromBind) const {
|
||||
if (jointIndex == -1 || _jointStates.isEmpty()) {
|
||||
if (jointIndex == -1 || jointIndex >= _jointStates.size()) {
|
||||
return false;
|
||||
}
|
||||
rotation = _jointStates[jointIndex]._combinedRotation *
|
||||
(fromBind ? _geometry->getFBXGeometry().joints[jointIndex].inverseBindRotation :
|
||||
_geometry->getFBXGeometry().joints[jointIndex].inverseDefaultRotation);
|
||||
rotation = _jointStates[jointIndex].getJointRotation(fromBind);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1156,9 +1154,11 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& translation, const
|
|||
glm::quat endRotation;
|
||||
if (useRotation) {
|
||||
JointState& state = _jointStates[jointIndex];
|
||||
getJointRotation(jointIndex, endRotation, true);
|
||||
|
||||
// TODO: figure out what this is trying to do and combine it into one JointState method
|
||||
endRotation = state.getJointRotation(true);
|
||||
state.applyRotationDelta(rotation * glm::inverse(endRotation), true, priority);
|
||||
getJointRotation(jointIndex, endRotation, true);
|
||||
endRotation = state.getJointRotation(true);
|
||||
}
|
||||
|
||||
// then, we go from the joint upwards, rotating the end as close as possible to the target
|
||||
|
@ -1895,6 +1895,10 @@ void JointState::updateWorldTransform(const glm::mat4& baseTransform, const glm:
|
|||
_combinedRotation = parentRotation * combinedRotation;
|
||||
}
|
||||
|
||||
glm::quat JointState::getJointRotation(bool fromBind) const {
|
||||
return _combinedRotation * (fromBind ? _fbxJoint->inverseBindRotation : _fbxJoint->inverseDefaultRotation);
|
||||
}
|
||||
|
||||
void JointState::applyRotationDelta(const glm::quat& delta, bool constrain, float priority) {
|
||||
if (priority < _animationPriority) {
|
||||
return;
|
||||
|
|
|
@ -41,6 +41,10 @@ public:
|
|||
void copyState(const JointState& state);
|
||||
|
||||
void updateWorldTransform(const glm::mat4& baseTransform, const glm::quat& parentRotation);
|
||||
|
||||
/// \return rotation from the joint's default (or bind) orientation
|
||||
glm::quat getJointRotation(bool fromBind = false) const;
|
||||
|
||||
void applyRotationDelta(const glm::quat& delta, bool constrain = true, float priority = 1.0f);
|
||||
|
||||
glm::vec3 _translation; // translation relative to parent
|
||||
|
|
Loading…
Reference in a new issue