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:Gouraud.java

/**
 * init Methoden fur die Darstellung als Applet Es muss also kein extra
 * Konstruktor definert werden//from   www  . ja  v a 2s.  c om
 */
public void init() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    canvas3D = new Canvas3D(config);
    add("Center", canvas3D);
    BranchGroup szene = macheSzene();
    szene.compile();
    universe = new SimpleUniverse(canvas3D);
    universe.getViewingPlatform().setNominalViewingTransform();
    universe.addBranchGraph(szene);
}

From source file:PickCallbackApp.java

public PickCallbackApp() {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(null);
    add("Center", canvas3D);

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

    BranchGroup scene = createSceneGraph(canvas3D);

    // This will move the ViewPlatform back a bit
    simpleU.getViewingPlatform().setNominalViewingTransform();

    simpleU.addBranchGraph(scene);//  w  ww .  jav a  2s . com
}

From source file:AlternateAppearanceBoundsTest.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);

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

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

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

From source file:PlatformTest.java

public PlatformTest() {
    m_KeyHashtable = new Hashtable();
    m_Bounds = new BoundingSphere(new Point3d(0, 0, 0), 100);
    // get the graphics configuration for the graphics device
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    // create the first canvas, this is the top-down view
    Canvas3D c = new Canvas3D(config);
    c.setSize(m_kWidth, m_kHeight);/*  w  ww  .  java 2s . c  om*/
    add(c);

    // create the second canvas, this is used for "Jim's" Viewer
    Canvas3D c2 = new Canvas3D(config);
    c2.setSize(m_kWidth, m_kHeight);
    add(c2);

    // create the third canvas, this is used for "Dan's" Viewer
    Canvas3D c3 = new Canvas3D(config);
    c3.setSize(m_kWidth, m_kHeight);
    add(c3);

    // Create the simple environment
    BranchGroup scene = createSceneGraph();

    // create the first Viewer, this is a static top-down view
    // create a ViewingPlatform with 2 TransformGroups above the
    // ViewPlatform
    ViewingPlatform vp = new ViewingPlatform(2);

    // create the Viewer and attach to the first canvas
    Viewer viewer = new Viewer(c);

    // rotate and position the first Viewer above the environment
    Transform3D t3d = new Transform3D();
    t3d.rotX(Math.PI / 2.0);
    t3d.setTranslation(new Vector3d(0, 0, -40));
    t3d.invert();

    MultiTransformGroup mtg = vp.getMultiTransformGroup();
    mtg.getTransformGroup(0).setTransform(t3d);

    // create a SimpleUniverse from the ViewingPlatform and Viewer
    SimpleUniverse u = new SimpleUniverse(vp, viewer);

    // add the geometry to the scenegraph
    u.addBranchGraph(scene);

    // add two more Viewers to the scenegraph
    u.getLocale().addBranchGraph(createViewer(c2, "Jim", new Color3f(0.1f, 1.0f, 1.0f), -5, 8));
    u.getLocale().addBranchGraph(createViewer(c3, "Dan", new Color3f(1.0f, 0.1f, 0.1f), 2, -8));

}

From source file:ShadowApp.java

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

    BranchGroup scene = new BranchGroup();

    Shape3D plane = new LitQuad(new Point3f(-0.3f, 0.6f, 0.2f), new Point3f(-0.3f, -0.3f, 0.2f),
            new Point3f(0.6f, -0.3f, -0.3f), new Point3f(0.6f, 0.6f, -0.3f));
    scene.addChild(plane);/*from   w  w w .  j ava 2 s  .  c om*/

    Shape3D floor = new LitQuad(new Point3f(-1.0f, -0.5f, -1.0f), new Point3f(-1.0f, -0.5f, 1.0f),
            new Point3f(1.0f, -0.5f, 1.0f), new Point3f(1.0f, -0.5f, -1.0f));
    scene.addChild(floor);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    Vector3f direction = new Vector3f(-1.0f, -1.0f, -1.0f);
    direction.normalize();
    lightD1.setDirection(direction);
    scene.addChild(lightD1);

    Shape3D shadow = new SimpleShadow((GeometryArray) plane.getGeometry(), direction,
            new Color3f(0.2f, 0.2f, 0.2f), -0.5f);
    scene.addChild(shadow);

    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:TextureImage.java

public void init() {
    if (texImage == null) {
        // the path to the image for an applet
        try {/*  w w w.j a  v a2 s . c o m*/
            texImage = new java.net.URL(getCodeBase().toString() + "/stone.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:Text3DApp.java

public Text3DApp() {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(null);
    canvas3D.setStereoEnable(false);//from w w  w  .  ja v  a 2  s.  c  om
    add("Center", canvas3D);

    BranchGroup scene = createSceneGraph();

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

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

    simpleU.addBranchGraph(scene);
}

From source file:FPSCounterDemo.java

 public void init() {
   setLayout(new BorderLayout());
   GraphicsConfiguration config = SimpleUniverse
         .getPreferredConfiguration();/*from w  w  w . j  a v  a  2s  .c om*/

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

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

   // Parse the command line to set the various parameters

   // Have Java 3D perform optimizations on this scene graph.
   scene.compile();
   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);

   JOptionPane
         .showMessageDialog(
               this,
               "\nThis program measures the number of frames rendered per second.\nNote that the frame rate is limited by the refresh rate of the monitor.\nTo get the true frame rate you need to disable vertical retrace.\n\nOn Windows(tm) you do this through the Control Panel.\n\nOn Unix set the environment variable OGL_NO_VBLANK\n(i.e. type \"setenv OGL_NO_VBLANK\" at the command prompt)",
               "Frame Counter", JOptionPane.INFORMATION_MESSAGE);
}

From source file:HelloUniverse.java

public void init() {
    // These are the string arguments given to the VirtualInputDevice
    // constructor. These are settable parameters. Look in the
    // VirtualInputDevice constructor for a complete list.
    String[] args = new String[10];
    args[0] = "printvalues";
    args[1] = "true";
    args[2] = "yscreeninitloc";
    args[3] = "50";
    args[4] = null;/*from  www.  ja v  a  2 s .c  o m*/

    InputDevice device = new VirtualInputDevice(args);

    // now create the HelloUniverse Canvas
    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);

    // The InputDevice must be initialized before registering it
    // with the PhysicalEnvironment object.
    device.initialize();

    // Register the VirtualInputDevice with Java 3D
    u.getViewer().getPhysicalEnvironment().addInputDevice(device);

    TransformGroup viewTrans = u.getViewingPlatform().getViewPlatformTransform();
    SensorBehavior s = new SensorBehavior(viewTrans, device.getSensor(0));
    s.setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0), Float.MAX_VALUE));
    scene.addChild(s);
    u.addBranchGraph(scene);
}

From source file:AxisApp.java

public AxisApp() {
    setLayout(new BorderLayout());
    Canvas3D canvas3D = new Canvas3D(null);
    add("Center", canvas3D);

    BranchGroup scene = createSceneGraph();

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

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

    simpleU.addBranchGraph(scene);// w  ww.  ja  va  2 s .c om
}