home *** CD-ROM | disk | FTP | other *** search
- // VRML Generator
- // Copyright Justin Couch 1996
- //
- // Chapter 13: Late Night VRML 2.0 and Java
- //
- // Box class
-
- package geometry;
-
- import java.io.*;
- import java.awt.*;
- import vrml.external.*;
- import vrml.external.field.*;
- import vrml.external.exception.*;
- import geometry.Geometry;
-
- public class Box extends Geometry
- {
- private float[] size = null;
-
- // constructor builds a default box node
- public Box()
- {
- Browser b = Browser.getBrowser();
-
- if(b == null)
- return;
-
- node = b.createVrmlFromString("Box {}")[0];
- }
-
- public Box(Browser b)
- {
- if(b == null)
- return;
-
- node = b.createVrmlFromString("Box {}")[0];
- }
-
- public Box(float x, float y, float z)
- {
- Browser b = Browser.getBrowser();
-
- size = new float[3];
-
- size[0] = x;
- size[1] = y;
- size[2] = z;
-
- if(b == null)
- return;
-
- node = b.createVrmlFromString("Box { size " +
- x + " " +
- y + " " +
- z + "}")[0];
- have_browser = true;
- }
-
- public Box(Browser b, float x, float y, float z)
- {
- size = new float[3];
-
- size[0] = x;
- size[1] = y;
- size[2] = z;
-
- if(b == null)
- return;
-
- node = b.createVrmlFromString("Box { size " +
- x + " " +
- y + " " +
- z + "}")[0];
- have_browser = true;
- }
-
- public void finalize()
- {
- node = null;
- size = null;
- }
-
- public void writeToFile(PrintStream fp, int indent)
- {
- int i;
- StringBuffer buffer = new StringBuffer();
-
- for(i = 0; i < indent; i++)
- buffer.append(" ");
-
- fp.print(buffer.toString() + "geometry ");
- if(name != null)
- fp.print("DEF " + name + " ");
-
- fp.print("Box {");
-
- if(size != null)
- fp.print(" size " +
- size[0] + " " +
- size[1] + " " +
- size[2]);
-
- fp.println("}");
- }
- }
-