diff --git a/example/src/controls/PointerTracker.js b/example/src/controls/PointerTracker.js index 12c22b9ec..c73a5e1c1 100644 --- a/example/src/controls/PointerTracker.js +++ b/example/src/controls/PointerTracker.js @@ -16,10 +16,24 @@ export class PointerTracker { } + reset() { + + this.buttons = 0; + this.pointerType = null; + this.pointerOrder = []; + this.previousPositions = {}; + this.pointerPositions = {}; + this.startPositions = {}; + this.pointerSetThisFrame = {}; + this.hoverPosition = new Vector2(); + this.hoverSet = false; + + } + // The pointers can be set multiple times per frame so track whether the pointer has // been set this frame or not so we don't overwrite the previous position and lose information // about pointer movement - resetFrame() { + updateFrame() { const { previousPositions, pointerPositions } = this; for ( const id in pointerPositions ) { diff --git a/example/src/controls/TileControls.js b/example/src/controls/TileControls.js index 2f03e8bb9..3c5706cc2 100644 --- a/example/src/controls/TileControls.js +++ b/example/src/controls/TileControls.js @@ -42,6 +42,24 @@ const _endEvent = { type: 'end' }; export class TileControls extends EventDispatcher { + get enabled() { + + return this._enabled || true; + + } + + set enabled( v ) { + + if ( v !== this.enabled ) { + + this.resetState(); + this.pointerTracker.reset(); + this._enabled = v; + + } + + } + constructor( scene, camera, domElement ) { super(); @@ -51,6 +69,7 @@ export class TileControls extends EventDispatcher { this.scene = null; // settings + this._enabled = true; this.state = NONE; this.pinchState = NONE; this.cameraRadius = 5; @@ -423,7 +442,7 @@ export class TileControls extends EventDispatcher { this._detachCallback(); this._detachCallback = null; - this.pointerTracker = new PointerTracker(); + this.pointerTracker.reset(); } @@ -468,6 +487,12 @@ export class TileControls extends EventDispatcher { update() { + if ( ! this.enabled ) { + + return; + + } + const { camera, cameraRadius, @@ -558,7 +583,7 @@ export class TileControls extends EventDispatcher { } - this.pointerTracker.resetFrame(); + this.pointerTracker.updateFrame(); }