{"action":"created","comment":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/62703098","id":62703098,"diff_hunk":"@@ -0,0 +1,410 @@\n+\"use strict\";\n+/*jslint vars: true, plusplus: true*/\n+/*globals Script, Overlays, Controller, Reticle, HMD, Camera, Entities, MyAvatar, Settings, Menu, ScriptDiscoveryService, Window, Vec3, Quat, print */\n+\n+//\n+//  handControllerPointer.js\n+//  examples/controllers\n+//\n+//  Created by Howard Stearns on 2016/04/22\n+//  Copyright 2016 High Fidelity, Inc.\n+//\n+//  Distributed under the Apache License, Version 2.0.\n+//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html\n+//\n+\n+// Control the \"mouse\" using hand controller. (HMD and desktop.)\n+// For now:\n+// Hydra thumb button 3 is left-mouse, button 4 is right-mouse.\n+// A click in the center of the vive thumb pad is left mouse. Vive menu button is context menu (right mouse).\n+// First-person only.\n+// Starts right handed, but switches to whichever is free: Whichever hand was NOT most recently squeezed.\n+//   (For now, the thumb buttons on both controllers are always on.)\n+// When over a HUD element, the reticle is shown where the active hand controller beam intersects the HUD.\n+// Otherwise, the active hand controller shows a red ball where a click will act.\n+//\n+// Bugs:\n+// On Windows, the upper left corner of Interface must be in the upper left corner of the screen, and the title bar must be 50px high. (System bug.)\n+// While hardware mouse move switches to mouse move, hardware mouse click (without amove) does not.\n+\n+\n+// UTILITIES -------------\n+//\n+\n+// Utility to make it easier to setup and disconnect cleanly.\n+function setupHandler(event, handler) {\n+    event.connect(handler);\n+    Script.scriptEnding.connect(function () { event.disconnect(handler); });\n+}\n+// If some capability is not available until expiration milliseconds after the last update.\n+function TimeLock(expiration) {\n+    var last = 0;\n+    this.update = function (optionalNow) {\n+        last = optionalNow || Date.now();\n+    };\n+    this.expired = function (optionalNow) {\n+        return ((optionalNow || Date.now()) - last) > expiration;\n+    };\n+}\n+var handControllerLockOut = new TimeLock(2000);\n+\n+// Calls onFunction() or offFunction() when swtich(on), but only if it is to a new value.\n+function LatchedToggle(onFunction, offFunction, state) {\n+    this.getState = function () {\n+        return state;\n+    };\n+    this.setState = function (on) {\n+        if (state === on) { return; }\n+        state = on;\n+        if (on) {\n+            onFunction();\n+        } else {\n+            offFunction();\n+        }\n+    };\n+}\n+\n+// VERTICAL FIELD OF VIEW ---------\n+//\n+// Cache the verticalFieldOfView setting and update it every so often.\n+var verticalFieldOfView, DEFAULT_VERTICAL_FIELD_OF_VIEW = 45; // degrees\n+function updateFieldOfView() {\n+    verticalFieldOfView = Settings.getValue('fieldOfView') || DEFAULT_VERTICAL_FIELD_OF_VIEW;\n+}\n+\n+// SHIMS ----------\n+//\n+var weMovedReticle = false;\n+function ignoreMouseActivity() {\n+    // If we're paused, or if change in cursor position is from this script, not the hardware mouse.\n+    if (!Reticle.allowMouseCapture) { return true; }\n+    // Only we know if we moved it, which is why this script has to replace depthReticle.js\n+    if (!weMovedReticle) { return false; }\n+    weMovedReticle = false;\n+    return true;\n+}\n+var setReticlePosition = function (point2d) {\n+    weMovedReticle = true;\n+    Reticle.setPosition(point2d);\n+};\n+\n+// Generalizations of utilities that work with system and overlay elements.\n+function findRayIntersection(pickRay) {\n+    // Check 3D overlays and entities. Argument is an object with origin and direction.\n+    var result = Overlays.findRayIntersection(pickRay);\n+    if (!result.intersects) {\n+        result = Entities.findRayIntersection(pickRay, true);\n+    }\n+    return result;\n+}\n+function isPointingAtOverlay(optionalHudPosition2d) {\n+    return Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(optionalHudPosition2d || Reticle.position);\n+}\n+\n+// Generalized HUD utilities, with or without HMD:\n+// These two \"vars\" are for documentation. Do not change their values!\n+var SPHERICAL_HUD_DISTANCE = 1; // meters.\n+var PLANAR_PERPENDICULAR_HUD_DISTANCE = SPHERICAL_HUD_DISTANCE;\n+function calculateRayUICollisionPoint(position, direction) {\n+    // Answer the 3D intersection of the HUD by the given ray, or falsey if no intersection.\n+    if (HMD.active) {\n+        return HMD.calculateRayUICollisionPoint(position, direction);\n+    }\n+    // interect HUD plane, 1m in front of camera, using formula:\n+    //   scale = hudNormal dot (hudPoint - position) / hudNormal dot direction\n+    //   intersection = postion + scale*direction\n+    var hudNormal = Quat.getFront(Camera.getOrientation());\n+    var hudPoint = Vec3.sum(Camera.getPosition(), hudNormal); // must also scale if PLANAR_PERPENDICULAR_HUD_DISTANCE!=1\n+    var denominator = Vec3.dot(hudNormal, direction);\n+    if (denominator === 0) { return null; } // parallel to plane","path":"scripts/system/controllers/handControllerPointer.js","position":119,"original_position":119,"commit_id":"9edd18c0178835371b2732035d514f2610130bb7","original_commit_id":"9edd18c0178835371b2732035d514f2610130bb7","user":{"login":"ZappoMan","id":2093195,"avatar_url":"https://avatars.githubusercontent.com/u/2093195?v=3","gravatar_id":"","url":"https://api.github.com/users/ZappoMan","html_url":"https://github.com/ZappoMan","followers_url":"https://api.github.com/users/ZappoMan/followers","following_url":"https://api.github.com/users/ZappoMan/following{/other_user}","gists_url":"https://api.github.com/users/ZappoMan/gists{/gist_id}","starred_url":"https://api.github.com/users/ZappoMan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ZappoMan/subscriptions","organizations_url":"https://api.github.com/users/ZappoMan/orgs","repos_url":"https://api.github.com/users/ZappoMan/repos","events_url":"https://api.github.com/users/ZappoMan/events{/privacy}","received_events_url":"https://api.github.com/users/ZappoMan/received_events","type":"User","site_admin":false},"body":"coding standard: brace placement","created_at":"2016-05-10T16:16:51Z","updated_at":"2016-05-10T16:16:51Z","html_url":"https://github.com/highfidelity/hifi/pull/7809#discussion_r62703098","pull_request_url":"https://api.github.com/repos/highfidelity/hifi/pulls/7809","_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments/62703098"},"html":{"href":"https://github.com/highfidelity/hifi/pull/7809#discussion_r62703098"},"pull_request":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/7809"}}},"pull_request":{"url":"https://api.github.com/repos/highfidelity/hifi/pulls/7809","id":68784782,"html_url":"https://github.com/highfidelity/hifi/pull/7809","diff_url":"https://github.com/highfidelity/hifi/pull/7809.diff","patch_url":"https://github.com/highfidelity/hifi/pull/7809.patch","issue_url":"https://api.github.com/repos/highfidelity/hifi/issues/7809","number":7809,"state":"open","locked":false,"title":"Hand controller pointer","user":{"login":"howard-stearns","id":7015115,"avatar_url":"https://avatars.githubusercontent.com/u/7015115?v=3","gravatar_id":"","url":"https://api.github.com/users/howard-stearns","html_url":"https://github.com/howard-stearns","followers_url":"https://api.github.com/users/howard-stearns/followers","following_url":"https://api.github.com/users/howard-stearns/following{/other_user}","gists_url":"https://api.github.com/users/howard-stearns/gists{/gist_id}","starred_url":"https://api.github.com/users/howard-stearns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howard-stearns/subscriptions","organizations_url":"https://api.github.com/users/howard-stearns/orgs","repos_url":"https://api.github.com/users/howard-stearns/repos","events_url":"https://api.github.com/users/howard-stearns/events{/privacy}","received_events_url":"https://api.github.com/users/howard-stearns/received_events","type":"User","site_admin":false},"body":"Control the mouse with hand controllers (Razer Hydra and Vive)\r\n\r\nControlling the mouse:\r\nOne hand controller drives the mouse.\r\nPointer is shown if over HUD element, otherwise a ball is shown at the item that would receive the click.\r\n  Hydra: Upper left thumb buton (#3) is left mouse click, upper right thumb button (#4) is right (context menu) click. (Both hands. Also works in desktop display.)\r\n  Vive: Center click on track pad is left mouse click, menu button is context menu click. (Both hands.)\r\nSwitch hands by left-click of the hand you want.\r\nFirst-person only. \r\n\r\nAlso:\r\n- Makes deadband Controller filter work for negative values.\r\n- Introduces deadband in Vive standard controller mapping so that you don't accidentally combine turn with jump, or strafe with forward.\r\n- Fixes a bug in which setting Reticle.position had to compensate for the main window position and menu bar height, which scripts don't know how to do.\r\n- Removes debug logging \"Contrller::ScriptingInterface ---- UNREASONABLE CHANGE!\"\r\n\r\nNote:\r\n- Replaces depthReticle.js\r\n- Does not address existing issues with recognizing new hardware.\r\n","created_at":"2016-05-03T22:20:29Z","updated_at":"2016-05-10T16:16:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b633dfa4b68d351020769077db594a8f8f288df1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/highfidelity/hifi/pulls/7809/commits","review_comments_url":"https://api.github.com/repos/highfidelity/hifi/pulls/7809/comments","review_comment_url":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/highfidelity/hifi/issues/7809/comments","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/9edd18c0178835371b2732035d514f2610130bb7","head":{"label":"howard-stearns:hand-controller-pointer","ref":"hand-controller-pointer","sha":"9edd18c0178835371b2732035d514f2610130bb7","user":{"login":"howard-stearns","id":7015115,"avatar_url":"https://avatars.githubusercontent.com/u/7015115?v=3","gravatar_id":"","url":"https://api.github.com/users/howard-stearns","html_url":"https://github.com/howard-stearns","followers_url":"https://api.github.com/users/howard-stearns/followers","following_url":"https://api.github.com/users/howard-stearns/following{/other_user}","gists_url":"https://api.github.com/users/howard-stearns/gists{/gist_id}","starred_url":"https://api.github.com/users/howard-stearns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howard-stearns/subscriptions","organizations_url":"https://api.github.com/users/howard-stearns/orgs","repos_url":"https://api.github.com/users/howard-stearns/repos","events_url":"https://api.github.com/users/howard-stearns/events{/privacy}","received_events_url":"https://api.github.com/users/howard-stearns/received_events","type":"User","site_admin":false},"repo":{"id":34746667,"name":"hifi","full_name":"howard-stearns/hifi","owner":{"login":"howard-stearns","id":7015115,"avatar_url":"https://avatars.githubusercontent.com/u/7015115?v=3","gravatar_id":"","url":"https://api.github.com/users/howard-stearns","html_url":"https://github.com/howard-stearns","followers_url":"https://api.github.com/users/howard-stearns/followers","following_url":"https://api.github.com/users/howard-stearns/following{/other_user}","gists_url":"https://api.github.com/users/howard-stearns/gists{/gist_id}","starred_url":"https://api.github.com/users/howard-stearns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/howard-stearns/subscriptions","organizations_url":"https://api.github.com/users/howard-stearns/orgs","repos_url":"https://api.github.com/users/howard-stearns/repos","events_url":"https://api.github.com/users/howard-stearns/events{/privacy}","received_events_url":"https://api.github.com/users/howard-stearns/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/howard-stearns/hifi","description":"Open source software for shared virtual worlds using HMDs and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.com/jobs  Documentation at http://docs.highfidelity.com  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":true,"url":"https://api.github.com/repos/howard-stearns/hifi","forks_url":"https://api.github.com/repos/howard-stearns/hifi/forks","keys_url":"https://api.github.com/repos/howard-stearns/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/howard-stearns/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/howard-stearns/hifi/teams","hooks_url":"https://api.github.com/repos/howard-stearns/hifi/hooks","issue_events_url":"https://api.github.com/repos/howard-stearns/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/howard-stearns/hifi/events","assignees_url":"https://api.github.com/repos/howard-stearns/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/howard-stearns/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/howard-stearns/hifi/tags","blobs_url":"https://api.github.com/repos/howard-stearns/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/howard-stearns/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/howard-stearns/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/howard-stearns/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/howard-stearns/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/howard-stearns/hifi/languages","stargazers_url":"https://api.github.com/repos/howard-stearns/hifi/stargazers","contributors_url":"https://api.github.com/repos/howard-stearns/hifi/contributors","subscribers_url":"https://api.github.com/repos/howard-stearns/hifi/subscribers","subscription_url":"https://api.github.com/repos/howard-stearns/hifi/subscription","commits_url":"https://api.github.com/repos/howard-stearns/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/howard-stearns/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/howard-stearns/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/howard-stearns/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/howard-stearns/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/howard-stearns/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/howard-stearns/hifi/merges","archive_url":"https://api.github.com/repos/howard-stearns/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/howard-stearns/hifi/downloads","issues_url":"https://api.github.com/repos/howard-stearns/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/howard-stearns/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/howard-stearns/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/howard-stearns/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/howard-stearns/hifi/labels{/name}","releases_url":"https://api.github.com/repos/howard-stearns/hifi/releases{/id}","deployments_url":"https://api.github.com/repos/howard-stearns/hifi/deployments","created_at":"2015-04-28T17:54:06Z","updated_at":"2016-01-17T00:01:04Z","pushed_at":"2016-05-09T21:06:55Z","git_url":"git://github.com/howard-stearns/hifi.git","ssh_url":"git@github.com:howard-stearns/hifi.git","clone_url":"https://github.com/howard-stearns/hifi.git","svn_url":"https://github.com/howard-stearns/hifi","homepage":"","size":221076,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"highfidelity:master","ref":"master","sha":"ab0a77c82be653bd7ff6896865a11f5f7d214ad3","user":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"repo":{"id":5372872,"name":"hifi","full_name":"highfidelity/hifi","owner":{"login":"highfidelity","id":1565370,"avatar_url":"https://avatars.githubusercontent.com/u/1565370?v=3","gravatar_id":"","url":"https://api.github.com/users/highfidelity","html_url":"https://github.com/highfidelity","followers_url":"https://api.github.com/users/highfidelity/followers","following_url":"https://api.github.com/users/highfidelity/following{/other_user}","gists_url":"https://api.github.com/users/highfidelity/gists{/gist_id}","starred_url":"https://api.github.com/users/highfidelity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/highfidelity/subscriptions","organizations_url":"https://api.github.com/users/highfidelity/orgs","repos_url":"https://api.github.com/users/highfidelity/repos","events_url":"https://api.github.com/users/highfidelity/events{/privacy}","received_events_url":"https://api.github.com/users/highfidelity/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/highfidelity/hifi","description":"Open source software for shared virtual worlds using HMDs and dynamically assigned devices as servers.  San Francisco based startup, we are hiring: http://highfidelity.com/jobs  Documentation at http://docs.highfidelity.com  Contribute by reporting bugs & doing jobs on http://worklist.net","fork":false,"url":"https://api.github.com/repos/highfidelity/hifi","forks_url":"https://api.github.com/repos/highfidelity/hifi/forks","keys_url":"https://api.github.com/repos/highfidelity/hifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/highfidelity/hifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/highfidelity/hifi/teams","hooks_url":"https://api.github.com/repos/highfidelity/hifi/hooks","issue_events_url":"https://api.github.com/repos/highfidelity/hifi/issues/events{/number}","events_url":"https://api.github.com/repos/highfidelity/hifi/events","assignees_url":"https://api.github.com/repos/highfidelity/hifi/assignees{/user}","branches_url":"https://api.github.com/repos/highfidelity/hifi/branches{/branch}","tags_url":"https://api.github.com/repos/highfidelity/hifi/tags","blobs_url":"https://api.github.com/repos/highfidelity/hifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/highfidelity/hifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/highfidelity/hifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/highfidelity/hifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/highfidelity/hifi/statuses/{sha}","languages_url":"https://api.github.com/repos/highfidelity/hifi/languages","stargazers_url":"https://api.github.com/repos/highfidelity/hifi/stargazers","contributors_url":"https://api.github.com/repos/highfidelity/hifi/contributors","subscribers_url":"https://api.github.com/repos/highfidelity/hifi/subscribers","subscription_url":"https://api.github.com/repos/highfidelity/hifi/subscription","commits_url":"https://api.github.com/repos/highfidelity/hifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/highfidelity/hifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/highfidelity/hifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/highfidelity/hifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/highfidelity/hifi/contents/{+path}","compare_url":"https://api.github.com/repos/highfidelity/hifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/highfidelity/hifi/merges","archive_url":"https://api.github.com/repos/highfidelity/hifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/highfidelity/hifi/downloads","issues_url":"https://api.github.com/repos/highfidelity/hifi/issues{/number}","pulls_url":"https://api.github.com/repos/highfidelity/hifi/pulls{/number}","milestones_url":"https://api.github.com/repos/highfidelity/hifi/milestones{/number}","notifications_url":"https://api.github.com/repos/highfidelity/hifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/highfidelity/hifi/labels{/name}","releases_url":"https://api.github.com/repos/highfidelity/hifi/releases{/id}","deployments_url":"https://api.github.com/repos/highfidelity/hifi/deployments","created_at":"2012-08-10T18:26:22Z","updated_at":"2016-05-08T17:13:48Z","pushed_at":"2016-05-10T16:06:38Z","git_url":"git://github.com/highfidelity/hifi.git","ssh_url":"git@github.com:highfidelity/hifi.git","clone_url":"https://github.com/highfidelity/hifi.git","svn_url":"https://github.com/highfidelity/hifi","homepage":"","size":266635,"stargazers_count":376,"watchers_count":376,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":223,"mirror_url":null,"open_issues_count":28,"forks":223,"open_issues":28,"watchers":376,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/7809"},"html":{"href":"https://github.com/highfidelity/hifi/pull/7809"},"issue":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/7809"},"comments":{"href":"https://api.github.com/repos/highfidelity/hifi/issues/7809/comments"},"review_comments":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/7809/comments"},"review_comment":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/highfidelity/hifi/pulls/7809/commits"},"statuses":{"href":"https://api.github.com/repos/highfidelity/hifi/statuses/9edd18c0178835371b2732035d514f2610130bb7"}}}}