diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 4b7f64cb6f..abe9975a50 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -347,14 +347,19 @@ void MyAvatar::updateFromGyrosAndOrWebcam(bool gyroLook, } else if (webcam->isActive()) { estimatedRotation = webcam->getEstimatedRotation(); - } else if (_leadingAvatar) { - _head.getFace().clearFrame(); - return; - } else { - _head.setMousePitch(pitchFromTouch); - _head.setPitch(pitchFromTouch); + if (!_leadingAvatar) { + _head.setMousePitch(pitchFromTouch); + _head.setPitch(pitchFromTouch); + } _head.getFace().clearFrame(); + + // restore rotation, lean to neutral positions + const float RESTORE_RATE = 0.5f; + _head.setYaw(glm::mix(_head.getYaw(), 0.0f, RESTORE_RATE)); + _head.setRoll(glm::mix(_head.getRoll(), 0.0f, RESTORE_RATE)); + _head.setLeanSideways(glm::mix(_head.getLeanSideways(), 0.0f, RESTORE_RATE)); + _head.setLeanForward(glm::mix(_head.getLeanForward(), 0.0f, RESTORE_RATE)); return; } _head.setMousePitch(pitchFromTouch); diff --git a/interface/src/devices/Faceshift.cpp b/interface/src/devices/Faceshift.cpp index 399369cdd3..991a406cc7 100644 --- a/interface/src/devices/Faceshift.cpp +++ b/interface/src/devices/Faceshift.cpp @@ -73,6 +73,7 @@ void Faceshift::connectSocket() { const quint16 FACESHIFT_PORT = 33433; _socket.connectToHost("localhost", FACESHIFT_PORT); + _tracking = false; } } @@ -102,7 +103,7 @@ void Faceshift::readFromSocket() { switch (msg->id()) { case fsMsg::MSG_OUT_TRACKING_STATE: { const fsTrackingData& data = static_cast(msg.get())->tracking_data(); - if (data.m_trackingSuccessful) { + if ((_tracking = data.m_trackingSuccessful)) { _headRotation = glm::quat(data.m_headRotation.w, -data.m_headRotation.x, data.m_headRotation.y, -data.m_headRotation.z); const float TRANSLATION_SCALE = 0.02f; diff --git a/interface/src/devices/Faceshift.h b/interface/src/devices/Faceshift.h index 408513e5d7..586f336c04 100644 --- a/interface/src/devices/Faceshift.h +++ b/interface/src/devices/Faceshift.h @@ -24,7 +24,7 @@ public: Faceshift(); - bool isActive() const { return _socket.state() == QAbstractSocket::ConnectedState; } + bool isActive() const { return _socket.state() == QAbstractSocket::ConnectedState && _tracking; } const glm::quat& getHeadRotation() const { return _headRotation; } const glm::vec3& getHeadTranslation() const { return _headTranslation; } @@ -66,6 +66,7 @@ private: QTcpSocket _socket; fs::fsBinaryStream _stream; bool _enabled; + bool _tracking; glm::quat _headRotation; glm::vec3 _headTranslation;