Example usage for javax.media.j3d Screen3D setPhysicalScreenWidth

List of usage examples for javax.media.j3d Screen3D setPhysicalScreenWidth

Introduction

In this page you can find the example usage for javax.media.j3d Screen3D setPhysicalScreenWidth.

Prototype

public void setPhysicalScreenWidth(double width) 

Source Link

Document

Sets the screen physical width in meters.

Usage

From source file:PrintFromButton.java

public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);

    ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage);
    buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);

    Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer,
            null);// w  w w  . j  a  v  a  2s.  c o m

    drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE);

    // create the main scene graph
    BranchGroup scene = createSceneGraph(drawRaster);

    // create the on-screen canvas
    Canvas3D d = new Canvas3D(config, false);
    add("Center", d);

    // create a simple universe
    u = new SimpleUniverse(d);

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

    // create an off Screen Buffer

    c = new OffScreenCanvas3D(config, true, drawRaster);

    // set the offscreen to match the onscreen
    Screen3D sOn = d.getScreen3D();
    Screen3D sOff = c.getScreen3D();
    sOff.setSize(sOn.getSize());
    sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth());
    sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight());

    // attach the same view to the offscreen canvas
    u.getViewer().getView().addCanvas3D(c);

    // create the gui
    Button b = new Button("Print");
    b.addActionListener(this);
    Panel p = new Panel();
    p.add(b);
    add("North", p);

    u.addBranchGraph(scene);
}

From source file:OffScreenTest.java

public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);

    ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage);
    buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ);

    Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer,
            null);//from  ww w  .  j  a  v  a2s .  c o m

    drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE);

    // create the main scene graph
    BranchGroup scene = createSceneGraph(drawRaster);

    // create the on-screen canvas
    OnScreenCanvas3D d = new OnScreenCanvas3D(config, false);
    add("Center", d);

    // create a simple universe
    u = new SimpleUniverse(d);

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

    // create an off Screen Canvas

    OffScreenCanvas3D c = new OffScreenCanvas3D(config, true, drawRaster);

    // set the offscreen to match the onscreen
    Screen3D sOn = d.getScreen3D();
    Screen3D sOff = c.getScreen3D();
    sOff.setSize(sOn.getSize());
    sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth());
    sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight());

    // attach the same view to the offscreen canvas
    View v = u.getViewer().getView();
    v.addCanvas3D(c);

    // tell onscreen about the offscreen so it knows to
    // render to the offscreen at postswap
    d.setOffScreenCanvas(c);

    u.addBranchGraph(scene);
    v.stopView();
    // Make sure that image are render completely
    // before grab it in postSwap().
    d.setImageReady();
    v.startView();

}

From source file:LineTypes.java

public void init() {

    // set up a NumFormat object to print out float with only 3 fraction
    // digits/*from   ww  w  . j  a  v  a  2s  .c  o m*/
    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(3);

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

    canvas = new Canvas3D(config);

    add("Center", canvas);

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();
    u = new SimpleUniverse(canvas);

    if (isApplication) {
        offScreenCanvas = new OffScreenCanvas3D(config, true);
        // set the size of the off-screen canvas based on a scale
        // of the on-screen size
        Screen3D sOn = canvas.getScreen3D();
        Screen3D sOff = offScreenCanvas.getScreen3D();
        Dimension dim = sOn.getSize();
        dim.width *= 1.0f;
        dim.height *= 1.0f;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale);

        // attach the offscreen canvas to the view
        u.getViewer().getView().addCanvas3D(offScreenCanvas);
    }

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

    view = u.getViewer().getView();

    add("South", guiPanel());
}

From source file:Human1.java

