From c63fc8557cda1fa992ca12ac9134ce355f6f790c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Brisset?= Date: Tue, 3 Nov 2015 10:11:25 -0800 Subject: [PATCH] More baseball test code --- interface/src/avatar/AvatarActionHold.cpp | 53 ++++++++++--------- .../input-plugins/ViveControllerManager.cpp | 32 ++++++----- 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/interface/src/avatar/AvatarActionHold.cpp b/interface/src/avatar/AvatarActionHold.cpp index 5bec513fd4..b6e3ea408f 100644 --- a/interface/src/avatar/AvatarActionHold.cpp +++ b/interface/src/avatar/AvatarActionHold.cpp @@ -52,32 +52,35 @@ void AvatarActionHold::updateActionWorker(float deltaTimeStep) { glm::vec3 offset; glm::vec3 palmPosition; glm::quat palmRotation; - - const auto& plugins = PluginManager::getInstance()->getInputPlugins(); - auto it = std::find_if(std::begin(plugins), std::end(plugins), [](const InputPluginPointer& plugin) { - return plugin->getName() == ViveControllerManager::NAME; - }); - - if (it != std::end(plugins)) { - const auto& vive = it->dynamicCast(); - auto index = (_hand == "right") ? 0 : 1; + +#ifdef Q_OS_WIN + const auto& plugins = PluginManager::getInstance()->getInputPlugins(); + auto it = std::find_if(std::begin(plugins), std::end(plugins), [](const InputPluginPointer& plugin) { + return plugin->getName() == ViveControllerManager::NAME; + }); + + if (it != std::end(plugins)) { + const auto& vive = it->dynamicCast(); + auto index = (_hand == "left") ? 0 : 1; auto userInputMapper = DependencyManager::get(); - auto translation = extractTranslation(userInputMapper->getSensorToWorldMat()); - auto rotation = glm::quat_cast(userInputMapper->getSensorToWorldMat()); - - - const glm::quat quarterX = glm::angleAxis(PI / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f)); - const glm::quat yFlip = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); - palmPosition = translation + rotation * vive->getPosition(index); - palmRotation = rotation * vive->getRotation(index) * yFlip * quarterX; - } else if (_hand == "right") { - palmPosition = holdingAvatar->getRightPalmPosition(); - palmRotation = holdingAvatar->getRightPalmRotation(); - } else { - palmPosition = holdingAvatar->getLeftPalmPosition(); - palmRotation = holdingAvatar->getLeftPalmRotation(); - } - + auto translation = extractTranslation(userInputMapper->getSensorToWorldMat()); + auto rotation = glm::quat_cast(userInputMapper->getSensorToWorldMat()); + + + const glm::quat quarterX = glm::angleAxis(PI / 2.0f, glm::vec3(1.0f, 0.0f, 0.0f)); + const glm::quat yFlip = glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); + palmPosition = translation + rotation * vive->getPosition(index); + palmRotation = rotation * vive->getRotation(index) * yFlip * quarterX * glm::angleAxis(PI, glm::vec3(1.0f, 0.0f, 0.0f)) * glm::angleAxis(PI_OVER_TWO, glm::vec3(0.0f, 0.0f, 1.0f)); + } else +#endif + if (_hand == "right") { + palmPosition = holdingAvatar->getRightPalmPosition(); + palmRotation = holdingAvatar->getRightPalmRotation(); + } else { + palmPosition = holdingAvatar->getLeftPalmPosition(); + palmRotation = holdingAvatar->getLeftPalmRotation(); + } + rotation = palmRotation * _relativeRotation; offset = rotation * _relativePosition; position = palmPosition + offset; diff --git a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp index b8755ea2e3..f5863c6ed0 100644 --- a/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp +++ b/libraries/input-plugins/src/input-plugins/ViveControllerManager.cpp @@ -278,12 +278,18 @@ void ViveControllerManager::update(float deltaTime, bool jointsCaptured) { //qDebug() << "Trackpad: " << controllerState.rAxis[0].x << " " << controllerState.rAxis[0].y; //qDebug() << "Trigger: " << controllerState.rAxis[1].x << " " << controllerState.rAxis[1].y; for (uint32_t i = 0; i < vr::k_EButton_Max; ++i) { - auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)i); - bool pressed = 0 != (controllerState.ulButtonPressed & mask); + auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)i); + bool pressed = 0 != (controllerState.ulButtonPressed & mask); handleButtonEvent(i, pressed, left); } - for (uint32_t i = 0; i < vr::k_unControllerStateAxisCount; i++) { - handleAxisEvent(i, controllerState.rAxis[i].x, controllerState.rAxis[i].y, left); + for (uint32_t i = 0; i < vr::k_unControllerStateAxisCount; i++) { + auto mask = vr::ButtonMaskFromId((vr::EVRButtonId)(i + vr::k_EButton_Axis0)); + bool pressed = 0 != (controllerState.ulButtonPressed & mask); + if (pressed || true) { + handleAxisEvent(i, controllerState.rAxis[i].x, controllerState.rAxis[i].y, left); + } else { + handleAxisEvent(i, 0.0f, 0.0f, left); + } } } } @@ -412,16 +418,14 @@ void ViveControllerManager::handlePoseEvent(const mat4& mat, bool left) { const glm::quat signedQuaterZ = glm::angleAxis(sign * PI / 2.0f, glm::vec3(0.0f, 0.0f, 1.0f)); const glm::quat eighthX = glm::angleAxis(PI / 4.0f, glm::vec3(1.0f, 0.0f, 0.0f)); - - const glm::quat rotationOffset = glm::inverse(signedQuaterZ * eighthX) * yFlip * quarterX; - const glm::vec3 translationOffset = glm::vec3(sign * CONTROLLER_LENGTH_OFFSET / 2.0f, - CONTROLLER_LENGTH_OFFSET / 2.0f, - 2.0f * CONTROLLER_LENGTH_OFFSET); - - position += rotation * translationOffset; - rotation = rotation * rotationOffset; - //{quat, x = 0.653281, y = -0.270598, z = 0.653281, w = 0.270598}{vec3, x = 0.0381, y = -0.0381, z = -0.1524} - + const glm::quat rotationOffset = glm::inverse(signedQuaterZ * eighthX) * yFlip * quarterX; + const glm::vec3 translationOffset = glm::vec3(sign * CONTROLLER_LENGTH_OFFSET / 2.0f, + CONTROLLER_LENGTH_OFFSET / 2.0f, + 2.0f * CONTROLLER_LENGTH_OFFSET); + + position += rotation * translationOffset; + rotation = rotation * rotationOffset; + _poseStateMap[left ? controller::LEFT_HAND : controller::RIGHT_HAND] = controller::Pose(position, rotation); }