Game Engine Architecture

(Ben Green) #1

142 4. 3D Math for Games


a+ b


  • b b


a–b a

Figure 4.6. Vector addition and subtraction.

The scale factor can be diff erent along each axis. We call this nonuniform
scale , and it can be represented as the component-wise product of a scaling vector
s and the vector in question, which we’ll denote with the ⊗ operator. Techni-
cally speaking, this special kind of product between two vectors is known as
the Hadamard product. It is rarely used in the game industry—in fact, nonuni-
form scaling is one of its only commonplace uses in games:
(4.1)
As we’ll see in Section 4.3.7.3, a scaling vector s is really just a compact way to
represent a 3 × 3 diagonal scaling matrix S. So another way to write Equation
(4.1) is as follows:

4.2.4.2. Addition and Subtraction
The addition of two vectors a and b is defi ned as the vector whose components
are the sums of the components of a and b. This can be visualized by placing the
head of vector a onto the tail of vector b—the sum is then the vector from the
tail of a to the head of b:
a + b = [ (ax + bx), (ay + by), (az + bz) ].
Vector subtraction a – b is nothing more than addition of a and –b (i.e., the
result of scaling b by –1, which fl ips it around). This corresponds to the vector

v 2 v

v

Figure 4.5. Multiplication of a vector by the scalar 2.

sa⊗=(sa sa saxxyyzz, , ).

00


[ ] 0 0 [ ].


00


x
x y z y xxyyzz
z

s
aaa s sasasa
s

⎡⎤


==⎢⎥


⎢⎥


⎢⎥⎣⎦


aS
Free download pdf