From 9c4143e1beb7234ec03852b5001e850739f257e2 Mon Sep 17 00:00:00 2001
From: Andrzej Kapolka <drzej.k@gmail.com>
Date: Tue, 18 Feb 2014 17:03:43 -0800
Subject: [PATCH] Working on gaze deflection.

---
 interface/src/Application.cpp    | 14 +++++++++++++-
 interface/src/devices/Visage.cpp | 10 +++++++---
 interface/src/devices/Visage.h   |  6 ++++++
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp
index fc8bf8e899..88c7af102b 100644
--- a/interface/src/Application.cpp
+++ b/interface/src/Application.cpp
@@ -2070,13 +2070,25 @@ void Application::updateMyAvatarLookAtPosition(glm::vec3& lookAtSpot) {
         }
         lookAtSpot = _mouseRayOrigin + _mouseRayDirection * distance;
     }
+    bool trackerActive = false;
+    float eyePitch, eyeYaw;
     if (_faceshift.isActive()) {
+        eyePitch = _faceshift.getEstimatedEyePitch();
+        eyeYaw = _faceshift.getEstimatedEyeYaw();
+        trackerActive = true;
+        
+    } else if (_visage.isActive()) {
+        eyePitch = _visage.getEstimatedEyePitch();
+        eyeYaw = _visage.getEstimatedEyeYaw();
+        trackerActive = true;
+    }
+    if (trackerActive) {
         // deflect using Faceshift gaze data
         glm::vec3 origin = _myAvatar->getHead().calculateAverageEyePosition();
         float pitchSign = (_myCamera.getMode() == CAMERA_MODE_MIRROR) ? -1.0f : 1.0f;
         float deflection = Menu::getInstance()->getFaceshiftEyeDeflection();
         lookAtSpot = origin + _myCamera.getRotation() * glm::quat(glm::radians(glm::vec3(
-            _faceshift.getEstimatedEyePitch() * pitchSign * deflection, _faceshift.getEstimatedEyeYaw() * deflection, 0.0f))) *
+            eyePitch * pitchSign * deflection, eyeYaw * deflection, 0.0f))) *
                 glm::inverse(_myCamera.getRotation()) * (lookAtSpot - origin);
     }
     _myAvatar->getHead().setLookAtPosition(lookAtSpot);
diff --git a/interface/src/devices/Visage.cpp b/interface/src/devices/Visage.cpp
index cce5f66340..8696db3af4 100644
--- a/interface/src/devices/Visage.cpp
+++ b/interface/src/devices/Visage.cpp
@@ -24,11 +24,13 @@ namespace VisageSDK {
 
 using namespace VisageSDK;
 
-const glm::vec3 DEFAULT_HEAD_ORIGIN(0.0f, 0.0f, 0.3f);
+const glm::vec3 DEFAULT_HEAD_ORIGIN(0.0f, 0.0f, 0.7f);
 
 Visage::Visage() :
     _active(false),
-    _headOrigin(DEFAULT_HEAD_ORIGIN) {
+    _headOrigin(DEFAULT_HEAD_ORIGIN),
+    _estimatedEyePitch(0.0f),
+    _estimatedEyeYaw(0.0f) {
 #ifdef HAVE_VISAGE
     switchToResourcesParentIfRequired();
     QByteArray licensePath = "resources/visage/license.vlc";
@@ -54,7 +56,7 @@ Visage::~Visage() {
 #endif
 }
 
-const float TRANSLATION_SCALE = 50.0f;
+const float TRANSLATION_SCALE = 20.0f;
 
 void Visage::update() {
 #ifdef HAVE_VISAGE
@@ -65,6 +67,8 @@ void Visage::update() {
     _headRotation = glm::quat(glm::vec3(-_data->faceRotation[0], -_data->faceRotation[1], _data->faceRotation[2]));    
     _headTranslation = (glm::vec3(_data->faceTranslation[0], _data->faceTranslation[1], _data->faceTranslation[2]) -
         _headOrigin) * TRANSLATION_SCALE;
+    _estimatedEyePitch = glm::degrees(_data->gazeDirection[1]);
+    _estimatedEyeYaw = glm::degrees(_data->gazeDirection[0]);
 #endif
 }
 
diff --git a/interface/src/devices/Visage.h b/interface/src/devices/Visage.h
index 20c361bda0..966c41335e 100644
--- a/interface/src/devices/Visage.h
+++ b/interface/src/devices/Visage.h
@@ -29,6 +29,9 @@ public:
     const glm::quat& getHeadRotation() const { return _headRotation; }
     const glm::vec3& getHeadTranslation() const { return _headTranslation; }
     
+    float getEstimatedEyePitch() const { return _estimatedEyePitch; }
+    float getEstimatedEyeYaw() const { return _estimatedEyeYaw; }
+    
     void update();
     void reset();
     
@@ -42,6 +45,9 @@ private:
     glm::vec3 _headTranslation;
     
     glm::vec3 _headOrigin;
+    
+    float _estimatedEyePitch;
+    float _estimatedEyeYaw;
 };
 
 #endif /* defined(__interface__Visage__) */