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 Cone extends Geometry
- {
- private boolean isDefault = true;
-
- private float _radius = 1;
- private float _height = 2;
- private boolean _side = true;
- private boolean _bottom = true;
-
- // constructor builds a default box node
- public Cone()
- {
- Browser b = Browser.getBrowser();
-
- if(b == null)
- return;
-
- node = b.createVrmlFromString("Cone {}")[0];
- }
-
- public Cone(Browser b)
- {
- if(b == null)
- return;
-
- node = b.createVrmlFromString("Cone {}")[0];
- }
-
- public Cone(float radius,
- float height,
- boolean showSide,
- boolean showBottom)
- {
- String vrml_string = "Cone {";
-
- if(radius != 1)
- vrml_string += " bottomRadius " + radius;
-
- if(height != 2)
- vrml_string += " height " + height;
-
- if(!showSide)
- vrml_string += " side FALSE";
-
- if(!showBottom)
- vrml_string += "bottom FALSE";
-
- vrml_string += " }";
-
- Browser b = Browser.getBrowser();
-
- if(b != null)
- {
- node = b.createVrmlFromString(vrml_string)[0];
- have_browser = true;
- }
-
- _radius = radius;
- _height = height;
- _side = showSide;
- _bottom = showBottom;
-
- isDefault = false;
- }
-
- public Cone(Browser b,
- float radius,
- float height,
- boolean showSide,
- boolean showBottom)
- {
- String vrml_string = "Cone {";
-
- if(radius != 1)
- vrml_string += " bottomRadius " + radius;
-
- if(height != 2)
- vrml_string += " height " + height;
-
- if(!showSide)
- vrml_string += " side FALSE";
-
- if(!showBottom)
- vrml_string += "bottom FALSE";
-
- vrml_string += " }";
-
- if(b != null)
- {
- node = b.createVrmlFromString(vrml_string)[0];
- have_browser = true;
- }
-
- _radius = radius;
- _height = height;
- _side = showSide;
- _bottom = showBottom;
-
- isDefault = false;
- }
-
- public void finalize()
- {
- node = 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 + " ");
-
-
- if(isDefault)
- {
- fp.println("Cone {}");
- return;
- }
-
- fp.println("Cone {");
-
- if(_radius != 1)
- fp.println(buffer.toString() +
- " bottomRadius " +
- _radius);
-
- if(_height != 2)
- fp.println(buffer.toString() +
- " height " +
- _height);
- if(!_side)
- fp.println(buffer.toString() + " side FALSE");
-
- if(!_bottom)
- fp.println(buffer.toString() + " bottom FALSE ");
-
- fp.println(buffer.toString() + "}");
- }
- }
-