// Wendy Chien
// Recitation F11
// Project 4

// This is code supplied in class.  There are two new functions
// which make it a little easier to access the values in the Z buffer.
// (setZ and getZ)

import java.awt.*;
import Raster;

public class ZRaster extends Raster {
  public final static int MAXZ = (1 << 16) - 1;
  public int zbuff[];
  
  ///////////////////////// Constructors //////////////////////
  
  /**
   *  This constructor which takes no arguments
   *  allows for future extension.
   */
  public ZRaster()
  {
  }
  
  /**
   *  This constructor creates an uninitialized
     *  Raster Object of a given size (w x h).
     */
  public ZRaster(int w, int h)
  {
    super(w, h);
    zbuff = new int[w*h];
  }
  
  /**
   *  This constructor creates an Raster initialized
   *  with the contents of an image.
   */
  public ZRaster(Image img)
  {
    super(img);
    zbuff = new int[this.size()];
  }
  
  /**
   *    Set all z values in the zbuffer
   *    to the maximum value
   */
  public final void resetz()
  {
    for (int i = 0; i < zbuff.length; i++)
      zbuff[i] = MAXZ;
  }

  public float getZ(int x, int y) {
    return (zbuff[y*width+x]);
  }

  public void setZ(int z, int x, int y) {
    zbuff[y*width+x] = z;
  }

}

