Mxir1. The CSB. 8 E8 app / 0% % 83% % c…
function check(gl, n, x, y, currentAngle, u_Clicked, viewProjMatrix, u_MvpMatrix) {
var picked = false;
gl.uniform1i(u_Clicked, 1); // Pass true to u_Clicked(Draw cube with red)
draw(gl, n, currentAngle, viewProjMatrix, u_MvpMatrix); // Completely red
// Read pixel at the clicked position
var pixels = new Uint8Array(4); // Array for storing the pixel value
gl.readPixels(x, y, 1.1, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
if (pixels[0] = =255) // If red = 255, clicked on cube directly to determine If red
picked = true;
gl.uniform1i(u_Clicked, 0); // Pass false to u_Clicked(Draw cube with specified color)
draw(gl, n, currentAngle, viewProjMatrix, u_MvpMatrix); //draw the original color
if (picked) alert('The cube was selected! ');
}
Copy the code