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() 

Source Link

Document

Constructs and initializes a TransformGroup using an identity transform.

Usage

From source file:LightTest.java

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

    // create the 4 lights - the actual creation
    // and UI managment is delegated to an object
    // that "shadows" (no pun intended) the functionality
    // of the particular light
    createLight(new AmbientLightObject(), objRoot);
    createLight(new PointLightObject(), objRoot);
    createLight(new DirectionalLightObject(), objRoot);
    createLight(new SpotLightObject(), objRoot);

    // rotate some of the spheres in the scene
    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(getApplicationBounds());
    objTrans.addChild(rotator);//  w  w  w .  ja  va2  s .  c  o  m

    // create a large sphere in the center of the
    // scene and the floor as staionary objects
    objRoot.addChild(createSphere(0, 0, 0, 2));
    objRoot.addChild(createFloor());

    // create a smaller sphere at the corners of a cube
    final int nCubeSize = 3;
    objTrans.addChild(createSphere(nCubeSize, nCubeSize, nCubeSize, 1));
    objTrans.addChild(createSphere(nCubeSize, nCubeSize, -nCubeSize, 1));
    objTrans.addChild(createSphere(nCubeSize, -nCubeSize, nCubeSize, 1));
    objTrans.addChild(createSphere(nCubeSize, -nCubeSize, -nCubeSize, 1));
    objTrans.addChild(createSphere(-nCubeSize, nCubeSize, nCubeSize, 1));
    objTrans.addChild(createSphere(-nCubeSize, nCubeSize, -nCubeSize, 1));
    objTrans.addChild(createSphere(-nCubeSize, -nCubeSize, nCubeSize, 1));
    objTrans.addChild(createSphere(-nCubeSize, -nCubeSize, -nCubeSize, 1));

    // add some small spheres here and there to
    // make things interesting
    objRoot.addChild(createSphere(-6, -6, 2, 1));
    objRoot.addChild(createSphere(8, -5, 3, 1));
    objRoot.addChild(createSphere(6, 7, -1, 1));
    objRoot.addChild(createSphere(-5, 6, -3.5f, 0.5f));

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:CustomAlphaTest.java

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

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

    ColorCube cube = new ColorCube(2);
    objTrans.addChild(cube);//from   ww w .  ja va 2  s.co  m

    FileAlpha fileAlpha = null;

    try {
        fileAlpha = new FileAlpha(new URL(getWorkingDirectory(), "values.xls"), this);
    } catch (Exception e) {
        e.toString();
    }

    PositionInterpolator posInterpolator = new PositionInterpolator(fileAlpha, objTrans, new Transform3D(), -6,
            6);
    posInterpolator.setSchedulingBounds(getApplicationBounds());

    objTrans.addChild(posInterpolator);
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:Human1.java

