{
let count = 0;
let cameraAt = [0, 0, 0];
let cameraUp = [0, 1, 0];
let M = twgl.m4.axisRotation(cameraUp, deg2rad(1));
let cameraU = [1, 0, 0],
cameraV = [0, 1, 0],
cameraW = [0, 0, 1];
const computeUVW = () => {
cameraW = twgl.v3.normalize([
cameraEye[0] - cameraAt[0],
cameraEye[1] - cameraAt[1],
cameraEye[2] - cameraAt[2]
]);
cameraU = twgl.v3.normalize(twgl.v3.cross(cameraUp, cameraW));
cameraV = twgl.v3.normalize(twgl.v3.cross(cameraW, cameraU));
};
const rotateCamera = () => {
mutable cameraEye = twgl.m4.transformDirection(M, cameraEye);
computeUVW();
return count++;
};
computeUVW();
render();
function render() {
gl.clear(gl.COLOR_BUFFER_BIT);
const uniforms = {
Background: hex2rgb(backgroundColor),
resolution: [gl.canvas.width, gl.canvas.height],
cameraU: cameraU,
cameraV: cameraV,
cameraW: cameraW,
cameraEye: cameraEye,
fov: deg2rad(30),
minBound: [-0.5, -0.5, -0.5],
maxBound: [0.5, 0.5, 0.5]
};
gl.useProgram(programInfo.program);
twgl.setBuffersAndAttributes(gl, programInfo, bufferInfo);
twgl.setUniforms(programInfo, uniforms);
twgl.drawBufferInfo(gl, bufferInfo);
return count++;
}
while (rotate) {
render();
yield Promises.delay(1000 / 30, rotateCamera());
}
return md`### WebGL Render code`;
}