Game Development Reference
In-Depth Information
Note that p
and friends are actually row vectors, we are just writing them
as transposed column vectors to fit on the page.
Constructing the matrix from these basis vectors, we get
2
4 p
3
3D matrix to rotate
about an arbitrary axis
5
R ( n ,θ) =
q
r
n x 2 (1 − cos θ) + cos θ
n x n y (1 − cos θ) + n z sin θ
n x n z (1 − cos θ) − n y sin θ
=
.
n y 2 (1 − cos θ) + cos θ
n x n y (1 − cos θ) − n z sin θ
n y n z (1 − cos θ) + n x sin θ
n z 2 (1 − cos θ) + cos θ
n x n z (1 − cos θ) + n y sin θ
n y n z (1 − cos θ) − n x sin θ
5.2
Scale
We can scale an object to make it proportionally bigger or smaller by a
factor of k. If we apply this scale to the entire object, thus “dilating” the
object about the origin, we are performing a uniform scale. Uniform scale
preserves angles and proportions. Lengths increase or decrease uniformly
by a factor of k, areas by a factor of k 2 , and volumes (in 3D) by a factor of
k 3 .
If we wish to “stretch” or “squash” the object, we can apply different
scale factors in different directions, resulting in nonuniform scale. Nonuni-
form scale does not preserve angles. Lengths, areas, and volumes are ad-
justed by a factor that varies according to the orientation relative to the
direction of scale.
If |k| < 1, then the object gets “shorter” in that direction. If |k| > 1,
then the object gets “longer.” If k = 0, then we have an orthographic
projection, discussed in Section 5.3. If k < 0, then we have a reflection,
covered in Section 5.4. For the remainder of this section, we will assume
that k > 0.
Section 5.2.1 begins with the simple case of scaling along the cardi-
nal axes. Then Section 5.2.2 examines the general case, scaling along an
arbitrary axis.
5.2.1 Scaling along the Cardinal Axes
The simplest scale operation applies a separate scale factor along each car-
dinal axis. The scale along an axis is applied about the perpendicular axis
(in 2D) or plane (in 3D). If the scale factors for all axes are equal, then the
scale is uniform; otherwise, it is nonuniform.
In 2D, we have two scale factors, k x and k y . Figure 5.6 shows an object
with various scale values for k x and k y .
 
Search WWH ::




Custom Search