
ptg11539634
Specifying the Visible Range Using a Quadrangular Pyramid 259
76 function initVertexBuffers(gl) {
77 var verticesColors = new Float32Array([
78 // Three triangles on the right side
79 0.75, 1.0, -4.0, 0.4, 1.0, 0.4, // The green triangle in back
80 0.25, -1.0, -4.0, 0.4, 1.0, 0.4,
81 1.25, -1.0, -4.0, 1.0, 0.4, 0.4,
82
83 0.75, 1.0, -2.0, 1.0, 1.0, 0.4, // The yellow triangle in middle
84 0.25, -1.0, -2.0, 1.0, 1.0, 0.4,
85 1.25, -1.0, -2.0, 1.0, 0.4, 0.4,
86
87 0.75, 1.0, 0.0, 0.4, 0.4, 1.0, // The blue triangle in front
88 0.25, -1.0, 0.0, 0.4, 0.4, 1.0,
89 1.25, -1.0, 0.0, 1.0, 0.4, 0.4,
90
91 // Three triangles on the left side
92 -0.75, 1.0, -4.0, 0.4, 1.0, 0.4, // The green triangle in back
93 -1.25, -1.0, -4.0, 0.4, 1.0, 0.4,
94 -0.25, -1.0, -4.0, 1.0, 0.4, 0.4,
95
96 -0.75, 1.0, -2.0, 1.0, 1.0, 0.4, // The yellow triangle in middle
97 -1.25, -1.0, -2.0, 1.0, 1.0, 0.4,
98 -0.25, -1.0, -2.0, 1.0, 0.4, 0.4,
99
100 -0.75, 1.0, 0.0, 0.4, 0.4, 1.0, // The blue triangle in front
101 -1.25, -1.0, 0.0, 0.4, 0.4, 1.0,
102 -0.25, -1.0, 0.0, 1.0, 0.4, 0.4,
103 ]);
104 var n = 18; // Three vertices per triangle * 6
...
138 return n;
139 }
The vertex and fragment shaders are completely identical (including the names of the
variables) to the ones used in
LookAtTriangles_ViewVolume.js.
The processing flow of main() in JavaScript is also similar. Calling initVertexBuffers()
at line 42 writes the vertex coordinates and colors of the six triangles to be displayed into
the buffer object. In
initVertexBuffers(), the vertex coordinates and colors for the six
triangles are specified: three triangles positioned on the right side from line 79 and three
triangles positioned on the left side from line 92. As a result, the number of vertices to be
drawn at line 104 is changed to 18 (3×6=18, to handle six triangles).
At lines 52 and 53 in
main(), the locations of the uniform variables that store the view
matrix and perspective projection matrix are retrieved. Then at line 59 and 60, the vari-
ables used to hold the matrices are created.