So far, we have learned to draw 2D triangles on the canvas, given the 2D coordinates of their vertices. However, the goal of this book is to render 3D scenes. So in this chapter, we’ll take a break from 2D triangles and focus on how to turn 3D scene coordinates into 2D canvas coordinates. We’ll then use this to draw 3D triangles on the 2D canvas.

Basic Assumptions

Just like we did at the beginning of Chapter 2, we’ll start by defining a camera. We’ll use the same conventions as before: the camera is at O = (0,0,0), looking in the direction of , and its “up” vector is . We’ll also define a rectangular viewport of size

Get Computer Graphics from Scratch now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.