public void init() {

    // set up a NumFormat object to print out float with only 3 fraction
    // digits/*w  ww .  ja  va2 s . co  m*/
    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(3);

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

    canvas = new Canvas3D(config);

    add("Center", canvas);

    u = new SimpleUniverse(canvas);

    if (isApplication) {
        offScreenCanvas = new OffScreenCanvas3D(config, true);
        // set the size of the off-screen canvas based on a scale
        // of the on-screen size
        Screen3D sOn = canvas.getScreen3D();
        Screen3D sOff = offScreenCanvas.getScreen3D();
        Dimension dim = sOn.getSize();
        dim.width *= offScreenScale;
        dim.height *= offScreenScale;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale);

        // attach the offscreen canvas to the view
        u.getViewer().getView().addCanvas3D(offScreenCanvas);
    }

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();

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

    view = u.getViewer().getView();

    add("East", guiPanel());
}

From source file:PolygonOffset.java

public void init() {
    setLayout(new BorderLayout());

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    JPanel canvasPanel = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    canvasPanel.setLayout(gridbag);/*from  www .  j  av a  2  s.  co m*/

    canvas = new Canvas3D(config);
    canvas.setSize(600, 600);
    add(canvas, BorderLayout.CENTER);

    u = new SimpleUniverse(canvas);

    if (isApplication) {
        offScreenCanvas = new OffScreenCanvas3D(config, true);
        // set the size of the off-screen canvas based on a scale
        // of the on-screen size
        Screen3D sOn = canvas.getScreen3D();
        Screen3D sOff = offScreenCanvas.getScreen3D();
        Dimension dim = sOn.getSize();
        dim.width *= offScreenScale;
        dim.height *= offScreenScale;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale);

        // attach the offscreen canvas to the view
        u.getViewer().getView().addCanvas3D(offScreenCanvas);
    }

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();

    // set the eye at z = 2.0
    viewingPlatform = u.getViewingPlatform();
    Transform3D vpTrans = new Transform3D();
    vpTrans.set(new Vector3f(0.0f, 0.0f, 2.0f));
    viewingPlatform.getViewPlatformTransform().setTransform(vpTrans);

    // set up a parallel projection with clip limits at 1 and -1
    view = u.getViewer().getView();
    view.setProjectionPolicy(View.PARALLEL_PROJECTION);
    view.setFrontClipPolicy(View.VIRTUAL_EYE);
    view.setBackClipPolicy(View.VIRTUAL_EYE);
    view.setFrontClipDistance(1.0f);
    view.setBackClipDistance(3.0f);

    u.addBranchGraph(scene);

    // set up the sliders
    JPanel guiPanel = new JPanel();
    guiPanel.setLayout(new GridLayout(0, 1));
    FloatLabelJSlider dynamicSlider = new FloatLabelJSlider("Dynamic Offset", 0.1f, 0.0f, 2.0f, dynamicOffset);
    dynamicSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            dynamicOffset = e.getValue();
            solidPa.setPolygonOffsetFactor(dynamicOffset);
        }
    });
    guiPanel.add(dynamicSlider);

    LogFloatLabelJSlider staticSlider = new LogFloatLabelJSlider("Static Offset", 0.1f, 10000.0f, staticOffset);
    staticSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            staticOffset = e.getValue();
            solidPa.setPolygonOffset(staticOffset);
        }
    });
    guiPanel.add(staticSlider);

    FloatLabelJSlider innerSphereSlider = new FloatLabelJSlider("Inner Sphere Scale", 0.001f, 0.90f, 1.0f,
            innerScale);
    innerSphereSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            innerScale = e.getValue();
            updateInnerScale();
        }
    });
    guiPanel.add(innerSphereSlider);

    if (isApplication) {
        JButton snapButton = new JButton("Snap Image");
        snapButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Point loc = canvas.getLocationOnScreen();
                offScreenCanvas.setOffScreenLocation(loc);
                Dimension dim = canvas.getSize();
                dim.width *= offScreenScale;
                dim.height *= offScreenScale;
                nf.setMinimumIntegerDigits(3);
                offScreenCanvas.snapImageFile(outFileBase + nf.format(outFileSeq++), dim.width, dim.height);
                nf.setMinimumIntegerDigits(0);
            }
        });
        guiPanel.add(snapButton);
    }
    add(guiPanel, BorderLayout.EAST);
}

