com.brackeen.javagamebook.graphics3D
Class ZBuffer

java.lang.Object
  extended bycom.brackeen.javagamebook.graphics3D.ZBuffer

public class ZBuffer
extends java.lang.Object

The ZBuffer class implements a z-buffer, or depth-buffer, that records the depth of every pixel in a 3D view window. The value recorded for each pixel is the inverse of the depth (1/z), so there is higher precision for close objects and a lower precision for far-away objects (where high depth precision is not as visually important).


Constructor Summary
ZBuffer(int width, int height)
          Creates a new z-buffer with the specified width and height.
 
Method Summary
 boolean checkDepth(int offset, short depth)
          Checks the depth at the specified offset, and if the specified depth is lower (is greater than or equal to the current depth at the specified offset), then the depth is set and this method returns true.
 void clear()
          Clears the z-buffer.
 short[] getArray()
          Gets the array used for the depth buffer
 int getHeight()
          Gets the height of this z-buffer.
 int getWidth()
          Gets the width of this z-buffer.
 void setDepth(int offset, short depth)
          Sets the depth of the pixel at at specified offset, overwriting its current depth.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZBuffer

public ZBuffer(int width,
               int height)
Creates a new z-buffer with the specified width and height.

Method Detail

getWidth

public int getWidth()
Gets the width of this z-buffer.


getHeight

public int getHeight()
Gets the height of this z-buffer.


getArray

public short[] getArray()
Gets the array used for the depth buffer


clear

public void clear()
Clears the z-buffer. All depth values are set to 0.


setDepth

public void setDepth(int offset,
                     short depth)
Sets the depth of the pixel at at specified offset, overwriting its current depth.


checkDepth

public boolean checkDepth(int offset,
                          short depth)
Checks the depth at the specified offset, and if the specified depth is lower (is greater than or equal to the current depth at the specified offset), then the depth is set and this method returns true. Otherwise, no action occurs and this method returns false.