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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Lights<br />

The Lights section includes functions for controlling subtle, yet very important, aspects of<br />

3D rendering. In general, lighting in 3D is modeled on the real world <strong>and</strong> the concept of<br />

placing real lights in a space. The virtual camera is a similar such construct. Of course, in<br />

<strong>Processing</strong>, all the lights are virtual, <strong>and</strong> really just a bunch of pixel color calculations. That<br />

being said, just as in the real world, virtual lights can have direction, falloff (how far <strong>and</strong><br />

intensely they illuminate), color, cone angles (in the case of spotlights), <strong>and</strong> overall spatial<br />

illumination (in the case of ambient light). Lighting is one of the key research areas in 3D,<br />

<strong>and</strong> has an enormous impact on the overall quality of rendering.<br />

Camera<br />

Camera functions control the virtual camera that you view the virtual world through. This<br />

might sound like an odd concept if you haven’t played with any 3D applications. A “real”<br />

3D projection is impossible on a flat 2D monitor, so ultimately all the 3D spatial calculations<br />

need to be converted, or projected, back to the 2D Cartesian system. This translation<br />

is one of the aspects that makes 3D complicated. During this geometric flattening (which<br />

usually happens in real time), different algorithms can be applied that control how we<br />

view the implied 3D space. For example, one of the most common approaches is to try to<br />

simulate the effects of perspective, similar to how we, with our binocular vision, experience<br />

the real world.<br />

Based on the rules of perspective, objects get smaller as they go back in space, <strong>and</strong> in a<br />

one-point perspective system, lines going into the distance converge. When objects get<br />

close to us <strong>and</strong> appear very large, distortions such as a fish-eye effect can occur. We can<br />

easily simulate these types of effects in 3D—that is, with a lot of math. Conversely, we can<br />

also create a more synthetic, or orthogonal, projection, in which there is no perspective.<br />

This is quite useful for precisely modeling geometry, where you might need to work with a<br />

set of undistorted 2D projections—for example, in an engineering application. Perspective<br />

looks good, but it is often hard to know precisely where you are (actually, where the cursor<br />

is) when working in this mode.<br />

Virtual cameras also utilize a viewing volume <strong>and</strong> clipping planes that specify minimum<br />

<strong>and</strong> maximum values for the x-, y-, <strong>and</strong> z-axes. Normally, only stuff within the camera’s<br />

viewing volume, called the frustum, can be seen. The boundaries of the frustum are called<br />

the clipping planes. If the clipping planes are not set correctly, imagery can disappear <strong>and</strong><br />

appear unexpectedly. However, without any clipping, geometry not visible within the camera’s<br />

view can get rendered, which is obviously a waste of memory. Finally, as the virtual<br />

camera is not bound by the physics of the real world, it has the ability to produce highly<br />

distorted <strong>and</strong> strange effects. This can be an interesting thing to experiment with, but also<br />

a potential source of frustration—especially when you don’t want it to happen (or can’t<br />

track down the problem).<br />

Coordinates<br />

The Coordinates section includes six (conceptually) advanced functions that return coordinate<br />

values. The six functions are modelZ(), modelX(), modelY(), screenZ(), screenX(),<br />

PROCESSING LANGUAGE API<br />

719<br />

A

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

Saved successfully!

Ooh no, something went wrong!