Example usage for javax.media.j3d Transform3D mul

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

Introduction

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

Prototype

public final void mul(Transform3D t1) 

Source Link

Document

Sets the value of this transform to the result of multiplying itself with transform t1 (this = this * t1).

Usage

From source file:OffScreenTest.java

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

    // spin object has composited transformation matrix
    Transform3D spin = new Transform3D();
    Transform3D tempspin = new Transform3D();

    spin.rotX(Math.PI / 4.0d);/*from  w ww  . ja v a  2 s  .c o  m*/
    tempspin.rotY(Math.PI / 5.0d);
    spin.mul(tempspin);
    spin.setScale(0.7);
    spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0));

    TransformGroup objTrans = new TransformGroup(spin);
    objRoot.addChild(objTrans);

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

    //Create a raster
    Shape3D shape = new Shape3D(drawRaster);
    objRoot.addChild(shape);

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

    return objRoot;
}

From source file:BooksDemo.java

public void createScene() {
    BufferedImage image = new BufferedImage(xpanel.getWidth(), xpanel.getHeight(), BufferedImage.TYPE_INT_RGB);
    getContentPane().paint(image.getGraphics());

    BufferedImage subImage = new BufferedImage(CANVAS3D_WIDTH, CANVAS3D_HEIGHT, BufferedImage.TYPE_INT_RGB);
    ((Graphics2D) subImage.getGraphics()).drawImage(image, null, -c3d.getX(), -c3d.getY());

    Background bg = new Background(new ImageComponent2D(ImageComponent2D.FORMAT_RGB, subImage));
    BoundingSphere bounds = new BoundingSphere();
    bounds.setRadius(100.0);/*from   w w  w.  ja va 2  s.co m*/
    bg.setApplicationBounds(bounds);

    BranchGroup objRoot = new BranchGroup();
    objRoot.addChild(bg);

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

    Transform3D yAxis = new Transform3D();
    rotor1Alpha = new Alpha(1, 400);
    rotator1 = new RotationInterpolator(rotor1Alpha, objTg, yAxis, (float) Math.PI * 1.0f,
            (float) Math.PI * 2.0f);
    rotator1.setSchedulingBounds(bounds);

    textures.put("pages_top", createTexture("pages_top.jpg"));
    textures.put("pages", createTexture("amazon.jpg"));
    textures.put("amazon", createTexture("amazon.jpg"));
    textures.put("cover1", createTexture("cover1.jpg"));
    textures.put("cover2", createTexture("cover2.jpg"));
    textures.put("cover3", createTexture("cover3.jpg"));

    book = new com.sun.j3d.utils.geometry.Box(0.5f, 0.7f, 0.15f,
            com.sun.j3d.utils.geometry.Box.GENERATE_TEXTURE_COORDS, new Appearance());
    book.getShape(book.TOP).setAppearance((Appearance) textures.get("pages_top"));
    book.getShape(book.RIGHT).setAppearance((Appearance) textures.get("pages"));
    book.getShape(book.LEFT).setAppearance((Appearance) textures.get("amazon"));
    book.getShape(book.FRONT).setAppearance((Appearance) textures.get("cover1"));

    book.getShape(book.BACK).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    book.getShape(book.FRONT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    // book.getShape(book.LEFT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    // book.getShape(book.RIGHT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

    objTg.addChild(book);
    objTg.addChild(rotator1);

    Transform3D spin = new Transform3D();
    Transform3D tempspin = new Transform3D();

    spin.rotX(Math.PI / 8.0d);
    tempspin.rotY(Math.PI / 7.0d);
    spin.mul(tempspin);

    TransformGroup objTrans = new TransformGroup(spin);
    objTrans.addChild(objTg);

    objRoot.addChild(objTrans);

    SimpleUniverse u = new SimpleUniverse(c3d);
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(objRoot);

    View view = u.getViewer().getView();
    view.setSceneAntialiasingEnable(true);
}

From source file:SimpleTransform.java

/**
 * This processes the AWT events and performs the appropriate operations.
 * The exit button causes the program to terminate, the left button causes a
 * rotation to be applied to the shape's transformation to spin it to the
 * left and the right has the similar effect but to the right button.
 * /*from w w w.  jav a  2 s . c o m*/
 * @param e
 *            ActionEvent that has been performed
 */
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == exitButton) {
        dispose();
        System.exit(0);
    } else if (e.getSource() == leftButton) {
        //Create a temporary transform
        Transform3D temp = new Transform3D();
        //Read the transform from the shape
        rotationGroup.getTransform(temp);
        //Create a rotation that will be applied
        Transform3D tempDelta = new Transform3D();
        tempDelta.rotY(-0.3);
        //Apply the rotation
        temp.mul(tempDelta);
        //Write the value back into the scene graph
        rotationGroup.setTransform(temp);
    } else if (e.getSource() == rightButton) {
        //Do the same for the right rotation
        Transform3D temp = new Transform3D();
        rotationGroup.getTransform(temp);
        Transform3D tempDelta = new Transform3D();
        tempDelta.rotY(0.3);
        temp.mul(tempDelta);
        rotationGroup.setTransform(temp);
    }
}

