diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 673813b0db..35a8f65c06 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4429,9 +4429,7 @@ void Application::update(float deltaTime) { myAvatar->setSpineControllerPosesInSensorFrame(hipsPose.transform(avatarToSensorMatrix), spine2Pose.transform(avatarToSensorMatrix)); controller::Pose headPose = userInputMapper->getPoseState(controller::Action::HEAD); - if (headPose.isValid()) { - myAvatar->setHeadControllerPoseInSensorFrame(headPose.transform(avatarToSensorMatrix)); - } + myAvatar->setHeadControllerPoseInSensorFrame(headPose.transform(avatarToSensorMatrix)); controller::Pose leftArmPose = userInputMapper->getPoseState(controller::Action::LEFT_ARM); controller::Pose rightArmPose = userInputMapper->getPoseState(controller::Action::RIGHT_ARM); @@ -4867,20 +4865,6 @@ bool Application::isHMDMode() const { return getActiveDisplayPlugin()->isHmd(); } -bool Application::isHeadControllerEnabled() const { - auto pluginManager = PluginManager::getInstance(); - if (!pluginManager) { - return false; - } - const InputPluginList& inputPlugins = pluginManager->getInputPlugins(); - for (auto& ip : inputPlugins) { - if (ip && ip->isActive() && ip->isHeadController()) { - return true; - } - } - return false; -} - float Application::getTargetFrameRate() const { return getActiveDisplayPlugin()->getTargetFrameRate(); } QRect Application::getDesirableApplicationGeometry() const { diff --git a/interface/src/Application.h b/interface/src/Application.h index ec3792ea75..9cf03f1cef 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -248,7 +248,6 @@ public: // rendering of several elements depend on that // TODO: carry that information on the Camera as a setting virtual bool isHMDMode() const override; - bool isHeadControllerEnabled() const; glm::mat4 getHMDSensorPose() const; glm::mat4 getEyeOffset(int eye) const; glm::mat4 getEyeProjection(int eye) const; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index c26cdf0b01..7e998b11c0 100755 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -641,9 +641,13 @@ void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) { // Ignore unreasonable HMD sensor data return; } + _hmdSensorPosition = newHmdSensorPosition; _hmdSensorOrientation = glm::quat_cast(hmdSensorMatrix); - _headControllerFacing = getFacingDir2D(_headControllerPoseInSensorFrameCache.get().rotation); + auto headPose = _headControllerPoseInSensorFrameCache.get(); + if (headPose.isValid()) { + _headControllerFacing = getFacingDir2D(headPose.rotation); + } } void MyAvatar::updateJointFromController(controller::Action poseKey, ThreadSafeValueCache& matrixCache) { @@ -1884,7 +1888,7 @@ void MyAvatar::updateOrientation(float deltaTime) { getHead()->setBasePitch(getHead()->getBasePitch() + getDriveKey(PITCH) * _pitchSpeed * deltaTime); - if (qApp->isHeadControllerEnabled()) { + if (getHeadControllerPoseInAvatarFrame().isValid()) { glm::quat localOrientation = getHeadControllerPoseInAvatarFrame().rotation; // these angles will be in radians // ... so they need to be converted to degrees before we do math... diff --git a/interface/src/avatar/MySkeletonModel.cpp b/interface/src/avatar/MySkeletonModel.cpp index 3721eea569..e74df4cf0f 100644 --- a/interface/src/avatar/MySkeletonModel.cpp +++ b/interface/src/avatar/MySkeletonModel.cpp @@ -52,26 +52,18 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) { // input action is the highest priority source for head orientation. auto avatarHeadPose = myAvatar->getHeadControllerPoseInAvatarFrame(); if (avatarHeadPose.isValid()) { - glm::mat4 rigHeadMat = Matrices::Y_180 * createMatFromQuatAndPos(avatarHeadPose.getRotation(), avatarHeadPose.getTranslation()); + glm::mat4 rigHeadMat = Matrices::Y_180 * + createMatFromQuatAndPos(avatarHeadPose.getRotation(), avatarHeadPose.getTranslation()); headParams.rigHeadPosition = extractTranslation(rigHeadMat); headParams.rigHeadOrientation = glmExtractRotation(rigHeadMat); headParams.headEnabled = true; } else { - if (qApp->isHMDMode()) { - // get HMD position from sensor space into world space, and back into rig space - glm::mat4 worldHMDMat = myAvatar->getHeadControllerPoseInWorldFrame().getMatrix(); - glm::mat4 rigToWorld = createMatFromQuatAndPos(getRotation(), getTranslation()); - glm::mat4 worldToRig = glm::inverse(rigToWorld); - glm::mat4 rigHMDMat = worldToRig * worldHMDMat; - _rig.computeHeadFromHMD(AnimPose(rigHMDMat), headParams.rigHeadPosition, headParams.rigHeadOrientation); - headParams.headEnabled = true; - } else { - // even though full head IK is disabled, the rig still needs the head orientation to rotate the head up and down in desktop mode. - // preMult 180 is necessary to convert from avatar to rig coordinates. - // postMult 180 is necessary to convert head from -z forward to z forward. - headParams.rigHeadOrientation = Quaternions::Y_180 * head->getFinalOrientationInLocalFrame() * Quaternions::Y_180; - headParams.headEnabled = false; - } + // even though full head IK is disabled, the rig still needs the head orientation to rotate the head up and + // down in desktop mode. + // preMult 180 is necessary to convert from avatar to rig coordinates. + // postMult 180 is necessary to convert head from -z forward to z forward. + headParams.rigHeadOrientation = Quaternions::Y_180 * head->getFinalOrientationInLocalFrame() * Quaternions::Y_180; + headParams.headEnabled = false; } auto avatarHipsPose = myAvatar->getHipsControllerPoseInAvatarFrame(); diff --git a/plugins/oculus/src/OculusControllerManager.cpp b/plugins/oculus/src/OculusControllerManager.cpp index ff3e614077..4b7873c86d 100644 --- a/plugins/oculus/src/OculusControllerManager.cpp +++ b/plugins/oculus/src/OculusControllerManager.cpp @@ -210,10 +210,8 @@ void OculusControllerManager::RemoteDevice::focusOutEvent() { _buttonPressedMap.clear(); } -bool OculusControllerManager::isHeadController() const { - // this plugin is a head controller if the HMD is mounted. +bool OculusControllerManager::isHeadControllerMounted() const { ovrSessionStatus status; - bool success = OVR_SUCCESS(ovr_GetSessionStatus(_session, &status)); if (!success) { return false; @@ -224,12 +222,12 @@ bool OculusControllerManager::isHeadController() const { void OculusControllerManager::TouchDevice::update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { _buttonPressedMap.clear(); - _poseStateMap.erase(controller::HEAD); + // _poseStateMap.erase(controller::HEAD); - if (!_parent.isHeadController()) { - // if the HMD isn't on someone's head, don't take input from the controllers - return; - } + // if (!_parent.isHeadControllerMounted()) { + // // if the HMD isn't on someone's head, don't take input from the controllers + // return; + // } int numTrackedControllers = 0; quint64 currentTime = usecTimestampNow(); @@ -261,7 +259,11 @@ void OculusControllerManager::TouchDevice::update(float deltaTime, handleRotationForUntrackedHand(inputCalibrationData, hand, tracking.HandPoses[hand]); }); - handleHeadPose(deltaTime, inputCalibrationData, tracking.HeadPose); + if (_parent.isHeadControllerMounted()) { + handleHeadPose(deltaTime, inputCalibrationData, tracking.HeadPose); + } else { + _poseStateMap[controller::HEAD].valid = false; + } using namespace controller; // Axes diff --git a/plugins/oculus/src/OculusControllerManager.h b/plugins/oculus/src/OculusControllerManager.h index 54237645eb..69187f94a6 100644 --- a/plugins/oculus/src/OculusControllerManager.h +++ b/plugins/oculus/src/OculusControllerManager.h @@ -28,7 +28,8 @@ public: const QString getName() const override { return NAME; } bool isHandController() const override { return _touch != nullptr; } - bool isHeadController() const override; + bool isHeadController() const override { return true; } + bool isHeadControllerMounted() const; QStringList getSubdeviceNames() override; bool activate() override; diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index abff0770a7..b5fa7cadad 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -164,8 +164,8 @@ void ViveControllerManager::deactivate() { _registeredWithInputMapper = false; } -bool ViveControllerManager::isHeadController() const { - if (_inputDevice && _inputDevice->isHeadController()) { +bool ViveControllerManager::isHeadControllerMounted() const { + if (_inputDevice && _inputDevice->isHeadControllerMounted()) { return true; } vr::EDeviceActivityLevel activityLevel = _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd); diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index d03818ea34..35ad2df359 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -41,7 +41,8 @@ public: const QString getName() const override { return NAME; } bool isHandController() const override { return true; } - bool isHeadController() const override; + bool isHeadController() const override { return true; } + bool isHeadControllerMounted() const; bool activate() override; void deactivate() override; @@ -55,7 +56,7 @@ private: class InputDevice : public controller::InputDevice { public: InputDevice(vr::IVRSystem*& system); - bool isHeadController() const { return _overrideHead; } + bool isHeadControllerMounted() const { return _overrideHead; } private: // Device functions controller::Input::NamedVector getAvailableInputs() const override;