Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for enabling / disabling the controls #467

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion example/src/controls/PointerTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
29 changes: 27 additions & 2 deletions example/src/controls/TileControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -423,7 +442,7 @@ export class TileControls extends EventDispatcher {

this._detachCallback();
this._detachCallback = null;
this.pointerTracker = new PointerTracker();
this.pointerTracker.reset();

}

Expand Down Expand Up @@ -468,6 +487,12 @@ export class TileControls extends EventDispatcher {

update() {

if ( ! this.enabled ) {

return;

}

const {
camera,
cameraRadius,
Expand Down Expand Up @@ -558,7 +583,7 @@ export class TileControls extends EventDispatcher {

}

this.pointerTracker.resetFrame();
this.pointerTracker.updateFrame();

}

Expand Down
Loading