home *** CD-ROM | disk | FTP | other *** search
/ Late Night VRML 2.0 with Java CD-ROM / code.zip / Ch13 / nff / Vertex.java < prev   
Text File  |  1996-11-27  |  2KB  |  62 lines

  1. // A class for NFF vertices
  2.  
  3. // Written by Bernie Roehl, November 1996
  4.  
  5. package nff;
  6.  
  7. import java.io.*;
  8. import java.util.*;
  9.  
  10. public class Vertex {
  11.     protected Vec3f position;
  12.     protected Vec3f normal;
  13.     protected boolean use_default_normal = false;
  14.     protected Color color;
  15.     protected Float u, v;
  16.     protected boolean has_texture = false;
  17.  
  18.     public Vec3f getPosition() { return position; }
  19.     public Vec3f getNormal() { return normal; }
  20.     public float getU() { return (u == null) ? 0 : u.floatValue(); }
  21.     public float getV() { return (v == null) ? 0 : v.floatValue(); }
  22.     public Color getColor() { return color; }
  23.     public boolean hasTexture() { return has_texture; }
  24.     public boolean useDefaultNormal() { return use_default_normal; }
  25.  
  26.     public void dump() {
  27.         if (position != null)
  28.             System.out.print(position);
  29.         if (color != null)
  30.            System.out.print(" rgb = " + color);
  31.         if (u != null && v != null)
  32.            System.out.print(" uv = " + u + " " + v);
  33.         if (normal != null)
  34.            System.out.print(" normal = " + normal);
  35.         else if (use_default_normal)
  36.            System.out.print(" default_normal");
  37.         System.out.println();
  38.     }
  39.  
  40.     public Vertex(CommentStripperInputStream input)
  41.        throws IOException, NffSyntaxException  {
  42.        String line = input.readLine();
  43.        StringTokenizer s = new StringTokenizer(line);
  44.        position = new Vec3f(s);
  45.        while (s.hasMoreTokens()) {
  46.            String token = s.nextToken();
  47.            if (token.equals("norm"))
  48.                normal = new Vec3f(s);
  49.            else if (token.equals("N"))
  50.                use_default_normal = true;
  51.            else if (token.equals("rgb"))
  52.                color = new Color(s.nextToken());
  53.            else if (token.equals("uv")) {
  54.                u = new Float(s.nextToken());
  55.                v = new Float(s.nextToken());
  56.                has_texture = true;
  57.            } 
  58.        }
  59.     }
  60. }
  61.  
  62.