Spaces:
Running
Running
undo
Browse files
index.js
CHANGED
@@ -75,11 +75,11 @@ async function main() {
|
|
75 |
state.width = width;
|
76 |
state.height = height;
|
77 |
|
78 |
-
requestAnimationFrame(render);
|
79 |
}
|
80 |
|
81 |
-
function render() {
|
82 |
-
|
83 |
const fov = 60 * Math.PI / 180;
|
84 |
const aspect = canvas.clientWidth / canvas.clientHeight;
|
85 |
const projectionMatrix = mat4.perspective(fov, aspect, config.render.zNear, config.render.zFar);
|
@@ -89,7 +89,7 @@ function render() {
|
|
89 |
const encoder = state.device.createCommandEncoder();
|
90 |
const pass = encoder.beginRenderPass(RENDER_PASS_DESCRIPTOR);
|
91 |
pass.setPipeline(state.pipeline);
|
92 |
-
mat4.rotateY(viewProjectionMatrix,
|
93 |
mat4.translate(state.matrix, [-state.width / 2, -state.height / 2, 0], state.matrix);
|
94 |
state.device.queue.writeBuffer(state.uniformBuffer, 0, state.uniformValues);
|
95 |
pass.setBindGroup(0, state.bindGroup);
|
@@ -98,7 +98,7 @@ function render() {
|
|
98 |
pass.drawIndexed(state.numGlyphs * 6);
|
99 |
pass.end();
|
100 |
state.device.queue.submit([encoder.finish()]);
|
101 |
-
requestAnimationFrame(render);
|
102 |
}
|
103 |
|
104 |
main();
|
|
|
75 |
state.width = width;
|
76 |
state.height = height;
|
77 |
|
78 |
+
requestAnimationFrame((time) => render(time, mat4, context, state, RENDER_PASS_DESCRIPTOR));
|
79 |
}
|
80 |
|
81 |
+
function render(time, mat4, context, state, RENDER_PASS_DESCRIPTOR) {
|
82 |
+
time *= config.time.phase;
|
83 |
const fov = 60 * Math.PI / 180;
|
84 |
const aspect = canvas.clientWidth / canvas.clientHeight;
|
85 |
const projectionMatrix = mat4.perspective(fov, aspect, config.render.zNear, config.render.zFar);
|
|
|
89 |
const encoder = state.device.createCommandEncoder();
|
90 |
const pass = encoder.beginRenderPass(RENDER_PASS_DESCRIPTOR);
|
91 |
pass.setPipeline(state.pipeline);
|
92 |
+
mat4.rotateY(viewProjectionMatrix, time, state.matrix);
|
93 |
mat4.translate(state.matrix, [-state.width / 2, -state.height / 2, 0], state.matrix);
|
94 |
state.device.queue.writeBuffer(state.uniformBuffer, 0, state.uniformValues);
|
95 |
pass.setBindGroup(0, state.bindGroup);
|
|
|
98 |
pass.drawIndexed(state.numGlyphs * 6);
|
99 |
pass.end();
|
100 |
state.device.queue.submit([encoder.finish()]);
|
101 |
+
requestAnimationFrame((t) => render(t, mat4, context, state, RENDER_PASS_DESCRIPTOR));
|
102 |
}
|
103 |
|
104 |
main();
|