import javax.media.j3d.*; // Canvas3D etc import java.applet.Applet; // Applet import java.awt.BorderLayout; // BorderLayout, Frame import com.sun.j3d.utils.applet.MainFrame; // MainFrame import com.sun.j3d.utils.universe.*; import java.awt.Frame; import com.sun.j3d.utils.behaviors.mouse.*; import javax.vecmath.*; /* Started from Prog3 */ public class Universe extends Applet { public Universe() { setLayout ( new BorderLayout() ); Canvas3D c = new Canvas3D ( null ); add ( "Center", c ); BranchGroup scene = createSceneGraph(); SimpleUniverse u = new SimpleUniverse ( c ); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph ( scene ); } /* from SpinMouse.java */ public TransformGroup defaultMouseGroup() { TransformGroup mouseGroup = new TransformGroup(); mouseGroup.setCapability ( TransformGroup.ALLOW_TRANSFORM_READ ); mouseGroup.setCapability ( TransformGroup.ALLOW_TRANSFORM_WRITE ); BoundingSphere bounds = new BoundingSphere ( new Point3d ( 0.0, 0.0, 0.0 ), 100.0 ); //MouseDrag behavior1 = new MouseDrag ( mouseGroup ); MouseRotate behavior1 = new MouseRotate ( mouseGroup ); mouseGroup.addChild ( behavior1 ); behavior1.setSchedulingBounds ( bounds ); MouseZoom behavior2 = new MouseZoom ( mouseGroup ); mouseGroup.addChild ( behavior2 ); behavior2.setSchedulingBounds ( bounds ); MouseTranslate behavior3 = new MouseTranslate ( mouseGroup ); mouseGroup.addChild ( behavior3 ); behavior3.setSchedulingBounds ( bounds ); return mouseGroup; } public BranchGroup createSceneGraph() { Color3f red = new Color3f ( 1, 0, 0 ); Color3f green = new Color3f ( 0, 1, 0 ); Color3f blue = new Color3f ( 0, 0, 1 ); BranchGroup objRoot = new BranchGroup(); TransformGroup objTrans = defaultMouseGroup(); objRoot.addChild ( objTrans ); Helix h = new Helix(1,1); ParametricCurve3D x = new ParametricCurve3D(0,3,0.25f,h); objTrans.addChild ( x ); Axes a = new Axes(1,1,3); objTrans.addChild ( a ); Alpha alpha = new Alpha(-1,5000); TransformGroup tg = new TransformGroup (); tg.setCapability( TransformGroup.ALLOW_TRANSFORM_READ ); tg.setCapability( TransformGroup.ALLOW_TRANSFORM_WRITE ); objTrans.addChild ( tg ); tg.addChild ( new Axes(0.5f,0.5f,0.5f, green, red, blue ) ); tg.setTransform ( h.frameAt ( 0.5f ) ); FrameBehavior fb = new FrameBehavior ( alpha, h, 3.0f, tg ); fb.setSchedulingBounds( new BoundingSphere(new Point3d(0,0,0), 100) ); objTrans.addChild ( fb ); return objRoot; } public static void main ( String[] args ) { Frame frame = new MainFrame ( new Universe(), 256, 256 ); } }