Keenan's Blog

Computer Graphics From Scratch

2022-10-31

2-2 Basic Assumptions

One of the points of computer graphics is to draw stuff to the screen but in order to do this as soon as possible a few simplifying assumptions need to be made. This will impose some restrictions on what we will be able to do but these will be lifted in later chapters.

The first assumption we are going to make is that our view will be in a fixed position. This viewing position is commonly called the camera position, but for now we will call it O. The camera occupies a single point in space located at the origin of the coordinate system and never moves, so for now O = (0, 0, 0).

Secondly we'll assume the cameras orientation is in a fixed position as well. The orientation determines where the camera is pointing. For now we are going to assume the camera is looking in the direction of the positive Z axis.

Figure 2-3: The position and orientation of our camera

Now we have the position and orientation in fixed positions next we need the frame through which we see the scene. We'll assume this frame has the dimensions width and height and is in front of the camera perpendicular to the Z axis. we'll also assume its at a distance represented by d and its sides are parallel to the X and Y axis.

This rectangle will be called the viewport and will be our window into the scene we want to create. The size of the viewport and the distance to the camera determines the angle visible from the camera, called the field of view or FOV for short. For now we will set the Viewports width, heigth and distance equal to 1. This will give us an FOV of about 53 degrees. This will produce reasonably looking images that are not overly distorted.

Figure 2-4: The position and orientation of our viewport

If we look back at our algorithm from the last post


1 Place Camera and the viewport as desired
  For each pixel on the canvas
    2 Determine which square on the viewport corresponds to this pixel
    3 Determine the color seen through that square
    4 Paint the pixel with that color

we have already done step 1 in this post. Step 4 is trivial and to do it we will use PutPixel(x, y, color). The next post will cover step 2 and step 3 will be covered over the next few chapters.

<- 2-1 Rendering a Swiss Landscape 2-3 Canvas to Viewport->