FileDocCategorySizeDatePackage
Text2DApp.javaAPI DocExample6789Fri Sep 22 15:08:06 BST 2000None

Text2DApp

public class Text2DApp extends Applet

Fields Summary
Constructors Summary
public Text2DApp()

        setLayout(new BorderLayout());
        GraphicsConfiguration config =
            SimpleUniverse.getPreferredConfiguration();

        Canvas3D canvas3D = new Canvas3D(config);
        canvas3D.setStereoEnable(false);
        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 BranchGroupcreateSceneGraph()


         // Create the root of the branch graph
         BranchGroup objRoot = 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);
         objRoot.addChild(objSpin);
 
         // Create a simple Text2D leaf node, add it to the scene graph.
         Text2D text2d = new Text2D("2D text in Java 3D", 
                                      new Color3f(0.9f, 1.0f, 1.0f), 
                                      "Helvetica", 24, Font.ITALIC);

         objSpin.addChild(text2d);

         Appearance textAppear = text2d.getAppearance();

// The following 4 lines of code (commented out) make the Text2D object
// 2-sided.
// This code depends on the line of code above that sets TextAppear.
//         PolygonAttributes polyAttrib = new PolygonAttributes();
//         polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
//         polyAttrib.setBackFaceNormalFlip(true);
//         textAppear.setPolygonAttributes(polyAttrib);


// The following 12 lines of code (commented out) use the texture from
// the previous Text2D object on another object.
// This code depends on the line of code above that sets TextAppear.
//         QuadArray qa = new QuadArray(4, QuadArray.COORDINATES |
//                                         QuadArray.TEXTURE_COORDINATE_2);
//         qa.setCoordinate(0, new Point3f(-10.0f, 1.0f, -5.0f));
//         qa.setCoordinate(1, new Point3f(-10.0f, -1.0f, -5.0f));
//         qa.setCoordinate(2, new Point3f(10.0f, -1.0f, -5.0f));
//         qa.setCoordinate(3, new Point3f(10.0f, 1.0f, -5.0f));
//         qa.setTextureCoordinate(0, new Point2f(0.0f, 1.0f));
//         qa.setTextureCoordinate(1, new Point2f(0.0f, 0.0f));
//         qa.setTextureCoordinate(2, new Point2f(1.0f, 0.0f));
//         qa.setTextureCoordinate(3, new Point2f(1.0f, 1.0f));
//
//         objRoot.addChild(new Shape3D(qa, textAppear));
 
         // Create a new Behavior object that will perform the desired
         // operation on the specified transform object and add it into
         // the scene graph.
         Alpha rotationAlpha = new Alpha(-1, 8000);
  
         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 100
         BoundingSphere bounds = new BoundingSphere();
         rotator.setSchedulingBounds(bounds);
         objSpin.addChild(rotator);

         Background backg = new Background();
         backg.setColor(0.4f, 0.4f, 1.0f);
         backg.setApplicationBounds(new BoundingSphere());
         objRoot.addChild(backg);
 
         return objRoot;
     
public static voidmain(java.lang.String[] args)

        System.out.println("Text2DApp.java - a demonstration of Text2D in Java 3D");
        System.out.println("The scene is of a rotating Text2D object.");
        System.out.print("If you don't have a 3D card, it may take a few seconds ");
        System.out.println("before you see anything.");
        System.out.println("The Java 3D Tutorial is available on the web at:");
        System.out.println("http://java.sun.com/products/java-media/3D/collateral");
        Frame frame = new MainFrame(new Text2DApp(), 256, 32);