Game Development Reference
In-Depth Information
/ /
Check
f o r
g i m b a l
l o c k ,
s i n c e
t h e
l i b r a r y
a t a n 2
/ /
f u n c t i o n
i s
u n d e f i n e d
a t
t h e
(2D)
o r i g i n
i f
( f a b s ( p i t c h ) > = PIOVERTWO 0 . 9 9 9 9 )
{
h e a d i n g
=
0 . 0 f ;
}
e l s e {
h e a d i n g
=
a t a n 2 ( x , z ) ;
}
}
e l s e
{
/ /
At
t h e
o r i g i n
slam
a n g l e s
t o
z e r o
h e a d i n g
=
p i t c h
=
0 . 0 f ;
}
Listing 7.4
Cartesian to spherical coordinate conversion
7.4
Using Polar Coordinates to Specify Vectors
We've seen how to describe a point by using polar coordinates, and how to
describe a vector by using Cartesian coordinates. It's also possible to use
polar form to describe vectors. Actually, to say that we can “also” use polar
form is sort of like saying that a computer is controlled with a keyboard
but it can “also” be controlled with the mouse. Polar coordinates directly
describe the two key properties of a vector—its direction and length. In
Cartesian form, these values are stored indirectly and obtained only through
some computations that essentially boil down to a conversion to polar form.
This is why, as we discussed in Section 7.2, polar coordinates are the local
currency in everyday conversation.
But it isn't just laymen who prefer polar form. It's interesting to notice
that most physics textbooks contain a brief introduction to vectors, and
this introduction is carried out using a framework of polar coordinates.
This is done despite the fact that it makes the math significantly more
complicated.
As for the details of how polar vectors work, we've actually already
covered them. Consider our “algorithm” for locating a point described by
2D polar coordinates on page 192. If you take out the phrase “start at the
origin” and leave the rest intact, the instructions describe how to visualize
the displacement (vector) described by any given polar coordinates. This
is the same idea from Section 2.4: a vector is related to the point with the
same coordinates because it gives us the displacement from the origin to
that point.
We've also already learned the math for converting vectors between
Cartesian and polar form. The methods discussed in Section 7.1.3 were
presented in terms of points, but they are equally valid for vectors.
 
Search WWH ::




Custom Search