HTML and CSS Reference
In-Depth Information
Figure 15-6. A bunch of rubber bouncy balls! (Trust me, it looks much better in motion.)
Wrapping
Recall in Chapter 6, we discussed three possible reactions when an object hits a boundary. We just
covered bouncing, and there was also wrapping and regeneration. For 3D, wrapping can be useful, but
primarily on the z axis.
In 2D wrapping, you check whether the object went off the screen on the x or y axis. This works pretty well,
because when the object goes beyond one of those boundaries, you can't see it anymore, so you can
easily reposition it without jarring the viewer's attention. You don't have that luxury in 3D.
In 3D wrapping, there are only two points where it's safe to remove and reposition an object. One is when
the object has gone behind the viewpoint. The previous examples test for this and make the object
invisible in such a case. The other is when the object is so far in the distance and shrunk to such a small
size that it's practically invisible. This means that you can safely wrap on the z axis. When something goes
behind you, you toss it way out in front of you, and let it come at you again. Or, if something has gone so
far out that you can barely see it, remove it and replace it behind you. If you want, you can try wrapping on
the x or y axis as well, but in most cases, you're going to wind up with an unnatural popping in and out of
existence effect.
It's worth mentioning, if an object has moved too far out of sight on the x or y axis, you can always
reposition it along the z-axis. This is not really screen wrapping, but can be an effective way to reuse
objects.
But z-axis wrapping can be useful, especially in 3D racing type games, and we'll create a basic setup here.
The idea is to place various 3D objects in front of the viewpoint, then, you move those objects toward the
viewpoint. In other words, you give them some negative z velocity. Depending on how you set it up, this
can either look like a lot of objects coming toward you, or it can trick the eye to look like you're moving
 
Search WWH ::




Custom Search