From source file:EnvironmentExplorer.java

public void init() {
    // initialize the code base
    try {/*from w w  w .j  a v a 2 s  .  c  o m*/
        java.net.URL codeBase = getCodeBase();
        codeBaseString = codeBase.toString();
    } catch (Exception e) {
        // probably running as an application, try the application
        // code base
        codeBaseString = "file:./";
    }

    if (colorMode == USE_COLOR) {
        objColor = red;
    } else {
        objColor = white;
    }

    Container contentPane = getContentPane();

    contentPane.setLayout(new BorderLayout());

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    canvas = new Canvas3D(config);

    u = new SimpleUniverse(canvas);

    if (isApplication) {
        offScreenCanvas = new OffScreenCanvas3D(config, true);
        // set the size of the off-screen canvas based on a scale
        // of the on-screen size
        Screen3D sOn = canvas.getScreen3D();
        Screen3D sOff = offScreenCanvas.getScreen3D();
        Dimension dim = sOn.getSize();
        dim.width *= OFF_SCREEN_SCALE;
        dim.height *= OFF_SCREEN_SCALE;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * OFF_SCREEN_SCALE);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * OFF_SCREEN_SCALE);

        // attach the offscreen canvas to the view
        u.getViewer().getView().addCanvas3D(offScreenCanvas);

    }
    contentPane.add("Center", canvas);

    // setup the env nodes and their GUI elements
    setupLights();
    setupBackgrounds();
    setupFogs();
    setupSounds();

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();

    // set up sound
    u.getViewer().createAudioDevice();

    // get the view
    view = u.getViewer().getView();

    // Get the viewing platform
    ViewingPlatform viewingPlatform = u.getViewingPlatform();

    // Move the viewing platform back to enclose the -4 -> 4 range
    double viewRadius = 4.0; // want to be able to see circle
    // of viewRadius size around origin
    // get the field of view
    double fov = u.getViewer().getView().getFieldOfView();

    // calc view distance to make circle view in fov
    float viewDistance = (float) (viewRadius / Math.tan(fov / 2.0));
    tmpVector.set(0.0f, 0.0f, viewDistance);// setup offset
    tmpTrans.set(tmpVector); // set trans to translate
    // move the view platform
    viewingPlatform.getViewPlatformTransform().setTransform(tmpTrans);

    // add an orbit behavior to move the viewing platform
    OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.STOP_ZOOM);
    orbit.setSchedulingBounds(infiniteBounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    contentPane.add("East", guiPanel());
}

From source file:TransformExplorer.java

public void init() {

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

    canvas = new Canvas3D(config);
    add("Center", canvas);

    u = new SimpleUniverse(canvas);

    if (isApplication) {
        offScreenCanvas = new OffScreenCanvas3D(config, true);
        // set the size of the off-screen canvas based on a scale
        // of the on-screen size
        Screen3D sOn = canvas.getScreen3D();
        Screen3D sOff = offScreenCanvas.getScreen3D();
        Dimension dim = sOn.getSize();
        dim.width *= offScreenScale;/*from ww w . jav a 2 s .  c o m*/
        dim.height *= offScreenScale;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale);

        // attach the offscreen canvas to the view
        u.getViewer().getView().addCanvas3D(offScreenCanvas);
    }

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();

    // get the view
    view = u.getViewer().getView();

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

    // add an orbit behavior to move the viewing platform
    OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.STOP_ZOOM);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    add("East", guiPanel());
}

From source file:ViewProj.java

