colors.set(c2Array,colorIndex);
colorIndex += c2Array.length;
}
}
}
gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
boxesVertexColorBuffer.itemSize = 4;
boxesVertexColorBuffer.numItems = 36 * NUM_BOXES;
}
function drawScene() {
gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
pMatrix.setPerspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0);
mvMatrix.identity();
mvMatrix.translateSelf(0.0, 0.0, -8.0);
mvPushMatrix();
var rot = new toxi.geom.Vec3D(0.45,1,0.125)
.scaleSelf(toxi.math.MathUtils.radians(rotBoxes))
.addSelf(rotation);
mvMatrix.rotateX(rot.x)
.rotateY(rot.y)
.rotateZ(rot.z);
gl.bindBuffer(gl.ARRAY_BUFFER, boxesVertexPositionBuffer);
gl.vertexAttribPointer(
shaderProgram.vertexPositionAttribute,
boxesVertexPositionBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
gl.bindBuffer(gl.ARRAY_BUFFER, boxesVertexColorBuffer);
gl.vertexAttribPointer(
shaderProgram.vertexColorAttribute,
boxesVertexColorBuffer.itemSize,
gl.FLOAT,
false,
0,
0
);
setMatrixUniforms();
gl.drawArrays(gl.TRIANGLES, 0, boxesVertexPositionBuffer.numItems);
mvPopMatrix();
}
function animate() {
var timeNow = new Date().getTime();
if (lastTime !== 0) {
var elapsed = timeNow - lastTime;
rotBoxes += (90 * elapsed) / 8000.0;
}
lastTime = timeNow;
}
function tick() {