From source file:Pyramid2Cube.java

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

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);//from  w w w.j  a  va2  s . c o  m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

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

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    //
    // Create the transform group nodes for the 3 original objects
    // and the morphed object. Add them to the root of the
    // branch graph.
    //
    TransformGroup objTrans[] = new TransformGroup[4];

    for (int i = 0; i < 4; i++) {
        objTrans[i] = new TransformGroup();
        objScale.addChild(objTrans[i]);
    }

    Transform3D tr = new Transform3D();
    Transform3D rotY15 = new Transform3D();
    rotY15.rotY(15.0 * Math.PI / 180.0);

    objTrans[0].getTransform(tr);
    tr.setTranslation(new Vector3d(-3.0, 1.5, -6.5));
    tr.mul(rotY15);
    objTrans[0].setTransform(tr);

    objTrans[1].getTransform(tr);
    tr.setTranslation(new Vector3d(0.0, 1.5, -6.5));
    tr.mul(rotY15);
    objTrans[1].setTransform(tr);

    objTrans[2].getTransform(tr);
    tr.setTranslation(new Vector3d(3.0, 1.5, -6.5));
    tr.mul(rotY15);
    objTrans[2].setTransform(tr);

    objTrans[3].getTransform(tr);
    tr.setTranslation(new Vector3d(0.0, -2.0, -5.0));
    tr.mul(rotY15);
    objTrans[3].setTransform(tr);

    // Now create simple geometries.

    QuadArray g[] = new QuadArray[3];
    Shape3D shape[] = new Shape3D[3];
    for (int i = 0; i < 3; i++) {
        g[i] = null;
        shape[i] = null;
    }

    g[0] = new ColorPyramidUp();
    g[1] = new ColorCube();
    g[2] = new ColorPyramidDown();

    Appearance a = new Appearance();

    for (int i = 0; i < 3; i++) {
        shape[i] = new Shape3D(g[i], a);
        objTrans[i].addChild(shape[i]);
    }

    //
    // Create a Morph node, and set the appearance and input geometry
    // arrays. Set the Morph node's capability bits to allow the weights
    // to be modified at runtime.
    //
    Morph morph = new Morph((GeometryArray[]) g, a);
    morph.setCapability(Morph.ALLOW_WEIGHTS_READ);
    morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE);

    objTrans[3].addChild(morph);

    // Now create the Alpha object that controls the speed of the
    // morphing operation.
    Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 4000, 1000, 500,
            4000, 1000, 500);

    // Finally, create the morphing behavior
    MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph);
    mBeh.setSchedulingBounds(bounds);
    objScale.addChild(mBeh);

    return objRoot;
}

From source file:InterleavedTest.java

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

    // Set up attributes to render lines
    app = new Appearance();
    app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE);

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);//  ww  w  .  j a  v a 2s. c om
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    // load textures
    TextureAttributes texAttr1 = new TextureAttributes();
    texAttr1.setTextureMode(TextureAttributes.DECAL);
    TextureAttributes texAttr2 = new TextureAttributes();
    texAttr2.setTextureMode(TextureAttributes.MODULATE);

    TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this);
    if (tex == null)
        return null;
    tex1 = tex.getTexture();

    tex = new TextureLoader(texImage2, new String("RGB"), this);
    if (tex == null)
        return null;
    tex2 = tex.getTexture();

    textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null);
    textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null);

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

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

    objRoot.addChild(trans);
    trans.addChild(shape);

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

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -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);

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

    return objRoot;
}

