Game Engine Architecture

(Ben Green) #1

182 4. 3D Math for Games


x
z

y

C r

Figure 4.27. Point-radius representation of a sphere.

A ray is a line that extends to infi nity in only one direction. This is easily
expressed as P(t) with the constraint t ≥ 0, as shown in Figure 4.25.
A line segment is bounded at both ends by P 0 and P 1. It too can be repre-
sented by P(t), in either one of the following two ways (where L = P 1 – P 0 and
L = |L| is the length of the line segment):


  1. P(t) = P 0 + tu, where 0 ≤ t ≤ L, or

  2. P(t) = P 0 + tL, where 0 ≤ t ≤ 1.
    The latt er format, depicted in Figure 4.26, is particularly convenient because
    the parameter t is normalized; in other words, t always goes from zero to one,
    no matt er which particular line segment we are dealing with. This means we
    do not have to store the constraint L in a separate fl oating-point parameter; it
    is already encoded in the vector L = Lu (which we have to store anyway).


t = 0

t = 1

t = 2
P 0 u t = 3

Figure 4.25. Parametric equation of a ray.

t = 0

t = 1

L = P 1 – P 0
P 0

P 1

t = 0.5

Figure 4.26. Parametric equation of a line segment, with normalized parameter t.

4.6.2. Spheres
Spheres are ubiquitous in game engine programming. A sphere is typically
defi ned as a center point C plus a radius r, as shown in Figure 4.27. This packs
Free download pdf