Fix the interaction between the camera and SSAA in the SVG demo
This commit is contained in:
parent
5c45b6f94e
commit
a21afa9bb7
|
@ -53,11 +53,15 @@ export abstract class Camera {
|
|||
}
|
||||
|
||||
export class OrthographicCamera extends Camera {
|
||||
constructor(canvas: HTMLCanvasElement, minScale?: number, maxScale?: number) {
|
||||
constructor(canvas: HTMLCanvasElement, options?: OrthographicCameraOptions) {
|
||||
super(canvas);
|
||||
|
||||
this.minScale = _.defaultTo(minScale, ORTHOGRAPHIC_DEFAULT_MIN_SCALE);
|
||||
this.maxScale = _.defaultTo(maxScale, ORTHOGRAPHIC_DEFAULT_MAX_SCALE);
|
||||
if (options == null)
|
||||
options = {};
|
||||
|
||||
this.minScale = _.defaultTo(options.minScale, ORTHOGRAPHIC_DEFAULT_MIN_SCALE);
|
||||
this.maxScale = _.defaultTo(options.maxScale, ORTHOGRAPHIC_DEFAULT_MAX_SCALE);
|
||||
this.scaleBounds = !!options.scaleBounds;
|
||||
|
||||
this.translation = glmatrix.vec2.create();
|
||||
this.scale = 1.0;
|
||||
|
@ -117,7 +121,7 @@ export class OrthographicCamera extends Camera {
|
|||
}
|
||||
|
||||
private clampViewport() {
|
||||
const bounds = glmatrix.vec4.clone(this._bounds);
|
||||
const bounds = this.bounds;
|
||||
for (let axis = 0; axis < 2; axis++) {
|
||||
const viewportLength = axis === 0 ? this.canvas.width : this.canvas.height;
|
||||
const axisBounds = [bounds[axis + 0], bounds[axis + 2]];
|
||||
|
@ -187,7 +191,10 @@ export class OrthographicCamera extends Camera {
|
|||
}
|
||||
|
||||
get bounds(): glmatrix.vec4 {
|
||||
return this._bounds;
|
||||
const bounds = glmatrix.vec4.clone(this._bounds);
|
||||
if (this.scaleBounds)
|
||||
glmatrix.vec4.scale(bounds, bounds, this.scale);
|
||||
return bounds;
|
||||
}
|
||||
|
||||
set bounds(newBounds: glmatrix.vec4) {
|
||||
|
@ -204,6 +211,7 @@ export class OrthographicCamera extends Camera {
|
|||
|
||||
private readonly minScale: number;
|
||||
private readonly maxScale: number;
|
||||
private readonly scaleBounds: boolean;
|
||||
}
|
||||
|
||||
export class PerspectiveCamera extends Camera {
|
||||
|
@ -315,3 +323,9 @@ export class PerspectiveCamera extends Camera {
|
|||
private movementDelta: glmatrix.vec3;
|
||||
private movementInterval: number | null;
|
||||
}
|
||||
|
||||
export interface OrthographicCameraOptions {
|
||||
minScale?: number;
|
||||
maxScale?: number;
|
||||
scaleBounds?: boolean;
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ class SVGDemoView extends PathfinderDemoView {
|
|||
|
||||
this.appController = appController;
|
||||
|
||||
this.camera = new OrthographicCamera(this.canvas);
|
||||
this.camera = new OrthographicCamera(this.canvas, { scaleBounds: true });
|
||||
this.camera.onPan = () => this.setDirty();
|
||||
this.camera.onZoom = () => this.setDirty();
|
||||
}
|
||||
|
@ -286,8 +286,6 @@ class SVGDemoView extends PathfinderDemoView {
|
|||
[2.0 / this.canvas.width, 2.0 / this.canvas.height, 1.0]);
|
||||
glmatrix.mat4.translate(transform, transform, [translation[0], translation[1], 0]);
|
||||
glmatrix.mat4.scale(transform, transform, [this.camera.scale, this.camera.scale, 1.0]);
|
||||
if (this.antialiasingStrategy != null)
|
||||
glmatrix.mat4.mul(transform, transform, this.antialiasingStrategy.transform);
|
||||
return transform;
|
||||
}
|
||||
|
||||
|
|
|
@ -246,7 +246,10 @@ class TextDemoView extends MonochromePathfinderView {
|
|||
|
||||
this.appController = appController;
|
||||
|
||||
this.camera = new OrthographicCamera(this.canvas, MIN_SCALE, MAX_SCALE);
|
||||
this.camera = new OrthographicCamera(this.canvas, {
|
||||
minScale: MIN_SCALE,
|
||||
maxScale: MAX_SCALE,
|
||||
});
|
||||
this.camera.onPan = () => this.onPan();
|
||||
this.camera.onZoom = () => this.onZoom();
|
||||
|
||||
|
|
Loading…
Reference in New Issue