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
85 var HAPTIC_STYLUS_STRENGTH = 1.0;85 var HAPTIC_STYLUS_STRENGTH = 1.0;
86 var HAPTIC_STYLUS_DURATION = 20.0;86 var HAPTIC_STYLUS_DURATION = 20.0;
87 87
88 function stylusTargetHasKeyboardFocus(stylusTarget) {88 function stylusTargetHasKeyboardFocus(laserTarget) {
89 if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {89 if (laserTarget && laserTarget !== NULL_UUID) {
90 return Entities.keyboardFocusEntity === stylusTarget.entityID;90 return Overlays.keyboardFocusOverlay === laserTarget;
91 } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
92 return Overlays.keyboardFocusOverlay === stylusTarget.overlayID;
93 }91 }
94 }92 }
95 93
96 function setKeyboardFocusOnStylusTarget(stylusTarget) {94 function setKeyboardFocusOnStylusTarget(laserTarget) {
97 if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID &&95 if (laserTarget && laserTarget !== NULL_UUID) {
98 Entities.wantsHandControllerPointerEvents(stylusTarget.entityID)) {96 Overlays.keyboardFocusOverlay = laserTarget;
99 Overlays.keyboardFocusOverlay = NULL_UUID;
100 Entities.keyboardFocusEntity = stylusTarget.entityID;
101 } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
102 Overlays.keyboardFocusOverlay = stylusTarget.overlayID;
103 Entities.keyboardFocusEntity = NULL_UUID;97 Entities.keyboardFocusEntity = NULL_UUID;
104 }98 }
105 }99 }
106 100
107 function sendHoverEnterEventToStylusTarget(hand, stylusTarget) {101 function sendHoverEnterEventToStylusTarget(hand, laserTarget) {
102 if (!laserTarget) {
103 return;
104 }
108 var pointerEvent = {105 var pointerEvent = {
109 type: "Move",106 type: "Move",
110 id: hand + 1, // 0 is reserved for hardware mouse107 id: hand + 1, // 0 is reserved for hardware mouse
111 pos2D: stylusTarget.position2D,108 pos2D: laserTarget.position2D,
112 pos3D: stylusTarget.position,109 pos3D: laserTarget.position,
113 normal: stylusTarget.normal,110 normal: laserTarget.normal,
114 direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),111 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
115 button: "None"112 button: "None"
116 };113 };
117 114
118 if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {115 if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
119 Entities.sendHoverEnterEntity(stylusTarget.entityID, pointerEvent);116 Overlays.sendHoverEnterOverlay(laserTarget.overlayID, pointerEvent);
120 } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
121 Overlays.sendHoverEnterOverlay(stylusTarget.overlayID, pointerEvent);
122 }117 }
123 }118 }
124 119
125 function sendHoverOverEventToStylusTarget(hand, stylusTarget) {120 function sendHoverOverEventToStylusTarget(hand, laserTarget) {
121
122 if (!laserTarget) {
123 return;
124 }
126 var pointerEvent = {125 var pointerEvent = {
127 type: "Move",126 type: "Move",
128 id: hand + 1, // 0 is reserved for hardware mouse127 id: hand + 1, // 0 is reserved for hardware mouse
129 pos2D: stylusTarget.position2D,128 pos2D: laserTarget.position2D,
130 pos3D: stylusTarget.position,129 pos3D: laserTarget.position,
131 normal: stylusTarget.normal,130 normal: laserTarget.normal,
132 direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),131 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
133 button: "None"132 button: "None"
134 };133 };
135 134
136 if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {135 if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
137 Entities.sendMouseMoveOnEntity(stylusTarget.entityID, pointerEvent);136 Overlays.sendMouseMoveOnOverlay(laserTarget.overlayID, pointerEvent);
138 Entities.sendHoverOverEntity(stylusTarget.entityID, pointerEvent);137 Overlays.sendHoverOverOverlay(laserTarget.overlayID, pointerEvent);
139 } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
140 Overlays.sendMouseMoveOnOverlay(stylusTarget.overlayID, pointerEvent);
141 Overlays.sendHoverOverOverlay(stylusTarget.overlayID, pointerEvent);
142 }138 }
143 }139 }
144 140
145 function sendTouchStartEventToStylusTarget(hand, stylusTarget) {141 function sendTouchStartEventToStylusTarget(hand, laserTarget) {
142 if (!laserTarget) {
143 return;
144 }
145
146 var pointerEvent = {146 var pointerEvent = {
147 type: "Press",147 type: "Press",
148 id: hand + 1, // 0 is reserved for hardware mouse148 id: hand + 1, // 0 is reserved for hardware mouse
149 pos2D: stylusTarget.position2D,149 pos2D: laserTarget.position2D,
150 pos3D: stylusTarget.position,150 pos3D: laserTarget.position,
151 normal: stylusTarget.normal,151 normal: laserTarget.normal,
152 direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),152 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
153 button: "Primary",153 button: "Primary",
154 isPrimaryHeld: true154 isPrimaryHeld: true
155 };155 };
156 156
157 if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {157 if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
158 Entities.sendMousePressOnEntity(stylusTarget.entityID, pointerEvent);158 Overlays.sendMousePressOnOverlay(laserTarget.overlayID, pointerEvent);
159 Entities.sendClickDownOnEntity(stylusTarget.entityID, pointerEvent);
160 } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
161 Overlays.sendMousePressOnOverlay(stylusTarget.overlayID, pointerEvent);
162 }159 }
163 }160 }
164 161
165 function sendTouchEndEventToStylusTarget(hand, stylusTarget) {162 function sendTouchEndEventToStylusTarget(hand, laserTarget) {
163 if (!laserTarget) {
164 return;
165 }
166 var pointerEvent = {166 var pointerEvent = {
167 type: "Release",167 type: "Release",
168 id: hand + 1, // 0 is reserved for hardware mouse168 id: hand + 1, // 0 is reserved for hardware mouse
169 pos2D: stylusTarget.position2D,169 pos2D: laserTarget.position2D,
170 pos3D: stylusTarget.position,170 pos3D: laserTarget.position,
171 normal: stylusTarget.normal,171 normal: laserTarget.normal,
172 direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),172 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
173 button: "Primary"173 button: "Primary"
174 };174 };
175 175
176 if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {176 if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
177 Entities.sendMouseReleaseOnEntity(stylusTarget.entityID, pointerEvent);177 Overlays.sendMouseReleaseOnOverlay(laserTarget.overlayID, 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);
182 }178 }
183 }179 }
184 180
185 function sendTouchMoveEventToStylusTarget(hand, stylusTarget) {181 function sendTouchMoveEventToStylusTarget(hand, laserTarget) {
182 if (!laserTarget) {
183 return;
184 }
186 var pointerEvent = {185 var pointerEvent = {
187 type: "Move",186 type: "Move",
188 id: hand + 1, // 0 is reserved for hardware mouse187 id: hand + 1, // 0 is reserved for hardware mouse
189 pos2D: stylusTarget.position2D,188 pos2D: laserTarget.position2D,
190 pos3D: stylusTarget.position,189 pos3D: laserTarget.position,
191 normal: stylusTarget.normal,190 normal: laserTarget.normal,
192 direction: Vec3.subtract(ZERO_VEC, stylusTarget.normal),191 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
193 button: "Primary",192 button: "Primary",
194 isPrimaryHeld: true193 isPrimaryHeld: true
195 };194 };
196 195
197 if (stylusTarget.entityID && stylusTarget.entityID !== NULL_UUID) {196 if (laserTarget.overlayID && laserTarget.overlayID !== NULL_UUID) {
198 Entities.sendMouseMoveOnEntity(stylusTarget.entityID, pointerEvent);197 Overlays.sendMouseReleaseOnOverlay(laserTarget.overlayID, pointerEvent);
199 Entities.sendHoldingClickOnEntity(stylusTarget.entityID, pointerEvent);
200 } else if (stylusTarget.overlayID && stylusTarget.overlayID !== NULL_UUID) {
201 Overlays.sendMouseMoveOnOverlay(stylusTarget.overlayID, pointerEvent);
202 }198 }
203 }199 }
204 200
205 // will return undefined if overlayID does not exist.201 // will return undefined if overlayID does not exist.
206 function calculateStylusTargetFromOverlay(stylusTip, overlayID) {202 function calculateLaserTargetFromOverlay(laserTip, overlayID) {
207 var overlayPosition = Overlays.getProperty(overlayID, "position");203 var overlayPosition = Overlays.getProperty(overlayID, "position");
208 if (overlayPosition === undefined) {204 if (overlayPosition === undefined) {
209 return;205 return;
@@ -215,8 +211,8 @@ Script.include("/~/system/libraries/controllers.js"); · 5 unmodified lines
215 return;211 return;
216 }212 }
217 var normal = Vec3.multiplyQbyV(overlayRotation, {x: 0, y: 0, z: 1});213 var normal = Vec3.multiplyQbyV(overlayRotation, {x: 0, y: 0, z: 1});
218 var distance = Vec3.dot(Vec3.subtract(stylusTip.position, overlayPosition), normal);214 var distance = Vec3.dot(Vec3.subtract(laserTip, overlayPosition), normal);
219 var position = Vec3.subtract(stylusTip.position, Vec3.multiply(normal, distance));215 var position = Vec3.subtract(laserTip, Vec3.multiply(normal, distance));
220 216
221 // calclulate normalized position217 // calclulate normalized position
222 var invRot = Quat.inverse(overlayRotation);218 var invRot = Quat.inverse(overlayRotation);
@@ -267,92 +263,6 @@ Script.include("/~/system/libraries/controllers.js"); · 44 unmodified lines
267 };263 };
268 }264 }
269 265
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
356 function distance2D(a, b) {266 function distance2D(a, b) {
357 var dx = (a.x - b.x);267 var dx = (a.x - b.x);
358 var dy = (a.y - b.y);268 var dy = (a.y - b.y);
@@ -361,12 +271,14 @@ Script.include("/~/system/libraries/controllers.js"); · 2 unmodified lines
361 271
362 function TabletLaserInput(hand) {272 function TabletLaserInput(hand) {
363 this.hand = hand;273 this.hand = hand;
364 this.previousStylusTouchingTarget = false;274 this.previousLaserClikcedTarget = false;
365 this.stylusTouchingTarget = false;275 this.laserPressingTarget = false;
366 this.tabletScreenID = HMD.tabletScreenID;276 this.tabletScreenID = HMD.tabletScreenID;
367 277 this.mode = "none";
368 this.useFingerInsteadOfStylus = false;278 this.laserTargetID = null;
369 this.fingerPointing = false;279 this.laserTarget = null;
280 this.pressEnterLaserTarget = null;
281 this.hover = false;
370 282
371 283
372 this.parameters = makeDispatcherModuleParameters(284 this.parameters = makeDispatcherModuleParameters(
@@ -384,159 +296,118 @@ Script.include("/~/system/libraries/controllers.js"); · 11 unmodified lines
384 };296 };
385 297
386 this.stealTouchFocus = function(laserTarget) {298 this.stealTouchFocus = function(laserTarget) {
387 // send hover events to target299 this.requestTouchFocus(laserTarget);
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);
394 };300 };
395 301
396 this.requestTouchFocus = function(laserTarget) {302 this.requestTouchFocus = function(laserTarget) {
397 303 sendHoverEnterEventToStylusTarget(this.hand, this.laserTarget);
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 }
411 };304 };
412 305
413 this.hasTouchFocus = function(laserTarget) {306 this.hasTouchFocus = function(laserTarget) {
414 return ((stylusTarget.entityID && stylusTarget.entityID === this.hoverEntity) ||307 return (this.laserTargetID === HMD.tabletScreenID);
415 (stylusTarget.overlayID && stylusTarget.overlayID === this.hoverOverlay));
416 };308 };
417 309
418 this.relinquishTouchFocus = function() {310 this.relinquishTouchFocus = function() {
419 // send hover leave event.311 // send hover leave event.
420 var pointerEvent = { type: "Move", id: this.hand + 1 };312 var pointerEvent = { type: "Move", id: this.hand + 1 };
421 if (this.hoverEntity) {313 Overlays.sendMouseMoveOnOverlay(this.tabletScreenID, pointerEvent);
422 Entities.sendHoverLeaveEntity(this.hoverEntity, pointerEvent);314 Overlays.sendHoverOverOverlay(this.tabletScreenID, pointerEvent);
423 this.hoverEntity = null;315 Overlays.sendHoverLeaveOverlay(this.tabletScreenID, pointerEvent);
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 }
430 };316 };
431 317
432 this.updateLaserPointer = function(controllerData) {318 this.updateLaserPointer = function(controllerData) {
433 var RADIUS = 0.005;319 var RADIUS = 0.005;
434 var dim = { x: RADIUS, y: RADIUS, z: RADIUS };320 var dim = { x: RADIUS, y: RADIUS, z: RADIUS };
435
436 var mode = "none";
437 321
438 if (controllerData.triggerClicks[this.hand]) {322 if (this.mode === "full") {
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") {
448 this.fullEnd.dimensions = dim;323 this.fullEnd.dimensions = dim;
449 LaserPointers.editRenderState(this.laserPointer, mode, {path: fullPath, end: this.fullEnd});324 LaserPointers.editRenderState(this.laserPointer, this.mode, {path: fullPath, end: this.fullEnd});
450 } else if (mode === "half") {325 } else if (this.mode === "half") {
451 this.halfEnd.dimensions = dim;326 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});
453 }328 }
454 329
455 LaserPointers.enableLaserPointer(this.laserPointer);330 LaserPointers.enableLaserPointer(this.laserPointer);
456 LaserPointers.setRenderState(this.laserPointer, mode);331 LaserPointers.setRenderState(this.laserPointer, this.mode);
457 };332 };
458 333
459 this.pointFinger = function(value) {334 this.processControllerTriggers = function(controllerData) {
460 var HIFI_POINT_INDEX_MESSAGE_CHANNEL = "Hifi-Point-Index";335 var rayPickIntersection = controllerData.rayPicks[this.hand].intersection;
461 if (this.fingerPointing !== value) {336 this.laserTarget = calculateLaserTargetFromOverlay(rayPickIntersection, HMD.tabletScreenID);
462 var message;337 if (controllerData.triggerClicks[this.hand]) {
463 if (this.hand === RIGHT_HAND) {338 this.mode = "full";
464 message = { pointRightIndex: value };339 this.laserPressingTarget = true;
465 } else {340 this.hover = false;
466 message = { pointLeftIndex: value };341 } else if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
467 }342 this.mode = "half";
468 Messages.sendMessage(HIFI_POINT_INDEX_MESSAGE_CHANNEL, JSON.stringify(message), true);343 this.laserPressingTarget = false;
469 this.fingerPointing = value;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
470 }352 }
353 this.homeButtonTouched = false;
471 };354 };
472 355
473 this.processLaser = function(controllerData) {356 this.hovering = function() {
474 if (controllerData.rayPicks[this.hand].objectID === HMD.tabletScreenID) {357 if (this.hasTouchFocus(this.laserTargetID)) {
475 358 sendHoverOverEventToStylusTarget(this.hand, this.laserTarget);
476 } 359 }
477 this.homeButtonTouched = false;
478 };360 };
479 361
480 this.laserTouchingEnter = function () {362 this.laserPressEnter = function () {
481 this.stealTouchFocus(this.stylusTarget);363 this.stealTouchFocus(this.laserTarget.overlayID);
482 sendTouchStartEventToStylusTarget(this.hand, this.stylusTarget);364 sendTouchStartEventToStylusTarget(this.hand, this.laserTarget);
483 Controller.triggerHapticPulse(HAPTIC_STYLUS_STRENGTH, HAPTIC_STYLUS_DURATION, this.hand);365 Controller.triggerHapticPulse(HAPTIC_STYLUS_STRENGTH, HAPTIC_STYLUS_DURATION, this.hand);
484 366
485 this.touchingEnterTimer = 0;367 this.touchingEnterTimer = 0;
486 this.touchingEnterStylusTarget = this.stylusTarget;368 this.pressEnterLaserTarget = this.laserTarget;
487 this.deadspotExpired = false;369 this.deadspotExpired = false;
488 370
489 var TOUCH_PRESS_TO_MOVE_DEADSPOT = 0.0381;371 var TOUCH_PRESS_TO_MOVE_DEADSPOT = 0.0381;
490 this.deadspotRadius = TOUCH_PRESS_TO_MOVE_DEADSPOT;372 this.deadspotRadius = TOUCH_PRESS_TO_MOVE_DEADSPOT;
491 };373 };
492 374
493 this.laserTouchingExit = function () {375 this.laserPressExit = function () {
494 376
495 if (this.stylusTarget === undefined) {377 if (this.laserTarget === undefined) {
496 return;378 return;
497 }379 }
498 380
499 // special case to handle home button.381 // special case to handle home button.
500 if (this.stylusTarget.overlayID === HMD.homeButtonID) {382 if (this.laserTargetID === HMD.homeButtonID) {
501 Messages.sendLocalMessage("home", this.stylusTarget.overlayID);383 Messages.sendLocalMessage("home", this.laserTargetID);
502 }384 }
503 385
504 // send press event386 // send press event
505 if (this.deadspotExpired) {387 if (this.deadspotExpired) {
506 sendTouchEndEventToStylusTarget(this.hand, this.stylusTarget);388 sendTouchEndEventToStylusTarget(this.hand, this.laserTarget);
507 } else {389 } else {
508 sendTouchEndEventToStylusTarget(this.hand, this.touchingEnterStylusTarget);390 print(this.pressEnterLaserTarget);
391 sendTouchEndEventToStylusTarget(this.hand, this.pressEnterLaserTarget);
509 }392 }
510 };393 };
511 394
512 this.laserTouching = function (controllerData, dt) {395 this.laserPressing = function (controllerData, dt) {
513 396
514 this.touchingEnterTimer += dt;397 this.touchingEnterTimer += dt;
515 398
516 if (this.stylusTarget.entityID) {399 if (this.laserTarget) {
517 this.stylusTarget = calculateStylusTargetFromEntity(this.stylusTip, this.stylusTarget.entityProps);400
518 } else if (this.stylusTarget.overlayID) {401 var POINTER_PRESS_TO_MOVE_DELAY = 0.33; // seconds
519 this.stylusTarget = calculateStylusTargetFromOverlay(this.stylusTip, this.stylusTarget.overlayID);402 if (this.deadspotExpired || this.touchingEnterTimer > POINTER_PRESS_TO_MOVE_DELAY ||
520 }403 distance2D(this.laserTarget.position2D,
521 404 this.pressEnterLaserTarget.position2D) > this.deadspotRadius) {
522 var TABLET_MIN_TOUCH_DISTANCE = -0.1;405 sendTouchMoveEventToStylusTarget(this.hand, this.laserTarget);
523 var TABLET_MAX_TOUCH_DISTANCE = 0.01;406 this.deadspotExpired = true;
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;
537 }407 }
408
538 } else {409 } else {
539 this.stylusTouchingTarget = false;410 this.laserPressingTarget = false;
540 }411 }
541 };412 };
542 413
@@ -556,38 +427,61 @@ Script.include("/~/system/libraries/controllers.js"); · 13 unmodified lines
556 var target = controllerData.rayPicks[this.hand].objectID;427 var target = controllerData.rayPicks[this.hand].objectID;
557 if (this.pointingAtTabletScreen(target) || this.pointingAtHomeButton(target) || this.pointingAtTablet(target)) {428 if (this.pointingAtTabletScreen(target) || this.pointingAtHomeButton(target) || this.pointingAtTablet(target)) {
558 if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {429 if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
430 this.tabletScrenID = HMD.tabletScreenID;
559 return makeRunningValues(true, [], []);431 return makeRunningValues(true, [], []);
560 }432 }
561 }433 }
562 //this.processLaser(controllerData);
563 return makeRunningValues(false, [], []);434 return makeRunningValues(false, [], []);
564 };435 };
565 436
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
566 this.run = function (controllerData, deltaTime) {448 this.run = function (controllerData, deltaTime) {
567 var target = controllerData.rayPicks[this.hand].objectID;449 var target = controllerData.rayPicks[this.hand].objectID;
450
451
568 if (!this.pointingAtTabletScreen(target) && !this.pointingAtHomeButton(target) && !this.pointingAtTablet(target)) {452 if (!this.pointingAtTabletScreen(target) && !this.pointingAtHomeButton(target) && !this.pointingAtTablet(target)) {
569 LaserPointers.disableLaserPointer(this.laserPointer);453 LaserPointers.disableLaserPointer(this.laserPointer);
454 this.laserPressExit();
455 this.relinquishTouchFocus();
456 this.reset();
457 this.updateLaserPointer();
570 return makeRunningValues(false, [], []);458 return makeRunningValues(false, [], []);
571 }459 }
460
461 this.processControllerTriggers(controllerData);
572 this.updateLaserPointer(controllerData);462 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 }
574 469
575/* if (!this.previousStylusTouchingTarget && this.stylusTouchingTarget) {470 if (!this.previousLaserClickedTarget && this.laserPressingTarget) {
576 this.stylusTouchingEnter();471 this.laserPressEnter();
577 }472 }
578 if (this.previousStylusTouchingTarget && !this.stylusTouchingTarget) {473 if (this.previousLaserClickedTarget && !this.laserPressingTarget) {
579 this.stylusTouchingExit();474 this.laserPressExit();
580 }475 }
581 this.previousStylusTouchingTarget = this.stylusTouchingTarget;476 this.previousLaserClickedTarget = this.laserPressingTarget;
582 477
583 if (this.stylusTouchingTarget) {478 if (this.laserPressingTarget) {
584 this.stylusTouching(controllerData, deltaTime);479 this.laserPressing(controllerData, deltaTime);
585 }*/480 }
586 /*if (this.processLaser(controllerData)) {481
587 return makeRunningValues(true, [], []);482 if (this.hover) {
588 } else {483 this.hovering();
589 return makeRunningValues(false, [], []);484 }
590 }*/
591 485
592 return makeRunningValues(true, [], []);486 return makeRunningValues(true, [], []);
593 };487 };
@@ -608,6 +502,8 @@ Script.include("/~/system/libraries/controllers.js"); · 14 unmodified lines
608 faceAvatar: true,502 faceAvatar: true,
609 defaultRenderStates: defaultRenderStates503 defaultRenderStates: defaultRenderStates
610 });504 });
505
506 LaserPointers.setIgnoreOverlays(this.laserPointer, [HMD.tabletID]);
611 };507 };
612 508
613 var leftTabletLaserInput = new TabletLaserInput(LEFT_HAND);509 var leftTabletLaserInput = new TabletLaserInput(LEFT_HAND);