started writing the first chapter
[gfxbook] / gl1 / spaces.tex
1 \chapter{Transformations \& coordinate systems}
2
3 \section{Overview}
4
5 In the previous chapter we saw how to use GLUT to create a window in any
6 operating system, and then used OpenGL to fill it with a single color, and draw
7 our first 2D triangle onto it. In this chapter we will enter the world of
8 3-dimensions, and learn how to go from a single triangle, to rendering a
9 polygonal object in 3D space. To do that we'll have to grasp the concept of
10 coordinate systems, and how to transform vertices from one to another. OpenGL
11 will help us quite a lot in this, with its \em{matrix stacks}, but in
12 later chapters we will revisit the underlying mathematics and their
13 implementation in more detail.
14
15 \section{Mathematical fundamentals}
16
17 The fundamental mathematical tools necessary to do anything in 3D graphics, are
18 vectors, matrices, and the concept of coordinate systems from linear algebra.
19
20 \subsection{Coordinate systems and vectors}
21
22 A coordinate system represents a \em{space} which has a certain point as its
23 \em{origin}, the point from which every measurement starts, the place where all
24 coordinates are defined to be 0. It also has a number of basis vectors, defining
25 the axes of the coordinate system. By stepping varying distances along each
26 axis, we can reach any point in space. How much we step along each axis to reach
27 a certain point is defined by a pair of numbers in 2-space, or a triplet of
28 numbers in 3-space, or more generally an \em{n-tuple} for n-dimensional spaces.
29 These tuples are what we call \em{vectors}.
30
31 Consider the triangle we defined in the previous chapter. We arbitrarily used
32 vectors $v_0 = (42, 42)$, $v_1 = (42, 42)$, and $v_2 = (42, 42)$  % TODO
33 to
34 define the positions in space of each vertex of the triangle. We chose these
35 numbers arbitrarily, because they will result in a big clearly visible triangle
36 in our case, due to the extends of the screen ranging from $-1$ to $1$ both
37 horizontally and vertically. In essence we were dealing with a coordinate
38 system, called \em{normalized screen space} or sometimes known by the initials
39 \em{NDC} (normalized device coordinates), which has its origin at the center of
40 our window, and basis vectors $i = (1, 0)$ and $j = (0, 1)$.