From f83254882aff25e823a1d19c64962616736c1492 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 18 Feb 2014 16:07:08 -0800 Subject: [PATCH] Attempting to get the head rotation from Visage. --- interface/src/Application.cpp | 10 ++++++++++ interface/src/Application.h | 2 ++ interface/src/avatar/MyAvatar.cpp | 24 +++++++++++++++++------- interface/src/devices/Visage.cpp | 28 ++++++++++++++++++++++++---- interface/src/devices/Visage.h | 16 ++++++++++++++++ 5 files changed, 69 insertions(+), 11 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b316548ad4..098b42dccf 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2041,6 +2041,15 @@ void Application::updateFaceshift() { } } +void Application::updateVisage() { + + bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); + PerformanceWarning warn(showWarnings, "Application::updateVisage()"); + + // Update Visage + _visage.update(); +} + void Application::updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot) { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); @@ -2318,6 +2327,7 @@ void Application::update(float deltaTime) { glm::vec3 lookAtSpot; updateFaceshift(); + updateVisage(); _myAvatar->updateLookAtTargetAvatar(lookAtSpot); updateMyAvatarLookAtPosition(lookAtSpot); diff --git a/interface/src/Application.h b/interface/src/Application.h index f9c1005c13..06a19f13b1 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -161,6 +161,7 @@ public: const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; } const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; } Faceshift* getFaceshift() { return &_faceshift; } + Visage* getVisage() { return &_visage; } SixenseManager* getSixenseManager() { return &_sixenseManager; } BandwidthMeter* getBandwidthMeter() { return &_bandwidthMeter; } QSettings* getSettings() { return _settings; } @@ -284,6 +285,7 @@ private: // Various helper functions called during update() void updateMouseRay(); void updateFaceshift(); + void updateVisage(); void updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot); void updateHoverVoxels(float deltaTime, float& distance, BoxFace& face); void updateMouseVoxels(float deltaTime, float& distance, BoxFace& face); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 17b80089a7..51de5a944c 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -337,22 +337,32 @@ const float MAX_PITCH = 90.0f; // Update avatar head rotation with sensor data void MyAvatar::updateFromGyros(float deltaTime) { Faceshift* faceshift = Application::getInstance()->getFaceshift(); + Visage* visage = Application::getInstance()->getVisage(); glm::vec3 estimatedPosition, estimatedRotation; + bool trackerActive = false; if (faceshift->isActive()) { estimatedPosition = faceshift->getHeadTranslation(); estimatedRotation = safeEulerAngles(faceshift->getHeadRotation()); + trackerActive = true; + + } else if (visage->isActive()) { + estimatedPosition = visage->getHeadTranslation(); + estimatedRotation = safeEulerAngles(visage->getHeadRotation()); + trackerActive = true; + } + if (trackerActive) { // Rotate the body if the head is turned beyond the screen if (Menu::getInstance()->isOptionChecked(MenuOption::TurnWithHead)) { - const float FACESHIFT_YAW_TURN_SENSITIVITY = 0.5f; - const float FACESHIFT_MIN_YAW_TURN = 15.f; - const float FACESHIFT_MAX_YAW_TURN = 50.f; - if ( (fabs(estimatedRotation.y) > FACESHIFT_MIN_YAW_TURN) && - (fabs(estimatedRotation.y) < FACESHIFT_MAX_YAW_TURN) ) { + const float TRACKER_YAW_TURN_SENSITIVITY = 0.5f; + const float TRACKER_MIN_YAW_TURN = 15.f; + const float TRACKER_MAX_YAW_TURN = 50.f; + if ( (fabs(estimatedRotation.y) > TRACKER_MIN_YAW_TURN) && + (fabs(estimatedRotation.y) < TRACKER_MAX_YAW_TURN) ) { if (estimatedRotation.y > 0.f) { - _bodyYawDelta += (estimatedRotation.y - FACESHIFT_MIN_YAW_TURN) * FACESHIFT_YAW_TURN_SENSITIVITY; + _bodyYawDelta += (estimatedRotation.y - TRACKER_MIN_YAW_TURN) * TRACKER_YAW_TURN_SENSITIVITY; } else { - _bodyYawDelta += (estimatedRotation.y + FACESHIFT_MIN_YAW_TURN) * FACESHIFT_YAW_TURN_SENSITIVITY; + _bodyYawDelta += (estimatedRotation.y + TRACKER_MIN_YAW_TURN) * TRACKER_YAW_TURN_SENSITIVITY; } } } diff --git a/interface/src/devices/Visage.cpp b/interface/src/devices/Visage.cpp index 6a612eb59d..59b3ac06f8 100644 --- a/interface/src/devices/Visage.cpp +++ b/interface/src/devices/Visage.cpp @@ -24,18 +24,38 @@ namespace VisageSDK { using namespace VisageSDK; -Visage::Visage() { +Visage::Visage() : + _active(false) { #ifdef HAVE_VISAGE switchToResourcesParentIfRequired(); initializeLicenseManager("resources/visage/license.vlc"); _tracker = new VisageTracker2("resources/visage/Facial Features Tracker - Asymmetric.cfg"); - _tracker->trackFromCam(); + if (_tracker->trackFromCam()) { + _data = new FaceData(); + + } else { + delete _tracker; + _tracker = NULL; + } #endif } Visage::~Visage() { #ifdef HAVE_VISAGE - _tracker->stop(); - delete _tracker; + if (_tracker) { + _tracker->stop(); + delete _tracker; + delete _data; + } +#endif +} + +void Visage::update() { +#ifdef HAVE_VISAGE + _active = (_tracker->getTrackingData(_data) == TRACK_STAT_OK); + if (!_active) { + return; + } + _headRotation = glm::quat(glm::vec3(_data->faceRotation[0], _data->faceRotation[1], _data->faceRotation[2])); #endif } diff --git a/interface/src/devices/Visage.h b/interface/src/devices/Visage.h index 1b9d283bb3..f16119cdbd 100644 --- a/interface/src/devices/Visage.h +++ b/interface/src/devices/Visage.h @@ -9,7 +9,11 @@ #ifndef __interface__Visage__ #define __interface__Visage__ +#include +#include + namespace VisageSDK { + class FaceData; class VisageTracker2; } @@ -20,9 +24,21 @@ public: Visage(); ~Visage(); + bool isActive() const { return _active; } + + const glm::quat& getHeadRotation() const { return _headRotation; } + const glm::vec3& getHeadTranslation() const { return _headTranslation; } + + void update(); + private: VisageSDK::VisageTracker2* _tracker; + VisageSDK::FaceData* _data; + + bool _active; + glm::quat _headRotation; + glm::vec3 _headTranslation; }; #endif /* defined(__interface__Visage__) */