The cameras `eye`, `at` and `direction` are stored - we then check for key events using the `onkeydown`. Then we can update the camera dynamically on the fly. The camera displacement step is set as a fixed size.
let counter = 0.0; let frameNumber = 0; let fpsTime = performance.now();
let cameraAt = [ 0, 0, 0 ]; let cameraDir = [ 0, 0, 1 ]; let cameraEye = [ cameraAt[0]-cameraDir[0], cameraAt[1]-cameraDir[1], cameraAt[2]-cameraDir[2] ];
function frame() { var startTime = performance.now();
// setup a transform for triangle const t = { p:{x:0,y:0,z:0}, r:{x:0,y:0.0,z:0.0}, s:{x:1.0, y:1.0,z:1.0} };
let modelMatrix = buildMatrix(t.p, t.r, t.s); // update the local matrix for each triangle draw differently device.queue.writeBuffer(mvpUniformBuffer, 0, modelMatrix);
// Rotate the camera around the origin in the circle mat4.lookAt(viewMatrix, cameraEye, cameraAt, [0, 1, 0]); device.queue.writeBuffer(mvpUniformBuffer, 64, viewMatrix);