From 777a0b51c11775615dd7fbdc6ac9a201679650e8 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 18 Feb 2017 13:35:16 +1300 Subject: [PATCH] Ignore spurious finger tip position values --- scripts/system/fingerPaint.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/system/fingerPaint.js b/scripts/system/fingerPaint.js index 1c4527b6ad..416b0dede1 100644 --- a/scripts/system/fingerPaint.js +++ b/scripts/system/fingerPaint.js @@ -70,7 +70,9 @@ function drawLine(position, width) { // Add a stroke to the polyline if stroke is a sufficient length. - var localPosition; + var localPosition, + distanceToPrevious, + MAX_DISTANCE_TO_PREVIOUS = 1.0; if (!isDrawingLine) { print("ERROR: drawLine() called when not drawing line"); @@ -78,8 +80,14 @@ } localPosition = Vec3.subtract(position, basePosition); + distanceToPrevious = Vec3.distance(localPosition, strokePoints[strokePoints.length - 1]); - if (Vec3.distance(localPosition, strokePoints[strokePoints.length - 1]) >= MIN_STROKE_LENGTH + if (distanceToPrevious > MAX_DISTANCE_TO_PREVIOUS) { + // Ignore occasional spurious finger tip positions. + return; + } + + if (distanceToPrevious >= MIN_STROKE_LENGTH && strokePoints.length < MAX_POINTS_PER_LINE) { strokePoints.push(localPosition); strokeNormals.push(strokeNormal());