When devices become inactive (including when Faceshift reports loss of

tracking), smoothly restore neutral head rotation/lean.
This commit is contained in:
Andrzej Kapolka 2013-09-10 11:14:36 -07:00
parent 13a19e2986
commit c56778c3bf
3 changed files with 15 additions and 8 deletions

View file

@ -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);

View file

@ -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<fsMsgTrackingState*>(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;

View file

@ -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;