Example usage for javax.media.j3d Transform3D Transform3D

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

Introduction

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

Prototype

public Transform3D() 

Source Link

Document

Constructs and initializes a transform to the identity matrix.

Usage

From source file:edu.uci.ics.jung.visualization3d.VisualizationViewer.java

public BranchGroup createSceneGraph(final Canvas3D canvas) {

    objRoot = new BranchGroup();
    objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    objRoot.setCapability(Group.ALLOW_CHILDREN_WRITE);

    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    //      t3d.setScale(0.05);
    objScale.setTransform(t3d);//from w  w  w  .java2s  .c om
    objRoot.addChild(objScale);

    Transform3D tt = new Transform3D();
    tt.setScale(.05);
    tt.setTranslation(new Vector3f(0, 0, -30.f));
    objTrans = new TransformGroup(tt);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
    objScale.addChild(objTrans);
    //      objRoot.addChild(objTrans);

    // Create Colors, Materials,  and Appearances.
    Appearance look = new Appearance();
    Color3f objColor = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f black = new Color3f(0.f, 0.f, 0.f);
    Color3f white = new Color3f(1.0f, 1.0f, 0.6f);
    Color3f gray = new Color3f(.2f, .2f, .2f);
    Color3f red = new Color3f(1.0f, 0, 0);
    Color3f yellow = new Color3f(1, 1, 0);

    Material objMaterial = new Material(objColor, black, objColor, white, 100.0f);
    Material blackMaterial = new Material(objColor, black, black, objColor, 10.0f);
    Material whiteMaterial = new Material(white, white, white, white, 100.0f);
    Material grayMaterial = new Material(gray, black, gray, gray, 100.0f);

    Material redMaterial = new Material(red, black, red, red, 100.0f);
    Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100);

    look.setMaterial(new Material(objColor, black, objColor, white, 100.0f));
    Appearance blackLook = new Appearance();
    blackLook.setMaterial(blackMaterial);

    Appearance whiteLook = new Appearance();
    whiteLook.setMaterial(whiteMaterial);

    Appearance grayLook = new Appearance();
    grayLook.setMaterial(grayMaterial);
    grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ);
    grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    final Appearance redLook = new Appearance();
    redLook.setMaterial(redMaterial);
    //      vertexLook = redLook;

    Appearance objLook = new Appearance();
    objLook.setMaterial(objMaterial);
    grayLook = objLook;
    final Appearance yellowLook = new Appearance();
    yellowLook.setMaterial(yellowMaterial);
    Bounds bounds = new BoundingSphere(new Point3d(), 300);

    MouseRotate behavior1 = new MouseRotate();
    behavior1.setTransformGroup(objTrans);
    objTrans.addChild(behavior1);
    behavior1.setSchedulingBounds(bounds);

    MouseWheelZoom behavior2 = new MouseWheelZoom();
    behavior2.setTransformGroup(objTrans);
    //      behavior2.setFactor(10);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(objTrans);
    objTrans.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

    PickTranslateBehavior ptb = new PickTranslateBehavior(objRoot, canvas, bounds, PickTool.GEOMETRY);
    ptb.setSchedulingBounds(bounds);
    //      objTrans.addChild(ptb);
    ptb.setupCallback(new PickingCallback() {

        public void transformChanged(int type, TransformGroup tg) {
            if (tg == null)
                return;
            Transform3D t3d = new Transform3D();
            tg.getTransform(t3d);
            //            System.err.println(tg+" transformChanged \n"+t3d);
            Point3f p1 = new Point3f();
            V v = vertexMap.getKey(tg);
            //            Transform3D lvw = new Transform3D();
            //            tg.getLocalToVworld(lvw);
            //            System.err.println("lvw = \n"+lvw);
            //            lvw.invert();
            //            System.err.println("invert lvw = \n"+lvw);
            Point3f p0 = layout.transform(v);
            //            Transform3D vwip = new Transform3D();
            //            canvas.getVworldToImagePlate(vwip);
            //            System.err.println("vwip=\n"+vwip);
            //            t3d.mul(lvw);
            t3d.transform(p1);
            //            scale.transform(p1);
            System.err.println(
                    "change location for vertex " + v + ", transformGroup " + tg + " from " + p0 + " to " + p1);
            //            p1.set(p1.getX()*2,p1.getY()*2,p1.getZ()*2);
            //            layout.setLocation(v, p1);

        }
    });

    PickSphereBehavior psb = new PickSphereBehavior(objRoot, canvas, bounds);

    PickVertexBehavior pvb = new PickVertexBehavior(objRoot, canvas, bounds,
            renderContext.getPickedVertexState());
    objTrans.addChild(pvb);
    pvb.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            for (V v : graph.getVertices()) {
                VertexGroup<V> vg = vertexMap.get(v);
                Appearance look = redLook;
                if (renderContext.getPickedVertexState().isPicked(v)) {
                    look = yellowLook;
                }
                Node node = vg.getShape();
                if (node instanceof Primitive) {
                    ((Primitive) node).setAppearance(look);
                }
            }

        }
    });

    //Shine it with two colored lights.
    Color3f lColor1 = new Color3f(.5f, .5f, .5f);
    Color3f lColor2 = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(-1.0f, 0.0f, -1.0f);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    AmbientLight ambient = new AmbientLight(lColor1);
    lgt2.setInfluencingBounds(bounds);
    ambient.setInfluencingBounds(bounds);
    objRoot.addChild(lgt2);
    objRoot.addChild(ambient);

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

    //      VisRunner runner = new VisRunner((IterativeContext)elayout);
    //      runner.relax();

    return objRoot;
}

