Multi-Camera Action!

We have a nice simulation of the Sun, Earth, and Moon from above the solar system. Let’s add a second camera to the scene so that we can switch the view from above the solar system to a view from the Earth. This will help us better understand the phases of the Moon.

Remember from the Getting Started part of this chapter that we named our current camera aboveCam. Let’s add moonCam, which will show the Moon from the Earth. Add the following code below the code for the Moon:

​ ​var​ moonCam = ​new​ THREE.PerspectiveCamera(70, aspectRatio, 1, 10000);
​ moonCam.position.z = 25;
​ moonCam.rotation.y = Math.PI;
​ moonOrbit.add(moonCam);
​ 
​ camera = moonCam;

That last line assigns camera to our new moonCam ...

Get 3D Game Programming for Kids, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.