3D Game Programming

(C. Jardin) #1
varshape =newTHREE.CubeGeometry(200, 1000, 10);
varcover =newTHREE.MeshBasicMaterial({color:0x990000});
varroad =newTHREE.Mesh(shape, cover);
scene.add(road);
road.position.set(0, 400, 0);
road.rotation.set(-Math.PI/4, 0, 0);

Our perspective camera makes the road look something like this:


This is a rectangular road, but it doesn’t look rectangular. It looks as though
it’s getting smaller the farther away it gets. The perspective camera does this
for us:

varaspect_ratio = window.innerWidth / window.innerHeight;
varcamera =newTHREE.PerspectiveCamera(75, aspect_ratio, 1, 10000);

If we use an orthographic camera, on the other hand, everything looks flat:


Chapter 9. What’s All That Other Code? • 90


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf