History

lasers on tablet working

Dante Ruiz committed 9 years ago

Commit fa676aa1 parent eb624841 file · +166 −270Browse files

Showing the changes to scripts/system/controllers/controllerModules (1 of 1 file). Show all

Unified · Split

scripts/system/controllers/controllerModules/tabletLaserInput.js+166−270
@@ -85,125 +85,121 @@ Script.include("/~/system/libraries/controllers.js"); · 84 unmodified lines
8585 var HAPTIC_STYLUS_STRENGTH = 1.0;
8686 var HAPTIC_STYLUS_DURATION = 20.0;
8787
88− function stylusTargetHasKeyboardFocus(stylusTarget) {
89− if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {
90− return Entities.keyboardFocusEntity === stylusTarget.entityID;
91− } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
92− return Overlays.keyboardFocusOverlay === stylusTarget.overlayID;
88+ function stylusTargetHasKeyboardFocus(laserTarget) {
89+ if (laserTarget && laserTarget !== NULL_UUID) {
90+ return Overlays.keyboardFocusOverlay === laserTarget;
9391 }
9492 }
9593
96− function setKeyboardFocusOnStylusTarget(stylusTarget) {
97− if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID &&
98− Entities.wantsHandControllerPointerEvents(stylusTarget.entityID)) {
99− Overlays.keyboardFocusOverlay = NULL_UUID;
100− Entities.keyboardFocusEntity = stylusTarget.entityID;
101− } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
102− Overlays.keyboardFocusOverlay = stylusTarget.overlayID;
94+ function setKeyboardFocusOnStylusTarget(laserTarget) {
95+ if (laserTarget && laserTarget !== NULL_UUID) {
96+ Overlays.keyboardFocusOverlay = laserTarget;
10397 Entities.keyboardFocusEntity = NULL_UUID;
10498 }
10599 }
106100
107− function sendHoverEnterEventToStylusTarget(hand, stylusTarget) {
101+ function sendHoverEnterEventToStylusTarget(hand, laserTarget) {
102+ if (!laserTarget) {
103+ return;
104+ }
108105 var pointerEvent = {
109106 type: "Move",
110107 id: hand + 1, // 0 is reserved for hardware mouse
111− pos2D: stylusTarget.position2D,
112− pos3D: stylusTarget.position,
113− normal: stylusTarget.normal,
114− direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),
108+ pos2D: laserTarget.position2D,
109+ pos3D: laserTarget.position,
110+ normal: laserTarget.normal,
111+ direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
115112 button: "None"
116113 };
117114
118− if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {
119− Entities.sendHoverEnterEntity(stylusTarget.entityID, pointerEvent);
120− } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
121− Overlays.sendHoverEnterOverlay(stylusTarget.overlayID, pointerEvent);
115+ if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
116+ Overlays.sendHoverEnterOverlay(laserTarget.overlayID, pointerEvent);
122117 }
123118 }
124119
125− function sendHoverOverEventToStylusTarget(hand, stylusTarget) {
120+ function sendHoverOverEventToStylusTarget(hand, laserTarget) {
121+
122+ if (!laserTarget) {
123+ return;
124+ }
126125 var pointerEvent = {
127126 type: "Move",
128127 id: hand + 1, // 0 is reserved for hardware mouse
129− pos2D: stylusTarget.position2D,
130− pos3D: stylusTarget.position,
131− normal: stylusTarget.normal,
132− direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),
128+ pos2D: laserTarget.position2D,
129+ pos3D: laserTarget.position,
130+ normal: laserTarget.normal,
131+ direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
133132 button: "None"
134133 };
135134
136− if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {
137− Entities.sendMouseMoveOnEntity(stylusTarget.entityID, pointerEvent);
138− Entities.sendHoverOverEntity(stylusTarget.entityID, pointerEvent);
139− } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
140− Overlays.sendMouseMoveOnOverlay(stylusTarget.overlayID, pointerEvent);
141− Overlays.sendHoverOverOverlay(stylusTarget.overlayID, pointerEvent);
135+ if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
136+ Overlays.sendMouseMoveOnOverlay(laserTarget.overlayID, pointerEvent);
137+ Overlays.sendHoverOverOverlay(laserTarget.overlayID, pointerEvent);
142138 }
143139 }
144140
145− function sendTouchStartEventToStylusTarget(hand, stylusTarget) {
141+ function sendTouchStartEventToStylusTarget(hand, laserTarget) {
142+ if (!laserTarget) {
143+ return;
144+ }
145+
146146 var pointerEvent = {
147147 type: "Press",
148148 id: hand + 1, // 0 is reserved for hardware mouse
149− pos2D: stylusTarget.position2D,
150− pos3D: stylusTarget.position,
151− normal: stylusTarget.normal,
152− direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),
149+ pos2D: laserTarget.position2D,
150+ pos3D: laserTarget.position,
151+ normal: laserTarget.normal,
152+ direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
153153 button: "Primary",
154154 isPrimaryHeld: true
155155 };
156156
157− if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {
158− Entities.sendMousePressOnEntity(stylusTarget.entityID, pointerEvent);
159− Entities.sendClickDownOnEntity(stylusTarget.entityID, pointerEvent);
160− } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
161− Overlays.sendMousePressOnOverlay(stylusTarget.overlayID, pointerEvent);
157+ if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
158+ Overlays.sendMousePressOnOverlay(laserTarget.overlayID, pointerEvent);
162159 }
163160 }
164161
165− function sendTouchEndEventToStylusTarget(hand, stylusTarget) {
162+ function sendTouchEndEventToStylusTarget(hand, laserTarget) {
163+ if (!laserTarget) {
164+ return;
165+ }
166166 var pointerEvent = {
167167 type: "Release",
168168 id: hand + 1, // 0 is reserved for hardware mouse
169− pos2D: stylusTarget.position2D,
170− pos3D: stylusTarget.position,
171− normal: stylusTarget.normal,
172− direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),
169+ pos2D: laserTarget.position2D,
170+ pos3D: laserTarget.position,
171+ normal: laserTarget.normal,
172+ direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
173173 button: "Primary"
174174 };
175175
176− if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {
177− Entities.sendMouseReleaseOnEntity(stylusTarget.entityID, pointerEvent);
178− Entities.sendClickReleaseOnEntity(stylusTarget.entityID, pointerEvent);
179− Entities.sendHoverLeaveEntity(stylusTarget.entityID, pointerEvent);
180− } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
181− Overlays.sendMouseReleaseOnOverlay(stylusTarget.overlayID, pointerEvent);
176+ if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
177+ Overlays.sendMouseReleaseOnOverlay(laserTarget.overlayID, pointerEvent);
182178 }
183179 }
184180
185− function sendTouchMoveEventToStylusTarget(hand, stylusTarget) {
181+ function sendTouchMoveEventToStylusTarget(hand, laserTarget) {
182+ if (!laserTarget) {
183+ return;
184+ }
186185 var pointerEvent = {
187186 type: "Move",
188187 id: hand + 1, // 0 is reserved for hardware mouse
189− pos2D: stylusTarget.position2D,
190− pos3D: stylusTarget.position,
191− normal: stylusTarget.normal,
192− direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),
188+ pos2D: laserTarget.position2D,
189+ pos3D: laserTarget.position,
190+ normal: laserTarget.normal,
191+ direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
193192 button: "Primary",
194193 isPrimaryHeld: true
195194 };
196−
197− if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {
198− Entities.sendMouseMoveOnEntity(stylusTarget.entityID, pointerEvent);
199− Entities.sendHoldingClickOnEntity(stylusTarget.entityID, pointerEvent);
200− } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
201− Overlays.sendMouseMoveOnOverlay(stylusTarget.overlayID, pointerEvent);
195+
196+ if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
197+ Overlays.sendMouseReleaseOnOverlay(laserTarget.overlayID, pointerEvent);
202198 }
203199 }
204200
205201 // will return undefined if overlayID does not exist.
206− function calculateStylusTargetFromOverlay(stylusTip, overlayID) {
202+ function calculateLaserTargetFromOverlay(laserTip, overlayID) {
207203 var overlayPosition = Overlays.getProperty(overlayID, "position");
208204 if (overlayPosition === undefined) {
209205 return;
@@ -215,8 +211,8 @@ Script.include("/~/system/libraries/controllers.js"); · 5 unmodified lines
215211 return;
216212 }
217213 var normal = Vec3.multiplyQbyV(overlayRotation, {x: 0, y: 0, z: 1});
218− var distance = Vec3.dot(Vec3.subtract(stylusTip.position, overlayPosition), normal);
219− var position = Vec3.subtract(stylusTip.position, Vec3.multiply(normal, distance));
214+ var distance = Vec3.dot(Vec3.subtract(laserTip, overlayPosition), normal);
215+ var position = Vec3.subtract(laserTip, Vec3.multiply(normal, distance));
220216
221217 // calclulate normalized position
222218 var invRot = Quat.inverse(overlayRotation);
@@ -267,92 +263,6 @@ Script.include("/~/system/libraries/controllers.js"); · 44 unmodified lines
267263 };
268264 }
269265
270− // will return undefined if entity does not exist.
271− function calculateStylusTargetFromEntity(stylusTip, props) {
272− if (props.rotation === undefined) {
273− // if rotation is missing from props object, then this entity has probably been deleted.
274− return;
275− }
276−
277− // project stylus tip onto entity plane.
278− var normal = Vec3.multiplyQbyV(props.rotation, {x: 0, y: 0, z: 1});
279− Vec3.multiplyQbyV(props.rotation, {x: 0, y: 1, z: 0});
280− var distance = Vec3.dot(Vec3.subtract(stylusTip.position, props.position), normal);
281− var position = Vec3.subtract(stylusTip.position, Vec3.multiply(normal, distance));
282−
283− // generate normalized coordinates
284− var invRot = Quat.inverse(props.rotation);
285− var localPos = Vec3.multiplyQbyV(invRot, Vec3.subtract(position, props.position));
286− var invDimensions = { x: 1 / props.dimensions.x, y: 1 / props.dimensions.y, z: 1 / props.dimensions.z };
287− var normalizedPosition = Vec3.sum(Vec3.multiplyVbyV(localPos, invDimensions), props.registrationPoint);
288−
289− // 2D position on entity plane in meters, relative to the bounding box upper-left hand corner.
290− var position2D = { x: normalizedPosition.x * props.dimensions.x,
291− y: (1 - normalizedPosition.y) * props.dimensions.y }; // flip y-axis
292−
293− return {
294− entityID: props.id,
295− entityProps: props,
296− overlayID: null,
297− distance: distance,
298− position: position,
299− position2D: position2D,
300− normal: normal,
301− normalizedPosition: normalizedPosition,
302− dimensions: props.dimensions,
303− valid: true
304− };
305− }
306−
307− function isNearStylusTarget(stylusTargets, edgeBorder, minNormalDistance, maxNormalDistance) {
308− for (var i = 0; i < stylusTargets.length; i++) {
309− var stylusTarget = stylusTargets[i];
310−
311− // check to see if the projected stylusTip is within within the 2d border
312− var borderMin = {x: -edgeBorder, y: -edgeBorder};
313− var borderMax = {x: stylusTarget.dimensions.x + edgeBorder, y: stylusTarget.dimensions.y + edgeBorder};
314− if (stylusTarget.distance >= minNormalDistance && stylusTarget.distance <= maxNormalDistance &&
315− stylusTarget.position2D.x >= borderMin.x && stylusTarget.position2D.y >= borderMin.y &&
316− stylusTarget.position2D.x <= borderMax.x && stylusTarget.position2D.y <= borderMax.y) {
317− return true;
318− }
319− }
320− return false;
321− }
322−
323− function calculateNearestStylusTarget(stylusTargets) {
324− var nearestStylusTarget;
325−
326− for (var i = 0; i < stylusTargets.length; i++) {
327− var stylusTarget = stylusTargets[i];
328−
329− if ((!nearestStylusTarget || stylusTarget.distance < nearestStylusTarget.distance) &&
330− stylusTarget.normalizedPosition.x >= 0 && stylusTarget.normalizedPosition.y >= 0 &&
331− stylusTarget.normalizedPosition.x <= 1 && stylusTarget.normalizedPosition.y <= 1) {
332− nearestStylusTarget = stylusTarget;
333− }
334− }
335−
336− return nearestStylusTarget;
337− }
338−
339− function getFingerWorldLocation(hand) {
340− var fingerJointName = (hand === RIGHT_HAND) ? "RightHandIndex4" : "LeftHandIndex4";
341−
342− var fingerJointIndex = MyAvatar.getJointIndex(fingerJointName);
343− var fingerPosition = MyAvatar.getAbsoluteJointTranslationInObjectFrame(fingerJointIndex);
344− var fingerRotation = MyAvatar.getAbsoluteJointRotationInObjectFrame(fingerJointIndex);
345− var worldFingerRotation = Quat.multiply(MyAvatar.orientation, fingerRotation);
346− var worldFingerPosition = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, fingerPosition));
347−
348− return {
349− position: worldFingerPosition,
350− orientation: worldFingerRotation,
351− rotation: worldFingerRotation,
352− valid: true
353− };
354− }
355−
356266 function distance2D(a, b) {
357267 var dx = (a.x - b.x);
358268 var dy = (a.y - b.y);
@@ -361,12 +271,14 @@ Script.include("/~/system/libraries/controllers.js"); · 2 unmodified lines
361271
362272 function TabletLaserInput(hand) {
363273 this.hand = hand;
364− this.previousStylusTouchingTarget = false;
365− this.stylusTouchingTarget = false;
274+ this.previousLaserClikcedTarget = false;
275+ this.laserPressingTarget = false;
366276 this.tabletScreenID = HMD.tabletScreenID;
367−
368− this.useFingerInsteadOfStylus = false;
369− this.fingerPointing = false;
277+ this.mode = "none";
278+ this.laserTargetID = null;
279+ this.laserTarget = null;
280+ this.pressEnterLaserTarget = null;
281+ this.hover = false;
370282
371283
372284 this.parameters = makeDispatcherModuleParameters(
@@ -384,159 +296,118 @@ Script.include("/~/system/libraries/controllers.js"); · 11 unmodified lines
384296 };
385297
386298 this.stealTouchFocus = function(laserTarget) {
387− // send hover events to target
388− // record the entity or overlay we are hovering over.
389− if ((stylusTarget.entityID === this.getOtherHandController().hoverEntity) ||
390− (stylusTarget.overlayID === this.getOtherHandController().hoverOverlay)) {
391− this.getOtherHandController().relinquishTouchFocus();
392− }
393− this.requestTouchFocus(stylusTarget);
299+ this.requestTouchFocus(laserTarget);
394300 };
395301
396302 this.requestTouchFocus = function(laserTarget) {
397−
398− // send hover events to target if we can.
399− // record the entity or overlay we are hovering over.
400− if (stylusTarget.entityID &&
401− stylusTarget.entityID !== this.hoverEntity &&
402− stylusTarget.entityID !== this.getOtherHandController().hoverEntity) {
403− this.hoverEntity = stylusTarget.entityID;
404− sendHoverEnterEventToStylusTarget(this.hand, stylusTarget);
405− } else if (stylusTarget.overlayID &&
406− stylusTarget.overlayID !== this.hoverOverlay &&
407− stylusTarget.overlayID !== this.getOtherHandController().hoverOverlay) {
408− this.hoverOverlay = stylusTarget.overlayID;
409− sendHoverEnterEventToStylusTarget(this.hand, stylusTarget);
410− }
303+ sendHoverEnterEventToStylusTarget(this.hand, this.laserTarget);
411304 };
412305
413306 this.hasTouchFocus = function(laserTarget) {
414− return ((stylusTarget.entityID && stylusTarget.entityID === this.hoverEntity) ||
415− (stylusTarget.overlayID && stylusTarget.overlayID === this.hoverOverlay));
307+ return (this.laserTargetID === HMD.tabletScreenID);
416308 };
417309
418310 this.relinquishTouchFocus = function() {
419311 // send hover leave event.
420312 var pointerEvent = { type: "Move", id: this.hand + 1 };
421− if (this.hoverEntity) {
422− Entities.sendHoverLeaveEntity(this.hoverEntity, pointerEvent);
423− this.hoverEntity = null;
424− } else if (this.hoverOverlay) {
425− Overlays.sendMouseMoveOnOverlay(HMD.tabletScreenID, pointerEvent);
426− Overlays.sendHoverOverOverlay(this.hoverOverlay, pointerEvent);
427− Overlays.sendHoverLeaveOverlay(this.hoverOverlay, pointerEvent);
428− this.hoverOverlay = null;
429− }
313+ Overlays.sendMouseMoveOnOverlay(this.tabletScreenID, pointerEvent);
314+ Overlays.sendHoverOverOverlay(this.tabletScreenID, pointerEvent);
315+ Overlays.sendHoverLeaveOverlay(this.tabletScreenID, pointerEvent);
430316 };
431317
432318 this.updateLaserPointer = function(controllerData) {
433319 var RADIUS = 0.005;
434320 var dim = { x: RADIUS, y: RADIUS, z: RADIUS };
435−
436− var mode = "none";
437321
438− if (controllerData.triggerClicks[this.hand]) {
439− mode = "full";
440− } else if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
441− mode = "half";
442− } else {
443− LaserPointers.disableLaserPointer(this.laserPointer);
444− return;
445− }
446−
447− if (mode === "full") {
322+ if (this.mode === "full") {
448323 this.fullEnd.dimensions = dim;
449− LaserPointers.editRenderState(this.laserPointer, mode, {path: fullPath, end: this.fullEnd});
450− } else if (mode === "half") {
324+ LaserPointers.editRenderState(this.laserPointer, this.mode, {path: fullPath, end: this.fullEnd});
325+ } else if (this.mode === "half") {
451326 this.halfEnd.dimensions = dim;
452− LaserPointers.editRenderState(this.laserPointer, mode, {path: halfPath, end: this.halfEnd});
327+ LaserPointers.editRenderState(this.laserPointer, this.mode, {path: halfPath, end: this.halfEnd});
453328 }
454329
455330 LaserPointers.enableLaserPointer(this.laserPointer);
456− LaserPointers.setRenderState(this.laserPointer, mode);
331+ LaserPointers.setRenderState(this.laserPointer, this.mode);
457332 };
458333
459− this.pointFinger = function(value) {
460− var HIFI_POINT_INDEX_MESSAGE_CHANNEL = "Hifi-Point-Index";
461− if (this.fingerPointing !== value) {
462− var message;
463− if (this.hand === RIGHT_HAND) {
464− message = { pointRightIndex: value };
465− } else {
466− message = { pointLeftIndex: value };
467− }
468− Messages.sendMessage(HIFI_POINT_INDEX_MESSAGE_CHANNEL, JSON.stringify(message), true);
469− this.fingerPointing = value;
334+ this.processControllerTriggers = function(controllerData) {
335+ var rayPickIntersection = controllerData.rayPicks[this.hand].intersection;
336+ this.laserTarget = calculateLaserTargetFromOverlay(rayPickIntersection, HMD.tabletScreenID);
337+ if (controllerData.triggerClicks[this.hand]) {
338+ this.mode = "full";
339+ this.laserPressingTarget = true;
340+ this.hover = false;
341+ } else if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
342+ this.mode = "half";
343+ this.laserPressingTarget = false;
344+ this.hover = true;
345+ this.requestTouchFocus(HMD.tabletScreenID);
346+ } else {
347+ this.mode = "none";
348+ this.laserPressingTarget = false;
349+ this.hover = false;
350+ this.relinquishTouchFocus();
351+
470352 }
353+ this.homeButtonTouched = false;
471354 };
472355
473− this.processLaser = function(controllerData) {
474− if (controllerData.rayPicks[this.hand].objectID === HMD.tabletScreenID) {
475−
476− }
477− this.homeButtonTouched = false;
356+ this.hovering = function() {
357+ if (this.hasTouchFocus(this.laserTargetID)) {
358+ sendHoverOverEventToStylusTarget(this.hand, this.laserTarget);
359+ }
478360 };
479361
480− this.laserTouchingEnter = function () {
481− this.stealTouchFocus(this.stylusTarget);
482− sendTouchStartEventToStylusTarget(this.hand, this.stylusTarget);
362+ this.laserPressEnter = function () {
363+ this.stealTouchFocus(this.laserTarget.overlayID);
364+ sendTouchStartEventToStylusTarget(this.hand, this.laserTarget);
483365 Controller.triggerHapticPulse(HAPTIC_STYLUS_STRENGTH, HAPTIC_STYLUS_DURATION, this.hand);
484366
485367 this.touchingEnterTimer = 0;
486− this.touchingEnterStylusTarget = this.stylusTarget;
368+ this.pressEnterLaserTarget = this.laserTarget;
487369 this.deadspotExpired = false;
488370
489371 var TOUCH_PRESS_TO_MOVE_DEADSPOT = 0.0381;
490372 this.deadspotRadius = TOUCH_PRESS_TO_MOVE_DEADSPOT;
491373 };
492374
493− this.laserTouchingExit = function () {
375+ this.laserPressExit = function () {
494376
495− if (this.stylusTarget === undefined) {
377+ if (this.laserTarget === undefined) {
496378 return;
497379 }
498380
499381 // special case to handle home button.
500− if (this.stylusTarget.overlayID === HMD.homeButtonID) {
501− Messages.sendLocalMessage("home", this.stylusTarget.overlayID);
382+ if (this.laserTargetID === HMD.homeButtonID) {
383+ Messages.sendLocalMessage("home", this.laserTargetID);
502384 }
503385
504386 // send press event
505387 if (this.deadspotExpired) {
506− sendTouchEndEventToStylusTarget(this.hand, this.stylusTarget);
388+ sendTouchEndEventToStylusTarget(this.hand, this.laserTarget);
507389 } else {
508− sendTouchEndEventToStylusTarget(this.hand, this.touchingEnterStylusTarget);
390+ print(this.pressEnterLaserTarget);
391+ sendTouchEndEventToStylusTarget(this.hand, this.pressEnterLaserTarget);
509392 }
510393 };
511394
512− this.laserTouching = function (controllerData, dt) {
395+ this.laserPressing = function (controllerData, dt) {
513396
514397 this.touchingEnterTimer += dt;
515398
516− if (this.stylusTarget.entityID) {
517− this.stylusTarget = calculateStylusTargetFromEntity(this.stylusTip, this.stylusTarget.entityProps);
518− } else if (this.stylusTarget.overlayID) {
519− this.stylusTarget = calculateStylusTargetFromOverlay(this.stylusTip, this.stylusTarget.overlayID);
520− }
521−
522− var TABLET_MIN_TOUCH_DISTANCE = -0.1;
523− var TABLET_MAX_TOUCH_DISTANCE = 0.01;
524−
525− if (this.stylusTarget) {
526− if (this.stylusTarget.distance > TABLET_MIN_TOUCH_DISTANCE &&
527− this.stylusTarget.distance < TABLET_MAX_TOUCH_DISTANCE) {
528− var POINTER_PRESS_TO_MOVE_DELAY = 0.33; // seconds
529− if (this.deadspotExpired || this.touchingEnterTimer > POINTER_PRESS_TO_MOVE_DELAY ||
530− distance2D(this.stylusTarget.position2D,
531− this.touchingEnterStylusTarget.position2D) > this.deadspotRadius) {
532− sendTouchMoveEventToStylusTarget(this.hand, this.stylusTarget);
533− this.deadspotExpired = true;
534− }
535− } else {
536− this.stylusTouchingTarget = false;
399+ if (this.laserTarget) {
400+
401+ var POINTER_PRESS_TO_MOVE_DELAY = 0.33; // seconds
402+ if (this.deadspotExpired || this.touchingEnterTimer > POINTER_PRESS_TO_MOVE_DELAY ||
403+ distance2D(this.laserTarget.position2D,
404+ this.pressEnterLaserTarget.position2D) > this.deadspotRadius) {
405+ sendTouchMoveEventToStylusTarget(this.hand, this.laserTarget);
406+ this.deadspotExpired = true;
537407 }
408+
538409 } else {
539− this.stylusTouchingTarget = false;
410+ this.laserPressingTarget = false;
540411 }
541412 };
542413
@@ -556,38 +427,61 @@ Script.include("/~/system/libraries/controllers.js"); · 13 unmodified lines
556427 var target = controllerData.rayPicks[this.hand].objectID;
557428 if (this.pointingAtTabletScreen(target) || this.pointingAtHomeButton(target) || this.pointingAtTablet(target)) {
558429 if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
430+ this.tabletScrenID = HMD.tabletScreenID;
559431 return makeRunningValues(true, [], []);
560432 }
561433 }
562− //this.processLaser(controllerData);
563434 return makeRunningValues(false, [], []);
564435 };
565436
437+ this.reset = function() {
438+ this.laserPressExit();
439+ this.hover = false;
440+ this.pressEnterLaserTarget = null;
441+ this.laserTarget = null;
442+ this.laserTargetID = null;
443+ this.laserPressingTarget = false;
444+ this.previousLaserClickedTarget = null;
445+ this.mode = "none";
446+ };
447+
566448 this.run = function (controllerData, deltaTime) {
567449 var target = controllerData.rayPicks[this.hand].objectID;
450+
451+
568452 if (!this.pointingAtTabletScreen(target) && !this.pointingAtHomeButton(target) && !this.pointingAtTablet(target)) {
569453 LaserPointers.disableLaserPointer(this.laserPointer);
454+ this.laserPressExit();
455+ this.relinquishTouchFocus();
456+ this.reset();
457+ this.updateLaserPointer();
570458 return makeRunningValues(false, [], []);
571459 }
460+
461+ this.processControllerTriggers(controllerData);
572462 this.updateLaserPointer(controllerData);
573− //this.updateFingerAsStylusSetting();
463+ var intersection = LaserPointers.getPrevRayPickResult(this.laserPointer);
464+ this.laserTargetID = intersection.objectID;
465+ this.laserTarget = calculateLaserTargetFromOverlay(intersection.intersection, intersection.objectID);
466+ if (this.laserTarget === undefined) {
467+ return makeRunningValues(true, [], []);
468+ }
574469
575−/* if (!this.previousStylusTouchingTarget && this.stylusTouchingTarget) {
576− this.stylusTouchingEnter();
470+ if (!this.previousLaserClickedTarget && this.laserPressingTarget) {
471+ this.laserPressEnter();
577472 }
578− if (this.previousStylusTouchingTarget && !this.stylusTouchingTarget) {
579− this.stylusTouchingExit();
473+ if (this.previousLaserClickedTarget && !this.laserPressingTarget) {
474+ this.laserPressExit();
580475 }
581− this.previousStylusTouchingTarget = this.stylusTouchingTarget;
476+ this.previousLaserClickedTarget = this.laserPressingTarget;
582477
583− if (this.stylusTouchingTarget) {
584− this.stylusTouching(controllerData, deltaTime);
585− }*/
586− /*if (this.processLaser(controllerData)) {
587− return makeRunningValues(true, [], []);
588− } else {
589− return makeRunningValues(false, [], []);
590− }*/
478+ if (this.laserPressingTarget) {
479+ this.laserPressing(controllerData, deltaTime);
480+ }
481+
482+ if (this.hover) {
483+ this.hovering();
484+ }
591485
592486 return makeRunningValues(true, [], []);
593487 };
@@ -608,6 +502,8 @@ Script.include("/~/system/libraries/controllers.js"); · 14 unmodified lines
608502 faceAvatar: true,
609503 defaultRenderStates: defaultRenderStates
610504 });
505+
506+ LaserPointers.setIgnoreOverlays(this.laserPointer, [HMD.tabletID]);
611507 };
612508
613509 var leftTabletLaserInput = new TabletLaserInput(LEFT_HAND);