void createHuman() {
    Human_body = new TransformGroup();

    // center the body
    tmpVector.set(0.0f, -1.5f, 0.0f);/*  w w  w  .  j a v a  2  s .co m*/
    tmpTrans.set(tmpVector);
    Human_body.setTransform(tmpTrans);

    // Set up an appearance to make the body with red ambient,
    // black emmissive, red diffuse and white specular coloring
    Material material = new Material(red, black, red, white, 64);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);

    // offset and place the cylinder for the body
    tmpTG = new TransformGroup();
    // offset the shape
    tmpVector.set(0.0f, 1.5f, 0.0f);
    tmpTrans.set(tmpVector);
    tmpTG.setTransform(tmpTrans);
    tmpCyl = new Cylinder(0.75f, 3.0f, appearance);
    tmpTG.addChild(tmpCyl);

    // add the shape to the body
    Human_body.addChild(tmpTG);

    // create the r_shoulder TransformGroup
    Human_r_shoulder = new TransformGroup();
    Human_r_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    Human_r_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // translate from the waist
    tmpVector.set(-0.95f, 2.9f, -0.2f);
    tmpTrans.set(tmpVector);
    Human_r_shoulder.setTransform(tmpTrans);

    // place the sphere for the r_shoulder
    tmpSphere = new Sphere(0.22f, appearance);
    Human_r_shoulder.addChild(tmpSphere);

    // offset and place the cylinder for the r_shoulder
    tmpTG = new TransformGroup();
    // offset the shape
    tmpVector.set(0.0f, -0.5f, 0.0f);
    tmpTrans.set(tmpVector);
    tmpTG.setTransform(tmpTrans);
    tmpCyl = new Cylinder(0.2f, 1.0f, appearance);
    tmpTG.addChild(tmpCyl);

    // add the shape to the r_shoulder
    Human_r_shoulder.addChild(tmpTG);

    // add the shoulder to the body group
    Human_body.addChild(Human_r_shoulder);

    // create the r_elbow TransformGroup
    Human_r_elbow = new TransformGroup();
    Human_r_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    Human_r_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tmpVector.set(0.0f, -1.054f, 0.0f);
    tmpTrans.set(tmpVector);
    Human_r_elbow.setTransform(tmpTrans);

    // place the sphere for the r_elbow
    tmpSphere = new Sphere(0.22f, appearance);
    Human_r_elbow.addChild(tmpSphere);

    // offset and place the cylinder for the r_shoulder
    tmpTG = new TransformGroup();
    // offset the shape
    tmpVector.set(0.0f, -0.5f, 0.0f);
    tmpTrans.set(tmpVector);
    tmpTG.setTransform(tmpTrans);
    tmpCyl = new Cylinder(0.2f, 1.0f, appearance);
    tmpTG.addChild(tmpCyl);

    // add the shape to the r_shoulder
    Human_r_elbow.addChild(tmpTG);

    // add the elbow to the shoulder group
    Human_r_shoulder.addChild(Human_r_elbow);

    // create the l_shoulder TransformGroup
    Human_l_shoulder = new TransformGroup();
    Human_l_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    Human_l_shoulder.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tmpVector.set(0.95f, 2.9f, -0.2f);
    tmpTrans.set(tmpVector);
    Human_l_shoulder.setTransform(tmpTrans);

    // place the sphere for the l_shoulder
    tmpSphere = new Sphere(0.22f, appearance);
    Human_l_shoulder.addChild(tmpSphere);

    // offset and place the cylinder for the l_shoulder
    tmpTG = new TransformGroup();
    // offset the shape
    tmpVector.set(0.0f, -0.5f, 0.0f);
    tmpTrans.set(tmpVector);
    tmpTG.setTransform(tmpTrans);
    tmpCyl = new Cylinder(0.2f, 1.0f, appearance);
    tmpTG.addChild(tmpCyl);

    // add the shape to the l_shoulder
    Human_l_shoulder.addChild(tmpTG);

    // add the shoulder to the body group
    Human_body.addChild(Human_l_shoulder);

    // create the r_elbow TransformGroup
    Human_l_elbow = new TransformGroup();
    Human_l_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    Human_l_elbow.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tmpVector.set(0.0f, -1.054f, 0.0f);
    tmpTrans.set(tmpVector);
    Human_l_elbow.setTransform(tmpTrans);

    // place the sphere for the l_elbow
    tmpSphere = new Sphere(0.22f, appearance);
    Human_l_elbow.addChild(tmpSphere);

    // offset and place the cylinder for the l_elbow
    tmpTG = new TransformGroup();
    // offset the shape
    tmpVector.set(0.0f, -0.5f, 0.0f);
    tmpTrans.set(tmpVector);
    tmpTG.setTransform(tmpTrans);
    tmpCyl = new Cylinder(0.2f, 1.0f, appearance);
    tmpTG.addChild(tmpCyl);

    // add the shape to the l_elbow
    Human_l_elbow.addChild(tmpTG);

    // add the shoulder to the body group
    Human_l_shoulder.addChild(Human_l_elbow);

    // create the skullbase TransformGroup
    Human_skullbase = new TransformGroup();
    tmpVector.set(0.0f, 3.632f, 0.0f);
    tmpTrans.set(tmpVector);
    Human_skullbase.setTransform(tmpTrans);

    // offset and place the sphere for the skull
    tmpSphere = new Sphere(0.5f, appearance);

    // add the shape to the l_shoulder
    Human_skullbase.addChild(tmpSphere);

    // add the shoulder to the body group
    Human_body.addChild(Human_skullbase);

}

From source file:VrmlPickingTest.java

private TransformGroup createMouseBehaviorsGroup() {
    TransformGroup examineGroup = new TransformGroup();
    examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    Bounds behaviorBounds = getApplicationBounds();

    MouseRotate mr = new MouseRotate(examineGroup);
    mr.setSchedulingBounds(behaviorBounds);
    examineGroup.addChild(mr);/*from   ww w. j av a  2 s.co m*/

    MouseTranslate mt = new MouseTranslate(examineGroup);
    mt.setSchedulingBounds(behaviorBounds);
    examineGroup.addChild(mt);

    MouseZoom mz = new MouseZoom(examineGroup);
    mz.setSchedulingBounds(behaviorBounds);
    examineGroup.addChild(mz);

    return examineGroup;
}

From source file:ScenegraphTest.java

