Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a WebGL program that displays a cube with colored faces using an orthographic projection. Allow an interactive user to rotate the cube 15 degrees
Write a WebGL program that displays a cube with colored faces using an orthographic projection. Allow an interactive user to rotate the cube 15 degrees about the x and y axes. Use ColoredCube from matsuda/ch07 as a template, and make the following modifications. 1) Replace the cuon-matrix.js functions setPerspective and lookAt by functions setOrtho, translate, and rotate. The viewing volume defined by setOrtho should be chosen so that the cube occupies most of the volume but no clipping occurs. 2) Add buttons labeled 'Rotate x' and 'Rotate y', along with callback functions that redraw the cube with the modified rotation angles. This requires a drawing function that creates the modelview-projection matrix mvpMatrix, passes it to the shader variable u_MvpMatrix, clears the color and depth buffers, and calls gl.drawElements. Also, since this drawing function is called by main() and the button callbacks, several variables must be converted from local to global.
use program below as outline:
// ColoredCube.js (c) 2012 matsuda // Vertex shader program var VSHADER_SOURCE = 'attribute vec4 a_Position; ' + 'attribute vec4 a_Color; ' + 'uniform mat4 u_MvpMatrix; ' + 'varying vec4 v_Color; ' + 'void main() { ' + ' gl_Position = u_MvpMatrix * a_Position; ' + ' v_Color = a_Color; ' + '} '; // Fragment shader program var FSHADER_SOURCE = '#ifdef GL_ES ' + 'precision mediump float; ' + '#endif ' + 'varying vec4 v_Color; ' + 'void main() { ' + ' gl_FragColor = v_Color; ' + '} '; function main() { // Retrieve
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started