From source file:TextureTransformTest.java

private TransformGroup createRotator() {
    // create a ColorCube to illustrate the current rotation
    TransformGroup transTg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(-70, -70, 50));
    transTg.setTransform(t3d);//from  w  w w  .ja  v a2  s  .com

    TransformGroup subTg = new TransformGroup();
    subTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    subTg.addChild(new ColorCube(10.0));

    // attach a MouseRotate behavior so we can
    // rotate the color cube with the left mouse button
    MouseRotate mouseRot = new MouseRotate(subTg);
    subTg.addChild(mouseRot);

    // assign a transformChanged callback as we want to be
    // notified whenever the rotation of the ColorCube
    // changed ("this" implements MouseBehaviorCallback );
    mouseRot.setupCallback(this);
    mouseRot.setSchedulingBounds(getApplicationBounds());

    transTg.addChild(subTg);

    return transTg;
}

From source file:ExTransform.java

public Group buildScene() {
    // Turn on the headlight
    setHeadlightEnable(true);//from w ww .  j  a v a 2  s.com

    // Build the scene root
    switchGroup = new Switch();
    switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Create application bounds
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    Transform3D t3d;

    Appearance app = new Appearance();
    Material mat = new Material();
    mat.setAmbientColor(0.2f, 0.8f, 0.4f);
    mat.setDiffuseColor(0.2f, 0.8f, 0.4f);
    mat.setSpecularColor(0.0f, 0.0f, 0.f);
    app.setMaterial(mat);

    // Build the 3D object:
    Box box = new Box(3.0f, 2.0f, 1.0f, app);

    // Build the shared object:
    sharedObject = new SharedGroup();
    sharedObject.addChild(box);

    // Build 4 separate transforms:

    Transform3D id = new Transform3D();
    TransformGroup idGroup = new TransformGroup(id);
    idGroup.addChild(new Link(sharedObject));
    switchGroup.addChild(idGroup);

    Transform3D rot = new Transform3D();
    rot.set(new AxisAngle4d(0., 1., 0., Math.PI / 4.));
    TransformGroup rotGroup = new TransformGroup(rot);
    rotGroup.addChild(new Link(sharedObject));
    switchGroup.addChild(rotGroup);

    Transform3D trans = new Transform3D();
    trans.set(new Vector3d(2., 0., 0.));
    TransformGroup transGroup = new TransformGroup(trans);
    transGroup.addChild(new Link(sharedObject));
    switchGroup.addChild(transGroup);

    Transform3D scale = new Transform3D();
    scale.set(2.0);
    TransformGroup scaleGroup = new TransformGroup(scale);
    scaleGroup.addChild(new Link(sharedObject));
    switchGroup.addChild(scaleGroup);

    switchGroup.setWhichChild(options[currentSwitch].child);

    return switchGroup;
}

