Notes for Wednesday March 10 class -- mesh shapes

Matrix class

In class we finished implementing the matrix primitives, and we packaged up the matrix operations into a Matrix class. You can use this class in your homework.

Mesh shapes from triangle strips

We showed in class how to implement various mesh shapes as triangle strips, including sphere, tube and disk.

We showed how to glue together triangle strips into a single triangle strip. We used that method to create a cylinder mesh shape.

 

Homework

Due next Wednesday before the start of class

Start with the included code in hw5.zip.

  • Make a cube as a triangle strip mesh.

    Hint: you can do this by glueing together six squares. You can build each square by fixing one coordinate (x,y or z) at a value of either -1 or +1, and then creating a "Z" pattern with the other two coordinates. For example, the square that faces positive X is:

         x  y  z    x  y  z    x  y  z    x  y  z
       [ 1,-1, 1,   1, 1, 1,   1,-1,-1,   1, 1,-1 ]
    

  • Build your own hierarchical scene, using cubes, spheres and cylinders. Use M.save() and M.restore() to create hierarchy.

  • Extra credit 1: Make the different objects in the scene different colors.

    Hint: Create a uniform variable vec3 uBackground for the background color in the fragment shader. Before any call to drawMesh(), you can change the value of uBackground.

  • Extra credit 2: Add a torus (donut) to your set of shapes.

    The formula that maps (u,v) to points on a torus is:

    θ = 2 π u
    φ = 2 π v
    x = cosθ (1 + r cosφ)
    y = sinθ (1 + r cosφ)
    z = r sinφ
    where r is the radius of the inner tube (in other words, the "fatness" of the donut).

    Hint: Your uvToTorus function should contain a third argument r. The first line of its definition should therefore look something like this:

       let uvToTorus = (u,v,r) => {