public void init() {
    setLayout(new BorderLayout());

    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(3);/*from   w w  w.  j a  v a 2s. co  m*/

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    JPanel canvasPanel = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    canvasPanel.setLayout(gridbag);

    canvas = new Canvas3D(config);
    canvas.setSize(400, 400);

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridwidth = 2;
    constraints.gridheight = 2;
    constraints.insets = new Insets(5, 5, 5, 5);
    constraints.fill = GridBagConstraints.BOTH;
    gridbag.setConstraints(canvas, constraints);
    canvasPanel.add(canvas);

    constraints.fill = GridBagConstraints.REMAINDER;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.gridx = 2;
    constraints.gridy = 0;
    urCanvas = new Canvas3D(config);
    urCanvas.setSize(200, 200);
    gridbag.setConstraints(urCanvas, constraints);
    canvasPanel.add(urCanvas);

    constraints.gridx = 2;
    constraints.gridy = 1;
    lrCanvas = new Canvas3D(config);
    lrCanvas.setSize(200, 200);
    gridbag.setConstraints(lrCanvas, constraints);
    canvasPanel.add(lrCanvas);

    add(canvasPanel, BorderLayout.NORTH);

    SimpleUniverse u = new SimpleUniverse(canvas);
    urUniverse = new SimpleUniverse(urCanvas);
    lrUniverse = new SimpleUniverse(lrCanvas);

    if (isApplication) {
        offScreenCanvas = new OffScreenCanvas3D(config, true);
        // set the size of the off-screen canvas based on a scale
        // of the on-screen size
        Screen3D sOn = canvas.getScreen3D();
        Screen3D sOff = offScreenCanvas.getScreen3D();
        Dimension dim = sOn.getSize();
        dim.width *= offScreenScale;
        dim.height *= offScreenScale;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale);

        // attach the offscreen canvas to the view
        u.getViewer().getView().addCanvas3D(offScreenCanvas);

        urOffScreenCanvas = new OffScreenCanvas3D(config, true);
        // set the size of the off-screen canvas based on a scale
        // of the on-screen size
        sOn = urCanvas.getScreen3D();
        sOff = urOffScreenCanvas.getScreen3D();
        dim = sOn.getSize();
        dim.width *= urOffScreenScale;
        dim.height *= urOffScreenScale;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * urOffScreenScale);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * urOffScreenScale);

        // attach the offscreen canvas to the view
        urUniverse.getViewer().getView().addCanvas3D(urOffScreenCanvas);

        lrOffScreenCanvas = new OffScreenCanvas3D(config, true);
        // set the size of the off-screen canvas based on a scale
        // of the on-screen size
        sOn = lrCanvas.getScreen3D();
        sOff = lrOffScreenCanvas.getScreen3D();
        dim = sOn.getSize();
        dim.width *= lrOffScreenScale;
        dim.height *= lrOffScreenScale;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * lrOffScreenScale);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * lrOffScreenScale);

        // attach the offscreen canvas to the view
        lrUniverse.getViewer().getView().addCanvas3D(lrOffScreenCanvas);
    }

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();

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

    view = u.getViewer().getView();
    view.setFrontClipPolicy(View.VIRTUAL_EYE);
    view.setBackClipPolicy(View.VIRTUAL_EYE);
    view.setFrontClipDistance(frontClipDist);
    view.setBackClipDistance(backClipDist);

    u.addBranchGraph(scene);

    // init the clipGridPts arrays
    for (int i = 0; i < maxClipGridPts; i++) {
        clipGridPtsVW[i] = new Point3f();
        clipGridPtsProj[i] = new Point3f();
    }

    // init the circlePts arrays
    for (int i = 0; i < numCirclePts; i++) {
        circlePtsVW[i] = new Point3f();
        circlePtsProj[i] = new Point3f();
    }

    // setup the ur canvas
    urScene = createVWorldViewSG();
    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    urUniverse.getViewingPlatform().setNominalViewingTransform();
    View urView = urUniverse.getViewer().getView();
    urView.setProjectionPolicy(View.PARALLEL_PROJECTION);
    urUniverse.addBranchGraph(urScene);
    // set up the background on a separate BG so that it can stay there
    // when we replace the scene SG
    Background urBgWhite = new Background(white);
    urBgWhite.setApplicationBounds(infiniteBounds);
    BranchGroup urBackBG = new BranchGroup();
    urBackBG.addChild(urBgWhite);
    urUniverse.addBranchGraph(urBackBG);

    // setup the lr canvas
    lrScene = createProjViewSG();
    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    lrUniverse.getViewingPlatform().setNominalViewingTransform();
    View lrView = lrUniverse.getViewer().getView();
    lrView.setProjectionPolicy(View.PARALLEL_PROJECTION);
    lrUniverse.addBranchGraph(lrScene);
    // set up the background on a separate BG so that it can stay there
    // when we replace the scene SG
    Background lrBgWhite = new Background(white);
    lrBgWhite.setApplicationBounds(infiniteBounds);
    BranchGroup lrBackBG = new BranchGroup();
    lrBackBG.addChild(lrBgWhite);
    lrUniverse.addBranchGraph(lrBackBG);

    // set up the sliders
    JPanel guiPanel = new JPanel();
    guiPanel.setLayout(new GridLayout(0, 2));
    FloatLabelJSlider dynamicSlider = new FloatLabelJSlider("Dynamic Offset", 0.1f, 0.0f, 2.0f, dynamicOffset);
    dynamicSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            dynamicOffset = e.getValue();
            solidPa.setPolygonOffsetFactor(dynamicOffset);
        }
    });
    guiPanel.add(dynamicSlider);

    LogFloatLabelJSlider staticSlider = new LogFloatLabelJSlider("Static Offset", 0.1f, 10000.0f, staticOffset);
    staticSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            staticOffset = e.getValue();
            solidPa.setPolygonOffset(staticOffset);
        }
    });
    guiPanel.add(staticSlider);

    // These are declared final here so they can be changed by the
    // listener routines below.
    LogFloatLabelJSlider frontClipSlider = new LogFloatLabelJSlider("Front Clip Distance", 0.001f, 10.0f,
            frontClipDist);
    final LogFloatLabelJSlider backClipSlider = new LogFloatLabelJSlider("Back Clip Distance", 1.0f, 10000.0f,
            backClipDist);
    final LogFloatLabelJSlider backClipRatioSlider = new LogFloatLabelJSlider("Back Clip Ratio", 1.0f, 10000.0f,
            backClipRatio);

    frontClipSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            frontClipDist = e.getValue();
            view.setFrontClipDistance(frontClipDist);
            backClipRatio = backClipDist / frontClipDist;
            backClipRatioSlider.setValue(backClipRatio);
            updateViewWindows();
        }
    });
    guiPanel.add(frontClipSlider);

    backClipSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            backClipDist = e.getValue();
            backClipRatio = backClipDist / frontClipDist;
            backClipRatioSlider.setValue(backClipRatio);
            view.setBackClipDistance(backClipDist);
            updateViewWindows();
        }
    });
    guiPanel.add(backClipSlider);

    backClipRatioSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            backClipRatio = e.getValue();
            backClipDist = backClipRatio * frontClipDist;
            backClipSlider.setValue(backClipDist);
            updateViewWindows();
        }
    });
    guiPanel.add(backClipRatioSlider);
    FloatLabelJSlider innerSphereSlider = new FloatLabelJSlider("Inner Sphere Scale", 0.001f, 0.90f, 1.0f,
            innerScale);
    innerSphereSlider.addFloatListener(new FloatListener() {
        public void floatChanged(FloatEvent e) {
            innerScale = e.getValue();
            updateInnerScale();
        }
    });
    guiPanel.add(innerSphereSlider);

    JButton mainSnap = new JButton(snapImageString);
    mainSnap.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Point loc = canvas.getLocationOnScreen();
            offScreenCanvas.setOffScreenLocation(loc);
            Dimension dim = canvas.getSize();
            dim.width *= offScreenScale;
            dim.height *= offScreenScale;
            nf.setMinimumIntegerDigits(3);
            offScreenCanvas.snapImageFile(outFileBase + nf.format(outFileSeq++), dim.width, dim.height);
            nf.setMinimumIntegerDigits(0);
        }
    });
    guiPanel.add(mainSnap);

    JButton urSnap = new JButton(urSnapImageString);
    urSnap.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Snap UR");
            Point loc = urCanvas.getLocationOnScreen();
            urOffScreenCanvas.setOffScreenLocation(loc);
            Dimension dim = urCanvas.getSize();
            dim.width *= urOffScreenScale;
            dim.height *= urOffScreenScale;
            nf.setMinimumIntegerDigits(3);
            urOffScreenCanvas.snapImageFile(urOutFileBase + nf.format(urOutFileSeq++), dim.width, dim.height);
            nf.setMinimumIntegerDigits(0);
        }
    });
    guiPanel.add(urSnap);

    JButton lrSnap = new JButton(lrSnapImageString);
    lrSnap.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Snap LR");
            Point loc = lrCanvas.getLocationOnScreen();
            lrOffScreenCanvas.setOffScreenLocation(loc);
            Dimension dim = lrCanvas.getSize();
            dim.width *= lrOffScreenScale;
            dim.height *= lrOffScreenScale;
            nf.setMinimumIntegerDigits(3);
            lrOffScreenCanvas.snapImageFile(lrOutFileBase + nf.format(lrOutFileSeq++), dim.width, dim.height);
            nf.setMinimumIntegerDigits(0);
        }
    });
    guiPanel.add(lrSnap);
    add(guiPanel, BorderLayout.SOUTH);
}

