summaryrefslogtreecommitdiffstats
path: root/src/view/renderer/Renderer.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/view/renderer/Renderer.ts')
-rw-r--r--src/view/renderer/Renderer.ts13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/view/renderer/Renderer.ts b/src/view/renderer/Renderer.ts
index 344bccf..75dc265 100644
--- a/src/view/renderer/Renderer.ts
+++ b/src/view/renderer/Renderer.ts
@@ -3,6 +3,8 @@ import { mat4, vec2 } from 'gl-matrix';
import Shaders from './Shaders';
export default class Renderer {
+ private readonly viewScale = 64;
+
private readonly gl: WebGLRenderingContext;
private readonly shaders: Shaders;
@@ -49,11 +51,12 @@ export default class Renderer {
}
public setCenter(v: vec2|number[]) {
- vec2.copy(this.center, v);
+ this.snapToGrid(this.center, v);
}
public setTranslation(v: vec2|number[]) {
vec2.sub(this.translation, v, this.center);
+ this.snapToGrid(this.translation, this.translation);
this.gl.uniform2fv(this.shaders.translateLoc, this.translation);
}
@@ -63,6 +66,12 @@ export default class Renderer {
this.setTranslation([0, 0]);
}
+ public snapToGrid(out: vec2, a: vec2|number[]): void {
+ vec2.scale(out, a, this.viewScale);
+ vec2.round(out, out);
+ vec2.scale(out, out, 1 / this.viewScale);
+ }
+
private mkContext(): WebGLRenderingContext {
const gl = (
this.canvas.getContext('webgl') || this.canvas.getContext('experimental-webgl')
@@ -81,7 +90,7 @@ export default class Renderer {
this.clear();
mat4.identity(this.viewport);
- mat4.scale(this.viewport, this.viewport, [2 * 64 / w, -2 * 64 / h, 1.0]);
+ mat4.scale(this.viewport, this.viewport, [2 * this.viewScale / w, -2 * this.viewScale / h, 1.0]);
this.gl.uniformMatrix4fv(this.shaders.viewportLoc, false, this.viewport);
}
}