Question: Design an interactive Viewer using WebGL in javascript. Using all of these code snippets: 1 . The render function function render ( ) { gl

Design an interactive Viewer using WebGL in javascript. Using all of these code snippets:
1.The render function
function render()
{
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
eye = vec3(radius * Math.sin(theta)* Math.cos(phi),
radius * Math.sin(theta)* Math.sin(phi),
radius * Math.cos(theta));
modelViewMatrix = lookAt(eye, at, up);
projectionMatrix = ortho(left, right, bottom, ytop, near, far);
gl.uniformMatrix4fv(modelViewMatrixLoc, false, flatten(modelViewMatrix));
gl.uniformMatrix4fv(projectionMatrixLoc, false, flatten(projectionMatrix));
gl.drawArrays(gl.TRIANGLES, 0, numVertices);
requestAnimFrame(render);
}
2. The fixed values:
const at = vec3(0.0,0.0,0.0); const up = vec3(0.0,1.0,0.0)
3. The vertex shader:
attribute vec4 vPosition; attribute vec4 vColor; varying vec4 fcolor;
uniform mat4 modelViewMatrix; uniform mat4 projectionMatrix;
void main(){
fcolor = vColor; gl_Position = projectionMatrix * modelViewMatrix * vPosition;
}
4. The fragment shader:
varying vec4 color;
void main()
{
gl_FragColor = fcolor;
}
5. To control near and far distances:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!