< Zurück | Inhalt | Weiter >

8.4.2 Retrieving scene depth components using a Raster

The other, more unusual, application for a Raster is to use it to retrieve the depth components of the 3D scene. These are stored in the Z−buffer, a multibyte array that stores the depth into the scene for each rendered pixel. The depth to the first occurrence of geometry is stored in the Z−buffer, and floating point values are scaled such that the closest value to the user is zero while the farthest value is one.

Querying the Z−buffer directly is quite uncommon, but may be useful for such application−specific functionality as hit testing or rendering.

The following example illustrates overriding the Canvas3D postSwap method to retrieve the contents of the Z−buffer for the scene using a Raster object. The Z−buffer Raster is then used to

dynamically update an image Raster so that the depth components can be rendered graphically. The output from the RasterTest illustrating this technique is shown in figure 8.9.


Figure 8.9

Two frames from RasterTest. Each frame contains a rotating cube and a Raster displaying the depth components of the entire frame. The Raster is visible because it also has a depth component


From RasterTest.java