Programming Assignment Unit 2
Programming Assignment Unit 2
1. Vertex Definition: The vertices of the pentagon are defined in a Float32Array. Each
vertex represents a point in 3D space. The vertices are positioned to create a symmetrical
shape:
○ Vertex 1 (top)
○ Vertex 2 (bottom right)
○ Vertex 3 (middle right)
○ Vertex 4 (bottom left)
○ Vertex 5 (middle left)
2. Shaders:
○ Vertex Shader: This shader processes each vertex and applies a model-view
transformation to determine its final position on the screen. It takes the vertex
coordinates and applies the rotation matrix to achieve the spinning effect.
○ Fragment Shader: This shader determines the color of the polygon. In this
implementation, the color is set to red by using the gl_FragColor variable, which
defines the final color output for each pixel of the polygon.
3. Rotation Logic: The polygon spins slowly around the x-axis and y-axis. This is achieved
by incrementing the rotation angle in each frame of the rendering loop. The rotation is
performed using the gl-matrix library, which provides convenient functions for matrix
manipulation.
4. Rendering: The draw function clears the canvas, applies the rotation, and draws the
polygon using the drawArrays function. This function uses the TRIANGLE_FAN mode
to create the polygon by connecting the vertices.
Output:
References:
1. Guha. S. (2019). Computer graphics through OpenGL: From theory to experiments,
3rd edition. (Download/access book from syllabus/textbook)
https://my.uopeople.edu/pluginfile.php/1928367/mod_book/chapter/540580/EDUC
%205420_U1%20reading.pdf