home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch13 / hash / ControlPoint.java < prev    next >
Text File  |  1997-01-14  |  4KB  |  82 lines

  1. // A single AnimationMaster spline control point
  2.  
  3. // Written by Bernie Roehl, November 1996
  4.  
  5. package hash;
  6.  
  7. import java.io.*;
  8. import java.util.*;
  9.  
  10. public class ControlPoint {
  11.         protected int cpid;
  12.         protected boolean smooth;
  13.         protected boolean loop;
  14.         protected boolean attach;
  15.         protected int attached_cpid;
  16.         protected double x, y, z;
  17.         protected double outalpha, outgamma, outmag;
  18.         protected double inalpha, ingamma, inmag;
  19.  
  20.         public int getCPID() { return cpid; }
  21.         public boolean isSmooth() { return smooth; }
  22.         public boolean isLooped() { return loop; }
  23.         public boolean isAttached() { return attach; }
  24.         public int getAttachedCPID() { return attached_cpid; }
  25.         public double getX() { return x; }
  26.         public double getY() { return y; }
  27.         public double getZ() { return z; }
  28.  
  29.         public void dump() {
  30.                 System.out.println("  CPID = " + cpid + " smooth = " + smooth
  31.                         + " loop = " + loop + " attach = " + attach);
  32.                 if (attach) System.out.println("  attached_cpid = " + attached_cpid);
  33.                 else System.out.println("  x = " + x + " y = " + y + " z = " + z);
  34.                 System.out.print("  in: " + inalpha + " " + ingamma + " " + inmag);
  35.                 System.out.println("   out: " + outalpha + " " + outgamma + " " + outmag);
  36.         }
  37.  
  38.         public ControlPoint(DataInputStream input)
  39.                 throws IOException, HashSyntaxException {
  40.                 StringTokenizer s;
  41.  
  42.                 s = new StringTokenizer(input.readLine());
  43.                 if (s.countTokens() != 3)
  44.                         throw new HashSyntaxException("missing fields on spline point header");
  45.                 int type = Integer.parseInt(s.nextToken());
  46.                 smooth = ((type & 0x01) != 0) ? true : false;
  47.                 loop = ((type & 0x04) != 0) ? true : false;
  48.                 attach = (Integer.parseInt(s.nextToken()) != 0) ? true : false;
  49.                 cpid = Integer.parseInt(s.nextToken());
  50.  
  51.                 if (attach)
  52.                         attached_cpid = Integer.parseInt(input.readLine());
  53.                 else {
  54.                         s = new StringTokenizer(input.readLine());
  55.                         if (s.countTokens() != 3)
  56.                                 throw new HashSyntaxException("missing fields in spline point x,y,z line");
  57.                         x = Float.valueOf(s.nextToken()).floatValue();
  58.                         y = Float.valueOf(s.nextToken()).floatValue();
  59.                         z = Float.valueOf(s.nextToken()).floatValue();
  60.                 }
  61.  
  62.                 s = new StringTokenizer(input.readLine());
  63.                 outalpha = (new Float(s.nextToken())).floatValue();
  64.                 outmag = 100;  // default value
  65.                 if (s.hasMoreTokens()) {
  66.                         outgamma = Float.valueOf(s.nextToken()).floatValue();
  67.                         if (s.hasMoreTokens())
  68.                                 outmag = Float.valueOf(s.nextToken()).floatValue();
  69.                 }
  70.  
  71.                 s = new StringTokenizer(input.readLine());
  72.                 inalpha = Float.valueOf(s.nextToken()).floatValue();
  73.                 inmag = 100;  // default value
  74.                 if (s.hasMoreTokens()) {
  75.                         ingamma = Float.valueOf(s.nextToken()).floatValue();
  76.                         if (s.hasMoreTokens())
  77.                                 inmag = Float.valueOf(s.nextToken()).floatValue();
  78.                 }
  79.         }
  80. }
  81.  
  82.