8.2.6 Primitives and the geometry cache The Primitive-derived
//load or do something to the image here //wrap the BufferedImage in an ImageComponent2D ImageComponent2D imageComponent2D = new ImageComponent2D( ImageComponent2D.FORMAT_RGB, bufferedImage); imageComponent2D.setCapability( ImageComponent.ALLOW_IMAGE_READ ); imageComponent2D.setCapability( ImageComponent.ALLOW_SIZE_READ ); //create the Raster for the image m_RenderRaster = new Raster( new Point3f( 0.0f, 0.0f, 0.0f ), Raster.RASTER_COLOR, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), imageComponent2D, null ); m_RenderRaster.setCapability( Raster.ALLOW_IMAGE_WRITE ); m_RenderRaster.setCapability( Raster.ALLOW_SIZE_READ ); //wrap the Raster in a Shape3D Shape3D shape = new Shape3D( m_RenderRaster ); 8.4.2 Retrieving scene depth components using a Raster The other, more unusual, application for a Rasteris 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 postSwapmethod to retrieve the contents of the Z-buffer for the scene using a Rasterobject. The Z-buffer Rasteris then used to dynamically update an image Rasterso that the depth components can be rendered graphically. The output from the RasterTestillustrating 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 117
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services