From source file:BoundsTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    // do NOT auto compute bounds for this node
    objRoot.setBoundsAutoCompute(false);

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

    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);

    rotator.setSchedulingBounds(createApplicationBounds());
    objTrans.addChild(rotator);/* w  ww.  java  2s  .  com*/

    objTrans.addChild(createColorCubes());
    objTrans.addChild(createPoints());

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:AlternateAppearanceScopeTest.java

BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

    // Create influencing bounds
    worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.1f, 0.0f));
    // Shrink the object
    t.setScale(0.8);/*from   w  w w.  j av  a  2  s. co  m*/

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    otherApp = new Appearance();
    altMat = new Material();
    altMat.setCapability(Material.ALLOW_COMPONENT_WRITE);
    altMat.setDiffuseColor(new Color3f(0.0f, 1.0f, 0.0f));
    otherApp.setMaterial(altMat);

    altApp = new AlternateAppearance();
    altApp.setAppearance(otherApp);
    altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_WRITE);
    altApp.setCapability(AlternateAppearance.ALLOW_SCOPE_READ);
    altApp.setInfluencingBounds(worldBounds);
    objRoot.addChild(altApp);

    // Build foreground geometry into two groups. We'll
    // create three directional lights below, one each with
    // scope to cover the first geometry group only, the
    // second geometry group only, or both geometry groups.
    Appearance app1 = new Appearance();
    mat1 = new Material();
    mat1.setCapability(Material.ALLOW_COMPONENT_WRITE);
    mat1.setDiffuseColor(new Color3f(1.0f, 0.0f, 0.0f));
    app1.setMaterial(mat1);
    content1 = new SphereGroup(0.05f, // radius of spheres
            0.4f, // x spacing
            0.2f, // y spacing
            3, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    trans.addChild(content1);
    shapes1 = ((SphereGroup) content1).getShapes();

    content2 = new SphereGroup(0.05f, // radius of spheres
            .4f, // x spacing
            0.2f, // y spacing
            2, // number of spheres in X
            5, // number of spheres in Y
            app1, // appearance
            true); // alt app override = true
    trans.addChild(content2);
    shapes2 = ((SphereGroup) content2).getShapes();

    // Add lights
    DirectionalLight light1 = null;
    light1 = new DirectionalLight();
    light1.setEnable(true);
    light1.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f));
    light1.setInfluencingBounds(worldBounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight();
    light2.setEnable(true);
    light2.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    light2.setDirection(new Vector3f(-1.0f, 0.0f, 1.0f));
    light2.setInfluencingBounds(worldBounds);
    objRoot.addChild(light2);

    // Add an ambient light to dimly illuminate the rest of
    // the shapes in the scene to help illustrate that the
    // directional lights are being scoped... otherwise it looks
    // like we're just removing shapes from the scene
    AmbientLight ambient = new AmbientLight();
    ambient.setEnable(true);
    ambient.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    ambient.setInfluencingBounds(worldBounds);
    objRoot.addChild(ambient);

    objRoot.addChild(trans);

    return objRoot;
}

From source file:ExRaster.java

