import javax.media.j3d.*; import javax.vecmath.*; import com.sun.j3d.utils.geometry.*; /** * Adds a Sphere to the scene graph */ public class SphereBranch extends TransformGroup { Appearance appear = new Appearance(); Material material = new Material(); static final int NUM_DIVISIONS = 128; private Appearance createAppearance() { material.setCapability(Material.ALLOW_COMPONENT_WRITE); appear.setCapability(Appearance.ALLOW_MATERIAL_WRITE); appear.setCapability(Appearance.ALLOW_MATERIAL_READ); appear.setMaterial(material); ColoringAttributes colorAtt = new ColoringAttributes(); colorAtt.setColor(new Color3f(1.0f, 0.0f,0.0f)); colorAtt.setShadeModel(ColoringAttributes.SHADE_GOURAUD); appear.setColoringAttributes(colorAtt); return appear; } public Material getMaterial() { return material; } public SphereBranch() { addChild(new Sphere(0.9f, Sphere.GENERATE_NORMALS, NUM_DIVISIONS, createAppearance())); Transform3D translate = new Transform3D(); getTransform(translate); translate.setTranslation(new Vector3d(-1.0, 0.0, -1.0)); setTransform(translate); } } // SphereBranch