Example 23.19: The Sphere subclass
Finally Example 23.19 covers the last predefined shape in VRML, the sphere. This one's a little simpler because spheres are a little simpler. It only has a radius field.
package elharo.vrml;
public class Sphere extends shape {
double radius = 1.0;
public Sphere (double radius) {
this.radius = radius;
}
public Sphere ( double x,
double y, double z, double radius) {
this.x = x;
this.y = y;
this.z = z;
this.radius = radius;
}
public void sizeTo(double radius) {
this.radius = radius;
}
public void sizeRelative(double radius) {
this.radius += radius;
}
public String draw() {
String node1 = "Translation { \n" +
"translation " + x + " " + y + " " + z +
"\n}\n\n";
String node2 = "Cylinder {\n" +
" radius " + radius +
"\n}\n\n";
String node3 = "Translation { \n" +
" translation " + -x + " " + -y + " " + -z +
"\n" + "}\n\n";
return node1 + node2 + node3;
}
}
Copyright 1996 Elliotte Rusty Harold
elharo@sunsite.unc.edu
This Chapter
Examples
Home