Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a WebGL program that displays a rotating pendulum. The pendulum bob is free to rotate through 360 degrees about an anchor point at the
Write a WebGL program that displays a rotating pendulum. The pendulum bob is free to rotate through 360 degrees about an anchor point at the center of the canvas. The pendulum has the following three components. 1) The anchor point is a green square centered at the origin (0,0) with point size = 5 pixels. 2) The bob is a blue hexagon of radius r = 0.1. Render this with a triangle fan centered at the origin (along with a ModelView matrix that translates and rotates). 3) The bob is attached to the anchor point by a rigid red wire of length l = 0.8. Use global variables for the point size of the anchor, the radius of the bob, the length of the wire, and the angular velocity of rotation in degrees per second. Set the initial angular velocity to 45 and allow an interactive user to increase or decrease the value in multiples of 10 degrees per second with button presses. A good template for this program is RotatingTriangle_withButtons.js in matsuda/ch04.
RotatingTriangle_withButtons.js
// RotatingTranslatedTriangle.js (c) 2012 matsuda // Vertex shader program var VSHADER_SOURCE = 'attribute vec4 a_Position; ' + 'uniform mat4 u_ModelMatrix; ' + 'void main() { ' + ' gl_Position = u_ModelMatrix * a_Position; ' + '} '; // Fragment shader program var FSHADER_SOURCE = 'void main() { ' + ' gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); ' + '} '; // Rotation angle (degrees/second) var ANGLE_STEP = 45.0; 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