Showing the changes to scripts/system/controllers/controllerModules (1 of 1 file). Show all
Unified · Split
| @@ -85,125 +85,121 @@ Script.include("/~/system/libraries/controllers.js"); · 84 unmodified lines | ||
| 85 | 85 | var HAPTIC_STYLUS_STRENGTH = 1.0; |
| 86 | 86 | var HAPTIC_STYLUS_DURATION = 20.0; |
| 87 | 87 | |
| 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; | |
| 93 | 91 | } |
| 94 | 92 | } |
| 95 | 93 | |
| 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; | |
| 103 | 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 | 105 | var pointerEvent = { |
| 109 | 106 | type: "Move", |
| 110 | 107 | 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), | |
| 115 | 112 | button: "None" |
| 116 | 113 | }; |
| 117 | 114 | |
| 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); | |
| 122 | 117 | } |
| 123 | 118 | } |
| 124 | 119 | |
| 125 | − function sendHoverOverEventToStylusTarget(hand, stylusTarget) { | |
| 120 | + function sendHoverOverEventToStylusTarget(hand, laserTarget) { | |
| 121 | + | |
| 122 | + if (!laserTarget) { | |
| 123 | + return; | |
| 124 | + } | |
| 126 | 125 | var pointerEvent = { |
| 127 | 126 | type: "Move", |
| 128 | 127 | 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), | |
| 133 | 132 | button: "None" |
| 134 | 133 | }; |
| 135 | 134 | |
| 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); | |
| 142 | 138 | } |
| 143 | 139 | } |
| 144 | 140 | |
| 145 | − function sendTouchStartEventToStylusTarget(hand, stylusTarget) { | |
| 141 | + function sendTouchStartEventToStylusTarget(hand, laserTarget) { | |
| 142 | + if (!laserTarget) { | |
| 143 | + return; | |
| 144 | + } | |
| 145 | + | |
| 146 | 146 | var pointerEvent = { |
| 147 | 147 | type: "Press", |
| 148 | 148 | 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), | |
| 153 | 153 | button: "Primary", |
| 154 | 154 | isPrimaryHeld: true |
| 155 | 155 | }; |
| 156 | 156 | |
| 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); | |
| 162 | 159 | } |
| 163 | 160 | } |
| 164 | 161 | |
| 165 | − function sendTouchEndEventToStylusTarget(hand, stylusTarget) { | |
| 162 | + function sendTouchEndEventToStylusTarget(hand, laserTarget) { | |
| 163 | + if (!laserTarget) { | |
| 164 | + return; | |
| 165 | + } | |
| 166 | 166 | var pointerEvent = { |
| 167 | 167 | type: "Release", |
| 168 | 168 | 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), | |
| 173 | 173 | button: "Primary" |
| 174 | 174 | }; |
| 175 | 175 | |
| 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); | |
| 182 | 178 | } |
| 183 | 179 | } |
| 184 | 180 | |
| 185 | − function sendTouchMoveEventToStylusTarget(hand, stylusTarget) { | |
| 181 | + function sendTouchMoveEventToStylusTarget(hand, laserTarget) { | |
| 182 | + if (!laserTarget) { | |
| 183 | + return; | |
| 184 | + } | |
| 186 | 185 | var pointerEvent = { |
| 187 | 186 | type: "Move", |
| 188 | 187 | 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), | |
| 193 | 192 | button: "Primary", |
| 194 | 193 | isPrimaryHeld: true |
| 195 | 194 | }; |
| 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); | |
| 202 | 198 | } |
| 203 | 199 | } |
| 204 | 200 | |
| 205 | 201 | // will return undefined if overlayID does not exist. |
| 206 | − function calculateStylusTargetFromOverlay(stylusTip, overlayID) { | |
| 202 | + function calculateLaserTargetFromOverlay(laserTip, overlayID) { | |
| 207 | 203 | var overlayPosition = Overlays.getProperty(overlayID, "position"); |
| 208 | 204 | if (overlayPosition === undefined) { |
| 209 | 205 | return; |
| @@ -215,8 +211,8 @@ Script.include("/~/system/libraries/controllers.js"); · 5 unmodified lines | ||
| 215 | 211 | return; |
| 216 | 212 | } |
| 217 | 213 | 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)); | |
| 220 | 216 | |
| 221 | 217 | // calclulate normalized position |
| 222 | 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 | 266 | function distance2D(a, b) { |
| 357 | 267 | var dx = (a.x - b.x); |
| 358 | 268 | var dy = (a.y - b.y); |
| @@ -361,12 +271,14 @@ Script.include("/~/system/libraries/controllers.js"); · 2 unmodified lines | ||
| 361 | 271 | |
| 362 | 272 | function TabletLaserInput(hand) { |
| 363 | 273 | this.hand = hand; |
| 364 | − this.previousStylusTouchingTarget = false; | |
| 365 | − this.stylusTouchingTarget = false; | |
| 274 | + this.previousLaserClikcedTarget = false; | |
| 275 | + this.laserPressingTarget = false; | |
| 366 | 276 | 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; | |
| 370 | 282 | |
| 371 | 283 | |
| 372 | 284 | this.parameters = makeDispatcherModuleParameters( |
| @@ -384,159 +296,118 @@ Script.include("/~/system/libraries/controllers.js"); · 11 unmodified lines | ||
| 384 | 296 | }; |
| 385 | 297 | |
| 386 | 298 | 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); | |
| 394 | 300 | }; |
| 395 | 301 | |
| 396 | 302 | 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); | |
| 411 | 304 | }; |
| 412 | 305 | |
| 413 | 306 | 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); | |
| 416 | 308 | }; |
| 417 | 309 | |
| 418 | 310 | this.relinquishTouchFocus = function() { |
| 419 | 311 | // send hover leave event. |
| 420 | 312 | 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); | |
| 430 | 316 | }; |
| 431 | 317 | |
| 432 | 318 | this.updateLaserPointer = function(controllerData) { |
| 433 | 319 | var RADIUS = 0.005; |
| 434 | 320 | var dim = { x: RADIUS, y: RADIUS, z: RADIUS }; |
| 435 | − | |
| 436 | − var mode = "none"; | |
| 437 | 321 | |
| 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") { | |
| 448 | 323 | 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") { | |
| 451 | 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 | 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) { | |
| 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 | + | |
| 470 | 352 | } |
| 353 | + this.homeButtonTouched = false; | |
| 471 | 354 | }; |
| 472 | 355 | |
| 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 | + } | |
| 478 | 360 | }; |
| 479 | 361 | |
| 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); | |
| 483 | 365 | Controller.triggerHapticPulse(HAPTIC_STYLUS_STRENGTH, HAPTIC_STYLUS_DURATION, this.hand); |
| 484 | 366 | |
| 485 | 367 | this.touchingEnterTimer = 0; |
| 486 | − this.touchingEnterStylusTarget = this.stylusTarget; | |
| 368 | + this.pressEnterLaserTarget = this.laserTarget; | |
| 487 | 369 | this.deadspotExpired = false; |
| 488 | 370 | |
| 489 | 371 | var TOUCH_PRESS_TO_MOVE_DEADSPOT = 0.0381; |
| 490 | 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 | 378 | return; |
| 497 | 379 | } |
| 498 | 380 | |
| 499 | 381 | // 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); | |
| 502 | 384 | } |
| 503 | 385 | |
| 504 | 386 | // send press event |
| 505 | 387 | if (this.deadspotExpired) { |
| 506 | − sendTouchEndEventToStylusTarget(this.hand, this.stylusTarget); | |
| 388 | + sendTouchEndEventToStylusTarget(this.hand, this.laserTarget); | |
| 507 | 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 | 397 | this.touchingEnterTimer += dt; |
| 515 | 398 | |
| 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; | |
| 537 | 407 | } |
| 408 | + | |
| 538 | 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 | 427 | var target = controllerData.rayPicks[this.hand].objectID; |
| 557 | 428 | if (this.pointingAtTabletScreen(target) || this.pointingAtHomeButton(target) || this.pointingAtTablet(target)) { |
| 558 | 429 | if (controllerData.triggerValues[this.hand] > TRIGGER_ON_VALUE) { |
| 430 | + this.tabletScrenID = HMD.tabletScreenID; | |
| 559 | 431 | return makeRunningValues(true, [], []); |
| 560 | 432 | } |
| 561 | 433 | } |
| 562 | − //this.processLaser(controllerData); | |
| 563 | 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 | 448 | this.run = function (controllerData, deltaTime) { |
| 567 | 449 | var target = controllerData.rayPicks[this.hand].objectID; |
| 450 | + | |
| 451 | + | |
| 568 | 452 | if (!this.pointingAtTabletScreen(target) && !this.pointingAtHomeButton(target) && !this.pointingAtTablet(target)) { |
| 569 | 453 | LaserPointers.disableLaserPointer(this.laserPointer); |
| 454 | + this.laserPressExit(); | |
| 455 | + this.relinquishTouchFocus(); | |
| 456 | + this.reset(); | |
| 457 | + this.updateLaserPointer(); | |
| 570 | 458 | return makeRunningValues(false, [], []); |
| 571 | 459 | } |
| 460 | + | |
| 461 | + this.processControllerTriggers(controllerData); | |
| 572 | 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) { | |
| 576 | − this.stylusTouchingEnter(); | |
| 470 | + if (!this.previousLaserClickedTarget && this.laserPressingTarget) { | |
| 471 | + this.laserPressEnter(); | |
| 577 | 472 | } |
| 578 | − if (this.previousStylusTouchingTarget && !this.stylusTouchingTarget) { | |
| 579 | − this.stylusTouchingExit(); | |
| 473 | + if (this.previousLaserClickedTarget && !this.laserPressingTarget) { | |
| 474 | + this.laserPressExit(); | |
| 580 | 475 | } |
| 581 | − this.previousStylusTouchingTarget = this.stylusTouchingTarget; | |
| 476 | + this.previousLaserClickedTarget = this.laserPressingTarget; | |
| 582 | 477 | |
| 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 | + } | |
| 591 | 485 | |
| 592 | 486 | return makeRunningValues(true, [], []); |
| 593 | 487 | }; |
| @@ -608,6 +502,8 @@ Script.include("/~/system/libraries/controllers.js"); · 14 unmodified lines | ||
| 608 | 502 | faceAvatar: true, |
| 609 | 503 | defaultRenderStates: defaultRenderStates |
| 610 | 504 | }); |
| 505 | + | |
| 506 | + LaserPointers.setIgnoreOverlays(this.laserPointer, [HMD.tabletID]); | |
| 611 | 507 | }; |
| 612 | 508 | |
| 613 | 509 | var leftTabletLaserInput = new TabletLaserInput(LEFT_HAND); |