From b490f9e2c1967c9891b8f2f8214455e49718cf8d Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 13 Oct 2015 13:33:24 -0700 Subject: [PATCH] Drawing line width based on trigger squeeze --- .../whiteboard/whiteboardEntityScript.js | 18 +++++++++++++++--- .../painting/whiteboard/whiteboardSpawner.js | 1 + 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/examples/painting/whiteboard/whiteboardEntityScript.js b/examples/painting/whiteboard/whiteboardEntityScript.js index 9d62fbae54..6bf7a9fd65 100644 --- a/examples/painting/whiteboard/whiteboardEntityScript.js +++ b/examples/painting/whiteboard/whiteboardEntityScript.js @@ -25,6 +25,11 @@ var MIN_POINT_DISTANCE = 0.02; var MAX_POINT_DISTANCE = 0.5; var MAX_POINTS_PER_LINE = 40; + var MAX_DISTANCE = 5; + + var TRIGGER_ON_VALUE = 0.3; + var MIN_STROKE_WIDTH = 0.001; + var MAX_STROKE_WIDTH = 0.02; Whiteboard = function() { _this = this; @@ -41,6 +46,9 @@ }, startFarGrabNonColliding: function() { + if (this.painting) { + return; + } if (this.hand === RIGHT_HAND) { this.getHandPosition = MyAvatar.getRightPalmPosition; this.getHandRotation = MyAvatar.getRightPalmRotation; @@ -61,7 +69,12 @@ this.intersection = Entities.findRayIntersection(pickRay, true, [this.entityID]); if (this.intersection.intersects) { - this.paint(this.intersection.intersection, this.intersection.surfaceNormal); + var distance = Vec3.distance(handPosition, this.intersection.intersection); + if (distance < MAX_DISTANCE) { + this.triggerValue = Controller.getActionValue(this.triggerAction); + this.currentStrokeWidth = map(this.triggerValue, TRIGGER_ON_VALUE, 1, MIN_STROKE_WIDTH, MAX_STROKE_WIDTH); + this.paint(this.intersection.intersection, this.intersection.surfaceNormal); + } } else { this.painting = false; } @@ -157,11 +170,10 @@ blue: 190 }; this.strokes = []; - this.currentStrokeWidth = 0.02; }, unload: function() { - this.strokes.forEach(function(stroke){ + this.strokes.forEach(function(stroke) { Entities.deleteEntity(stroke); }); } diff --git a/examples/painting/whiteboard/whiteboardSpawner.js b/examples/painting/whiteboard/whiteboardSpawner.js index 6b7f23aecc..4b7b99dc5b 100644 --- a/examples/painting/whiteboard/whiteboardSpawner.js +++ b/examples/painting/whiteboard/whiteboardSpawner.js @@ -30,6 +30,7 @@ var whiteboard = Entities.addEntity({ color: {red: 255, green: 255, blue: 255} }); + function cleanup() { Entities.deleteEntity(whiteboard); }