public Group buildScene() {
    // Turn on the headlight
    setHeadlightEnable(true);/*from   ww w.j a v a  2  s.  c  o m*/

    // Default to examine navigation
    setNavigationType(Examine);

    // Build the scene root
    Group scene = new Group();

    if (debug)
        System.err.println("  rasters...");

    // BEGIN EXAMPLE TOPIC
    // Create three raster geometry shapes, each with a
    // different annotation text image

    // Load the texture images
    TextureLoader texLoader = new TextureLoader("one.jpg", this);
    ImageComponent2D oneImage = texLoader.getImage();
    if (oneImage == null) {
        System.err.println("Cannot load 'one.jpg'");
    }

    texLoader = new TextureLoader("two.jpg", this);
    ImageComponent2D twoImage = texLoader.getImage();
    if (twoImage == null) {
        System.err.println("Cannot load 'two.jpg'");
    }

    texLoader = new TextureLoader("three.jpg", this);
    ImageComponent2D threeImage = texLoader.getImage();
    if (threeImage == null) {
        System.err.println("Cannot load 'three.jpg'");
    }

    // Create raster geometries and shapes
    Vector3f trans = new Vector3f();
    Transform3D tr = new Transform3D();
    TransformGroup tg;

    // Left
    Raster raster = new Raster();
    raster.setPosition(new Point3f(-2.0f, 0.75f, 0.0f));
    raster.setType(Raster.RASTER_COLOR);
    raster.setOffset(0, 0);
    raster.setSize(64, 32);
    raster.setImage(oneImage);
    Shape3D sh = new Shape3D(raster, new Appearance());
    scene.addChild(sh);

    // Middle-back
    raster = new Raster();
    raster.setPosition(new Point3f(0.0f, 0.75f, -2.0f));
    raster.setType(Raster.RASTER_COLOR);
    raster.setOffset(0, 0);
    raster.setSize(64, 32);
    raster.setImage(twoImage);
    sh = new Shape3D(raster, new Appearance());
    scene.addChild(sh);

    // Right
    raster = new Raster();
    raster.setPosition(new Point3f(2.0f, 0.75f, 0.0f));
    raster.setType(Raster.RASTER_COLOR);
    raster.setOffset(0, 0);
    raster.setSize(64, 32);
    raster.setImage(threeImage);
    sh = new Shape3D(raster, new Appearance());
    scene.addChild(sh);
    // END EXAMPLE TOPIC

    // Build foreground geometry including a floor and
    // cones on which the raster images sit
    if (debug)
        System.err.println("  cones...");
    Appearance app0 = new Appearance();
    Material mat0 = new Material();
    mat0.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat0.setDiffuseColor(1.0f, 0.0f, 0.0f);
    mat0.setSpecularColor(0.7f, 0.7f, 0.7f);
    app0.setMaterial(mat0);

    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3f(-2.0f, 0.0f, 0.0f));
    TransformGroup tg0 = new TransformGroup(t3d);
    Cone cone0 = new Cone(0.5f, // radius
            1.5f, // height
            Primitive.GENERATE_NORMALS, // flags
            16, // x division
            16, // y division
            app0); // appearance
    tg0.addChild(cone0);
    scene.addChild(tg0);

    Appearance app1 = new Appearance();
    Material mat1 = new Material();
    mat1.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat1.setDiffuseColor(0.0f, 1.0f, 0.0f);
    mat1.setSpecularColor(0.7f, 0.7f, 0.7f);
    app1.setMaterial(mat1);

    t3d = new Transform3D();
    t3d.setTranslation(new Vector3f(0.0f, 0.0f, -2.0f));
    TransformGroup tg1 = new TransformGroup(t3d);
    Cone cone1 = new Cone(0.5f, // radius
            1.5f, // height
            Primitive.GENERATE_NORMALS, // flags
            16, // x division
            16, // y division
            app1); // appearance
    tg1.addChild(cone1);
    scene.addChild(tg1);

    Appearance app2 = new Appearance();
    Material mat2 = new Material();
    mat2.setAmbientColor(0.2f, 0.2f, 0.2f);
    mat2.setDiffuseColor(0.0f, 0.6f, 1.0f);
    mat2.setSpecularColor(0.7f, 0.7f, 0.7f);
    app2.setMaterial(mat2);

    t3d = new Transform3D();
    t3d.setTranslation(new Vector3f(2.0f, 0.0f, 0.0f));
    TransformGroup tg2 = new TransformGroup(t3d);
    Cone cone2 = new Cone(0.5f, // radius
            1.5f, // height
            Primitive.GENERATE_NORMALS, // flags
            16, // x division
            16, // y division
            app2); // appearance
    tg2.addChild(cone2);
    scene.addChild(tg2);

    return scene;
}

From source file:SimpleGame.java

/**
 * This builds the gun geometry. It uses box and cylinder primitives and
 * sets up a transform group so that we can rotate the gun.
 *//*from  w  w  w  .  j  av  a  2 s .c om*/
