History

finished webEntityLaserInput, now working on cloning

Dante Ruiz committed 9 years ago

Commit 4b592681 parent 63387026 files · +667 −16Browse files

Showing the changes to scripts/system/controllers/controllerModules (4 of 6 files). Show all

Unified · Split

4 files
  1. scripts/system/controllers/controllerModules/equipEntity.js +1 −0
  2. scripts/system/controllers/controllerModules/farActionGrabEntity.js +83 −14
  3. scripts/system/controllers/controllerModules/nearParentGrabEntity.js +13 −1
  4. scripts/system/controllers/controllerModules/webEntityLaserInput.js +478 −0
scripts/system/controllers/controllerModules/equipEntity.js+1−0
@@ -434,6 +434,7 @@ EquipHotspotBuddy.prototype.update = function(deltaTime, timestamp, controllerDa · 433 unmodified lines
434 };434 };
435 435
436 this.startEquipEntity = function (controllerData) {436 this.startEquipEntity = function (controllerData) {
437 print("------> starting to equip entity <-------");
437 this.dropGestureReset();438 this.dropGestureReset();
438 this.clearEquipHaptics();439 this.clearEquipHaptics();
439 Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);440 Controller.triggerHapticPulse(HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION, this.hand);
scripts/system/controllers/controllerModules/farActionGrabEntity.js+83−14
@@ -86,6 +86,24 @@ Script.include("/~/system/libraries/controllers.js"); · 85 unmodified lines
86 {name: "full", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: fullPath},86 {name: "full", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: fullPath},
87 {name: "hold", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: holdPath}];87 {name: "hold", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: holdPath}];
88 88
89 var GRABBABLE_PROPERTIES = [
90 "position",
91 "registrationPoint",
92 "rotation",
93 "gravity",
94 "collidesWith",
95 "dynamic",
96 "collisionless",
97 "locked",
98 "name",
99 "shapeType",
100 "parentID",
101 "parentJointIndex",
102 "density",
103 "dimensions",
104 "userData"
105 ];
106
89 107
90 function FarActionGrabEntity(hand) {108 function FarActionGrabEntity(hand) {
91 this.hand = hand;109 this.hand = hand;
@@ -317,18 +335,61 @@ Script.include("/~/system/libraries/controllers.js"); · 225 unmodified lines
317 this.grabbedThingID = null;335 this.grabbedThingID = null;
318 };336 };
319 337
320 this.pointingAtWebOverlay = function(controllerData) {338 this.pointingAtWebEntity = function(controllerData) {
321 var intersection = controllerData.rayPicks[this.hand];339 var intersection = controllerData.rayPicks[this.hand];
322 var overlayType = Overlays.getOverlayType(intersection.objectID);340 var entityProperty = Entities.getEntityProperties(intersection.objectID);
323 print(JSON.stringify(Entities.getEntityProperties(intersection.objectID)));341 var entityType = entityProperty.type;
324 if ((intersection.type === RayPick.INTERSECTED_OVERLAY && overlayType === "web3d") || intersection.objectID === HMD.tabletButtonID) {342 if ((intersection.type === RayPick.INTERSECTED_ENTITY && entityType === "Web") || intersection.objectID === HMD.tabletButtonID) {
325 return true;343 return true;
326 }344 }
327 return false345 return false
328 };346 };
329 347
348 this.distanceRotate = function(otherFarGrabModule) {
349 this.distanceRotating = true;
350 this.distanceHolding = false;
351
352 var worldControllerRotation = getControllerWorldLocation(this.handToController(), true).orientation;
353 var controllerRotationDelta = Quat.multiply(worldControllerRotation, Quat.inverse(this.previousWorldControllerRotation));
354 // Rotate entity by twice the delta rotation.
355 controllerRotationDelta = Quat.multiply(controllerRotationDelta, controllerRotationDelta);
356
357 // Perform the rotation in the translation controller's action update.
358 otherFarGrabModule.currentObjectRotation = Quat.multiply(controllerRotationDelta,
359 otherFarGrabModule.currentObjectRotation);
360
361 // Rotate about the translation controller's target position.
362 this.offsetPosition = Vec3.multiplyQbyV(controllerRotationDelta, this.offsetPosition);
363 otherFarGrabModule.offsetPosition = Vec3.multiplyQbyV(controllerRotationDelta,
364 otherFarGrabModule.offsetPosition);
365
366 this.updateLaserPointer();
367
368 this.previousWorldControllerRotation = worldControllerRotation;
369 };
370
371 this.prepareDistanceRotatingData = function(controllerData) {
372 var intersection = controllerData.rayPicks[this.hand];
373
374 var controllerLocation = getControllerWorldLocation(this.handToController(), true);
375 var worldControllerPosition = controllerLocation.position;
376 var worldControllerRotation = controllerLocation.orientation;
377
378 var grabbedProperties = Entities.getEntityProperties(intersection.objectID, GRABBABLE_PROPERTIES);
379 this.currentObjectPosition = grabbedProperties.position;
380 this.grabRadius = intersection.distance;
381
382 // Offset between controller vector at the grab radius and the entity position.
383 var targetPosition = Vec3.multiply(this.grabRadius, Quat.getUp(worldControllerRotation));
384 targetPosition = Vec3.sum(targetPosition, worldControllerPosition);
385 this.offsetPosition = Vec3.subtract(this.currentObjectPosition, targetPosition);
386
387 // Initial controller rotation.
388 this.previousWorldControllerRotation = worldControllerRotation;
389 };
390
330 this.isReady = function (controllerData) {391 this.isReady = function (controllerData) {
331 if (this.pointingAtWebOverlay(controllerData)) {392 if (this.pointingAtWebEntity(controllerData)) {
332 return makeRunningValues(false, [], []);393 return makeRunningValues(false, [], []);
333 }394 }
334 395
@@ -337,6 +398,7 @@ Script.include("/~/system/libraries/controllers.js"); · 2 unmodified lines
337 398
338 if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {399 if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
339 this.updateLaserPointer(controllerData);400 this.updateLaserPointer(controllerData);
401 this.prepareDistanceRotatingData(controllerData);
340 return makeRunningValues(true, [], []);402 return makeRunningValues(true, [], []);
341 } else {403 } else {
342 return makeRunningValues(false, [], []);404 return makeRunningValues(false, [], []);
@@ -344,7 +406,7 @@ Script.include("/~/system/libraries/controllers.js"); · 1 unmodified line
344 };406 };
345 407
346 this.run = function (controllerData) {408 this.run = function (controllerData) {
347 if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.pointingAtWebOverlay(controllerData)) {409 if (controllerData.triggerValues[this.hand] < TRIGGER_OFF_VALUE || this.pointingAtWebEntity(controllerData)) {
348 this.endNearGrabAction();410 this.endNearGrabAction();
349 this.laserPointerOff();411 this.laserPointerOff();
350 return makeRunningValues(false, [], []);412 return makeRunningValues(false, [], []);
@@ -374,6 +436,7 @@ Script.include("/~/system/libraries/controllers.js"); · 23 unmodified lines
374 }436 }
375 }437 }
376 438
439
377 this.continueDistanceHolding(controllerData);440 this.continueDistanceHolding(controllerData);
378 // this.updateLaserPointer(controllerData, false, false);441 // this.updateLaserPointer(controllerData, false, false);
379 442
@@ -398,26 +461,32 @@ Script.include("/~/system/libraries/controllers.js"); · 18 unmodified lines
398 "rotation", "dimensions", "density",461 "rotation", "dimensions", "density",
399 "userData", "locked", "type"]);462 "userData", "locked", "type"]);
400 if (entityIsDistanceGrabbable(targetProps)) {463 if (entityIsDistanceGrabbable(targetProps)) {
401 this.grabbedThingID = entityID;464 if (!this.distanceRotating) {
402 this.grabbedDistance = rayPickInfo.distance;465 this.grabbedThingID = entityID;
466 this.grabbedDistance = rayPickInfo.distance;
467 }
403 var otherModuleName =468 var otherModuleName =
404 this.hand == RIGHT_HAND ? "LeftFarActionGrabEntity" : "RightFarActionGrabEntity";469 this.hand == RIGHT_HAND ? "LeftFarActionGrabEntity" : "RightFarActionGrabEntity";
405 var otherFarGrabModule = getEnabledModuleByName(otherModuleName);470 var otherFarGrabModule = getEnabledModuleByName(otherModuleName);
406 if (otherFarGrabModule.grabbedThingID == this.grabbedThingID) {471 if (otherFarGrabModule.grabbedThingID == this.grabbedThingID && otherFarGrabModule.distanceHolding) {
407 this.distanceRotating = true;472 this.distanceRotate(otherFarGrabModule);
408 this.distanceHolding = false;
409 // XXX rotate
410 } else {473 } else {
411 this.distanceHolding = true;474 this.distanceHolding = true;
412 this.distanceRotating = false;475 this.distanceRotating = false;
413 this.startFarGrabAction(controllerData, targetProps);476 this.startFarGrabAction(controllerData, targetProps);
414 }477 }
415 }478 }
416 } else if (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(hudPoint2d || Reticle.position)) {479 } else if (this.distanceRotating) {
480 var otherModuleName =
481 this.hand == RIGHT_HAND ? "LeftFarActionGrabEntity" : "RightFarActionGrabEntity";
482 var otherFarGrabModule = getEnabledModuleByName(otherModuleName);
483 this.distanceRotate(otherFarGrabModule);
484 }
485 /* else if (Reticle.pointingAtSystemOverlay || Overlays.getOverlayAtPoint(hudPoint2d || Reticle.position)) {
417 this.endNearGrabAction();486 this.endNearGrabAction();
418 this.laserPointerOff();487 this.laserPointerOff();
419 return makeRunningValues(false, [], []);488 return makeRunningValues(false, [], []);
420 }489 }*/
421 }490 }
422 return makeRunningValues(true, [], []);491 return makeRunningValues(true, [], []);
423 };492 };
scripts/system/controllers/controllerModules/nearParentGrabEntity.js+13−1
@@ -14,6 +14,7 @@ · 13 unmodified lines
14*/14*/
15 15
16Script.include("/~/system/controllers/controllerDispatcherUtils.js");16Script.include("/~/system/controllers/controllerDispatcherUtils.js");
17Script.include("/~/system/libraries/cloneEntityUtils.js");
17 18
18(function() {19(function() {
19 20
@@ -187,7 +188,18 @@ Script.include("/~/system/controllers/controllerDispatcherUtils.js"); · 167 unmodified lines
187 if (controllerData.triggerClicks[this.hand] == 1) {188 if (controllerData.triggerClicks[this.hand] == 1) {
188 // switch to grab189 // switch to grab
189 var targetProps = this.getTargetProps(controllerData);190 var targetProps = this.getTargetProps(controllerData);
190 if (targetProps) {191 var targetCloneable = entityIsCloneable(targetProps);
192
193 if (targetCloneable) {
194 var worldEntityProps = controllerData.nearbyEntityProperties[this.hand];
195 var cloneID = cloneEntity(targetProps, worldEntityProps);
196 var cloneProps = Entities.getEntityProperties(cloneID);
197
198 this.grabbing = true;
199 this.targetEntityID = cloneID
200 this.startNearParentingGrabEntity(controllerData, cloneProps);
201
202 } else if (targetProps) {
191 this.grabbing = true;203 this.grabbing = true;
192 this.startNearParentingGrabEntity(controllerData, targetProps);204 this.startNearParentingGrabEntity(controllerData, targetProps);
193 }205 }
scripts/system/controllers/controllerModules/webEntityLaserInput.js+478−0
@@ -0,0 +1,478 @@
1"use strict";
2
3// webEntityLaserInput.js
4//
5// Distributed under the Apache License, Version 2.0.
6// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7
8/*jslint bitwise: true */
9
10/* global Script, Controller, LaserPointers, RayPick, RIGHT_HAND, LEFT_HAND, Mat4, MyAvatar, Vec3, Camera, Quat,
11 getGrabPointSphereOffset, getEnabledModuleByName, makeRunningValues, Entities, NULL_UUID,
12 enableDispatcherModule, disableDispatcherModule, entityIsDistanceGrabbable,
13 makeDispatcherModuleParameters, MSECS_PER_SEC, HAPTIC_PULSE_STRENGTH, HAPTIC_PULSE_DURATION,
14 PICK_MAX_DISTANCE, COLORS_GRAB_SEARCHING_HALF_SQUEEZE, COLORS_GRAB_SEARCHING_FULL_SQUEEZE, COLORS_GRAB_DISTANCE_HOLD,
15 AVATAR_SELF_ID, DEFAULT_SEARCH_SPHERE_DISTANCE, TRIGGER_OFF_VALUE, TRIGGER_ON_VALUE,
16
17*/
18
19Script.include("/~/system/controllers/controllerDispatcherUtils.js");
20Script.include("/~/system/libraries/controllers.js");
21
22(function() {
23 var halfPath = {
24 type: "line3d",
25 color: COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
26 visible: true,
27 alpha: 1,
28 solid: true,
29 glow: 1.0,
30 lineWidth: 5,
31 ignoreRayIntersection: true, // always ignore this
32 drawInFront: true, // Even when burried inside of something, show it.
33 parentID: AVATAR_SELF_ID
34 };
35 var halfEnd = {
36 type: "sphere",
37 solid: true,
38 color: COLORS_GRAB_SEARCHING_HALF_SQUEEZE,
39 alpha: 0.9,
40 ignoreRayIntersection: true,
41 drawInFront: true, // Even when burried inside of something, show it.
42 visible: true
43 };
44 var fullPath = {
45 type: "line3d",
46 color: COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
47 visible: true,
48 alpha: 1,
49 solid: true,
50 glow: 1.0,
51 lineWidth: 5,
52 ignoreRayIntersection: true, // always ignore this
53 drawInFront: true, // Even when burried inside of something, show it.
54 parentID: AVATAR_SELF_ID
55 };
56 var fullEnd = {
57 type: "sphere",
58 solid: true,
59 color: COLORS_GRAB_SEARCHING_FULL_SQUEEZE,
60 alpha: 0.9,
61 ignoreRayIntersection: true,
62 drawInFront: true, // Even when burried inside of something, show it.
63 visible: true
64 };
65 var holdPath = {
66 type: "line3d",
67 color: COLORS_GRAB_DISTANCE_HOLD,
68 visible: true,
69 alpha: 1,
70 solid: true,
71 glow: 1.0,
72 lineWidth: 5,
73 ignoreRayIntersection: true, // always ignore this
74 drawInFront: true, // Even when burried inside of something, show it.
75 parentID: AVATAR_SELF_ID
76 };
77
78 var renderStates = [{name: "half", path: halfPath, end: halfEnd},
79 {name: "full", path: fullPath, end: fullEnd},
80 {name: "hold", path: holdPath}];
81
82 var defaultRenderStates = [{name: "half", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: halfPath},
83 {name: "full", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: fullPath},
84 {name: "hold", distance: DEFAULT_SEARCH_SPHERE_DISTANCE, path: holdPath}];
85
86
87 // triggered when stylus presses a web overlay/entity
88 var HAPTIC_STYLUS_STRENGTH = 1.0;
89 var HAPTIC_STYLUS_DURATION = 20.0;
90
91 function laserTargetHasKeyboardFocus(laserTarget) {
92 if (laserTarget && laserTarget !== NULL_UUID) {
93 return Entities.keyboardFocusOverlay === laserTarget;
94 }
95 }
96
97 function setKeyboardFocusOnLaserTarget(laserTarget) {
98 if (laserTarget && laserTarget !== NULL_UUID) {
99 Entities.wantsHandControllerPointerEvents(laserTarget);
100 Overlays.keyboardFocusOverlay = NULL_UUID;
101 Entities.keyboardFocusEntity = laserTarget;
102 }
103 }
104
105 function sendHoverEnterEventToLaserTarget(hand, laserTarget) {
106 if (!laserTarget) {
107 return;
108 }
109 var pointerEvent = {
110 type: "Move",
111 id: hand + 1, // 0 is reserved for hardware mouse
112 pos2D: laserTarget.position2D,
113 pos3D: laserTarget.position,
114 normal: laserTarget.normal,
115 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
116 button: "None"
117 };
118
119 if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) {
120 Entities.sendHoverEnterEntity(laserTarget.entityID, pointerEvent);
121 }
122 }
123
124 function sendHoverOverEventToLaserTarget(hand, laserTarget) {
125
126 if (!laserTarget) {
127 return;
128 }
129 var pointerEvent = {
130 type: "Move",
131 id: hand + 1, // 0 is reserved for hardware mouse
132 pos2D: laserTarget.position2D,
133 pos3D: laserTarget.position,
134 normal: laserTarget.normal,
135 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
136 button: "None"
137 };
138
139 if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) {
140 Entities.sendMouseMoveOnEntity(laserTarget.entityID, pointerEvent);
141 Entities.sendHoverOverEntity(laserTarget.entityID, pointerEvent);
142 }
143 }
144
145
146 function sendTouchStartEventToLaserTarget(hand, laserTarget) {
147 var pointerEvent = {
148 type: "Press",
149 id: hand + 1, // 0 is reserved for hardware mouse
150 pos2D: laserTarget.position2D,
151 pos3D: laserTarget.position,
152 normal: laserTarget.normal,
153 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
154 button: "Primary",
155 isPrimaryHeld: true
156 };
157
158 if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) {
159 Entities.sendMousePressOnEntity(laserTarget.entityID, pointerEvent);
160 Entities.sendClickDownOnEntity(laserTarget.entityID, pointerEvent);
161 }
162 }
163
164 function sendTouchEndEventToLaserTarget(hand, laserTarget) {
165 var pointerEvent = {
166 type: "Release",
167 id: hand + 1, // 0 is reserved for hardware mouse
168 pos2D: laserTarget.position2D,
169 pos3D: laserTarget.position,
170 normal: laserTarget.normal,
171 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
172 button: "Primary"
173 };
174
175 if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) {
176 Entities.sendMouseReleaseOnEntity(laserTarget.entityID, pointerEvent);
177 Entities.sendClickReleaseOnEntity(laserTarget.entityID, pointerEvent);
178 Entities.sendHoverLeaveEntity(laserTarget.entityID, pointerEvent);
179 }
180 }
181
182 function sendTouchMoveEventToLaserTarget(hand, laserTarget) {
183 var pointerEvent = {
184 type: "Move",
185 id: hand + 1, // 0 is reserved for hardware mouse
186 pos2D: laserTarget.position2D,
187 pos3D: laserTarget.position,
188 normal: laserTarget.normal,
189 direction: Vec3.subtract(ZERO_VEC, laserTarget.normal),
190 button: "Primary",
191 isPrimaryHeld: true
192 };
193
194 if (laserTarget.entityID && laserTarget.entityID !== NULL_UUID) {
195 Entities.sendMouseMoveOnEntity(laserTarget.entityID, pointerEvent);
196 Entities.sendHoldingClickOnEntity(laserTarget.entityID, pointerEvent);
197 }
198 }
199
200 function calculateTargetFromEntity(intersection, props) {
201 if (props.rotation === undefined) {
202 // if rotation is missing from props object, then this entity has probably been deleted.
203 return null;
204 }
205
206 // project stylus tip onto entity plane.
207 var normal = Vec3.multiplyQbyV(props.rotation, {x: 0, y: 0, z: 1});
208 Vec3.multiplyQbyV(props.rotation, {x: 0, y: 1, z: 0});
209 var distance = Vec3.dot(Vec3.subtract(intersection, props.position), normal);
210 var position = Vec3.subtract(intersection, Vec3.multiply(normal, distance));
211
212 // generate normalized coordinates
213 var invRot = Quat.inverse(props.rotation);
214 var localPos = Vec3.multiplyQbyV(invRot, Vec3.subtract(position, props.position));
215 var invDimensions = { x: 1 / props.dimensions.x, y: 1 / props.dimensions.y, z: 1 / props.dimensions.z };
216 var normalizedPosition = Vec3.sum(Vec3.multiplyVbyV(localPos, invDimensions), props.registrationPoint);
217
218 // 2D position on entity plane in meters, relative to the bounding box upper-left hand corner.
219 var position2D = { x: normalizedPosition.x * props.dimensions.x,
220 y: (1 - normalizedPosition.y) * props.dimensions.y }; // flip y-axis
221
222 return {
223 entityID: props.id,
224 entityProps: props,
225 overlayID: null,
226 distance: distance,
227 position: position,
228 position2D: position2D,
229 normal: normal,
230 normalizedPosition: normalizedPosition,
231 dimensions: props.dimensions,
232 valid: true
233 };
234 }
235
236 function distance2D(a, b) {
237 var dx = (a.x - b.x);
238 var dy = (a.y - b.y);
239 return Math.sqrt(dx * dx + dy * dy);
240 }
241
242 function WebEntityLaserInput(hand) {
243 this.hand = hand;
244 this.active = false;
245 this.previousLaserClickedTarget = false;
246 this.laserPressingTarget = false;
247 this.hover = false;
248 this.mode = "none";
249 this.pressEnterLaserTarget = null;
250 this.laserTarget = null;
251 this.laserTargetID = null;
252 this.lastValidTargetID = null;
253
254 this.handToController = function() {
255 return (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand;
256 };
257
258 this.getOtherModule = function() {
259 return (this.hand === RIGHT_HAND) ? leftWebEntityLaserInput : rightWebEntityLaserInput;
260 };
261
262 this.parameters = makeDispatcherModuleParameters(
263 550,
264 this.hand === RIGHT_HAND ? ["rightHand"] : ["leftHand"],
265 [],
266 100);
267
268 this.requestTouchFocus = function(laserTarget) {
269 if (laserTarget !== null || laserTarget !== undefined) {
270 sendHoverEnterEventToLaserTarget(this.hand, this.laserTarget);
271 this.lastValidTargetID = laserTarget;
272 }
273 };
274
275 this.relinquishTouchFocus = function() {
276 // send hover leave event.
277 var pointerEvent = { type: "Move", id: this.hand + 1 };
278 Entities.sendMouseMoveOnEntity(this.lastValidTargetID, pointerEvent);
279 Entities.sendHoverOverEntity(this.lastValidTargetID, pointerEvent);
280 Entities.sendHoverLeaveEntity(this.lastValidID, pointerEvent);
281 };
282
283 this.updateLaserTargets = function(controllerData) {
284 var intersection = controllerData.rayPicks[this.hand];
285 this.laserTargetID = intersection.objectID;
286 var props = Entities.getEntityProperties(intersection.objectID);
287 this.laserTarget = calculateTargetFromEntity(intersection.intersection, props);
288 };
289
290 this.processControllerTriggers = function(controllerData) {
291 if (controllerData.triggerClicks[this.hand]) {
292 this.mode = "full";
293 this.laserPressingTarget = true;
294 this.hover = false;
295 } else if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) {
296 this.mode = "half";
297 this.laserPressingTarget = false;
298 this.hover = true;
299 this.requestTouchFocus(this.laserTargetID);
300 } else {
301 this.mode = "none";
302 this.laserPressingTarget = false;
303 this.hover = false;
304 this.relinquishTouchFocus();
305
306 }
307 };
308
309 this.hovering = function() {
310 if (!laserTargetHasKeyboardFocus(this.laserTagetID)) {
311 setKeyboardFocusOnLaserTarget(this.laserTargetID);
312 }
313 sendHoverOverEventToLaserTarget(this.hand, this.laserTarget);
314 };
315
316 this.laserPressEnter = function () {
317 sendTouchStartEventToLaserTarget(this.hand, this.laserTarget);
318 Controller.triggerHapticPulse(HAPTIC_STYLUS_STRENGTH, HAPTIC_STYLUS_DURATION, this.hand);
319
320 this.touchingEnterTimer = 0;
321 this.pressEnterLaserTarget = this.laserTarget;
322 this.deadspotExpired = false;
323
324 var LASER_PRESS_TO_MOVE_DEADSPOT = 0.026;
325 this.deadspotRadius = Math.tan(LASER_PRESS_TO_MOVE_DEADSPOT) * this.laserTarget.distance;
326 };
327
328 this.laserPressExit = function () {
329 if (this.laserTarget === null) {
330 return;
331 }
332
333 // send press event
334 if (this.deadspotExpired) {
335 sendTouchEndEventToLaserTarget(this.hand, this.laserTarget);
336 } else {
337 sendTouchEndEventToLaserTarget(this.hand, this.pressEnterLaserTarget);
338 }
339 };
340
341 this.laserPressing = function (controllerData, dt) {
342 this.touchingEnterTimer += dt;
343
344 if (this.laserTarget) {
345 var POINTER_PRESS_TO_MOVE_DELAY = 0.33; // seconds
346 if (this.deadspotExpired || this.touchingEnterTimer > POINTER_PRESS_TO_MOVE_DELAY ||
347 distance2D(this.laserTarget.position2D,
348 this.pressEnterLaserTarget.position2D) > this.deadspotRadius) {
349 sendTouchMoveEventToLaserTarget(this.hand, this.laserTarget);
350 this.deadspotExpired = true;
351 }
352 } else {
353 this.laserPressingTarget = false;
354 }
355 };
356
357 this.releaseTouchEvent = function() {
358 if (this.pressEnterLaserTarget === null) {
359 return;
360 }
361
362 sendTouchEndEventToLaserTarget(this.hand, this.pressEnterLaserTarget);
363 }
364
365 this.updateLaserPointer = function(controllerData) {
366 var RADIUS = 0.005;
367 var dim = { x: RADIUS, y: RADIUS, z: RADIUS };
368
369 if (this.mode === "full") {
370 fullEnd.dimensions = dim;
371 LaserPointers.editRenderState(this.laserPointer, this.mode, {path: fullPath, end: fullEnd});
372 } else if (this.mode === "half") {
373 halfEnd.dimensions = dim;
374 LaserPointers.editRenderState(this.laserPointer, this.mode, {path: halfPath, end: halfEnd});
375 }
376
377 LaserPointers.enableLaserPointer(this.laserPointer);
378 LaserPointers.setRenderState(this.laserPointer, this.mode);
379 };
380
381 this.isPointingAtWebEntity = function(controllerData) {
382 var intersection = controllerData.rayPicks[this.hand];
383 var entityProperty = Entities.getEntityProperties(intersection.objectID);
384 var entityType = entityProperty.type;
385
386 if ((intersection.type === RayPick.INTERSECTED_ENTITY && entityType === "Web")) {
387 return true;
388 }
389 return false
390 };
391
392 this.exitModule = function() {
393 this.releaseTouchEvent();
394 this.relinquishTouchFocus();
395 this.reset();
396 this.updateLaserPointer();
397 LaserPointers.disableLaserPointer(this.laserPointer);
398 };
399
400 this.reset = function() {
401 this.pressEnterLaserTarget = null;
402 this.laserTarget = null;
403 this.laserTargetID = null;
404 this.laserPressingTarget = false;
405 this.previousLaserClickedTarget = null;
406 this.mode = "none";
407 this.active = false;
408 };
409
410 this.isReady = function(controllerData) {
411 var otherModule = this.getOtherModule();
412 if (this.isPointingAtWebEntity(controllerData) && !otherModule.active) {
413 return makeRunningValues(true, [], []);
414 }
415
416 return makeRunningValues(false, [], []);
417 };
418
419 this.run = function(controllerData, deltaTime) {
420 if (!this.isPointingAtWebEntity(controllerData)) {
421 this.exitModule();
422 return makeRunningValues(false, [], []);
423 }
424
425 this.updateLaserTargets(controllerData);
426 this.processControllerTriggers(controllerData);
427 this.updateLaserPointer(controllerData);
428
429 if (!this.previousLaserClickedTarget && this.laserPressingTarget) {
430 this.laserPressEnter();
431 }
432 if (this.previousLaserClickedTarget && !this.laserPressingTarget) {
433 this.laserPressExit();
434 }
435 this.previousLaserClickedTarget = this.laserPressingTarget;
436
437 if (this.laserPressingTarget) {
438 this.laserPressing(controllerData, deltaTime);
439 }
440
441 if (this.hover) {
442 this.hovering();
443 }
444 return makeRunningValues(true, [], []);
445 };
446
447 this.cleanup = function() {
448 LaserPointers.disableLaserPointer(this.laserPointer);
449 LaserPointers.removeLaserPointer(this.laserPointer);
450 }
451
452 this.laserPointer = LaserPointers.createLaserPointer({
453 joint: (this.hand == RIGHT_HAND) ? "_CONTROLLER_RIGHTHAND" : "_CONTROLLER_LEFTHAND",
454 filter: RayPick.PICK_ENTITIES,
455 maxDistance: PICK_MAX_DISTANCE,
456 posOffset: getGrabPointSphereOffset(this.handToController()),
457 renderStates: renderStates,
458 faceAvatar: true,
459 defaultRenderStates: defaultRenderStates
460 });
461 };
462
463
464 var leftWebEntityLaserInput = new WebEntityLaserInput(LEFT_HAND);
465 var rightWebEntityLaserInput = new WebEntityLaserInput(RIGHT_HAND);
466
467 enableDispatcherModule("LeftWebEntityLaserInput", leftWebEntityLaserInput);
468 enableDispatcherModule("RightWebEntityLaserInput", rightWebEntityLaserInput);
469
470 this.cleanup = function() {
471 leftWebEntityLaserInput.cleanup();
472 rightWebEntityLaserInput.cleanup();
473 disableDispatcherModule("LeftWebEntityLaserInput");
474 disableDispatcherModule("RightWebEntityLaserInput");
475 };
476 Script.scriptEnding.connect(this.cleanup);
477
478}());

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t