-1

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.

1 Answers1

0

Ok, solved! The problem was in:

mat4.rotate (modelMatrix, modelMatrix, [0, angle, 0]);

for some reason mat4.rotate is not working well, so I had to change to:

mat4.rotateY (modelMatrix, modelMatrix, angle);

And now it works. I guess the mat4 library has bugs or something.