I wrote a code to animate 3D eyes in WebGL. Something that I don't understand is why a right-hand value in Javascript can change in a loop. Here are parts of the code:
function start() {
...
if (GL) {
...
tick(); // For animation
}
}
function tick() {
requestAnimationFrame(tick);
updateTime();
drawScene();
}
function updateTime() {
curTime = (new Date).getTime();
if (lastTime) { // Initial value: lastTime = 0
var delta = curTime - lastTime;
eyeFrame = Math.round((delta%60000)/20); // Initial value: eyeFrame = 0
} else {
lastTime = curTime;
}
}
function drawScene() {
updateBuffers(eyeFrame);
...
}
function updateBuffers(idx) {
curV = V; // V is the 3D coordinates, must not change
for (i=0; i<2; i++) {
for (j=0; j<329; j++) {
curV[i][3*j] += (xEyes[i][4*j]*eyeMov[idx][0]+xEyes[i][4*j+1]*eyeMov[idx][1]+xEyes[i][4*j+2]*eyeMov[idx][2]+xEyes[i][4*j+3]*eyeMov[idx][3]);
curV[i][3*j+1] += (yEyes[i][4*j]*eyeMov[idx][0]+yEyes[i][4*j+1]*eyeMov[idx][1]+yEyes[i][4*j+2]*eyeMov[idx][2]+yEyes[i][4*j+3]*eyeMov[idx][3]);
curV[i][3*j+2] += (zEyes[i][4*j]*eyeMov[idx][0]+zEyes[i][4*j+1]*eyeMov[idx][1]+zEyes[i][4*j+2]*eyeMov[idx][2]+zEyes[i][4*j+3]*eyeMov[idx][3]);
}
}
...
}
The values of V
, xEyes
, yEyes
, zEyes
and eyeMov
are read from files. The problem that I have is from the second visit to updateBuffers()
, the value of V
changes. But there is nowhere in the codes that V
is on the left-hand side of the equation. Any suggestion how to fix this?