home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch12
/
geometry
/
Cylinder.java
< prev
next >
Wrap
Text File
|
1997-01-02
|
3KB
|
176 lines
// 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 Cylinder extends Geometry
{
private boolean isDefault = true;
private float _radius = 1;
private float _height = 2;
private boolean _side = true;
private boolean _top = true;
private boolean _bottom = true;
// constructor builds a default box node
public Cylinder()
{
Browser b = Browser.getBrowser();
if(b == null)
return;
node = b.createVrmlFromString("Cylinder {}")[0];
}
public Cylinder(Browser b)
{
if(b == null)
return;
node = b.createVrmlFromString("Cylinder {}")[0];
}
public Cylinder(float radius,
float height,
boolean showSide,
boolean showTop,
boolean showBottom)
{
String vrml_string = "Cylinder {";
if(radius != 1)
vrml_string += " bottomRadius " + radius;
if(height != 2)
vrml_string += " height " + height;
if(!showSide)
vrml_string += " side FALSE";
if(!showTop)
vrml_string += " top 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;
_top = showTop;
_bottom = showBottom;
isDefault = false;
}
public Cylinder(Browser b,
float radius,
float height,
boolean showSide,
boolean showTop,
boolean showBottom)
{
String vrml_string = "Cylinder {";
if(radius != 1)
vrml_string += " bottomRadius " + radius;
if(height != 2)
vrml_string += " height " + height;
if(!showSide)
vrml_string += " side FALSE";
if(!showTop)
vrml_string += " top 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;
_top = showTop;
_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("Cylinder {}");
return;
}
fp.println("Cylinder {");
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(!_top)
fp.println(buffer.toString() + " top FALSE");
if(!_bottom)
fp.println(buffer.toString() + " bottom FALSE ");
fp.println(buffer.toString() + "}");
}
}