3D Game Programming
varshape =newTHREE.SphereGeometry(100); varcover =newTHREE.MeshBasicMaterial(); cover.color.setRGB(1, 0, 0); varball =newTHREE.M ...
12.3 Realism: Shininess The first thing we need to do for this exercise is switch renderers. We talked about renderers in Chapte ...
Below the donut code, add some sunlight: varsunlight =newTHREE.DirectionalLight(); sunlight.intensity = 0.5; sunlight.position.s ...
the shine—to three 0.9 values, which is pretty close to all 1.0 values that would make white. In other words, we see a little mo ...
// This will draw what the camera sees onto the screen: varrenderer =newTHREE.WebGLRenderer(); renderer.shadowMapEnabled = true; ...
12.5 Let’s Animate! That is all pretty cool, but you know what’s even cooler than a shiny donut casting a shadow? A shiny donut ...
The other interesting thing happening in the animate() function is requestAnima- tionFrame(). This is a function that is built i ...
CHAPTER 13 Project: Build Your Own Solar System Let’s take a break from our avatar to do something different, but just as cool: ...
// This is what sees the stuff: varaspect_ratio = window.innerWidth / window.innerHeight; varcamera =newTHREE.PerspectiveCamera( ...
light in the middle of the sun. A point light shines light in all directions from a single point, much like the sun. With that, ...
our planets to move up and down as well. This is what the cosine is for. When the sine function would move the planet through th ...
13.3 Earth-Cam! Let’s add the ability to watch the planet Mars from Earth. As you watch Mars from Earth over several months, Mar ...
Next we need to add earth_cam to Earth and rotate it so that it points to Mars. We do that inside the animate() function. Add th ...
Earth, you should notice something strange (but only if you’re using the WebGL renderer, unfortunately). Mars normally seems to ...
CHAPTER 14 Project: Phases of the Moon The retrograde-motion chapter was pretty amazing, but in this chapter we’ll cover somethi ...
15.1 Getting Started We’ll do something a little different in this chapter. Instead of starting anew, let’s make a copy of our M ...
Next we need to make the moon behave a bit more like a moon. Instead of orbiting around the sun, we need to make it orbit around ...
moon_orbit.add(earth_cam); earth_cam.rotation.set(Math.PI/2, 0, 0); Now comes the really cool part of frame of reference. Back i ...
The result is that we had to do very little work to orbit the moon or keep Earth-cam pointed at it. With Mars, we had to do all ...
functionanimate() { requestAnimationFrame(animate); renderer.render(scene, camera); if(pause)return; time = time + speed; vare_a ...
«
2
3
4
5
6
7
8
9
10
11
»
Free download pdf