TwistStripApppublic class TwistStripApp extends Applet
Constructors Summary |
---|
public TwistStripApp()
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config);
add("Center", canvas3D);
BranchGroup scene = createSceneGraph();
// SimpleUniverse is a Convenience Utility class
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene);
|
Methods Summary |
---|
public BranchGroup | createSceneGraph()
BranchGroup contentRoot = new BranchGroup();
// Create the transform group node and initialize it to the
// identity. Add it to the root of the subgraph.
TransformGroup objSpin = new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
contentRoot.addChild(objSpin);
Shape3D twist = new Twist();
objSpin.addChild(twist);
// Duplicate the twist strip geometry and set the
// appearance of the new Shape3D object to line mode
// without culling.
// Add the POLYGON_FILLED and POLYGON_LINE strips
// in the scene graph at the same point.
// This will show the triangles of the original Mobius strip that
// are clipped. The PolygonOffset is set to prevent stitching.
PolygonAttributes polyAttrib = new PolygonAttributes();
polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
polyAttrib.setPolygonMode(PolygonAttributes.POLYGON_LINE);
polyAttrib.setPolygonOffset(0.001f);
Appearance polyAppear = new Appearance();
polyAppear.setPolygonAttributes(polyAttrib);
objSpin.addChild(new Shape3D(twist.getGeometry(), polyAppear));
Alpha rotationAlpha = new Alpha(-1, 16000);
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, objSpin);
// a bounding sphere specifies a region a behavior is active
// create a sphere centered at the origin with radius of 1
BoundingSphere bounds = new BoundingSphere();
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);
// make background white
Background background = new Background(1.0f, 1.0f, 1.0f);
background.setApplicationBounds(bounds);
contentRoot.addChild(background);
// Let Java 3D perform optimizations on this scene graph.
contentRoot.compile();
return contentRoot;
| public static void | main(java.lang.String[] args)
System.out.println("TwistStripApp - Java 3D API");
System.out.println("This program demonstrates back face culling.");
System.out.print("In this program two visual objects rotate, ");
System.out.println("one wireframe and one solid surface.");
System.out.print("The wire frame is visible only when components");
System.out.println(" of the surface are culled.");
Frame frame = new MainFrame(new TwistStripApp(), 256, 256);
|
|