Game Development Reference
In-Depth Information
are added related to the pitch angle. First, pitch is restricted to be on the
interval [−90 o ,+90 o ]. Second, since the heading value is irrelevant when
pitch reaches the extreme values in the case of Gimbal lock, we force h = 0
in that case. The conditions that are satisfied by the points in the canonical
set are summarized by the criteria below. (Note that these criteria assume
our heading and pitch conventions, not the traditional math conventions
with θ and φ.)
r ≥ 0 We don't measure distances “backwards.”
−180 o < h ≤ 180 o Heading is limited to 1/2 revolution.
We use +180 o for “south.”
−90 o ≤ p ≤ 90 o Pitch limits are straight up and down.
We can't “pitch over backwards.”
r = 0 ⇒ h = p = 0 At the origin, we set the angles to zero.
|p| = 90 o ⇒ h = 0 When looking directly up or down,
we set the heading to zero.
The following algorithm can be used to convert a spherical coordinate
triple into its canonical form:
Conditions satisfied by
canonical spherical
coordinates, assuming
the conventions for
spherical coordinates in
this topic
1. If r = 0, then assign h = p = 0.
2. If r < 0, then negate r, add 180 o to h, and negate p.
3. If p < −90 o , then add 360 o to p until p ≥ −90 o .
4. If p > 270 o , then subtract 360 o from p until p ≤ 270 o .
5. If p > 90 o , then add 180 o to h and set p = 180 o − p.
6. If h ≤ −180 o , then add 360 o to h until h > −180 o .
Converting a spherical
coordinate triple (r, h, p)
to canonical form
7. If h > 180 o , then subtract 360 o from h until h ≤ 180 o .
Listing 7.3 shows how it could be done in C. Remember that computers
like radians.
/ /
R a d i a l
d i s t a n c e
f l o a t
r ;
/ /
A n g l e s
i n
r a d i a n s
f l o a t
h e a d i n g ,
p i t c h ;
/ /
D e c l a r e
a
few
c o n s t a n t s
c o n s t
f l o a t
TWOPI
=
2 . 0 f P I ;
/ /
360
d e g r e e s
c o n s t
f l o a t
PIOVERTWO
=
P I / 2 . 0 f ;
/ /
90
d e g r e e s
/ /
Check
i f
we
a r e
e x a c t l y
a t
t h e
o r i g i n
i f
( r
==
0 . 0 f )
{
Search WWH ::




Custom Search