Project B: Happy Halloween

Goals

This project aims to create a combined robot with animations, and sits on the tiles floor. There will be four position to view the whole scene.

User-Guide

Click RotateLeftWard to make the cones slow down and start to rotate clockwise more and more fast.

Click RotateLeftWard to make the cones slow down and start to rotate counterclockwise more and more fast.

makeVertices(): compiles all the vertices of the shapes into a single array, preparing them for rendering.

main(): Initialize shaders and locations for various attributes and uniform variables are retrieved. A buffer for the vertices is created, bound, and set with vertex attributes for position and color.

CODE-Guide

Shader Programs: Two shaders are defined- a vertex shader and a fragment shader (FSHADER_SOURCE). The vertex shader processes each vertex's position and color, while the fragment shader determines the color of each pixel.

 

Shape Objects: Several 3D shape objects are created (Torus, Cube, Pyramid, Cylinder, Cone, Sphere, Tiles), each with its starting vertex and length.

makeVertices(): compiles all the vertices of the shapes into a single array, preparing them for rendering.

 

main(): Initialize shaders and locations for various attributes and uniform variables are retrieved. A buffer for the vertices is created, bound, and set with vertex attributes for position and color.

Rendering

draw() : Rendering the scene. It clears the canvas and sets up different viewport quadrants with unique view and projection matrices, then calls drawShapes() for each quadrant.

 

 

Shape Drawing: drawCube(), drawTorus(), and others, set up transformation matrices for each shape and draw them.

 

animate(): updates the coneAngle and continuously requests draw() function.

 

Interactive Controls: Event listeners are added for buttons to control the rotation speed of the cone.

 

Tile Drawing:

drawTiles(): Recursively draws tiles on the canvas, utilizing a depth-first approach.

An event listener is added to the window to execute the main() function when the page loads.