Example usage for javax.media.j3d View VIRTUAL_EYE

List of usage examples for javax.media.j3d View VIRTUAL_EYE

Introduction

In this page you can find the example usage for javax.media.j3d View VIRTUAL_EYE.

Prototype

int VIRTUAL_EYE

To view the source code for javax.media.j3d View VIRTUAL_EYE.

Click Source Link

Document

Specifies that the associated distance is measured from the eye in virtual world coordinates.

Usage

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);/*  w w w  .  j  av a2s  .  c  o  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:ViewProj.java

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

    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(3);//from   ww  w .j  ava 2s  .c  o  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);
}