Draw smoother lines

This commit is contained in:
David Rowe 2017-02-18 13:39:59 +13:00
parent 777a0b51c1
commit 0689557ba5

View file

@ -33,8 +33,10 @@
strokePoints, strokePoints,
strokeNormals, strokeNormals,
strokeWidths, strokeWidths,
MIN_STROKE_LENGTH = 0.02, timeOfLastPoint,
MAX_POINTS_PER_LINE = 100; MIN_STROKE_LENGTH = 0.005, // m
MIN_STROKE_INTERVAL = 66, // ms
MAX_POINTS_PER_LINE = 70; // Hard-coded limit in PolyLineEntityItem.h.
function strokeNormal() { function strokeNormal() {
return Vec3.multiplyQbyV(Camera.getOrientation(), Vec3.UNIT_NEG_Z); return Vec3.multiplyQbyV(Camera.getOrientation(), Vec3.UNIT_NEG_Z);
@ -53,6 +55,7 @@
strokePoints = [Vec3.ZERO]; strokePoints = [Vec3.ZERO];
strokeNormals = [strokeNormal()]; strokeNormals = [strokeNormal()];
strokeWidths = [width]; strokeWidths = [width];
timeOfLastPoint = Date.now();
entityID = Entities.addEntity({ entityID = Entities.addEntity({
type: "PolyLine", type: "PolyLine",
@ -88,10 +91,12 @@
} }
if (distanceToPrevious >= MIN_STROKE_LENGTH if (distanceToPrevious >= MIN_STROKE_LENGTH
&& (Date.now() - timeOfLastPoint) >= MIN_STROKE_INTERVAL
&& strokePoints.length < MAX_POINTS_PER_LINE) { && strokePoints.length < MAX_POINTS_PER_LINE) {
strokePoints.push(localPosition); strokePoints.push(localPosition);
strokeNormals.push(strokeNormal()); strokeNormals.push(strokeNormal());
strokeWidths.push(width); strokeWidths.push(width);
timeOfLastPoint = Date.now();
Entities.editEntity(entityID, { Entities.editEntity(entityID, {
linePoints: strokePoints, linePoints: strokePoints,