public MovingLight() {
    // Mechanism for closing the window and ending the program.
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Default settings for the viewer parameters.
    myCanvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());

    // Construct the SimpleUniverse:
    // First generate it using the Canvas.
    SimpleUniverse simpUniv = new SimpleUniverse(myCanvas3D);

    // Default position of the viewer.
    simpUniv.getViewingPlatform().setNominalViewingTransform();

    // The scene is generated in this method.
    createSceneGraph(simpUniv);

    // Add some light to the scene.
    addLight(simpUniv);

    // The following three lines enable navigation through the scene using the mouse.
    OrbitBehavior ob = new OrbitBehavior(myCanvas3D);
    ob.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Double.MAX_VALUE));
    simpUniv.getViewingPlatform().setViewPlatformBehavior(ob);

    // Show the canvas/window.
    setTitle("A moving light source");
    setSize(700, 700);
    getContentPane().add("Center", myCanvas3D);
    setVisible(true);
  }
Example #2
0
  public ObjectViewer(URL url) {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    add("Center", canvas3D);

    BoundingSphere bounds = new BoundingSphere(new Point3d(), 1000);
    BranchGroup root = new BranchGroup();
    BranchGroup scene = createSceneGraph(url);
    scene.setBoundsAutoCompute(true);
    System.out.println(scene.getBounds());
    BoundingSphere sceneBounds = new BoundingSphere(scene.getBounds());

    SimpleUniverse univ = new SimpleUniverse(canvas3D);
    ViewingPlatform view = univ.getViewingPlatform();
    view.setNominalViewingTransform();

    Transform3D t = new Transform3D();
    TransformGroup viewTransform = view.getViewPlatformTransform();

    t.set(new Vector3d(0, 0, 3 * sceneBounds.getRadius()));
    viewTransform.setTransform(t);

    BranchGroup lights = new BranchGroup();
    Light light = new AmbientLight();
    light.setInfluencingBounds(bounds);
    lights.addChild(light);
    light = new DirectionalLight();
    light.setInfluencingBounds(bounds);
    lights.addChild(light);
    root.addChild(lights);

    TransformGroup tg = new TransformGroup();
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tg.addChild(scene);

    root.addChild(tg);

    MouseRotate mouse = new MouseRotate();
    mouse.setTransformGroup(tg);
    mouse.setSchedulingBounds(bounds);
    root.addChild(mouse);

    MouseZoom mousezoom = new MouseZoom();
    mousezoom.setTransformGroup(tg);
    mousezoom.setSchedulingBounds(bounds);
    root.addChild(mousezoom);

    Background background = new Background(1, 1, 1);
    background.setApplicationBounds(bounds);
    root.addChild(background);

    root.compile();

    univ.addBranchGraph(root);
  }
Example #3
0
  private Canvas3D createUniverse() {
    // Get the preferred graphics configuration for the default screen
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    // Create a Canvas3D using the preferred configuration
    Canvas3D c = new Canvas3D(config);

    // Create simple universe with view branch
    univ = new SimpleUniverse(c);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    univ.getViewingPlatform().setNominalViewingTransform();

    // Ensure at least 5 msec per frame (i.e., < 200Hz)
    univ.getViewer().getView().setMinimumFrameCycleTime(5);

    return c;
  }