This lab builds on your experience with 2D parametric surfaces from the last lab and adds in a projection transformation so that you can view portions of the world besides the unit cube. You will build a cylinder and then render it in perspective.
Your first challenge is to render a cylinder. Like the sphere, the cylinder is a cousin to the grid. Follow these steps to generate your cylinder:
main.jsof the cylinder application, write a function named
generateCylinder. Have it accept parameters for the number of lines of latitude, the number of lines of longitude, the height, and the radius.
make seeds array with four vertices as Vector4 for each longitude index compute longitude proportion compute degrees by applying longitude proportion generate a rotation matrix around y-axis for each of the four seed positions rotate seed position by matrix push rotated position into positions list
Your second challenge is to render the cylinder with a perspective projection. Send a perspective matrix to the vertex shader and transform all vertices by it. You are encouraged to name the matrix
clipFromWorld because this name communicates the spaces that the transformation spans.
The origin is where the eye lives. If you put something too close to your eye, it dominates your vision—both in real life and in computer graphics. To avoid this in your renderer, push the cylinder away from the eye using a translation matrix.
The starter code already applies a rotation. Combine the translation and rotation together into a matrix named
worldFromModel. Ensure that the rotation gets applied first. The vertex shader then receives just two matrices:
worldFromModel. These two will take the position attribute all the way from model space into clip space.
Show your instructor your working renderer to receive credit.