summaryrefslogtreecommitdiffstats
path: root/src/view/renderer
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2018-10-31 23:13:52 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2018-10-31 23:25:26 +0100
commit1ae0884a7376a87a2df4a77d1ba861cd58a4dda7 (patch)
treefa70185d4163d6a2a6132f4246ba550d38e831e5 /src/view/renderer
parent5372d1b4173234a5066010a4ca973a5b1ad2a629 (diff)
downloadrpgedit-1ae0884a7376a87a2df4a77d1ba861cd58a4dda7.tar
rpgedit-1ae0884a7376a87a2df4a77d1ba861cd58a4dda7.zip
controller: clean up GameContext a bit
Diffstat (limited to 'src/view/renderer')
-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);
}
}