p3nGu1nZz commited on
Commit
abb941d
1 Parent(s): 6d5881c

remove time.phase from config

Browse files
Files changed (2) hide show
  1. index.js +24 -26
  2. wgpu-config.js +0 -3
index.js CHANGED
@@ -76,36 +76,34 @@ async function main() {
76
  state.height = height;
77
 
78
  let lastTime = performance.now();
79
- function update(currentTime) {
80
- const deltaTime = (currentTime - lastTime) * config.time.phase;
 
81
  state.time += deltaTime;
82
- render(mat4, context, state, RENDER_PASS_DESCRIPTOR);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  lastTime = currentTime;
 
84
  }
85
 
86
- const interval = 16; // Roughly 60 FPS
87
- setInterval(() => update(performance.now()), interval);
88
- }
89
-
90
- function render(mat4, context, state, RENDER_PASS_DESCRIPTOR) {
91
- const fov = 60 * Math.PI / 180;
92
- const aspect = canvas.clientWidth / canvas.clientHeight;
93
- const projectionMatrix = mat4.perspective(fov, aspect, config.render.zNear, config.render.zFar);
94
- const viewMatrix = mat4.lookAt([0, 0, 5], [0, 0, 0], [0, 1, 0]);
95
- const viewProjectionMatrix = mat4.multiply(projectionMatrix, viewMatrix);
96
- RENDER_PASS_DESCRIPTOR.colorAttachments[0].view = context.getCurrentTexture().createView();
97
- const encoder = state.device.createCommandEncoder();
98
- const pass = encoder.beginRenderPass(RENDER_PASS_DESCRIPTOR);
99
- pass.setPipeline(state.pipeline);
100
- mat4.rotateY(viewProjectionMatrix, state.time, state.matrix);
101
- mat4.translate(state.matrix, [-state.width / 2, -state.height / 2, 0], state.matrix);
102
- state.device.queue.writeBuffer(state.uniformBuffer, 0, state.uniformValues);
103
- pass.setBindGroup(0, state.bindGroup);
104
- pass.setVertexBuffer(0, state.vertexBuffer);
105
- pass.setIndexBuffer(state.indexBuffer, 'uint32');
106
- pass.drawIndexed(state.numGlyphs * 6);
107
- pass.end();
108
- state.device.queue.submit([encoder.finish()]);
109
  }
110
 
111
  main();
 
76
  state.height = height;
77
 
78
  let lastTime = performance.now();
79
+ function update() {
80
+ const currentTime = performance.now();
81
+ const deltaTime = (currentTime - lastTime) / 1000; // Convert to seconds
82
  state.time += deltaTime;
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);
86
+ const viewMatrix = mat4.lookAt([0, 0, 5], [0, 0, 0], [0, 1, 0]);
87
+ const viewProjectionMatrix = mat4.multiply(projectionMatrix, viewMatrix);
88
+ RENDER_PASS_DESCRIPTOR.colorAttachments[0].view = context.getCurrentTexture().createView();
89
+ const encoder = state.device.createCommandEncoder();
90
+ const pass = encoder.beginRenderPass(RENDER_PASS_DESCRIPTOR);
91
+ pass.setPipeline(state.pipeline);
92
+ mat4.rotateY(viewProjectionMatrix, state.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);
96
+ pass.setVertexBuffer(0, state.vertexBuffer);
97
+ pass.setIndexBuffer(state.indexBuffer, 'uint32');
98
+ pass.drawIndexed(state.numGlyphs * 6);
99
+ pass.end();
100
+ state.device.queue.submit([encoder.finish()]);
101
+
102
  lastTime = currentTime;
103
+ setTimeout(update, 16); // Approximate 60 FPS
104
  }
105
 
106
+ update();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  }
108
 
109
  main();
wgpu-config.js CHANGED
@@ -21,8 +21,5 @@ export const config = {
21
  render: {
22
  zNear: 0.001,
23
  zFar: 50
24
- },
25
- time: {
26
- phase: 0.001
27
  }
28
  };
 
21
  render: {
22
  zNear: 0.001,
23
  zFar: 50
 
 
 
24
  }
25
  };