Earth, you should notice something strange (but only if you’re using the
WebGL renderer, unfortunately). Mars normally seems to be moving to the
left as time passes. But every now and then, it stops and seems to go backward
for a little while.
If you go outside and observe where Mars is in the sky for several months,
you’ll see the same phenomenon. Ancient astronomers called this “retrograde
motion.” Because they thought Earth was at the center of the universe, they
had no good explanation for why retrograde motion happened. Oh, some of
them came up with crazy explanations, but nothing as simple as we just
simulated.
But we know what’s going on, don’t we? If you switch to above_cam just as Mars
starts going backward, you’ll see that retrograde motion happens when Earth
catches up with Mars and passes it. It’s sort of like a fast car passing a
slower car—the slower car (Mars) almost looks like it’s going backward.
It took you just a hundred lines of JavaScript to solve a question that the
greatest minds in the world couldn’t solve for thousands of years. Awesome!
16.4 The Code So Far
If you would like to double-check the code in this chapter, turn to Section
A1.13, Code: Build Your Own Solar System, on page 241.
14.8 What’s Next
We have a pretty incredible view of the solar system here, which is not bad
for a quick, single-chapter project! Not only did you solve a mystery that has
perplexed great minds, but you learned some pretty useful things about 3D
programming along the way. You now know how to move objects in circular
motion. Even cooler, you can add multiple cameras to a 3D scene, move the
cameras around, and switch back and forth between them.
We’ll build on this project in the next chapter to do something that every 3D
programmer has to do at some point: simulate the phases of the moon as it
revolves around Earth.
report erratum • discuss
17.5 The Code So Far
Prepared exclusively for Michael Powell