private TransformGroup addLimb(Group parentGroup, String szName, double radius, double length, double rotMin,
        double rotMax) {
    // create the rotator
    TransformGroup tgJoint = new TransformGroup();
    tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // add a rotator if necessary
    if (rotMin != rotMax) {
        Transform3D xAxis = new Transform3D();
        xAxis.rotX(Math.PI / 2.0);
        Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

        RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, tgJoint, xAxis, (float) rotMin,
                (float) rotMax);
        rotator.setSchedulingBounds(createApplicationBounds());
        tgJoint.addChild(rotator);//from  www  .ja va 2s.  c o  m
    }

    // create a cylinder using length and radius
    tgJoint.addChild(createLimb(radius, length));

    // create the joint (the *next* TG should
    // be offset by the length of this limb)
    TransformGroup tgOffset = new TransformGroup();

    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(0, length, 0));
    tgOffset.setTransform(t3d);

    tgJoint.addChild(tgOffset);
    parentGroup.addChild(tgJoint);

    // return the offset TG, so any child TG's will be added
    // in the correct position.
    return tgOffset;
}

From source file:LightScopeApp.java

BranchGroup createScene() {
    BranchGroup scene = new BranchGroup();
    TransformGroup tableTG = new TransformGroup();
    TransformGroup lampTG = new TransformGroup();
    TransformGroup litBoxTG = new TransformGroup();
    TransformGroup unLitBoxTG = new TransformGroup();

    scene.addChild(tableTG);/*from   w w  w  .  j av  a 2  s  . c om*/
    tableTG.addChild(lampTG);
    tableTG.addChild(litBoxTG);
    tableTG.addChild(unLitBoxTG);

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

    Vector3f transVector = new Vector3f();
    Transform3D transTransform = new Transform3D();

    transVector.set(0.0f, -0.4f, 0.5f);
    transTransform.setTranslation(transVector);
    tableTG.setTransform(transTransform);

    transVector.set(-0.4f, 0.001f, 0.1f);
    transTransform.setTranslation(transVector);
    lampTG.setTransform(transTransform);

    transVector.set(-0.2f, 0.1f, 0.2f);
    transTransform.setTranslation(transVector);
    litBoxTG.setTransform(transTransform);

    transVector.set(0.3f, 0.1f, -0.4f);
    transTransform.setTranslation(transVector);
    unLitBoxTG.setTransform(transTransform);

    Shape3D tablePlane = createXZPlane(new Point3f(-1.0f, 0.0f, -1.0f), new Point3f(-1.0f, 0.0f, 1.0f),
            new Point3f(1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, -1.0f));
    tablePlane.setAppearance(createMaterialAppearance(white));
    tableTG.addChild(tablePlane);
    litBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, createMaterialAppearance(red)));
    Shape3D shadowPlane = createXZPlane(new Point3f(0.1f, -0.095f, -0.1f), new Point3f(0.1f, -0.095f, 0.1f),
            new Point3f(0.2f, -0.095f, 0.15f), new Point3f(0.2f, -0.095f, -0.15f));
    shadowPlane.setAppearance(createMaterialAppearance(black));
    litBoxTG.addChild(shadowPlane);

    Appearance redGlowMat = createMaterialAppearance(red);
    //    redGlowMat.getMaterial().setEmissiveColor(0.5f, 0.5f, 0.5f);
    unLitBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, redGlowMat));

    Shape3D lamp = createLampShape();
    Appearance lampAppearance = createMaterialAppearance(blue);
    PolygonAttributes polyAttrib = new PolygonAttributes();
    polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    polyAttrib.setBackFaceNormalFlip(true);
    lampAppearance.setPolygonAttributes(polyAttrib);
    lamp.setAppearance(lampAppearance);
    lampTG.addChild(lamp);

    PointLight lampLight = new PointLight();
    lampLight.setPosition(0.1f, 0.5f, -0.1f);
    lampLight.setInfluencingBounds(new BoundingSphere());
    lampTG.addChild(lampLight);

    Shape3D litPlane = createXZPlane(new Point3f(-0.4f, 0.0f, -0.4f), new Point3f(-0.4f, 0.0f, 0.4f),
            new Point3f(0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, -0.4f));
    litPlane.setAppearance(createMaterialAppearance(white));
    lampTG.addChild(litPlane);

    lampLight.addScope(lampTG);
    lampLight.addScope(litBoxTG);

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

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    lightD1.setColor(new Color3f(0.4f, 0.4f, 0.4f));
    Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f);
    lightDir.normalize();
    lightD1.setDirection(lightDir);
    scene.addChild(lightD1);

    DirectionalLight lightD2 = new DirectionalLight();
    lightD2.setInfluencingBounds(new BoundingSphere());
    lightD2.setColor(new Color3f(0.2f, 0.2f, 0.2f));
    lightDir.set(1.0f, -1.0f, -1.0f);
    lightDir.normalize();
    lightD2.setDirection(lightDir);
    scene.addChild(lightD2);

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

    return scene;
}

