3D Game Programming

(C. Jardin) #1

What happens without the parentheses? Can you guess why?^1


Geometry
We’re working on 3D game concepts in this book, which means geometry.
We’ll discuss geometry in more detail as part of the various project chapters
that need it. For now let’s consider two geometric functions: sine and cosine.
If you don’t know them, don’t worry—you’ll get to know them in the games.

Just remember that in JavaScript, we do not use degrees. Instead we use
radians. What are radians? Instead of saying that we turned 180° when we
spin half way around a circle, we would say that we turned pi radians around.

Pi is a special number in math. Its value is about 3.14159. You will often see
the symbol π used for pi. We’ll call it pi since JavaScript calls it Math.PI.

Going around a full circle is twice as much as 180° turn—more commonly
called a 360° turn, this is two pi radians, or 2 × pi.

By the way, 2 × pi is the 6.3 that we said was a full rotation way back when
we first started talking about rotation in Making Boxes with the Cube Shape,
on page 6. Since the number value of pi is about 3.15, then 2 × pi is 2 × 3.15,
or 6.3.


  1. Without parentheses, multiplication is done first, then division. Remember the “order
    of operations” from your math class!


report erratum • discuss

Changing Things • 71


Prepared exclusively for Michael Powell

Free download pdf