Game Development Reference

In-Depth Information

component is a numeric angle value, but in conversation it is often

referred to in looser terminology. For instance, the vector form of

the scalar example above could be something like

“

four miles per

hour, heading northwest,

though we would not necessarily be able

to do any calculation with that information until we assigned it a

number.

”

The Vector3D Class

Among the classes in Flash for handling complex math more effi-

ciently is the Vector3D class. It is the code representation of the

vector
concept we learned about earlier. It contains
x
,
y
,and
z

values to determine its magnitude, and a fourth value,
w
,which

stores information about the vector

'

sdirection,suchasanangle.

We will look at an example shortly where we will use the Vector3D

class to simplify some vector math.

VECTOR VERSUS VECTOR3D

There is another class in Flash known as Vector, which I mentioned in

Chapter 4. It has nothing to do with vectors in physics terms. Rather, it

is a special type of Array that stores only one type of value and uses

less memory than an Array by doing so. For instance, if you used Arrays

of Numbers in previous versions of Flash, you can now use a Vector

instead. It has all the same methods and properties of Arrays but is

faster to navigate and more efficient. The name Vector comes from the

C programming language, but really you can just think of it as a
typed

Array.

Displacement

Displacement is most easily thought of as the distance between any

two points in space when connected by a straight line. Though it is

technically a vector, we generally think of displacement in terms of

a scalar. That is to say, we don

'

t usually consider the direction of

one object relative to another when computing their distance apart

from each other. It would be odd to refer to the distance from

one

'

s self to a nearby table as

“

4ft,30

°

from my facing direction.

”

We simply say

“

four feet.

”

Velocity

Displacement over a period of time results in what we know as

speed
. For instance, if it takes me an hour to walk five miles, my

speed is five miles per hour (5 mph). However, as discussed above,

this is merely a scalar value as it has no directional information. If

we add a direction, such as 90

°

,wegetthevectorof
velocity
.