From 735fd70a8eff47b4060879218c935b2df37c159d Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 10 Nov 2015 17:04:53 -0800 Subject: [PATCH 1/3] Tweak perHandRotation/Position in action --- interface/src/avatar/AvatarActionHold.cpp | 36 +++++++++++++---------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index ad2465404c..7ca25dad42 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -35,8 +35,8 @@ AvatarActionHold::~AvatarActionHold() { void AvatarActionHold::updateActionWorker(float deltaTimeStep) { bool gotLock = false; - glm::quat rotation; - glm::vec3 position; + glm::quat rotation { Quaternions::IDENTITY }; + glm::vec3 position { Vectors::ZERO }; std::shared_ptr holdingAvatar = nullptr; gotLock = withTryReadLock([&]{ @@ -46,9 +46,11 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) { if (holdingAvatar) { bool isRightHand = (_hand == "right"); - glm::vec3 palmPosition; - glm::quat palmRotation; + glm::vec3 palmPosition { Vectors::ZERO }; + glm::quat palmRotation { Quaternions::IDENTITY }; + + static const glm::quat yFlip = glm::angleAxis(PI, Vectors::UNIT_Y); if (_ignoreIK && holdingAvatar->isMyAvatar()) { // 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. @@ -58,6 +60,7 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) { } else { palmPosition = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getPosition(); palmRotation = holdingAvatar->getHand()->getCopyOfPalmData(HandData::LeftHand).getRotation(); + palmRotation *= yFlip; // Match right hand frame of reference } } else { if (isRightHand) { @@ -66,28 +69,31 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) { } else { palmPosition = holdingAvatar->getLeftPalmPosition(); palmRotation = holdingAvatar->getLeftPalmRotation(); + palmRotation *= yFlip; // Match right hand frame of reference } } + rotation = palmRotation * _relativeRotation; + position = palmPosition + rotation * _relativePosition; + if (isRightHand) { - rotation = palmRotation * _perHandRelativeRotation; - position = palmPosition + rotation * _perHandRelativePosition; + rotation *= _perHandRelativeRotation; + position += rotation * _perHandRelativePosition; } else { auto mirroredRotation = _perHandRelativeRotation; auto mirroredPosition = _perHandRelativePosition; - // Mirror along x axis - mirroredRotation.x *= -1; - mirroredRotation.w *= -1; + // Mirror along z axis + auto eulerAngles = safeEulerAngles(mirroredRotation); + eulerAngles.x *= -1; + eulerAngles.y *= -1; + mirroredRotation = glm::quat(eulerAngles); - mirroredPosition.x *= -1; + mirroredPosition.z *= -1; - rotation = palmRotation * mirroredRotation; - position = palmPosition + rotation * mirroredPosition; + rotation *= mirroredRotation; + position += rotation * mirroredPosition; } - - rotation = rotation * _relativeRotation; - position = position + rotation * _relativePosition; } }); From 4f1420a5eeb242a6d9733981781be15de4a32c17 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 10 Nov 2015 17:05:27 -0800 Subject: [PATCH 2/3] Tweak bat offsets --- examples/baseball/createBatButton.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/baseball/createBatButton.js b/examples/baseball/createBatButton.js index 931ff185a4..f16f126f2c 100644 --- a/examples/baseball/createBatButton.js +++ b/examples/baseball/createBatButton.js @@ -52,9 +52,9 @@ grabbableKey: { spatialKey: { relativePosition: { x: 0.9, y: 0, z: 0 }, - relativeRotation: Quat.fromPitchYawRollDegrees(0, 90, 0), - perHandRelativePosition: { x: 0.0808223, y: 0.134704, z: 0.0381 }, - perHandRelativeRotation: Quat.fromPitchYawRollDegrees(-180, 90, 45) + relativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 45), + perHandRelativePosition: { x: 0.0, y: -0.05, z: -0.04 }, + perHandRelativeRotation: Quat.fromPitchYawRollDegrees(0, 0, 0) } } } From ce57488b9fe8f668757c90a8b3922fdfc11a1d73 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 10 Nov 2015 17:10:15 -0800 Subject: [PATCH 3/3] cleanup dead code --- .../src/input-plugins/ViveControllerManager.cpp | 12 +----------- .../src/input-plugins/ViveControllerManager.h | 11 ++++------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp index 9c95bb9426..88fdff4bce 100644 --- a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp +++ b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp @@ -206,16 +206,6 @@ void ViveControllerManager::renderHand(const controller::Pose& pose, gpu::Batch& batch.drawIndexed(gpu::TRIANGLES, mesh->getNumIndices(), 0); } -#ifdef Q_OS_WIN -glm::vec3 ViveControllerManager::getPosition(int hand) const { - const mat4& mat = _trackedDevicePoseMat4[hand ? 3 : 4]; - return extractTranslation(mat); -} -glm::quat ViveControllerManager::getRotation(int hand) const { - const mat4& mat = _trackedDevicePoseMat4[hand ? 3 : 4]; - return glm::quat_cast(mat); -} -#endif void ViveControllerManager::pluginUpdate(float deltaTime, bool jointsCaptured) { _inputDevice->update(deltaTime, jointsCaptured); @@ -263,7 +253,7 @@ void ViveControllerManager::InputDevice::update(float deltaTime, bool jointsCapt bool left = numTrackedControllers == 2; const mat4& mat = _trackedDevicePoseMat4[device]; - + if (!jointsCaptured) { handlePoseEvent(mat, numTrackedControllers - 1); } diff --git a/libraries/input-plugins/src/input-plugins/ViveControllerManager.h b/libraries/input-plugins/src/input-plugins/ViveControllerManager.h index d664326da8..02bdecb10a 100644 --- a/libraries/input-plugins/src/input-plugins/ViveControllerManager.h +++ b/libraries/input-plugins/src/input-plugins/ViveControllerManager.h @@ -31,7 +31,6 @@ namespace vr { class ViveControllerManager : public InputPlugin { Q_OBJECT public: - static const QString NAME; // Plugin functions virtual bool isSupported() const override; @@ -47,12 +46,6 @@ public: void updateRendering(RenderArgs* args, render::ScenePointer scene, render::PendingChanges pendingChanges); void setRenderControllers(bool renderControllers) { _renderControllers = renderControllers; } - - -#ifdef Q_OS_WIN - glm::vec3 getPosition(int device) const; - glm::quat getRotation(int device) const; -#endif private: class InputDevice : public controller::InputDevice { @@ -89,6 +82,10 @@ private: bool _renderControllers { false }; vr::IVRSystem* _hmd { nullptr }; std::shared_ptr _inputDevice { std::make_shared(_hmd) }; + + static const QString NAME; + + }; #endif // hifi__ViveControllerManager