home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch13
/
nff
/
Vertex.java
< prev
Wrap
Text File
|
1996-11-27
|
2KB
|
62 lines
// A class for NFF vertices
// Written by Bernie Roehl, November 1996
package nff;
import java.io.*;
import java.util.*;
public class Vertex {
protected Vec3f position;
protected Vec3f normal;
protected boolean use_default_normal = false;
protected Color color;
protected Float u, v;
protected boolean has_texture = false;
public Vec3f getPosition() { return position; }
public Vec3f getNormal() { return normal; }
public float getU() { return (u == null) ? 0 : u.floatValue(); }
public float getV() { return (v == null) ? 0 : v.floatValue(); }
public Color getColor() { return color; }
public boolean hasTexture() { return has_texture; }
public boolean useDefaultNormal() { return use_default_normal; }
public void dump() {
if (position != null)
System.out.print(position);
if (color != null)
System.out.print(" rgb = " + color);
if (u != null && v != null)
System.out.print(" uv = " + u + " " + v);
if (normal != null)
System.out.print(" normal = " + normal);
else if (use_default_normal)
System.out.print(" default_normal");
System.out.println();
}
public Vertex(CommentStripperInputStream input)
throws IOException, NffSyntaxException {
String line = input.readLine();
StringTokenizer s = new StringTokenizer(line);
position = new Vec3f(s);
while (s.hasMoreTokens()) {
String token = s.nextToken();
if (token.equals("norm"))
normal = new Vec3f(s);
else if (token.equals("N"))
use_default_normal = true;
else if (token.equals("rgb"))
color = new Color(s.nextToken());
else if (token.equals("uv")) {
u = new Float(s.nextToken());
v = new Float(s.nextToken());
has_texture = true;
}
}
}
}