Game Development Reference
In-Depth Information
particular shot we might want to capture. On the left, we see the layout of
the shot from an external perspective, and on the right is what the camera
sees.
It was easy to visualize transforming the model into world space. We
literally “moved” it into place. 5 But how do we transform from world
space to camera space? The objects are both already “in place,” so where
do we “move” them? For situations like this, it's helpful to think about
transforming the coordinate space rather than transforming the objects, a
technique we'll discuss in the next section. However, let's see if we can keep
the coordinate space stationary, and still achieve the desired result by only
“moving objects.”
When we transformed from object space to world space, we were able
to do so because we imagined the robot starting out at the origin in world
space. Of course, the robot never really was at the location in world space,
but we imagined it. Since we transformed from object space to world space
by moving the object, perhaps we can transform from world space to camera
space by moving the world! Imagine taking the entire world, including the
robot, the camera, and the kitchen, and moving everything around. Clearly,
such operations wouldn't affect what the camera would “see,” because they
don't change the relative relationship between the camera and the objects
in the world. If we moved the world and camera together, such that the
camera moved to the origin, then world-space coordinates and camera-space
coordinates would be the same. Figure 3.9 shows the two-step process that
we would use to achieve this.
Notice that, in this case, it's easier to translate before rotating. That's
because we want to rotate about the origin. Also, we use the opposite
translation and rotation amounts, compared to the camera's position and
orientation. For example, in Figure 3.9 the coordinates of the camera are
approximately (13.5,4,2). (The grid lines represent 10 units.) So to move
the camera to the origin, we translate everything by [−13.5,−4,−2]. The
camera is facing roughly northeast and thus has a clockwise heading com-
pared to north; a counterclockwise rotation is required to align camera-
space axes with the world-space axes.
After picking up and moving around an entire robot in the first step, and
then the entire world 6 in the second step, we finally have the coordinates
of the vertices in camera space, and can proceed with rendering. If all this
imaginary heavy lifting has worn you out, don't worry; in just a moment
we will discuss an alternate way to think about this process.
Before we move on, a few important notes about this example. First,
the world-to-camera transform is usually done in a vertex shader; you can
5 OK, since this is all taking place in our imagination, the word literally might be a
bit out of place.
6 Yes, including the kitchen sink.
Search WWH ::




Custom Search