Welcome to lab, which is a place where you and your peers complete exercises designed to help you learn the ideas discussed in the preceding lectures. It is intended to be a time where you encounter holes in your understanding and talk out loud with your peers and instructor.
Your instructor will bounce around between breakout rooms to check in with you. However, you are encouraged to request assistance if you find your progress blocked.
Designate one of your group to be the host. This individual will be responsible for setting up a Live Share session in Visual Studio Code and submitting your work. No team member should dominate or be expected to carry the group. All members should be writing code and contributing ideas.
Host, follow these steps:
Open Visual Studio Code.
Click File / Open Folder, create a new folder, and open it.
With the Live Share extension installed, select View / Command Palette, and choose Live Share: Start Collaborative Session.
Copy the invitation link to your chat.
Non-hosts, join the session.
Your task in this lab is to render a torus that is shaded and can be spun around. Follow these steps to complete this lab:
Add a function generateTorus that accepts an outer radius, an inner radius, number of latitudes, and a number of longitudes. The outer radius is the distance to the outer edge of the torus. The inner radius is the radius of the hole within the torus.
Generate seed positions initially around the unit circle to form a cross section of the torus. There should be as many seed positions as you have latitudes.
Generate seed normals, which are at this step identical to the seed positions.
Shift the seed positions right along the x-axis so the circular cross section is centered between the inner and outer radii. Do not transform the normals. Normals are vectors and don’t translate.
Scale the seed positions around their center so the circle fills the space between the two radii. Do not scale the normals. They already point the right direction. Scaling only changes their length, which we don’t want to do.
Create your empty positions, normals, and indices arrays.
Iterate through the longitudes. Turn each longitude into a proportion, apply it to the 360 degrees of the swept torus, and get a rotation-around-y matrix for that number of degrees.
For each longitude, iterate through the latitudes. Transform each latitude’s seed position and seed normal by the rotation matrix. Append the position and normal to their arrays.
Generate the indices connecting the faces together just as we did for the plane and sphere. Be sure the final lines of latitude and longitude wrap back to the first.
Return the positions, normal, and indices from the function.
Shade the torus using standard diffuse shading.
Use an orthographic projection that shows the entire torus and whose aspect ratio matches the viewport.
All the user to spin the torus with the cursor keys.
Enable the depth test and back-face culling.
Submit your index.js on Crowdsource. Enter the eIDs for your team members. If you need to make changes after you’ve already submitted, just reload the page and resubmit. If you haven’t finished by the end of the scheduled lab time, you are free to continue working. However, the submission must be made before the end of the day to receive credit.