From e2fded846f5e35d1cba697e8b0f3bbc54efab64a Mon Sep 17 00:00:00 2001
From: howard-stearns <howard.stearns@gmail.com>
Date: Fri, 11 Nov 2016 11:10:42 -0800
Subject: [PATCH] make hand-controller ui work in third person

---
 scripts/system/controllers/handControllerPointer.js | 4 ----
 scripts/system/hmd.js                               | 2 +-
 scripts/system/libraries/controllers.js             | 3 +++
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/scripts/system/controllers/handControllerPointer.js b/scripts/system/controllers/handControllerPointer.js
index ce9b8e403f..5e8c0cb6ba 100644
--- a/scripts/system/controllers/handControllerPointer.js
+++ b/scripts/system/controllers/handControllerPointer.js
@@ -511,10 +511,6 @@ function update() {
         return off(); // Let them use mouse in peace.
     }
 
-    if (!Menu.isOptionChecked("First Person")) {
-        return off(); // What to do? menus can be behind hand!
-    }
-
     if ((!Window.hasFocus() && !HMD.active) || !Reticle.allowMouseCapture) {
         // In desktop it's pretty clear when another app is on top. In that case we bail, because
         // hand controllers might be sputtering "valid" data and that will keep someone from deliberately
diff --git a/scripts/system/hmd.js b/scripts/system/hmd.js
index e1c846806f..bac8580222 100644
--- a/scripts/system/hmd.js
+++ b/scripts/system/hmd.js
@@ -26,7 +26,7 @@ var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
 var button;
 // Independent and Entity mode make people sick. Third Person and Mirror have traps that we need to work through.
 // Disable them in hmd.
-var desktopOnlyViews = ['Third Person', 'Mirror', 'Independent Mode', 'Entity Mode'];
+var desktopOnlyViews = ['Mirror', 'Independent Mode', 'Entity Mode'];
 function onHmdChanged(isHmd) {
     button.writeProperty('buttonState', isHmd ? 0 : 1);
     button.writeProperty('defaultState', isHmd ? 0 : 1);
diff --git a/scripts/system/libraries/controllers.js b/scripts/system/libraries/controllers.js
index 38febf2de4..51b44ecc5c 100644
--- a/scripts/system/libraries/controllers.js
+++ b/scripts/system/libraries/controllers.js
@@ -42,6 +42,9 @@ getControllerWorldLocation = function (handController, doOffset) {
         if (doOffset) {
             position = Vec3.sum(position, Vec3.multiplyQbyV(orientation, getGrabPointSphereOffset(handController)));
         }
+        if (Menu.isOptionChecked("Third Person")) {
+            position = Vec3.sum(position, Vec3.subtract(Camera.position, MyAvatar.getEyePosition()));
+        }
     } else if (!HMD.isHandControllerAvailable()) {
         position = MyAvatar.getHeadPosition();
         orientation = Quat.multiply(MyAvatar.headOrientation, Quat.angleAxis(-90, { x: 1, y: 0, z: 0 }));