Graphics Reference
In-Depth Information
Listing 15.10 represents our camera. The camera has a pinhole aperture, an
instantaneous shutter, and artificial near and far planes of constant (negative)
z
values. We assume that the camera is located at the origin and facing along
the
−
z
-axis.
Listing 15.10: Interface for a pinhole camera at the origin.
1
2
3
4
5
6
7
8
class
Camera
{
public
:
float
zNear;
float
zFar;
float
fieldOfViewX;
Camera
() : zNear(-0.1f), zFar(-100.0f), fieldOfViewX(PI / 2.0f) {}
};
We constrain the horizontal field of view of the camera to be
fieldOfViewX
.
This is the measure of the angle from the center of the leftmost pixel to the center
of the rightmost pixel along the horizon in the camera's view in radians (it is
shown later in Figure 15.3). During rendering, we will compute the aspect ratio of
the target image and implicitly use that to determine the vertical field of view. We
could alternatively specify the vertical field of view and compute the horizontal
field of view from the aspect ratio.
We'll test our renderers on a scene that contains one triangle whose vertices are
Point3(0,1,-2)
,
Point3(-1.9,-1,-2)
,
and Point3(1.6,-0.5,-2)
,
and whose vertex normals are
Vector3( 0.0f, 0.6f, 1.0f).direction()
,
Vector3(-0.4f,-0.4f, 1.0f).direction()
, and
Vector3( 0.4f,-0.4f, 1.0f).direction()
.
We create one light source in the scene, located at
Point3(1.0f,3.0f,1.0
f)
and emitting power
Power3(10, 10, 10)
. The camera is at the origin and is
facing along the
z
-axis, with
y
increasing upward in screen space and
x
increas-
ing to the right. The image has size 800
−
500 and is initialized to dark blue.
This choice of scene data was deliberate, because when debugging it is a good
idea to choose configurations that use nonsquare aspect ratios, nonprimary colors,
asymmetric objects, etc. to help find cases where you have accidentally swapped
axes or color channels. Having distinct values for the properties of each vertex
also makes it easier to track values through code. For example, on this trian-
gle, you can determine which vertex you are examining merely by looking at its
x
-coordinate.
On the other hand, the camera is the standard one, which allows us to avoid
transforming rays and geometry. That leads to some efficiency and simplicity in
the implementation and helps with debugging because the input data maps exactly
to the data rendered, and in practice, most rendering algorithms operate in the
camera's reference frame anyway.
×