From 36fdaa63509524cbaea9565195cc1ddb8941a347 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Sun, 15 Jan 2017 10:10:54 -0800 Subject: [PATCH] avoid a little pop when grabbing something with ignore-ik as true --- interface/src/avatar/AvatarActionHold.cpp | 34 +++++++++++++++-------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index f1b2ee1440..bb61074e73 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -128,32 +128,44 @@ bool AvatarActionHold::getTarget(float deltaTimeStep, glm::quat& rotation, glm:: glm::quat palmRotation; if (holdingAvatar->isMyAvatar()) { + std::shared_ptr myAvatar = avatarManager->getMyAvatar(); // fetch the hand controller pose controller::Pose pose; if (isRightHand) { - pose = avatarManager->getMyAvatar()->getRightHandControllerPoseInWorldFrame(); + pose = myAvatar->getRightHandControllerPoseInWorldFrame(); } else { - pose = avatarManager->getMyAvatar()->getLeftHandControllerPoseInWorldFrame(); + pose = myAvatar->getLeftHandControllerPoseInWorldFrame(); } if (pose.isValid()) { linearVelocity = pose.getVelocity(); angularVelocity = pose.getAngularVelocity(); - - if (isRightHand) { - pose = avatarManager->getMyAvatar()->getRightHandControllerPoseInAvatarFrame(); - } else { - pose = avatarManager->getMyAvatar()->getLeftHandControllerPoseInAvatarFrame(); - } } if (_ignoreIK && pose.isValid()) { + + // this position/rotation should be the same as the one in scripts/system/libraries/controllers.js + // otherwise things will do a little hop when you grab them. + + // if (isRightHand) { + // pose = myAvatar->getRightHandControllerPoseInAvatarFrame(); + // } else { + // pose = myAvatar->getLeftHandControllerPoseInAvatarFrame(); + // } + // glm::vec3 camRelPos = pose.getTranslation(); + // glm::quat camRelRot = pose.getRotation(); + + int camRelIndex = isRightHand ? + CAMERA_RELATIVE_CONTROLLER_RIGHTHAND_INDEX : + CAMERA_RELATIVE_CONTROLLER_LEFTHAND_INDEX; + glm::vec3 camRelPos = myAvatar->getAbsoluteJointTranslationInObjectFrame(camRelIndex); + glm::quat camRelRot = myAvatar->getAbsoluteJointRotationInObjectFrame(camRelIndex); + Transform avatarTransform; - auto myAvatar = DependencyManager::get()->getMyAvatar(); avatarTransform = myAvatar->getTransform(); - palmPosition = avatarTransform.transform(pose.getTranslation() / myAvatar->getDomainLimitedScale()); - palmRotation = avatarTransform.getRotation() * pose.getRotation(); + palmPosition = avatarTransform.transform(camRelPos / myAvatar->getDomainLimitedScale()); + palmRotation = avatarTransform.getRotation() * camRelRot; } else { glm::vec3 avatarRigidBodyPosition; glm::quat avatarRigidBodyRotation;