varsunlight =newTHREE.DirectionalLight();
sunlight.intensity = 0.5;
sunlight.position.set(100, 100, 100);
scene.add(sunlight);
sunlight.castShadow = true;varshape =newTHREE.PlaneGeometry(1000, 1000);
varcover =newTHREE.MeshBasicMaterial();
varground =newTHREE.Mesh(shape, cover);
scene.add(ground);
ground.position.set(0, -200, 0);
ground.rotation.set(-Math.PI/2, 0, 0);
ground.receiveShadow = true;varclock =newTHREE.Clock();
functionanimate() {
requestAnimationFrame(animate);vartime = clock.getElapsedTime();
donut.rotation.set(time, 2*time, 0);renderer.render(scene, camera);
}
animate();
</script>A1.13Code: Build Your Own Solar System
This is the final version of the solar-system code from Chapter 13, Project:
Build Your Own Solar System, on page 117.<body></body>
<script src="http://gamingJS.com/Three.js"></script>
<script src="http://gamingJS.com/ChromeFixes.js"></script>
<script>
// This is where stuff in our game will happen:
varscene =newTHREE.Scene();// This is what sees the stuff:
varaspect_ratio = window.innerWidth / window.innerHeight;
varabove_cam =newTHREE.PerspectiveCamera(75, aspect_ratio, 1, 1e6);
above_cam.position.z = 1000;
scene.add(above_cam);varearth_cam =newTHREE.PerspectiveCamera(75, aspect_ratio, 1, 1e6);
scene.add(earth_cam);varcamera = above_cam;// This will draw what the camera sees onto the screen:
varrenderer =newTHREE.WebGLRenderer();report erratum • discussCode: Build Your Own Solar System • 241
Prepared exclusively for Michael Powell