Skip to content

Camera: Zoom #12

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/Drawable.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ class Drawable {
this._position[0] = Math.round(position[0]);
this._position[1] = Math.round(position[1]);
}

const cameraState = this._renderer.cameraState;
this._position[0] /= cameraState.zoom;
this._position[1] /= cameraState.zoom;

this._renderer.dirty = true;
this.setTransformDirty();
}
Expand Down
6 changes: 3 additions & 3 deletions src/RenderWebGL.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
cos: 1,
zoom: 1,
width: 240,
height: 180,

Check failure on line 204 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected trailing comma

Check failure on line 204 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected trailing comma
};

/**
Expand Down Expand Up @@ -497,7 +497,7 @@
this._updateProjection();
}

_updateProjection() {

Check failure on line 500 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Missing space before function parentheses

Check failure on line 500 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Missing space before function parentheses
const sin = this.cameraState.sin;
const cos = this.cameraState.cos;
const width = this.cameraState.width;
Expand All @@ -519,8 +519,8 @@
0,
-1,
0,
(cos * -x + sin * -y) / width,

Check failure on line 522 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '+' and '*'. Use parentheses to clarify the intended order of operations

Check failure on line 522 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '+' and '*'. Use parentheses to clarify the intended order of operations

Check failure on line 522 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '*' and '+'. Use parentheses to clarify the intended order of operations

Check failure on line 522 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '*' and '+'. Use parentheses to clarify the intended order of operations

Check failure on line 522 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '+' and '*'. Use parentheses to clarify the intended order of operations

Check failure on line 522 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '+' and '*'. Use parentheses to clarify the intended order of operations

Check failure on line 522 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '*' and '+'. Use parentheses to clarify the intended order of operations

Check failure on line 522 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '*' and '+'. Use parentheses to clarify the intended order of operations
(cos * -y - sin * -x) / height,

Check failure on line 523 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '-' and '*'. Use parentheses to clarify the intended order of operations

Check failure on line 523 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '-' and '*'. Use parentheses to clarify the intended order of operations

Check failure on line 523 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '*' and '-'. Use parentheses to clarify the intended order of operations

Check failure on line 523 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '*' and '-'. Use parentheses to clarify the intended order of operations

Check failure on line 523 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '-' and '*'. Use parentheses to clarify the intended order of operations

Check failure on line 523 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '-' and '*'. Use parentheses to clarify the intended order of operations

Check failure on line 523 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '*' and '-'. Use parentheses to clarify the intended order of operations

Check failure on line 523 in src/RenderWebGL.js

View workflow job for this annotation

GitHub Actions / build

Unexpected mix of '*' and '-'. Use parentheses to clarify the intended order of operations
0,
1,
];
Expand Down Expand Up @@ -1559,14 +1559,14 @@

this._doExitDrawRegion();

const nativeCenterX = this._nativeSize[0] * 0.5;
const nativeCenterY = this._nativeSize[1] * 0.5;
const nativeCenterX = (this._nativeSize[0] / this.cameraState.zoom) * 0.5;
const nativeCenterY = (this._nativeSize[1] / this.cameraState.zoom) * 0.5;

const scratchBounds = drawable.getFastBounds();

const canvas = this.canvas;
// Ratio of the screen-space scale of the stage's canvas to the "native size" of the stage
const scaleFactor = canvas.width / this._nativeSize[0];
const scaleFactor = (canvas.width / this._nativeSize[0]) * this.cameraState.zoom;

// Bounds of the extracted drawable, in "canvas pixel space"
// (origin is 0, 0, destination is the canvas width, height).
Expand Down