Example usage for javax.media.j3d Canvas3D Canvas3D

List of usage examples for javax.media.j3d Canvas3D Canvas3D

Introduction

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

Prototype

public Canvas3D(GraphicsConfiguration graphicsConfiguration) 

Source Link

Document

Constructs and initializes a new Canvas3D object that Java 3D can render into.

Usage

From source file:GeometryByReferenceNIOBuffer.java

public void init() {
    Container contentPane = getContentPane();

    Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    contentPane.add("Center", c);

    BranchGroup scene = createSceneGraph();
    // SimpleUniverse is a Convenience Utility class
    u = new SimpleUniverse(c);

    // add mouse behaviors to the viewingPlatform
    ViewingPlatform viewingPlatform = u.getViewingPlatform();

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    viewingPlatform.setNominalViewingTransform();
    u.addBranchGraph(scene);/* w w w .j av a 2  s. c  o  m*/

    // add Orbit behavior to the ViewingPlatform
    OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    // Create GUI
    JPanel p = new JPanel();
    BoxLayout boxlayout = new BoxLayout(p, BoxLayout.Y_AXIS);
    p.add(createGeometryByReferencePanel());
    p.add(createUpdatePanel());
    p.setLayout(boxlayout);

    contentPane.add("South", p);
}

From source file:LightScopeApp.java

public LightScopeApp() {
    setLayout(new BorderLayout());
    Canvas3D c = new Canvas3D(null);
    add("Center", c);

    BranchGroup scene = createScene();//from  w w w.  j  a  va2  s  .co m
    scene.compile();

    SimpleUniverse u = new SimpleUniverse(c);

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

    u.addBranchGraph(scene);
}

From source file:AppearanceTest.java

public void init() {
    if (bgImage == null) {
        // the path to the image for an applet
        try {/*  w  w w  .j  a  v a 2s  .  c  om*/
            bgImage = new java.net.URL(getCodeBase().toString() + "bg.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }

    if (texImage == null) {
        // the path to the image for an applet
        try {
            texImage = new java.net.URL(getCodeBase().toString() + "apimage.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }
    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);

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

    u.addBranchGraph(scene);
}

From source file:BackgroundApp.java

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

    Canvas3D canvas3D = new Canvas3D(config);
    canvas3D.setStereoEnable(false);/*  ww  w .j  av a 2 s .  co m*/
    add("Center", canvas3D);

    // SimpleUniverse is a Convenience Utility class
    SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

    BranchGroup scene = createSceneGraph(simpleU);

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

    simpleU.addBranchGraph(scene);
    new OtherView(simpleU.getLocale()); /* see note below */
}

From source file:ExText.java

/**
 * Initializes the Example by parsing command-line arguments, building an
 * AWT Frame, constructing a menubar, and creating the 3D canvas.
 * //from   w w w  .  j av  a2 s.  co  m
 * @param args
 *            a String array of command-line arguments
 */
protected void initialize(String[] args) {
    example = this;

    // Parse incoming arguments
    parseArgs(args);

    // Build the frame
    if (debug)
        System.err.println("Building GUI...");
    exampleFrame = new Frame();
    exampleFrame.setSize(640, 480);
    exampleFrame.setTitle("Java 3D Example");
    exampleFrame.setLayout(new BorderLayout());

    // Set up a close behavior
    exampleFrame.addWindowListener(this);

    // Create a canvas
    exampleCanvas = new Canvas3D(null);
    exampleCanvas.setSize(630, 460);
    exampleFrame.add("Center", exampleCanvas);

    // Build the menubar
    exampleMenuBar = this.buildMenuBar();
    exampleFrame.setMenuBar(exampleMenuBar);

    // Pack
    exampleFrame.pack();
    exampleFrame.validate();
    //      exampleFrame.setVisible( true );
}

From source file:InterleavedNIOBuffer.java

public void init() {

    // create textures

    if (texImage1 == null) {
        // the path to the image for an applet
        try {/*w w  w  .j  a va 2s  . c o m*/
            texImage1 = new java.net.URL(getCodeBase().toString() + "/bg.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }

    if (texImage2 == null) {
        // the path to the image for an applet
        try {
            texImage2 = new java.net.URL(getCodeBase().toString() + "/one.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }

    Container contentPane = getContentPane();

    Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    contentPane.add("Center", c);

    BranchGroup scene = createSceneGraph();
    // SimpleUniverse is a Convenience Utility class
    u = new SimpleUniverse(c);

    // add mouse behaviors to the viewingPlatform
    ViewingPlatform viewingPlatform = u.getViewingPlatform();

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

    // add Orbit behavior to the viewing platform
    OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    // Create GUI
    JPanel p = new JPanel();
    BoxLayout boxlayout = new BoxLayout(p, BoxLayout.Y_AXIS);
    p.add(createGeometryByReferencePanel());
    p.setLayout(boxlayout);

    contentPane.add("South", p);
}

From source file:TexBug.java

public void init() {

    // initialize the code base
    try {//  w ww  .  j a  v a  2s  . c om
        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);

    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);

    // 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);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    add("South", 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;//www.j a v  a  2s.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:TickTockPicking.java

public void init() {
    if (texImage == null) {
        // the path to the image for an applet
        try {//from  w w w .  jav a2  s.c o  m
            texImage = new java.net.URL(getCodeBase().toString() + "/apimage.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }

    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(c);
    u = new SimpleUniverse(c);

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

    u.addBranchGraph(scene);

}

From source file:MixedTest.java

protected Canvas3D createCanvas3D() {
    GraphicsConfigTemplate3D gc3D = new GraphicsConfigTemplate3D();
    gc3D.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED);
    GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();

    Canvas3D c3d = new Canvas3D(gd[0].getBestConfiguration(gc3D));
    c3d.setSize(getCanvas3dWidth(c3d), getCanvas3dHeight(c3d));

    return c3d;//from   w w w. j  a v a  2s. c  o m
}