Digging a River

When we pulled up vertices[50], we pulled up the vertex at the top-middle of the plane. When we added 100, 10*100, and 50*100 to 50, we pulled up vertices in a straight line.

 var​ faces = 99;
 var​ shape = ​new​ THREE.PlaneGeometry(10, 20, faces, faces);
 shape.vertices[50].z = 5;
 shape.vertices[50 + 100].z = 5;
 shape.vertices[50 + 10*100].z = 5;
 shape.vertices[50 + 50*100].z = 5;

There are 99 rectangles across the top of the plane. That means there are 100 vertices—the 99 top-left corners plus the top-right corner on the end. So every time we move 100, we move to the next row.

We can make use of this in a for loop. Instead of starting the loop at 0, we can start at 50. And, instead of increasing by 1 each time through ...

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.