From source file:AppearanceExplorer.java

public void init() {

    // initialize the code base
    try {//from   www  .  ja v a  2  s. c o  m
        java.net.URL codeBase = getCodeBase();
        codeBaseString = codeBase.toString();
    } catch (Exception e) {
        // probably running as an application, try the application
        // code base
        codeBaseString = "file:./";
    }

    // set up a NumFormat object to print out float with only 3 fraction
    // digits
    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(3);

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

    canvas = new Canvas3D(config);
    canvas.setSize(600, 600);

    u = new SimpleUniverse(canvas);

    if (isApplication) {
        offScreenCanvas = new OffScreenCanvas3D(config, true);
        // set the size of the off-screen canvas based on a scale
        // of the on-screen size
        Screen3D sOn = canvas.getScreen3D();
        Screen3D sOff = offScreenCanvas.getScreen3D();
        Dimension dim = sOn.getSize();
        dim.width *= offScreenScale;
        dim.height *= offScreenScale;
        sOff.setSize(dim);
        sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale);
        sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale);

        // attach the offscreen canvas to the view
        u.getViewer().getView().addCanvas3D(offScreenCanvas);
    }
    contentPane.add("Center", canvas);

    BackgroundTool bgTool = new BackgroundTool(codeBaseString);
    bgSwitch = bgTool.getSwitch();
    bgChooser = bgTool.getChooser();

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();

    // set up sound
    u.getViewer().createAudioDevice();

    // get the view
    view = u.getViewer().getView();

    // Get the viewing platform
    ViewingPlatform viewingPlatform = u.getViewingPlatform();

    // Move the viewing platform back to enclose the -2 -> 2 range
    double viewRadius = 2.0; // want to be able to see circle
    // of viewRadius size around origin
    // get the field of view
    double fov = u.getViewer().getView().getFieldOfView();

    // calc view distance to make circle view in fov
    float viewDistance = (float) (viewRadius / Math.tan(fov / 2.0));
    tmpVector.set(0.0f, 0.0f, viewDistance);// setup offset
    tmpTrans.set(tmpVector); // set trans to translate
    // move the view platform
    viewingPlatform.getViewPlatformTransform().setTransform(tmpTrans);

    // add an orbit behavior to move the viewing platform
    OrbitBehavior orbit = new OrbitBehavior(canvas,
            OrbitBehavior.PROPORTIONAL_ZOOM | OrbitBehavior.REVERSE_ROTATE | OrbitBehavior.REVERSE_TRANSLATE);
    orbit.setZoomFactor(0.25);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    contentPane.add("East", guiPanel());
}