Desktop users of different height can shake hands

This commit is contained in:
David Kelly 2017-05-11 14:20:42 -07:00
parent e4df4369ad
commit 52c288bfed

View file

@ -198,7 +198,7 @@
}
var animationData = {};
function updateAnimationData() {
function updateAnimationData(verticalOffset) {
// all we are doing here is moving the right hand to a spot
// that is in front of and a bit above the hips. Basing how
// far in front as scaling with the avatar's height (say hips
@ -209,6 +209,9 @@
offset = 0.8 * MyAvatar.getAbsoluteJointTranslationInObjectFrame(headIndex).y;
}
animationData.rightHandPosition = Vec3.multiply(offset, {x: -0.25, y: 0.8, z: 1.3});
if (verticalOffset) {
animationData.rightHandPosition.y += verticalOffset;
}
animationData.rightHandRotation = Quat.fromPitchYawRollDegrees(90, 0, 90);
}
function shakeHandsAnimation() {
@ -347,7 +350,32 @@
}
return false;
}
function findNearestAvatar() {
// We only look some max distance away (much larger than the handshake distance, but still...)
var minDistance = MAX_AVATAR_DISTANCE * 20;
var closestAvatar;
AvatarList.getAvatarIdentifiers().forEach(function (id) {
var avatar = AvatarList.getAvatar(id);
if (avatar && avatar.sessionUUID != MyAvatar.sessionUUID) {
var currentDistance = Vec3.distance(avatar.position, MyAvatar.position);
if (minDistance > currentDistance) {
minDistance = currentDistance;
closestAvatar = avatar;
}
}
});
return closestAvatar;
}
function adjustAnimationHeight() {
var avatar = findNearestAvatar();
if (avatar) {
var myHeadIndex = MyAvatar.getJointIndex("Head");
var otherHeadIndex = avatar.getJointIndex("Head");
var diff = (avatar.getJointPosition(otherHeadIndex).y - MyAvatar.getJointPosition(myHeadIndex).y) / 2;
print("head height difference: " + diff);
updateAnimationData(diff);
}
}
function findNearestWaitingAvatar() {
var handPosition = getHandPosition(MyAvatar, currentHandJointIndex);
var minDistance = MAX_AVATAR_DISTANCE;
@ -436,6 +464,10 @@
handStringMessageSend({
key: "waiting",
});
// potentially adjust height of handshake
if (fromKeyboard) {
adjustAnimationHeight();
}
lookForWaitingAvatar();
}
}