fix: proper update with locking
This commit is contained in:
parent
b63b7d2b3f
commit
77c7b9cade
1 changed files with 22 additions and 21 deletions
43
main.mjs
43
main.mjs
|
@ -10,23 +10,25 @@ let mouse_pos = [0, 0];
|
||||||
|
|
||||||
// Update the Camera position
|
// Update the Camera position
|
||||||
function updateCamera(gl, program) {
|
function updateCamera(gl, program) {
|
||||||
if (keymap.get("w")) {
|
if (document.pointerLockElement) {
|
||||||
camera_pos[2] += 0.1;
|
if (keymap.get("w")) {
|
||||||
}
|
camera_pos[2] += 0.1;
|
||||||
if (keymap.get("a")) {
|
}
|
||||||
camera_pos[0] += -0.1;
|
if (keymap.get("a")) {
|
||||||
}
|
camera_pos[0] += -0.1;
|
||||||
if (keymap.get("s")) {
|
}
|
||||||
camera_pos[2] += -0.1;
|
if (keymap.get("s")) {
|
||||||
}
|
camera_pos[2] += -0.1;
|
||||||
if (keymap.get("d")) {
|
}
|
||||||
camera_pos[0] += 0.1;
|
if (keymap.get("d")) {
|
||||||
}
|
camera_pos[0] += 0.1;
|
||||||
if (keymap.get("e")) {
|
}
|
||||||
camera_pos[1] += 0.1;
|
if (keymap.get("e")) {
|
||||||
}
|
camera_pos[1] += 0.1;
|
||||||
if (keymap.get("q")) {
|
}
|
||||||
camera_pos[1] += -0.1;
|
if (keymap.get("q")) {
|
||||||
|
camera_pos[1] += -0.1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
|
@ -51,15 +53,15 @@ function draw(gl, program) {
|
||||||
TIME += 1 / 60;
|
TIME += 1 / 60;
|
||||||
gl.uniform1f(loc, TIME);
|
gl.uniform1f(loc, TIME);
|
||||||
|
|
||||||
if (document.pointerLockElement) {
|
updateCamera(gl, program);
|
||||||
updateCamera(gl, program);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw the frame recursively on next frame
|
// Draw the frame recursively on next frame
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||||
requestAnimationFrame(() => draw(gl, program));
|
requestAnimationFrame(() => draw(gl, program));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//** MAIN PROGRAM **//
|
||||||
|
|
||||||
// Initialize the shader
|
// Initialize the shader
|
||||||
const [gl, program, canvas] = await initShader(CANVAS_WIDTH, CANVAS_HEIGHT);
|
const [gl, program, canvas] = await initShader(CANVAS_WIDTH, CANVAS_HEIGHT);
|
||||||
|
|
||||||
|
@ -85,5 +87,4 @@ canvas.addEventListener("click", async () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update loop
|
// Update loop
|
||||||
updateCamera(gl, program);
|
|
||||||
draw(gl, program);
|
draw(gl, program);
|
||||||
|
|
Loading…
Reference in a new issue