Skip to content

Commit

Permalink
[gltiles] allow layers to be moved; with demo ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
jcorbin committed Oct 19, 2023
1 parent 1ebe101 commit fa3c6c0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
16 changes: 16 additions & 0 deletions gldemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@
updateWorldSize();
break;

// NOTE this is here only to provide a test path for layer movement,
// the more normative thing to do here would be to transalte the perspective,
// not every world layer transform
case 'h':
demo?.moveWorldBy(-1, 0);
break;
case 'j':
demo?.moveWorldBy(0, 1);
break;
case 'k':
demo?.moveWorldBy(0, -1);
break;
case 'l':
demo?.moveWorldBy(1, 0);
break;

}
});

Expand Down
12 changes: 12 additions & 0 deletions gldemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,18 @@ export default async function runDemo(opts) {
generateWorld();
},

/** @param {number} dx @param {number} dy */
moveWorldBy(dx, dy) {
this.moveWorldTo(bg.left + dx, bg.top + dy);
},

/** @param {number} x @param {number} y */
moveWorldTo(x, y) {
bg.moveTo(x, y);
fg.moveTo(x, y);
bgCurved.moveTo(x - 0.5, y - 0.5);
},

stop,
done,
};
Expand Down
14 changes: 9 additions & 5 deletions gltiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,10 @@ export default async function makeTileRenderer(gl) {
const [x, _] = vec2.transformMat4([0, 0], [0, 0], transform);
return x / cellSize.float;
},
// TODO set left()

get top() {
const [_, y] = vec2.transformMat4([0, 0], [0, 0], transform);
return y / cellSize.float;
},
// TODO set top()

get stride() { return stride.int },
set stride(w) {
Expand All @@ -259,7 +256,14 @@ export default async function makeTileRenderer(gl) {
}
},

// TODO moveTo(left, top)
/** @param {number} left @param {number} top */
moveTo(left, top) {
const size = cellSize.float;
const x = left * size;
const y = top * size;
mat4.fromTranslation(transform, [x, y, 0]);
paramsDirty = true;
},

get spinBuffer() { return spinBuffer },
get tileBuffer() { return tileBuffer },
Expand Down Expand Up @@ -421,7 +425,7 @@ export default async function makeTileRenderer(gl) {

gl.useProgram(null);
},
}, layer, 'texture', 'cellSize', 'left', 'top');
}, layer, 'texture', 'cellSize', 'left', 'top', 'moveTo');
},

};
Expand Down

0 comments on commit fa3c6c0

Please sign in to comment.