diff --git a/demo/client/src/benchmark.ts b/demo/client/src/benchmark.ts index c5b3171e..ccb8ae31 100644 --- a/demo/client/src/benchmark.ts +++ b/demo/client/src/benchmark.ts @@ -130,7 +130,7 @@ class BenchmarkTestView extends PathfinderDemoView { this.appController = appController; - this.camera = new OrthographicCamera(this.canvas); + this.camera = new OrthographicCamera(this.canvas, false); this.camera.onPan = () => this.setDirty(); this.camera.onZoom = () => this.setDirty(); } diff --git a/demo/client/src/camera.ts b/demo/client/src/camera.ts index cd12364b..8bf837db 100644 --- a/demo/client/src/camera.ts +++ b/demo/client/src/camera.ts @@ -18,6 +18,8 @@ const ORTHOGRAPHIC_ZOOM_SPEED: number = 1.0 / 100.0; const ORTHOGRAPHIC_ZOOM_IN_FACTOR: number = 1.2; const ORTHOGRAPHIC_ZOOM_OUT_FACTOR: number = 1.0 / ORTHOGRAPHIC_ZOOM_IN_FACTOR; +const ORTHOGRAPHIC_MAX_SCALE: number = 10.0; + const PERSPECTIVE_MOVEMENT_SPEED: number = 10.0; const PERSPECTIVE_ROTATION_SPEED: number = 1.0 / 300.0; @@ -50,9 +52,11 @@ export abstract class Camera { } export class OrthographicCamera extends Camera { - constructor(canvas: HTMLCanvasElement) { + constructor(canvas: HTMLCanvasElement, limitedZoom: boolean) { super(canvas); + this.limitedZoom = limitedZoom; + this.translation = glmatrix.vec2.create(); this.scale = 1.0; @@ -144,6 +148,8 @@ export class OrthographicCamera extends Camera { glmatrix.vec2.scale(absoluteTranslation, absoluteTranslation, 1.0 / this.scale); this.scale *= scale; + if (this.limitedZoom && this.scale > ORTHOGRAPHIC_MAX_SCALE) + this.scale = ORTHOGRAPHIC_MAX_SCALE; glmatrix.vec2.scale(absoluteTranslation, absoluteTranslation, this.scale); glmatrix.vec2.add(this.translation, absoluteTranslation, point); @@ -171,6 +177,8 @@ export class OrthographicCamera extends Camera { translation: glmatrix.vec2; scale: number; + + private readonly limitedZoom: boolean; } export class PerspectiveCamera extends Camera { diff --git a/demo/client/src/mesh-debugger.ts b/demo/client/src/mesh-debugger.ts index 90e169cc..4b3e4e4b 100644 --- a/demo/client/src/mesh-debugger.ts +++ b/demo/client/src/mesh-debugger.ts @@ -68,7 +68,7 @@ class MeshDebuggerView extends PathfinderView { super(); this.appController = appController; - this.camera = new OrthographicCamera(this.canvas); + this.camera = new OrthographicCamera(this.canvas, false); this.scale = 1.0; } diff --git a/demo/client/src/svg-demo.ts b/demo/client/src/svg-demo.ts index e38b9fd4..85859d19 100644 --- a/demo/client/src/svg-demo.ts +++ b/demo/client/src/svg-demo.ts @@ -213,7 +213,7 @@ class SVGDemoView extends PathfinderDemoView { this.appController = appController; - this.camera = new OrthographicCamera(this.canvas); + this.camera = new OrthographicCamera(this.canvas, false); this.camera.onPan = () => this.setDirty(); this.camera.onZoom = () => this.setDirty(); } diff --git a/demo/client/src/text-demo.ts b/demo/client/src/text-demo.ts index eff2e172..7bc323f0 100644 --- a/demo/client/src/text-demo.ts +++ b/demo/client/src/text-demo.ts @@ -251,7 +251,7 @@ class TextDemoView extends MonochromePathfinderView { this.appController = appController; - this.camera = new OrthographicCamera(this.canvas); + this.camera = new OrthographicCamera(this.canvas, true); this.camera.onPan = () => this.onPan(); this.camera.onZoom = () => this.onZoom();