From source file:InterleavedNIOBuffer.java

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

    // Set up attributes to render lines
    app = new Appearance();
    app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE);

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);/*from  ww w  .  j  av  a 2s.  c  o  m*/
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    // load textures
    TextureAttributes texAttr1 = new TextureAttributes();
    texAttr1.setTextureMode(TextureAttributes.DECAL);
    TextureAttributes texAttr2 = new TextureAttributes();
    texAttr2.setTextureMode(TextureAttributes.MODULATE);

    TextureLoader tex = new TextureLoader(texImage1, new String("RGB"), this);
    if (tex == null)
        return null;
    tex1 = tex.getTexture();

    tex = new TextureLoader(texImage2, new String("RGB"), this);
    if (tex == null)
        return null;
    tex2 = tex.getTexture();

    textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null);
    textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null);

    createInterleavedBuffers();

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

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

    objRoot.addChild(trans);
    trans.addChild(shape);

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

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -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);

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

    return objRoot;
}

From source file:GeometryByReferenceNIOBuffer.java

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

    // Set up attributes to render lines
    app = new Appearance();

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);//from  w w  w. j  a v  a2 s  .  co  m
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    //create the direct nio buffer
    createJ3DBuffers();

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

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

    objRoot.addChild(trans);
    trans.addChild(shape);

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

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -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);

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

    return objRoot;
}

From source file:GeometryByReferenceTest.java

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

    // Set up attributes to render lines
    app = new Appearance();

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);//from  w w w.j  ava 2 s  . co  m
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

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

    objRoot.addChild(trans);
    trans.addChild(shape);

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

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -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);

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

    return objRoot;
}

From source file:BackgroundGeometry.java

public BranchGroup createSceneGraph() {

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

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);// w  w  w . j a  va  2s  .  c om
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create the 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 objTrans = new TransformGroup();
    objScale.addChild(objTrans);

    Background bg = new Background();
    bg.setApplicationBounds(bounds);
    BranchGroup backGeoBranch = new BranchGroup();
    Sphere sphereObj = new Sphere(1.0f,
            Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45);
    Appearance backgroundApp = sphereObj.getAppearance();
    backGeoBranch.addChild(sphereObj);
    bg.setGeometry(backGeoBranch);
    objTrans.addChild(bg);

    TextureLoader tex = new TextureLoader(bgImage, new String("RGB"), this);
    if (tex != null)
        backgroundApp.setTexture(tex.getTexture());

    Vector3f tranlation = new Vector3f(2.0f, 0.0f, 0.0f);
    Transform3D modelTransform = new Transform3D();
    Transform3D tmpTransform = new Transform3D();
    double angleInc = Math.PI / 8.0;
    double angle = 0.0;
    int numBoxes = 16;

    float scaleX[] = { 0.1f, 0.2f, 0.2f, 0.3f, 0.2f, 0.1f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f, 0.3f, 0.1f, 0.3f, 0.2f,
            0.3f };

    float scaleY[] = { 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.4f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f,
            0.4f };

    float scaleZ[] = { 0.3f, 0.2f, 0.1f, 0.1f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f, 0.3f, 0.3f, 0.2f, 0.1f,
            0.2f };

    Appearance a1 = new Appearance();
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(0.5f, 0.5f, 1.0f);
    Color3f oColor = new Color3f(0.5f, 0.5f, 0.3f);

    Material m = new Material(oColor, eColor, oColor, sColor, 100.0f);
    m.setLightingEnable(true);
    a1.setMaterial(m);

    for (int i = 0; i < numBoxes; i++, angle += angleInc) {
        modelTransform.rotY(angle);
        tmpTransform.set(tranlation);
        modelTransform.mul(tmpTransform);

        TransformGroup tgroup = new TransformGroup(modelTransform);
        objTrans.addChild(tgroup);

        tgroup.addChild(new Box(scaleX[i], scaleY[i], scaleZ[i], Box.GENERATE_NORMALS, a1));
    }

    // Shine it with two lights.
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    return objRoot;
}

From source file:VrmlPickingTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[1];
    tgArray[0] = new TransformGroup();

    Transform3D viewTrans = new Transform3D();
    Transform3D eyeTrans = new Transform3D();

    BoundingSphere sceneBounds = (BoundingSphere) m_SceneBranchGroup.getBounds();

    // point the view at the center of the object
    Point3d center = new Point3d();
    sceneBounds.getCenter(center);//from ww  w. j  a  va  2  s .  c  o m
    double radius = sceneBounds.getRadius();
    Vector3d temp = new Vector3d(center);
    viewTrans.set(temp);

    // pull the eye back far enough to see the whole object
    double eyeDist = 1.4 * radius / Math.tan(Math.toRadians(40) / 2.0);
    temp.x = 0.0;
    temp.y = 0.0;
    temp.z = eyeDist;
    eyeTrans.set(temp);
    viewTrans.mul(eyeTrans);

    // set the view transform
    tgArray[0].setTransform(viewTrans);

    return tgArray;
}