I'm initializing my var like this at the top of my .js file:
var angle = 0;
And then I add an event handler to detect key pressing and increase that variable:
document.addEventListener("keydown",
function (event) {
switch (event.keyCode) {
case 65: angle += 0.02; break; // 'a'
case 68: angle -= 0.02; break; // 'd'
}
requestAnimationFrame(drawScene);
},
false);
But my html doesn't work. The console says "cannot read property '0' of undefined'
And well, I also use that variable for a matrix operation:
mat4.rotate (modelMatrix, modelMatrix, [0, angle, 0]);
maybe the error is there.
All I've found on the internet says that I must give an initial value to "angle" (angle = 0) but I already do.