mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 07:37:20 +02:00
do some hokey pokey to avoid jitter of held entities while walking
This commit is contained in:
parent
3b278adba3
commit
174a95a005
2 changed files with 35 additions and 5 deletions
|
@ -56,6 +56,12 @@ void AvatarActionHold::prepareForPhysicsSimulation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
withWriteLock([&]{
|
withWriteLock([&]{
|
||||||
|
glm::vec3 avatarRigidBodyPosition;
|
||||||
|
glm::quat avatarRigidBodyRotation;
|
||||||
|
getAvatarRigidBodyLocation(avatarRigidBodyPosition, avatarRigidBodyRotation);
|
||||||
|
_preStepAvatarPosition = avatarRigidBodyPosition;
|
||||||
|
_preStepAvatarRotation = avatarRigidBodyRotation;
|
||||||
|
|
||||||
if (_ignoreIK) {
|
if (_ignoreIK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -70,9 +76,6 @@ void AvatarActionHold::prepareForPhysicsSimulation() {
|
||||||
palmRotation = holdingAvatar->getUncachedLeftPalmRotation();
|
palmRotation = holdingAvatar->getUncachedLeftPalmRotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 avatarRigidBodyPosition;
|
|
||||||
glm::quat avatarRigidBodyRotation;
|
|
||||||
getAvatarRigidBodyLocation(avatarRigidBodyPosition, avatarRigidBodyRotation);
|
|
||||||
|
|
||||||
// determine the difference in translation and rotation between the avatar's
|
// determine the difference in translation and rotation between the avatar's
|
||||||
// rigid body and the palm position. The avatar's rigid body will be moved by bullet
|
// rigid body and the palm position. The avatar's rigid body will be moved by bullet
|
||||||
|
@ -129,8 +132,32 @@ bool AvatarActionHold::getTarget(float deltaTimeStep, glm::quat& rotation, glm::
|
||||||
if (_ignoreIK && pose.isValid()) {
|
if (_ignoreIK && pose.isValid()) {
|
||||||
// We cannot ignore other avatars IK and this is not the point of this option
|
// We cannot ignore other avatars IK and this is not the point of this option
|
||||||
// This is meant to make the grabbing behavior more reactive.
|
// This is meant to make the grabbing behavior more reactive.
|
||||||
palmPosition = pose.getTranslation();
|
|
||||||
palmRotation = pose.getRotation();
|
// The avatar moves between prepareForPhysicsSimulation and this, so do some stuff to avoid jitter:
|
||||||
|
// - transform the pose's world-position into the space relative to the old rigid-body
|
||||||
|
// - then transform this relative position back into world-space via the new rigid-body's transform
|
||||||
|
|
||||||
|
Transform poseTransform;
|
||||||
|
poseTransform.setTranslation(pose.getTranslation());
|
||||||
|
poseTransform.setRotation(pose.getRotation());
|
||||||
|
|
||||||
|
Transform preStepAvatarTransform;
|
||||||
|
preStepAvatarTransform.setTranslation(_preStepAvatarPosition);
|
||||||
|
preStepAvatarTransform.setRotation(_preStepAvatarRotation);
|
||||||
|
Transform inversePreStepAvatarTransform = Transform(preStepAvatarTransform.getInverseMatrix());
|
||||||
|
|
||||||
|
Transform avatarTransform;
|
||||||
|
glm::vec3 avatarRigidBodyPosition;
|
||||||
|
glm::quat avatarRigidBodyRotation;
|
||||||
|
getAvatarRigidBodyLocation(avatarRigidBodyPosition, avatarRigidBodyRotation);
|
||||||
|
avatarTransform.setTranslation(avatarRigidBodyPosition);
|
||||||
|
avatarTransform.setRotation(avatarRigidBodyRotation);
|
||||||
|
|
||||||
|
glm::mat4 adjustedMatrix = avatarTransform.getMatrix() *
|
||||||
|
(inversePreStepAvatarTransform.getMatrix() * poseTransform.getMatrix());
|
||||||
|
Transform adjustedTransform = Transform(adjustedMatrix);
|
||||||
|
palmPosition = adjustedTransform.getTranslation();
|
||||||
|
palmRotation = adjustedTransform.getRotation();
|
||||||
} else {
|
} else {
|
||||||
glm::vec3 avatarRigidBodyPosition;
|
glm::vec3 avatarRigidBodyPosition;
|
||||||
glm::quat avatarRigidBodyRotation;
|
glm::quat avatarRigidBodyRotation;
|
||||||
|
|
|
@ -68,6 +68,9 @@ private:
|
||||||
static const int velocitySmoothFrames;
|
static const int velocitySmoothFrames;
|
||||||
QVector<glm::vec3> _measuredLinearVelocities;
|
QVector<glm::vec3> _measuredLinearVelocities;
|
||||||
int _measuredLinearVelocitiesIndex { 0 };
|
int _measuredLinearVelocitiesIndex { 0 };
|
||||||
|
|
||||||
|
glm::vec3 _preStepAvatarPosition;
|
||||||
|
glm::quat _preStepAvatarRotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AvatarActionHold_h
|
#endif // hifi_AvatarActionHold_h
|
||||||
|
|
Loading…
Reference in a new issue