Lab: Torus
In this chapter, you've been learning how to represent triangle meshes and generate algorithmic shapes like cones, cylinders, and spheres. Let's apply this knowledge by writing a renderer that generates a torus—a donut.
Form a group of no more than three people. Host, open your top-level repository directory in Visual Studio Code and run npm run dev to start up a web server. Then open the command palette via View / Command Palette and enter Live Share: Start Collaboration Session. Share the link with your group.
Torus
Your challenge is to render two spinnable models colored by their normals. Complete these steps:
transfit renderer to make a new renderer named torus. We use transfit because it deals with the viewport distortion and has no HTML inputs.center variable in resizeCanvas to [0, 0] and size to 1.initialize with code like this:
window.addEventListener('keydown', event => {
if (event.key === 'ArrowDown') {
// ...
}
});
window.addEventListener('keydown', event => {
if (event.key === 'ArrowDown') {
// ...
}
});torus. Have it accept four parameters: the inner (or hole) radius, the outer radius, the longitude count, and the latitude count. Generate the torus geometry using a similar approach to how we generated a sphere: generate seed positions on one ring, and then rotate them. Unlike the sphere, wrap both latitude and longitude when forming triangles.Submission
To receive credit for your lab work, follow these steps:
torus folder before the host closes the session.#lab channel in Discord. No voiceover is necessary. Tag your group members with @.Only labs submitted on time will be granted credit. Late labs or forgot-to-submits are not accepted because Monday at noon is when your instructor has time to grade.