home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Late Night VRML 2.0 with Java CD-ROM
/
code.zip
/
Ch12
/
geometry
/
Sphere.java
< prev
next >
Wrap
Text File
|
1997-01-02
|
1KB
|
89 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 Sphere extends Geometry
{
private float _radius = 1;
// constructor builds a default box node
public Sphere()
{
Browser b = Browser.getBrowser();
if(b == null)
return;
node = b.createVrmlFromString("Sphere {}")[0];
}
public Sphere(Browser b)
{
if(b == null)
return;
node = b.createVrmlFromString("Sphere {}")[0];
}
public Sphere(float radius)
{
_radius = radius;
Browser b = Browser.getBrowser();
if(b == null)
return;
String tmp = "Sphere { radius " + radius + " }";
node = b.createVrmlFromString(tmp)[0];
}
public Sphere(Browser b, float radius)
{
_radius = radius;
if(b == null)
return;
String tmp = "Sphere { radius " + radius + " }";
node = b.createVrmlFromString(tmp)[0];
}
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 + " ");
fp.print("Sphere {");
if(_radius != 1)
fp.print(" radius " + _radius + " ");
fp.println("}");
}
}