home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch13 / quake / Skin.java < prev    next >
Text File  |  1996-11-17  |  2KB  |  48 lines

  1. // Skin for an MDL file from Quake
  2.  
  3. // Written by Bernie Roehl, November 1996
  4.  
  5. package quake;
  6.  
  7. import java.io.*;
  8.  
  9. public class Skin {
  10.         protected int height, width;
  11.         protected int npictures;
  12.         protected float[] times;
  13.         protected byte[][] pixels;
  14.  
  15.         public int getHeight() { return height; }
  16.         public int getWidth() { return width; }
  17.         public int getNumberOfPictures() { return npictures; }
  18.         public float getTime(int n) { return times[n]; }
  19.         public byte[] getPicture(int n) { return pixels[n]; }
  20.  
  21.         public byte getPixel(int picture, int horiz, int vert) {
  22.                 return pixels[picture][vert * width + horiz];
  23.         }
  24.  
  25.         public Skin(ByteFlipInputStream input, int w, int h) throws IOException {
  26.                 height = h;
  27.                 width = w;
  28.                 if (input.readFlippedInt() == 0) {
  29.                         npictures = 1;
  30.                         times = new float[1];
  31.                         times[0] = 0;
  32.                         pixels = new byte[1][height*width];
  33.                         input.read(pixels[0]);
  34.                 }
  35.                 else {
  36.                         npictures = input.readFlippedInt();
  37.                         times = new float[npictures];
  38.                         for (int i = 0; i < npictures; ++i)
  39.                                 times[i] = input.readFlippedFloat();
  40.                         pixels = new byte[npictures][height*width];
  41.                         for (int i = 0; i < npictures; ++i)
  42.                                 input.read(pixels[i]);
  43.                 }
  44.         }
  45. }
  46.  
  47.  
  48.