Example usage for javax.media.j3d View setBackClipDistance

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

Introduction

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

Prototype

public void setBackClipDistance(double distance) 

Source Link

Document

Sets the view model's back clip distance.

Usage

From source file:Viewer3D.java

public void init() {
    if (filename == null) {
        // the path to the file for an applet
        try {/*from   w  w w. jav a  2s . c  o  m*/
            java.net.URL path = getCodeBase();
            filename = new java.net.URL(path.toString() + "./ballcone.lws");
        } catch (java.net.MalformedURLException ex) {
            System.err.println(ex.getMessage());
            ex.printStackTrace();
            System.exit(1);
        }
    }

    // Construct the Lw3d loader and load the file
    Loader lw3dLoader = new Lw3dLoader(Loader.LOAD_ALL);
    Scene loaderScene = null;
    try {
        loaderScene = lw3dLoader.load(filename);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    // Construct the applet canvas
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

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

    // Create a basic universe setup and the root of our scene
    u = new SimpleUniverse(c);
    BranchGroup sceneRoot = new BranchGroup();

    // Change the back clip distance; the default is small for
    // some lw3d worlds
    View theView = u.getViewer().getView();
    theView.setBackClipDistance(50000f);

    // Now add the scene graph defined in the lw3d file
    if (loaderScene.getSceneGroup() != null) {
        // Instead of using the default view location (which may be
        // completely bogus for the particular file you're loading),
        // let's use the initial view from the file. We can get
        // this by getting the view groups from the scene (there's
        // only one for Lightwave 3D), then using the inverse of the
        // transform on that view as the transform for the entire scene.

        // First, get the view groups (shouldn't be null unless there
        // was something wrong in the load
        TransformGroup viewGroups[] = loaderScene.getViewGroups();

        // Get the Transform3D from the view and invert it
        Transform3D t = new Transform3D();
        viewGroups[0].getTransform(t);
        Matrix4d m = new Matrix4d();
        t.get(m);
        m.invert();
        t.set(m);

        // Now we've got the transform we want. Create an
        // appropriate TransformGroup and parent the scene to it.
        // Then insert the new group into the main BranchGroup.
        TransformGroup sceneTransform = new TransformGroup(t);
        sceneTransform.addChild(loaderScene.getSceneGroup());
        sceneRoot.addChild(sceneTransform);
    }

    // Make the scene graph live by inserting the root into the universe
    u.addBranchGraph(sceneRoot);
}

From source file:IntersectTest.java

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

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

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

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

    // Add picking behavior
    IntersectInfoBehavior behavior = new IntersectInfoBehavior(c, scene, 0.05f);
    behavior.setSchedulingBounds(bounds);
    scene.addChild(behavior);/*from   w  w  w . j  av  a  2s  . co m*/

    TransformGroup vpTrans = u.getViewingPlatform().getViewPlatformTransform();

    KeyNavigatorBehavior keybehavior = new KeyNavigatorBehavior(vpTrans);
    keybehavior.setSchedulingBounds(bounds);
    scene.addChild(keybehavior);
    scene.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scene.compile();
    u.addBranchGraph(scene);

    View view = u.getViewer().getView();
    view.setBackClipDistance(100000);

}

From source file:SwingTest.java

/**
 * Create a Java 3D View and attach it to a ViewPlatform
 *//*from  ww w . ja v  a2  s.  co m*/
protected View createView(ViewPlatform vp) {
    View view = new View();

    PhysicalBody pb = createPhysicalBody();
    PhysicalEnvironment pe = createPhysicalEnvironment();

    view.setPhysicalEnvironment(pe);
    view.setPhysicalBody(pb);

    if (vp != null)
        view.attachViewPlatform(vp);

    view.setBackClipDistance(getBackClipDistance());
    view.setFrontClipDistance(getFrontClipDistance());

    // create the visible canvas
    Canvas3D c3d = createCanvas3D(false);
    view.addCanvas3D(c3d);

    // create the off screen canvas
    view.addCanvas3D(createOffscreenCanvas3D());

    // add the visible canvas to a component
    addCanvas3D(c3d);

    return view;
}

From source file:MixedTest.java

protected View createView(ViewPlatform vp) {
    View view = new View();

    PhysicalBody pb = createPhysicalBody();
    PhysicalEnvironment pe = createPhysicalEnvironment();

    AudioDevice audioDevice = createAudioDevice(pe);

    if (audioDevice != null) {
        pe.setAudioDevice(audioDevice);/*from   w w  w  .j  a  v a  2s.com*/
        audioDevice.initialize();
    }

    view.setPhysicalEnvironment(pe);
    view.setPhysicalBody(pb);

    if (vp != null)
        view.attachViewPlatform(vp);

    view.setBackClipDistance(getBackClipDistance());
    view.setFrontClipDistance(getFrontClipDistance());

    Canvas3D c3d = createCanvas3D();
    view.addCanvas3D(c3d);
    addCanvas3D(c3d);

    return view;
}