protected BranchGroup buildGun() {
    BranchGroup theGun = new BranchGroup();
    Appearance gunApp = new Appearance();
    Color3f ambientColour = new Color3f(0.5f, 0.5f, 0.5f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f diffuseColour = new Color3f(0.5f, 0.5f, 0.5f);
    float shininess = 20.0f;
    gunApp.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    TransformGroup init = new TransformGroup();
    TransformGroup barrel = new TransformGroup();
    Transform3D gunXfm = new Transform3D();
    Transform3D barrelXfm = new Transform3D();
    barrelXfm.set(new Vector3d(0.0, -2.0, 0.0));
    barrel.setTransform(barrelXfm);
    Matrix3d gunXfmMat = new Matrix3d();
    gunXfmMat.rotX(Math.PI / 2);
    gunXfm.set(gunXfmMat, new Vector3d(0.0, 0.0, 0.0), 1.0);
    init.setTransform(gunXfm);
    gunXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    gunXfmGrp.addChild(new Box(1.0f, 1.0f, 0.5f, gunApp));
    barrel.addChild(new Cylinder(0.3f, 4.0f, gunApp));
    gunXfmGrp.addChild(barrel);
    theGun.addChild(init);
    init.addChild(gunXfmGrp);
    return theGun;
}

From source file:SimpleBillboard.java

/**
 * Build the content branch for the scene graph. This creates two cubes and
 * uses a billboard node to keep one face of one of the cubes facing the
 * viewer./*from  w  w w .  jav  a  2 s .com*/
 * 
 * @return BranchGroup that is the root of the content
 */
protected BranchGroup buildContentBranch() {
    //Create the appearance
    Appearance app = new Appearance();
    Color3f ambientColour = new Color3f(1.0f, 1.0f, 0.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f diffuseColour = new Color3f(1.0f, 1.0f, 0.0f);
    float shininess = 20.0f;
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    //Make the cubes
    Box leftCube = new Box(1.0f, 1.0f, 1.0f, app);
    ColorCube rightCube = new ColorCube();
    //Create the transformgroup used for the billboard
    TransformGroup billBoardGroup = new TransformGroup();
    //Set the access rights to the group
    billBoardGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    //Add the cube to the group
    billBoardGroup.addChild(rightCube);
    //Create and activate the billboard
    Billboard myBillboard = new Billboard(billBoardGroup, Billboard.ROTATE_ABOUT_AXIS,
            new Vector3f(0.0f, 1.0f, 0.0f));
    myBillboard.setSchedulingBounds(bounds);
    BranchGroup contentBranch = new BranchGroup();
    contentBranch.addChild(myBillboard);
    addLights(contentBranch);
    //Position the cubes
    TransformGroup bothGroup = new TransformGroup();
    Transform3D leftGroupXfm = new Transform3D();
    leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0));
    TransformGroup leftGroup = new TransformGroup(leftGroupXfm);
    Transform3D rightGroupXfm = new Transform3D();
    rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0));
    TransformGroup rightGroup = new TransformGroup(rightGroupXfm);
    //Put it all together
    bothGroup.addChild(leftGroup);
    leftGroup.addChild(leftCube);
    bothGroup.addChild(rightGroup);
    rightGroup.addChild(billBoardGroup);
    contentBranch.addChild(bothGroup);
    return contentBranch;

}

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);/*from w  w w .  jav  a  2  s. com*/
    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:SpotLightApp.java

