04.04.2013 Views

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

Processing: Creative Coding and Computational Art

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

void keyPressed(){<br />

if(key == CODED) {<br />

if (keyCode == UP) {<br />

if (depth70){<br />

depth-=20;<br />

detail-=2;<br />

}<br />

}<br />

}<br />

}<br />

Figure 13-27. sphereDetail() Example sketch<br />

If you play with the arrow keys, notice that the number of vertices making up the sphere<br />

increases as the sphere grows in size (it actually stays the same size, but comes closer to<br />

the screen on the z-axis), <strong>and</strong> vice versa. This represents another optimization approach<br />

used in 3D—only render the necessary resolution. Since the sphere is composed of triangles,<br />

when the sphere detail appears too low, the sphere loses its smooth, sphere-like quality.<br />

I simply changed the sphere detail based on the sphere’s position on the z-axis. In the<br />

next <strong>and</strong> final chapter, I’ll discuss a few other techniques for optimizing 3D, along with<br />

<strong>Processing</strong>’s virtual camera <strong>and</strong> lighting functions.<br />

3D<br />

671<br />

13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!