0% found this document useful (0 votes)
47 views5 pages

Programming Assignment Unit 2

Uploaded by

poposhwezinphyo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views5 pages

Programming Assignment Unit 2

Uploaded by

poposhwezinphyo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Programming Assignment Unit 2

In this assignment, I implemented a spinning polygon using WebGL, specifically creating a


pentagon (a polygon with five vertices) that rotates around its axes. Below is a summary of the
main components of the code:

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)

2. Massachusetts Institute of Technology (2020). Coordinates and Transformations.


MITOpenCourseware. https://ocw.mit.edu/courses/electrical-engineering-and-
computer-science/6-837-computer-graphics-fall-2012/lecture-notes/. (Original work
published 2001).

3. Mbise, M. (2017). Computer graphics. African Virtual University (AVU).

https://my.uopeople.edu/pluginfile.php/1928367/mod_book/chapter/540580/EDUC
%205420_U1%20reading.pdf

You might also like