public SpotLightApp() {
    BoundingSphere bound1 = new BoundingSphere(new Point3d(0.0, 0.9, 0.0), 0.5);
    BoundingSphere bound2 = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 0.5);
    BoundingSphere bound3 = new BoundingSphere(new Point3d(0.0, -0.9, 0.0), 0.5);

    Vector3f direction = new Vector3f(0.0f, 0.0f, -1.0f);

    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f green = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);

    BranchGroup scene = new BranchGroup();

    final int X = 101, Y = 102;
    final float dx = 0.01f, dy = -0.01f;
    final float epx = dx / 2.0f, epy = dy / 2.0f;
    final float top = 0.5f, left = -0.5f;
    final float right = left + dx * (X - 1);
    final float bottom = top + dy * (Y - 1);

    IndexedQuadArray qa = new IndexedQuadArray(X * Y, QuadArray.COORDINATES | QuadArray.NORMALS,
            (X - 1) * (Y - 1) * 4);//w  w  w . j av a2 s  . c  o  m

    float x, y;
    int i = 0;
    System.out.print("set " + X * Y + " coordiantes.....  ");
    for (y = top; y >= bottom - epx; y += dy)
        for (x = left; x <= right + epx; x += dx)
            qa.setCoordinate(i++, new Point3f(x, y, 0.0f));

    System.out.println(i + " coordiantes done");
    int row, col;
    i = 0;
    Vector3f n = new Vector3f(0.0f, 0.0f, 1.0f);

    System.out.print("set " + (X - 1) * (Y - 1) * 4 + " coordinate indices.....  ");
    for (row = 0; row < (Y - 1); row++) {
        for (col = 0; col < (X - 1); col++) {
            qa.setNormal(row * X + col, n);
            qa.setCoordinateIndex(i++, row * X + col);
            qa.setCoordinateIndex(i++, (row + 1) * X + col);
            qa.setCoordinateIndex(i++, (row + 1) * X + col + 1);
            qa.setCoordinateIndex(i++, row * X + col + 1);
        }
        qa.setNormal(row * X + col + 1, n);
    }
    System.out.println(i + " coordinate indices done");

    for (col = 0; col < (X - 1); col++) {
        qa.setNormal(X * (Y - 1) + 1 + col, n);
    }
    System.out.println("coordinate normals done");

    Appearance qAppear = createMatAppear(blue, white, 5.0f);
    Shape3D plane = new Shape3D(qa, qAppear);

    Transform3D translate = new Transform3D();
    translate.set(new Vector3f(-0.5f, 0.5f, 0.0f));
    TransformGroup tg1 = new TransformGroup(translate);
    scene.addChild(tg1);
    Shape3D plane1 = new Shape3D(qa, qAppear);
    plane1.setBounds(bound1);
    tg1.addChild(plane1);

    translate.set(new Vector3f(0.5f, 0.5f, 0.0f));
    TransformGroup tg2 = new TransformGroup(translate);
    scene.addChild(tg2);
    Shape3D plane2 = new Shape3D(qa, qAppear);
    plane2.setBounds(bound1);
    tg2.addChild(plane2);

    translate.set(new Vector3f(-0.5f, -0.5f, 0.0f));
    TransformGroup tg3 = new TransformGroup(translate);
    scene.addChild(tg3);
    Shape3D plane3 = new Shape3D(qa, qAppear);
    plane3.setBounds(bound3);
    tg3.addChild(plane3);

    translate.set(new Vector3f(0.5f, -0.5f, 0.0f));
    TransformGroup tg4 = new TransformGroup(translate);
    scene.addChild(tg4);
    Shape3D plane4 = new Shape3D(qa, qAppear);
    plane4.setBounds(bound3);
    tg4.addChild(plane4);

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

    scene.addChild(newSpotLight(bound1, new Point3f(-0.7f, 0.7f, 0.5f), 0.1f, 5.0f));
    scene.addChild(newSpotLight(bound1, new Point3f(0.0f, 0.7f, 0.5f), 0.1f, 50.0f));
    scene.addChild(newSpotLight(bound1, new Point3f(0.7f, 0.7f, 0.5f), 0.1f, 100.0f));
    scene.addChild(newSpotLight(bound2, new Point3f(-0.7f, 0.0f, 0.5f), 0.3f, 5.0f));
    scene.addChild(newSpotLight(bound2, new Point3f(0.0f, 0.0f, 0.5f), 0.3f, 50.0f));
    scene.addChild(newSpotLight(bound2, new Point3f(0.7f, 0.0f, 0.5f), 0.3f, 100.0f));
    scene.addChild(newSpotLight(bound3, new Point3f(-0.7f, -0.7f, 0.5f), 0.5f, 5.0f));
    scene.addChild(newSpotLight(bound3, new Point3f(0.0f, -0.7f, 0.5f), 0.5f, 50.0f));
    scene.addChild(newSpotLight(bound3, new Point3f(0.7f, -0.7f, 0.5f), 0.5f, 100.0f));

    Background background = new Background();
    background.setApplicationBounds(new BoundingSphere());
    background.setColor(1.0f, 1.0f, 1.0f);
    scene.addChild(background);

    scene.compile();

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

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