Example usage for javax.media.j3d BranchGroup BranchGroup

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

Introduction

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

Prototype

public BranchGroup() 

Source Link

Document

Constructs and initializes a new BranchGroup node object.

Usage

From source file:SimpleMouse.java

/**
 * Build the view branch of the scene graph
 * //from   w ww  .j a v a2s .  c  o  m
 * @return BranchGroup that is the root of the view branch
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 10.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    return viewBranch;
}

From source file:CanvasDemo.java

public CanvasDemo() {

    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D canvas = new Canvas3D(config);
    add("North", new Label("This is the top"));
    add("Center", canvas);
    add("South", new Label("This is the bottom"));
    BranchGroup contents = new BranchGroup();
    contents.addChild(new ColorCube(0.3));
    SimpleUniverse universe = new SimpleUniverse(canvas);
    universe.getViewingPlatform().setNominalViewingTransform();
    universe.addBranchGraph(contents);//w  ww. j  a v  a  2  s. com
}

From source file:SimpleWorld.java

/**
 * This function builds the view branch of the scene graph. It creates a
 * branch group and then creates the necessary view elements to give a
 * useful view of our content.//  w  w  w  .  j  a  va  2 s.com
 * 
 * @param c
 *            Canvas3D that will display the view
 * @return BranchGroup that is the root of the view elements
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    //This is the root of our view branch
    BranchGroup viewBranch = new BranchGroup();

    //The transform that will move our view
    //back 5 units along the z-axis
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 5.0f));

    //The transform group that will be the parent
    //of our view platform elements
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();

    //Next the physical elements are created
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();

    //Then we put it all together
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);

    return viewBranch;
}

From source file:SimpleLOD.java

/**
 * Build the view branch of the scene graph. In this case a key navigation
 * utility object is created and associated with the view transform so that
 * the view can be changed via the keyboard.
 * /*from   w  ww.jav  a 2 s .co m*/
 * @return BranchGroup that is the root of the view branch
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 10.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    BoundingSphere movingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    BoundingLeaf boundLeaf = new BoundingLeaf(movingBounds);
    ViewPlatform myViewPlatform = new ViewPlatform();
    viewXfmGroup.addChild(boundLeaf);
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);

    KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(viewXfmGroup);
    keyNav.setSchedulingBounds(movingBounds);
    viewBranch.addChild(keyNav);

    return viewBranch;
}

From source file:SimpleIndexedQuadSmooth.java

/**
 * This function builds the view branch of the scene graph. It creates a
 * branch group and then creates the necessary view elements to give a
 * useful view of our content.//from w  w  w  . ja  va2s .c o  m
 * 
 * @param c
 *            Canvas3D that will display the view
 * @return BranchGroup that is the root of the view elements
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 5.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    return viewBranch;
}

From source file:HelloJava3Dbalt.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // rotate object has composited transformation matrix
    Transform3D rotate = new Transform3D();
    Transform3D tempRotate = new Transform3D();

    rotate.rotX(Math.PI / 4.0d);//  ww w .  ja  va2s  .c o  m
    tempRotate.rotY(Math.PI / 5.0d);
    tempRotate.mul(rotate);

    TransformGroup objRotate = new TransformGroup(tempRotate);

    objRoot.addChild(objRotate);
    objRotate.addChild(new ColorCube(0.4));
    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:SimpleCombine.java

/**
 * This function builds the view branch of the scene graph. It creates a
 * branch group and then creates the necessary view elements to give a
 * useful view of our content.//from w  ww  . j a  v a  2  s . c  om
 * 
 * @param c
 *            Canvas3D that will display the view
 * @return BranchGroup that is the root of the view elements
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 7.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    return viewBranch;
}

From source file:HelloJava3Db.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // rotate object has composited transformation matrix
    Transform3D rotate = new Transform3D();
    Transform3D tempRotate = new Transform3D();

    rotate.rotX(Math.PI / 4.0d);/* w  w  w  .ja v a  2 s. c o  m*/
    tempRotate.rotY(Math.PI / 5.0d);
    rotate.mul(tempRotate);

    TransformGroup objRotate = new TransformGroup(rotate);

    objRoot.addChild(objRotate);
    objRotate.addChild(new ColorCube(0.4));
    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:HelloJava3Dc.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objSpin);/*from  w  ww .  ja  v a2s.  c  o m*/

    // Create a simple shape leaf node, add it to the scene graph.
    // ColorCube is a Convenience Utility class
    objSpin.addChild(new ColorCube(0.4));

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    Alpha rotationAlpha = new Alpha(-1, 4000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 100
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    return objRoot;
}

From source file:MouseBehaviorApp.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    TransformGroup objTransform = new TransformGroup();
    objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(objTransform);/*from   w  w w. jav a2 s .  co m*/
    objTransform.addChild(new ColorCube(0.4));
    objRoot.addChild(new Axis());

    MouseRotate myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objTransform);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseRotate);

    MouseTranslate myMouseTranslate = new MouseTranslate();
    myMouseTranslate.setTransformGroup(objTransform);
    myMouseTranslate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseTranslate);

    MouseZoom myMouseZoom = new MouseZoom();
    myMouseZoom.setTransformGroup(objTransform);
    myMouseZoom.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseZoom);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}