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.

PROCESSING: CREATIVE CODING AND COMPUTATIONAL ART<br />

720<br />

<strong>and</strong> screenY(). The model functions return the 3D coordinates in model space, which<br />

means the coordinate values after they’ve been transformed (rotated, scaled, <strong>and</strong>/or<br />

moved), but before they’re projected to the screen. In contrast, the screen functions<br />

return 3D coordinates in relation to screen space. If you’ve never worked in 3D, this may<br />

sound pretty confusing. Remember, computer-generated 3D simulates space, as everything<br />

really lives on the 2D screen surface. To simulate real space, geometry must be<br />

shifted around to give the illusion of perspective, depth layering, <strong>and</strong> so forth. The actual<br />

3D coordinate geometry we generate ultimately has to be mapped to the space of our 2D<br />

screens, taking into account any perspective calculations. This concept is most abstract in<br />

reference to the z-axis, which doesn’t really exist at all on the screen. Yet, when we work<br />

in 3D, geometry is calculated at specific locations on this illusory axis. To visualize the concept<br />

of screen coordinates vs. model coordinates, think about the classic one-point perspective<br />

image of railroad tracks receding into the distance to a point. In reality, of course,<br />

the tracks remain parallel <strong>and</strong> never actually converge—which you can think of as their<br />

model coordinates (the actual geometry). But visually, the receding tracks are no longer<br />

parallel, <strong>and</strong> these illusory coordinates can be thought of as their screen coordinates.<br />

Material Properties<br />

The Material Properties section includes four functions:<br />

shininess()<br />

specular()<br />

ambient()<br />

emissive()<br />

These functions control how object surfaces interact with the light in the scene. For example,<br />

glossy <strong>and</strong> reflective surfaces have concentrated areas of light, sometimes referred to<br />

as hotspots; think about the small, intense light spots on the surface of an eyeball, or how<br />

light reflects off of a highly polished piece of chrome. This light phenomenon is referred<br />

to as specularity. The specular() function controls the color of these hotspots.<br />

Ambient light, on the other h<strong>and</strong>, refers to more general <strong>and</strong> overall lighting—think about<br />

the light in a dense forest or in a room without a direct light source. The ambient() function<br />

controls the color of the ambient light. Like the other rendering attribute functions,<br />

the material functions affect the rendering state as well as the light functions. Once a<br />

material function (e.g., shininess()) is called, its influence will be felt by all future surfaces<br />

created in the scene, until another explicit call to the material function (using different<br />

rendering attributes) is made.<br />

To give an example that involves the Lights, Camera section of the API, I developed a 3D<br />

flythrough sketch that utilizes a lot of the features I’ve been discussing. (This is another<br />

complex sketch that I put in more for inspiration <strong>and</strong> pleasure than your edification—but<br />

it is cool, <strong>and</strong> will still be useful for you to take apart <strong>and</strong> experiment with.)<br />

The example (shown in Figure A-14) utilizes two images that need to be put within the<br />

sketch’s data directory. The images need to be named ground2.jpg <strong>and</strong> metal2.jpg, <strong>and</strong> I<br />

recommend making them around 400 by 400 pixels. If the example runs slowly on your

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

Saved successfully!

Ooh no, something went wrong!