mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 00:16:39 +02:00
Gravity adjustments.
This commit is contained in:
parent
1ae8a211bb
commit
be09d319b7
2 changed files with 14 additions and 13 deletions
|
@ -660,12 +660,13 @@ void Avatar::updateArmIKAndConstraints(float deltaTime, AvatarJointID fingerTipJ
|
||||||
float distance = glm::length(armVector);
|
float distance = glm::length(armVector);
|
||||||
|
|
||||||
// don't let right hand get dragged beyond maximum arm length...
|
// don't let right hand get dragged beyond maximum arm length...
|
||||||
if (distance > _maxArmLength) {
|
float armLength = _maxArmLength * 0.5f;
|
||||||
|
if (distance > armLength) {
|
||||||
// reset right hand to be constrained to maximum arm length
|
// reset right hand to be constrained to maximum arm length
|
||||||
fingerJoint.position = shoulderJoint.position;
|
fingerJoint.position = shoulderJoint.position;
|
||||||
glm::vec3 armNormal = armVector / distance;
|
glm::vec3 armNormal = armVector / distance;
|
||||||
armVector = armNormal * _maxArmLength;
|
armVector = armNormal * armLength;
|
||||||
distance = _maxArmLength;
|
distance = armLength;
|
||||||
glm::vec3 constrainedPosition = shoulderJoint.position;
|
glm::vec3 constrainedPosition = shoulderJoint.position;
|
||||||
constrainedPosition += armVector;
|
constrainedPosition += armVector;
|
||||||
fingerJoint.position = constrainedPosition;
|
fingerJoint.position = constrainedPosition;
|
||||||
|
|
|
@ -616,16 +616,16 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position) {
|
||||||
// this is a constraint relaxation algorithm: see
|
// this is a constraint relaxation algorithm: see
|
||||||
// http://www.ryanjuckett.com/programming/animation/22-constraint-relaxation-ik-in-2d
|
// http://www.ryanjuckett.com/programming/animation/22-constraint-relaxation-ik-in-2d
|
||||||
|
|
||||||
// start by optimistically setting the position of the end joint to our target
|
|
||||||
setJointTranslation(jointIndex, freeLineage.at(1), -1, relativePosition);
|
|
||||||
|
|
||||||
// the influence of gravity; lowers the potential energy of our configurations
|
// the influence of gravity; lowers the potential energy of our configurations
|
||||||
glm::vec3 gravity = _rotation * IDENTITY_UP * -0.1f;
|
glm::vec3 gravity = _rotation * IDENTITY_UP * -0.01f;
|
||||||
|
|
||||||
// over one or more iterations, apply the length constraints and update the rotations accordingly
|
// over one or more iterations, apply the length constraints and update the rotations accordingly
|
||||||
float uniformScale = (_scale.x + _scale.y + _scale.z) / 3.0f;
|
float uniformScale = (_scale.x + _scale.y + _scale.z) / 3.0f;
|
||||||
const int ITERATION_COUNT = 1;
|
const int ITERATION_COUNT = 3;
|
||||||
for (int i = 0; i < ITERATION_COUNT; i++) {
|
for (int i = 0; i < ITERATION_COUNT; i++) {
|
||||||
|
// start by optimistically setting the position of the end joint to our target
|
||||||
|
setJointTranslation(jointIndex, freeLineage.at(1), -1, relativePosition);
|
||||||
|
|
||||||
for (int j = 1; j < freeLineage.size(); j++) {
|
for (int j = 1; j < freeLineage.size(); j++) {
|
||||||
int sourceIndex = freeLineage.at(j);
|
int sourceIndex = freeLineage.at(j);
|
||||||
int destIndex = freeLineage.at(j - 1);
|
int destIndex = freeLineage.at(j - 1);
|
||||||
|
@ -657,11 +657,11 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position) {
|
||||||
destTranslation + boneVector * extension * 0.5f + gravity);
|
destTranslation + boneVector * extension * 0.5f + gravity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// now update the joint states from the top
|
// now update the joint states from the top
|
||||||
for (int i = freeLineage.size() - 1; i >= 0; i--) {
|
for (int j = freeLineage.size() - 1; j >= 0; j--) {
|
||||||
updateJointState(freeLineage.at(i));
|
updateJointState(freeLineage.at(j));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue