Example usage for javax.media.j3d TransformGroup TransformGroup

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

Introduction

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

Prototype

public TransformGroup(Transform3D t1) 

Source Link

Document

Constructs and initializes a TransformGroup from the Transform passed.

Usage

From source file:InterpolatorTest.java

TransformGroup createGeometry(Appearance app, double x, double y, double z) {
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(x, y, z));
    TransformGroup tg = new TransformGroup(t3d);

    tg.addChild(new Sphere(0.1f, Primitive.GENERATE_NORMALS, app));
    return tg;//ww w .j a v  a 2 s . co  m
}

From source file:SplineAnim.java

public BranchGroup createSceneGraph() {

    // Colors for lights and objects
    Color3f aColor = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f coneColor = new Color3f(0.9f, 0.1f, 0.1f);
    Color3f sphereColor = new Color3f(0.1f, 0.7f, 0.9f);
    Color3f bgColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f lightColor = new Color3f(1.0f, 1.0f, 1.0f);

    // Root of the branch grsph
    BranchGroup root = new BranchGroup();

    // Create transforms such that all objects appears in the scene
    sceneTransform = new Transform3D();
    sceneTransform.setScale(0.14f);/*from ww  w. j  a v  a  2 s.  c om*/
    Transform3D yrot = new Transform3D();
    yrot.rotY(-Math.PI / 5.0d);
    sceneTransform.mul(yrot);
    sceneTransformGroup = new TransformGroup(sceneTransform);
    sceneTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    sceneTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    root.addChild(sceneTransformGroup);

    // Create bounds for the background and lights
    bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0f);

    // Set up the background
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    sceneTransformGroup.addChild(bg);

    // Create the transform group node for the lights
    lightTransform1 = new Transform3D();
    lightTransform2 = new Transform3D();
    Vector3d lightPos1 = new Vector3d(0.0, 0.0, 2.0);
    Vector3d lightPos2 = new Vector3d(1.0, 0.0, -2.0);
    lightTransform1.set(lightPos1);
    lightTransform2.set(lightPos2);
    light1TransformGroup = new TransformGroup(lightTransform1);
    light2TransformGroup = new TransformGroup(lightTransform2);
    sceneTransformGroup.addChild(light1TransformGroup);
    sceneTransformGroup.addChild(light2TransformGroup);

    // Create lights
    AmbientLight ambLight = new AmbientLight(aColor);
    Light dirLight1;
    Light dirLight2;

    Vector3f lightDir1 = new Vector3f(lightPos1);
    Vector3f lightDir2 = new Vector3f(lightPos2);
    lightDir1.negate();
    lightDir2.negate();
    dirLight1 = new DirectionalLight(lightColor, lightDir1);
    dirLight2 = new DirectionalLight(lightColor, lightDir2);

    // Set the influencing bounds
    ambLight.setInfluencingBounds(bounds);
    dirLight1.setInfluencingBounds(bounds);
    dirLight2.setInfluencingBounds(bounds);

    // Add the lights into the scene graph
    sceneTransformGroup.addChild(ambLight);
    sceneTransformGroup.addChild(dirLight1);
    sceneTransformGroup.addChild(dirLight2);

    // Create a cone and add it to the scene graph.
    objTransform = new Transform3D();
    objTransformGroup = new TransformGroup(objTransform);
    objTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    sceneTransformGroup.addChild(objTransformGroup);

    Material m = new Material(coneColor, eColor, coneColor, sColor, 100.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Cone cone = new Cone(0.4f, 1.0f);
    cone.setAppearance(a);
    objTransformGroup.addChild(cone);

    // Create transform groups for each knot point
    // knot point 0
    Transform3D t3dKnot = new Transform3D();
    t3dKnot.set(pos0);
    TransformGroup k0TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k0TransformGroup);

    // knot point 1
    t3dKnot = new Transform3D();
    t3dKnot.set(pos1);
    TransformGroup k1TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k1TransformGroup);

    // knot point 2
    t3dKnot = new Transform3D();
    t3dKnot.set(pos2);
    TransformGroup k2TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k2TransformGroup);

    // knot point 3
    t3dKnot = new Transform3D();
    t3dKnot.set(pos3);
    TransformGroup k3TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k3TransformGroup);

    // knot point 4
    t3dKnot = new Transform3D();
    t3dKnot.set(pos4);
    TransformGroup k4TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k4TransformGroup);

    // knot point 5
    t3dKnot = new Transform3D();
    t3dKnot.set(pos5);
    TransformGroup k5TransformGroup = new TransformGroup(t3dKnot);
    sceneTransformGroup.addChild(k5TransformGroup);

    // Create spheres for each knot point's transform group
    ColoringAttributes sphereColorAttr = new ColoringAttributes();
    sphereColorAttr.setColor(sphereColor);
    Appearance sphereAppearance = new Appearance();
    sphereAppearance.setColoringAttributes(sphereColorAttr);
    k0TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k1TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k2TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k3TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k4TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));
    k5TransformGroup.addChild(new Sphere(0.10f, sphereAppearance));

    return root;
}

From source file:HiResCoordTest.java

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

    Transform3D t3dTilt = new Transform3D();
    t3dTilt.rotX(0.3);/*  w w  w .j  a v a2 s .  c om*/

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

    TransformGroup objTransPlanets = new TransformGroup();
    objTransPlanets.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    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, objTransPlanets, yAxis, 0.0f,
            (float) Math.PI * 2.0f);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), m_TranslateSunZ);
    rotator.setSchedulingBounds(bounds);
    objTransPlanets.addChild(rotator);

    // create the sun
    TransformGroup sunTg = createSun();

    // create Earth
    Transform3D t3dEarth = new Transform3D();
    t3dEarth.setScale(m_EarthRadius);
    t3dEarth.setTranslation(new Vector3d(m_EarthOrbit, 0, 0));
    objTransPlanets.addChild(createPlanet("Earth", new Color3f(0, 0.1f, 1.0f), t3dEarth, null));

    // create Mars
    Transform3D t3dMars = new Transform3D();
    t3dMars.setTranslation(
            new Vector3d(Math.sin(Math.PI * 1.5) * m_MarsOrbit, 0, Math.cos(Math.PI * 0.5) * m_MarsOrbit));
    t3dMars.setScale(m_MarsRadius);
    objTransPlanets.addChild(createPlanet("Mars", new Color3f(1, 0, 0), t3dMars, null));

    // create Mercury
    Transform3D t3dMercury = new Transform3D();
    t3dMercury.setTranslation(
            new Vector3d(Math.sin(Math.PI) * m_MercuryOrbit, 0, Math.cos(Math.PI) * m_MercuryOrbit));
    t3dMercury.setScale(m_MercuryRadius);
    objTransPlanets.addChild(createPlanet("Mercury", new Color3f(0.5f, 0.5f, 0.5f), t3dMercury, null));

    sunTg.addChild(objTransPlanets);
    objTrans.addChild(sunTg);
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:ExAppearance.java

private Group createObject(Appearance app, double scale, double xpos, double ypos) {

    // Create a transform group node to scale and position the object.
    Transform3D t = new Transform3D();
    t.set(scale, new Vector3d(xpos, ypos, 0.0));
    TransformGroup objTrans = new TransformGroup(t);

    // Create a second transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg = new TransformGroup();
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Create a simple shape leaf node and set the appearance
    Shape3D shape = new Tetrahedron();
    shape.setAppearance(app);//from   w w  w .  j a va2  s.  c o  m

    // add it to the scene graph.
    spinTg.addChild(shape);

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

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

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    rotator.setSchedulingBounds(bounds);

    // Add the behavior and the transform group to the object
    objTrans.addChild(rotator);
    objTrans.addChild(spinTg);

    return objTrans;
}

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

public void setGraphLayout(Layout<V, E> inLayout) {

    //      this.layout = inLayout;
    this.graph = inLayout.getGraph();
    BranchGroup branch = new BranchGroup();
    LayoutEventBroadcaster<V, E> elayout = new LayoutEventBroadcaster<V, E>(inLayout);
    this.layout = elayout;
    for (V v : graph.getVertices()) {
        VertexGroup<V> vg = new VertexGroup<V>(v, renderContext.getVertexShapeTransformer().transform(v));
        vg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        vg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        vertexMap.put(v, vg);/*from   w  w  w. j av  a2  s  . c o  m*/
        branch.addChild(vg);
        String label = renderContext.getVertexStringer().transform(v);
        if (label != null) {
            String fontName = "Serif";
            Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
            Text3D txt = new Text3D(f3d, label, new Point3f(2f, 2f, 0));
            OrientedShape3D textShape = new OrientedShape3D();
            textShape.setGeometry(txt);
            textShape.setAppearance(grayLook);
            //            textShape.setAlignmentAxis( 0.0f, 1.0f, 0.0f);
            textShape.setAlignmentMode(OrientedShape3D.ROTATE_ABOUT_POINT);
            textShape.setRotationPoint(new Point3f());
            //            objScale.addChild( textShape );
            //            BranchGroup bg = new BranchGroup();
            //            bg.addChild(textShape);
            //            branch.addChild(bg);

            //            Text2D text = new Text2D(label+" more text here", new Color3f(0,0,0),"Serif",50,Font.BOLD);
            Transform3D tt = new Transform3D();
            //            tt.setTranslation(new Vector3f(100,100,100));
            tt.setScale(5);
            TransformGroup tg = new TransformGroup(tt);
            //            textShape.setGeometry(text);
            tg.addChild(textShape);
            BranchGroup bg = new BranchGroup();
            bg.addChild(tg);
            //            branch.addChild(bg);
            vg.getLabelNode().addChild(bg);

        }

    }
    System.err.println("vertexMap = " + vertexMap);

    for (E edge : graph.getEdges()) {
        EdgeGroup<E> eg = new EdgeGroup<E>(edge, renderContext.getEdgeShapeTransformer()
                .transform(Context.<Graph<V, E>, E>getInstance(graph, edge)));
        eg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        eg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
        edgeMap.put(edge, eg);
        branch.addChild(eg);
    }

    //      System.err.println("branch is "+branch);
    //      for(int i=0; i<branch.numChildren(); i++) {
    //         System.err.println("branch child ["+i+"] is "+branch.getChild(i));
    //      }

    objTrans.addChild(branch);
    elayout.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            for (V v : vertexMap.keySet()) {
                Point3f p = VisualizationViewer.this.layout.transform(v);
                Vector3f pv = new Vector3f(p.getX(), p.getY(), p.getZ());
                Transform3D tx = new Transform3D();
                tx.setTranslation(pv);
                vertexMap.get(v).setTransform(tx);
            }

            for (E edge : graph.getEdges()) {
                Pair<V> endpoints = graph.getEndpoints(edge);
                V start = endpoints.getFirst();
                V end = endpoints.getSecond();
                EdgeGroup eg = edgeMap.get(edge);
                eg.setEndpoints(layout.transform(start), layout.transform(end));
            }
        }
    });

    elayout.setSize(new BoundingSphere(new Point3d(), 200));
    elayout.initialize();
    VisRunner runner = new VisRunner((IterativeContext) elayout);
    runner.relax();

    //      for(int i=0; i<objTrans.numChildren(); i++) {
    //         System.err.println("objTrans child ["+i+"] is "+objTrans.getChild(i));
    //      }

}

From source file:TickTockPicking.java

private Group createObject(Appearance app, double scale, double xpos, double ypos) {

    // Create a transform group node to scale and position the object.
    Transform3D t = new Transform3D();
    t.set(scale, new Vector3d(xpos, ypos, 0.0));
    TransformGroup objTrans = new TransformGroup(t);

    // Create a second transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg = new TransformGroup();
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // Create a simple shape leaf node and set the appearance
    Shape3D shape = new Tetrahedron();
    shape.setAppearance(app);/*from w  ww . j  av  a  2 s .c  o m*/
    shape.setCapability(shape.ALLOW_APPEARANCE_READ);
    shape.setCapability(shape.ALLOW_APPEARANCE_WRITE);

    // add it to the scene graph.
    spinTg.addChild(shape);

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

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

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    rotator.setSchedulingBounds(bounds);

    // Add the behavior and the transform group to the object
    objTrans.addChild(rotator);
    objTrans.addChild(spinTg);

    return objTrans;
}

From source file:HiResCoordTest.java

private TransformGroup createPlanet(String szName, Color3f color, Transform3D t3d, String szTexture) {
    TransformGroup objTrans = new TransformGroup(t3d);

    Appearance app = new Appearance();

    if (szTexture != null) {
        TextureLoader tex = new TextureLoader(szTexture, this);
        app.setTexture(tex.getTexture());
    } else {/*from   w  ww. ja va 2s .c  o m*/
        ColoringAttributes ca = new ColoringAttributes();
        ca.setColor(color);
        app.setColoringAttributes(ca);
    }

    objTrans.addChild(createLabel(szName, 1.2f, 1.2f, 0));
    objTrans.addChild(new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, app));

    return objTrans;
}

From source file:TextureByReference.java

public BranchGroup createSceneGraph() {

    // create the root of the branch group
    BranchGroup objRoot = new BranchGroup();

    // create the transform group node and initialize it
    // enable the TRANSFORM_WRITE capability so that it can be modified
    // at runtime. Add it to the root of the subgraph
    Transform3D rotate = new Transform3D();
    TransformGroup objTrans = new TransformGroup(rotate);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);//  ww w.j av  a 2 s  .com

    // bounds
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // set up some light
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -0.5f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    Appearance appearance = new Appearance();

    // enable the TEXTURE_WRITE so we can modify it at runtime
    appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    // load the first texture
    TextureLoader loader = new TextureLoader(urls[0], TextureLoader.BY_REFERENCE | TextureLoader.Y_UP, this);
    // get the texture from the loader
    Texture2D tex = (Texture2D) loader.getTexture();

    // get the BufferedImage to convert to TYPE_4BYTE_ABGR and flip
    // get the ImageComponent because we need it anyway
    ImageComponent2D imageComp = (ImageComponent2D) tex.getImage(0);
    BufferedImage bImage = imageComp.getImage();
    // convert the image
    bImage = ImageOps.convertImage(bImage, BufferedImage.TYPE_4BYTE_ABGR);
    // flip the image
    ImageOps.flipImage(bImage);
    imageComp.set(bImage);

    tex.setCapability(Texture.ALLOW_IMAGE_WRITE);
    tex.setBoundaryModeS(Texture.CLAMP);
    tex.setBoundaryModeT(Texture.CLAMP);
    tex.setBoundaryColor(1.0f, 1.0f, 1.0f, 1.0f);

    // set the image of the texture
    tex.setImage(0, imageComp);

    // set the texture on the appearance
    appearance.setTexture(tex);

    // set texture attributes
    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    appearance.setTextureAttributes(texAttr);

    // set material properties
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    appearance.setMaterial(new Material(white, black, white, black, 1.0f));

    // create a scale transform
    Transform3D scale = new Transform3D();
    scale.set(.6);
    TransformGroup objScale = new TransformGroup(scale);
    objTrans.addChild(objScale);

    tetra = new Tetrahedron(true);
    tetra.setAppearance(appearance);
    objScale.addChild(tetra);

    // create the behavior
    animate = new AnimateTexturesBehavior(tex, urls, appearance, this);
    animate.setSchedulingBounds(bounds);

    objTrans.addChild(animate);

    // add a rotation behavior so we can see all sides of the tetrahedron
    Transform3D yAxis = new Transform3D();
    Alpha rotorAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
    RotationInterpolator rotator = new RotationInterpolator(rotorAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    // have java3d perform optimizations on this scene graph
    objRoot.compile();

    return objRoot;
}

From source file:ExBackgroundImage.java

public TowerScene(Component observer) {
    BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center
            1000.0); // Extent

    // Add a few lights
    AmbientLight ambient = new AmbientLight();
    ambient.setEnable(true);// w ww.j ava  2  s . co  m
    ambient.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    ambient.setInfluencingBounds(worldBounds);
    addChild(ambient);

    DirectionalLight dir1 = new DirectionalLight();
    dir1.setEnable(true);
    dir1.setColor(new Color3f(1.0f, 0.15f, 0.15f));
    dir1.setDirection(new Vector3f(0.8f, -0.35f, -0.5f));
    dir1.setInfluencingBounds(worldBounds);
    addChild(dir1);

    DirectionalLight dir2 = new DirectionalLight();
    dir2.setEnable(true);
    dir2.setColor(new Color3f(0.15f, 0.15f, 1.0f));
    dir2.setDirection(new Vector3f(-0.7f, -0.35f, 0.5f));
    dir2.setInfluencingBounds(worldBounds);
    addChild(dir2);

    // Load textures
    TextureLoader texLoader = new TextureLoader("moon5.jpg", observer);
    Texture moon = texLoader.getTexture();
    if (moon == null)
        System.err.println("Cannot load moon5.jpg texture");
    else {
        moon.setBoundaryModeS(Texture.WRAP);
        moon.setBoundaryModeT(Texture.WRAP);
        moon.setMinFilter(Texture.NICEST);
        moon.setMagFilter(Texture.NICEST);
        moon.setMipMapMode(Texture.BASE_LEVEL);
        moon.setEnable(true);
    }

    texLoader = new TextureLoader("stonebrk2.jpg", observer);
    Texture stone = texLoader.getTexture();
    if (stone == null)
        System.err.println("Cannot load stonebrk2.jpg texture");
    else {
        stone.setBoundaryModeS(Texture.WRAP);
        stone.setBoundaryModeT(Texture.WRAP);
        stone.setMinFilter(Texture.NICEST);
        stone.setMagFilter(Texture.NICEST);
        stone.setMipMapMode(Texture.BASE_LEVEL);
        stone.setEnable(true);
    }

    //
    //  Build a rough terrain
    //
    Appearance moonApp = new Appearance();

    Material moonMat = new Material();
    moonMat.setAmbientColor(0.5f, 0.5f, 0.5f);
    moonMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    moonMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    moonApp.setMaterial(moonMat);

    TextureAttributes moonTexAtt = new TextureAttributes();
    moonTexAtt.setTextureMode(TextureAttributes.MODULATE);
    moonTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    moonApp.setTextureAttributes(moonTexAtt);

    if (moon != null)
        moonApp.setTexture(moon);

    CraterGrid grid = new CraterGrid(50, 50, // grid dimensions
            1.0, 1.0, // grid spacing
            4.0, // height exageration factor
            craters, // grid elevations
            moonApp); // grid appearance
    addChild(grid);

    //
    // Build several towers on the terrain
    //
    SharedGroup tower = new SharedGroup();
    Appearance towerApp = new Appearance();

    Material towerMat = new Material();
    towerMat.setAmbientColor(0.6f, 0.6f, 0.6f);
    towerMat.setDiffuseColor(1.0f, 1.0f, 1.0f);
    towerMat.setSpecularColor(0.0f, 0.0f, 0.0f);
    towerApp.setMaterial(towerMat);

    Transform3D tr = new Transform3D();
    tr.setScale(new Vector3d(4.0, 4.0, 1.0));

    TextureAttributes towerTexAtt = new TextureAttributes();
    towerTexAtt.setTextureMode(TextureAttributes.MODULATE);
    towerTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST);
    towerTexAtt.setTextureTransform(tr);
    towerApp.setTextureAttributes(towerTexAtt);

    if (stone != null)
        towerApp.setTexture(stone);

    Arch towerShape = new Arch(0.0, // start Phi
            1.571, // end Phi
            2, // nPhi
            0.0, // start Theta
            Math.PI * 2.0, // end Theta
            5, // nTheta
            3.0, // start radius
            8.0, // end radius
            0.0, // start phi thickness
            0.0, // end phi thickness
            towerApp); // appearance
    tower.addChild(towerShape);

    // Place towers
    Matrix3f rot = new Matrix3f();
    rot.setIdentity();

    TransformGroup tg = new TransformGroup(new Transform3D(rot, new Vector3d(2.0, -3.0, -8.0), 1.0));
    tg.addChild(new Link(tower));
    addChild(tg);

    tg = new TransformGroup(new Transform3D(rot, new Vector3d(-1.0, -3.0, -6.0), 0.5));
    tg.addChild(new Link(tower));
    addChild(tg);

    tg = new TransformGroup(new Transform3D(rot, new Vector3d(5.0, -3.0, -6.0), 0.75));
    tg.addChild(new Link(tower));
    addChild(tg);

    tg = new TransformGroup(new Transform3D(rot, new Vector3d(1.0, -3.0, -3.0), 0.35));
    tg.addChild(new Link(tower));
    addChild(tg);
}

From source file:HiResCoordTest.java

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

    Transform3D t3dTilt = new Transform3D();
    t3dTilt.rotX(0.3);/*w ww .java2s.com*/
    TransformGroup subTg = new TransformGroup(t3dTilt);

    subTg.addChild(new ColorCube(50.0));
    subTg.addChild(createLabel("House", 60, 60, 0));

    objRoot.addChild(subTg);

    return objRoot;
}