Tweak perHandRotation/Position in action

This commit is contained in:
Atlante45 2015-11-10 17:04:53 -08:00
parent 3cbe1bc4da
commit 735fd70a8e

View file

@ -35,8 +35,8 @@ AvatarActionHold::~AvatarActionHold() {
void AvatarActionHold::updateActionWorker(float deltaTimeStep) { void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
bool gotLock = false; bool gotLock = false;
glm::quat rotation; glm::quat rotation { Quaternions::IDENTITY };
glm::vec3 position; glm::vec3 position { Vectors::ZERO };
std::shared_ptr<Avatar> holdingAvatar = nullptr; std::shared_ptr<Avatar> holdingAvatar = nullptr;
gotLock = withTryReadLock([&]{ gotLock = withTryReadLock([&]{
@ -46,9 +46,11 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
if (holdingAvatar) { if (holdingAvatar) {
bool isRightHand = (_hand == "right"); bool isRightHand = (_hand == "right");
glm::vec3 palmPosition; glm::vec3 palmPosition { Vectors::ZERO };
glm::quat palmRotation; glm::quat palmRotation { Quaternions::IDENTITY };
static const glm::quat yFlip = glm::angleAxis(PI, Vectors::UNIT_Y);
if (_ignoreIK && holdingAvatar->isMyAvatar()) { if (_ignoreIK && holdingAvatar->isMyAvatar()) {
// 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.
@ -58,6 +60,7 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
} else { } else {
palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition(); palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition();
palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation(); palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation();
palmRotation *= yFlip; // Match right hand frame of reference
} }
} else { } else {
if (isRightHand) { if (isRightHand) {
@ -66,28 +69,31 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) {
} else { } else {
palmPosition = holdingAvatar->getLeftPalmPosition(); palmPosition = holdingAvatar->getLeftPalmPosition();
palmRotation = holdingAvatar->getLeftPalmRotation(); palmRotation = holdingAvatar->getLeftPalmRotation();
palmRotation *= yFlip; // Match right hand frame of reference
} }
} }
rotation = palmRotation * _relativeRotation;
position = palmPosition + rotation * _relativePosition;
if (isRightHand) { if (isRightHand) {
rotation = palmRotation * _perHandRelativeRotation; rotation *= _perHandRelativeRotation;
position = palmPosition + rotation * _perHandRelativePosition; position += rotation * _perHandRelativePosition;
} else { } else {
auto mirroredRotation = _perHandRelativeRotation; auto mirroredRotation = _perHandRelativeRotation;
auto mirroredPosition = _perHandRelativePosition; auto mirroredPosition = _perHandRelativePosition;
// Mirror along x axis // Mirror along z axis
mirroredRotation.x *= -1; auto eulerAngles = safeEulerAngles(mirroredRotation);
mirroredRotation.w *= -1; eulerAngles.x *= -1;
eulerAngles.y *= -1;
mirroredRotation = glm::quat(eulerAngles);
mirroredPosition.x *= -1; mirroredPosition.z *= -1;
rotation = palmRotation * mirroredRotation; rotation *= mirroredRotation;
position = palmPosition + rotation * mirroredPosition; position += rotation * mirroredPosition;
} }
rotation = rotation * _relativeRotation;
position = position + rotation * _relativePosition;
} }
}); });