From source file:PickTest.java

public BranchGroup createSceneGraph(Canvas3D canvas) {
    // 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(1.0);/*w w  w .j a  v a 2 s . com*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bunch of objects with a behavior and add them
    // into the scene graph.

    int row, col;
    int numRows = 4, numCols = 4;

    for (int i = 0; i < numRows; i++) {
        double ypos = (double) (i - numRows / 2) * 0.45 + 0.25;
        for (int j = 0; j < numCols; j++) {
            double xpos = (double) (j - numCols / 2) * 0.45 + 0.25;
            objScale.addChild(createObject(i * numCols + j, 0.1, xpos, ypos));
        }
    }

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

    // Add a light.
    Color3f lColor = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lDir = new Vector3f(0.0f, 0.0f, -1.0f);

    DirectionalLight lgt = new DirectionalLight(lColor, lDir);
    lgt.setInfluencingBounds(bounds);
    objRoot.addChild(lgt);

    // 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);
    objRoot.addChild(mBeh);

    behavior1 = new PickRotateBehavior(objRoot, canvas, bounds);
    objRoot.addChild(behavior1);

    behavior2 = new PickZoomBehavior(objRoot, canvas, bounds);
    objRoot.addChild(behavior2);

    behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds);
    objRoot.addChild(behavior3);

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

    return objRoot;
}

From source file:TexCoordTest.java

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

    // move the camera BACK a little...
    // note that we have to invert the matrix as
    // we are moving the viewer
    Transform3D t3d = new Transform3D();

    t3d.rotX(0.4);//  www . j a  v  a2 s  .com
    t3d.setScale(getScale());
    t3d.setTranslation(new Vector3d(0.0, 0, -20.0));
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:DoorApp.java

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

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

    OpenBehavior openObject = new OpenBehavior(doorTG);
    CloseBehavior closeObject = new CloseBehavior(doorTG);

    //prepare the behavior objects
    openObject.setBehaviorObjectPartner(closeObject);
    closeObject.setBehaviorObjectPartner(openObject);

    // set scheduling bounds for behavior objects
    BoundingSphere bounds = new BoundingSphere();
    openObject.setSchedulingBounds(bounds);
    closeObject.setSchedulingBounds(bounds);

    // assemble scene graph
    objRoot.addChild(openObject);/* ww  w  . j  av a 2  s  .c  o m*/
    objRoot.addChild(closeObject);
    objRoot.addChild(doorTG);
    doorTG.addChild(new ColorCube(0.4));

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

    return objRoot;
}

From source file:BehaviorTest.java

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

    // create a TransformGroup to rotate the hand
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // create a RotationInterpolator behavior to rotate the hand
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    m_RotationInterpolator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    m_RotationInterpolator.setSchedulingBounds(createApplicationBounds());
    objTrans.addChild(m_RotationInterpolator);

    // create an Appearance and Material
    Appearance app = new Appearance();

    TextureLoader tex = new TextureLoader("earth.jpg", this);
    app.setTexture(tex.getTexture());//  w  w w.  j  a v a 2  s .  co m

    Sphere sphere = new Sphere(3, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, 32, app);

    // connect the scenegraph
    objTrans.addChild(sphere);
    objRoot.addChild(objTrans);

    m_FpsBehavior = new FpsBehavior();
    m_FpsBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_FpsBehavior);

    m_BoundsBehavior = new BoundsBehavior(sphere);
    m_BoundsBehavior.setSchedulingBounds(getApplicationBounds());
    m_BoundsBehavior.addBehaviorToParentGroup(objTrans);

    m_StretchBehavior = new StretchBehavior((GeometryArray) sphere.getShape().getGeometry());
    m_StretchBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_StretchBehavior);
    m_StretchBehavior.setEnable(false);

    m_SizeBehavior = new ObjectSizeBehavior((GeometryArray) sphere.getShape().getGeometry());
    m_SizeBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_SizeBehavior);
    m_SizeBehavior.setEnable(false);

    m_ExplodeBehavior = new ExplodeBehavior(sphere.getShape(), 10000, 20, this);
    m_ExplodeBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_ExplodeBehavior);

    return objRoot;
}