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:SimpleDirLight.java

/**
 * This build the content branch of our scene graph. It creates a transform
 * group so that the shape is slightly tilted to reveal its 3D shape.
 * //w  w  w  .  j a  v a2  s . com
 * @param shape
 *            Node that represents the geometry for the content
 * @return BranchGroup that is the root of the content branch
 */
protected BranchGroup buildContentBranch() {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    TransformGroup rotationGroup = new TransformGroup(rotateCube);
    contentBranch.addChild(rotationGroup);
    //Create a new appearance
    Appearance app = new Appearance();
    //Create the colours for the material
    Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    //Define the shininess
    float shininess = 20.0f;
    //Set the material of the appearance
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    //Create and add a new sphere using the appearance
    rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app));
    //Use the addLights function to add the lights to the branch
    addLights(contentBranch);
    //Return the root of the content branch
    return contentBranch;
}

From source file:BackgroundApp.java

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

    Vector3f translate = new Vector3f();
    Transform3D T3D = new Transform3D();

    translate.set(0.0f, -0.3f, 0.0f);/*from w w w .  j a va2s  .c om*/
    T3D.setTranslation(translate);
    TransformGroup objRoot = new TransformGroup(T3D);
    objRootBG.addChild(objRoot);

    objRoot.addChild(createLand());

    BoundingLeaf boundingLeaf = new BoundingLeaf(new BoundingSphere());

    PlatformGeometry platformGeom = new PlatformGeometry();
    platformGeom.addChild(boundingLeaf);
    platformGeom.compile();
    su.getViewingPlatform().setPlatformGeometry(platformGeom);

    KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(
            su.getViewingPlatform().getViewPlatformTransform());
    keyNavBeh.setSchedulingBoundingLeaf(boundingLeaf);
    objRootBG.addChild(keyNavBeh);

    Background background = new Background();
    background.setApplicationBounds(new BoundingSphere(new Point3d(), 1000.0));
    background.setGeometry(createBackGraph());
    objRoot.addChild(background);

    AmbientLight ambientLight = new AmbientLight();
    ambientLight.setInfluencingBounds(new BoundingSphere());
    objRootBG.addChild(ambientLight);

    return objRootBG;
}

From source file:SimpleTransform.java

/**
 * This builds the content branch of our scene graph. The root of the shapes
 * supplied as a parameter is slightly tilted to reveal its 3D shape. It
 * also uses the addLights function to add some lights to the scene. The
 * group that the shape is added to has its capabilities set so that we can
 * read and write it.//from  w w w . j av a  2s.c  om
 * 
 * @param shape
 *            Node that represents the geometry for the content
 * @return BranchGroup that is the root of the content branch
 */
protected BranchGroup buildContentBranch(Node shape) {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    rotationGroup = new TransformGroup(rotateCube);
    //Set the capabilities so that the transform can be accessed
    rotationGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    rotationGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    contentBranch.addChild(rotationGroup);
    rotationGroup.addChild(shape);
    addLights(contentBranch);
    return contentBranch;
}

From source file:SimpleIndexedQuadSmooth.java

/**
 * This builds the content branch of our scene graph. It uses the buildShape
 * function to create the actual shape, adding to to the transform group so
 * that the shape is slightly tilted to reveal its 3D shape. It also uses
 * the addLights function to add some lights to the scene.
 * //from   w  w  w .j a  v  a  2  s.c o m
 * @param shape
 *            Node that represents the geometry for the content
 * @return BranchGroup that is the root of the content branch
 */
protected BranchGroup buildContentBranch(Node shape) {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    TransformGroup rotationGroup = new TransformGroup(rotateCube);
    contentBranch.addChild(rotationGroup);
    rotationGroup.addChild(shape);
    addLights(contentBranch);
    return contentBranch;
}

From source file:SimpleSpotLights.java

/**
 * This build the content branch of our scene graph. It creates a transform
 * group so that the shape is slightly tilted to reveal its 3D shape.
 * /*from www. j ava 2  s .c  om*/
 * @param shape
 *            Node that represents the geometry for the content
 * @return BranchGroup that is the root of the content branch
 */
protected BranchGroup buildContentBranch() {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    TransformGroup rotationGroup = new TransformGroup(rotateCube);
    contentBranch.addChild(rotationGroup);
    //Create a new appearance
    Appearance app = new Appearance();
    //Create the colours for the material
    Color3f ambientColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f diffuseColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    //Define the shininess
    float shininess = 20.0f;
    //Set the material of the appearance
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    //Create and add a new sphere using the appearance
    rotationGroup.addChild(new Sphere(2.0f, Sphere.GENERATE_NORMALS, 120, app));
    //Use the addLights function to add the lights to the branch
    addLights(contentBranch);
    //Return the root of the content branch
    return contentBranch;
}

From source file:Gouraud.java

/**
 * Erstellt den Szenegraphen/*from www.  j av  a2 s  .  co m*/
 * 
 * @return BranchGroup
 */
public BranchGroup macheSzene() {
    BranchGroup objWurzel = new BranchGroup();
    // Transformation, 2 Rotationen:
    Transform3D drehung = new Transform3D();
    Transform3D drehung2 = new Transform3D();
    drehung.rotX(Math.PI / 4.0d);
    drehung2.rotY(Math.PI / 5.0d);
    drehung.mul(drehung2);
    TransformGroup objDreh = new TransformGroup(drehung);
    //Loader
    ObjectFile file = new ObjectFile(ObjectFile.RESIZE);
    Scene scene = null;
    try {
        // Laden der Obj Datei mittels jar
        scene = file.load(ClassLoader.getSystemResource("teapot.obj"));
    } catch (Exception e) {
        System.err.println(e);
        System.exit(1);
    }
    objDreh.addChild(scene.getSceneGroup());

    DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f),
            new Vector3f(-1.0f, -1.0f, -1.0f));
    d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d));
    objDreh.addChild(d_Licht);
    objWurzel.addChild(objDreh);
    return objWurzel;
}

From source file:KeyNavigatorApp.java

public BranchGroup createSceneGraph(SimpleUniverse su) {
    // Create the root of the branch graph
    TransformGroup vpTrans = null;/*from   ww  w.j  a  v  a 2s  . c om*/

    BranchGroup objRoot = new BranchGroup();

    Vector3f translate = new Vector3f();
    Transform3D T3D = new Transform3D();
    TransformGroup TG = null;

    objRoot.addChild(createLand());

    SharedGroup share = new SharedGroup();
    share.addChild(createPyramid());

    float[][] position = { { 0.0f, 0.0f, -3.0f }, { 6.0f, 0.0f, 0.0f }, { 6.0f, 0.0f, 6.0f },
            { 3.0f, 0.0f, -10.0f }, { 13.0f, 0.0f, -30.0f }, { -13.0f, 0.0f, 30.0f }, { -13.0f, 0.0f, 23.0f },
            { 13.0f, 0.0f, 3.0f } };

    for (int i = 0; i < position.length; i++) {
        translate.set(position[i]);
        T3D.setTranslation(translate);
        TG = new TransformGroup(T3D);
        TG.addChild(new Link(share));
        objRoot.addChild(TG);
    }
    vpTrans = su.getViewingPlatform().getViewPlatformTransform();
    translate.set(0.0f, 0.3f, 0.0f);
    T3D.setTranslation(translate);
    vpTrans.setTransform(T3D);
    KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
    keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
    objRoot.addChild(keyNavBeh);

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

    return objRoot;
}

From source file:SimpleKeyNav.java

/**
 * Build the content branch for the scene graph
 * /*from  ww w. j  a  v  a2  s.co m*/
 * @return BranchGroup that is the root of the content
 */
protected BranchGroup buildContentBranch() {
    //Create the appearance an appearance for the two cubes
    Appearance app1 = new Appearance();
    Appearance app2 = new Appearance();
    Color3f ambientColour1 = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f ambientColour2 = 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 diffuseColour1 = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f diffuseColour2 = new Color3f(1.0f, 1.0f, 0.0f);
    float shininess = 20.0f;
    app1.setMaterial(new Material(ambientColour1, emissiveColour, diffuseColour1, specularColour, shininess));
    app2.setMaterial(new Material(ambientColour2, emissiveColour, diffuseColour2, specularColour, shininess));
    //Make two cubes
    Box leftCube = new Box(1.0f, 1.0f, 1.0f, app1);
    Box rightCube = new Box(1.0f, 1.0f, 1.0f, app2);

    BranchGroup contentBranch = new BranchGroup();
    addLights(contentBranch);
    //Put it all together
    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);

    leftGroup.addChild(leftCube);
    rightGroup.addChild(rightCube);
    contentBranch.addChild(leftGroup);
    contentBranch.addChild(rightGroup);
    return contentBranch;

}

From source file:IntersectTest.java

public BranchGroup createSceneGraph() {

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

    // Set up the ambient light
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);/*  w  w  w. ja v a  2 s .c  o m*/

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f);
    Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    Transform3D t3 = new Transform3D();

    // Shapes
    for (int x = 0; x < 3; x++) {
        for (int y = 0; y < 3; y++) {
            for (int z = 0; z < 3; z++) {
                t3.setTranslation(new Vector3d(-4 + x * 4.0, -4 + y * 4.0, -20 - z * 4.0));
                TransformGroup objTrans = new TransformGroup(t3);

                objRoot.addChild(objTrans);

                // Create a simple shape leaf node, add it to the scene
                // graph.
                GeometryArray geom = null;

                if (((x + y + z) % 2) == 0) {
                    geom = new RandomColorCube();
                } else {
                    geom = new RandomColorTetrahedron();
                }

                Shape3D shape = new Shape3D(geom);

                // use the utility method to set the capabilities
                PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);

                objTrans.addChild(shape);
            }
        }
    }

    // Lines
    Point3f[] verts = { new Point3f(-2.0f, 0.0f, 0.0f), new Point3f(2.0f, 0.0f, 0.0f) };
    Color3f grey = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f[] colors = { grey, grey };

    for (int y = 0; y < 5; y++) {
        for (int z = 0; z < 5; z++) {
            t3.setTranslation(new Vector3d(7.0, -4 + y * 2.0, -20.0 - z * 2.0));
            TransformGroup objTrans = new TransformGroup(t3);

            objRoot.addChild(objTrans);

            LineArray la = new LineArray(verts.length, LineArray.COORDINATES | LineArray.COLOR_3);
            la.setCoordinates(0, verts);
            la.setColors(0, colors);

            Shape3D shape = new Shape3D();
            shape.setGeometry(la);

            // use the utility method to set the capabilities
            PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);

            objTrans.addChild(shape);
        }
    }

    // Points
    for (double x = -2.0; x <= 2.0; x += 1.0) {
        for (double y = -2.0; y <= 2.0; y += 1.0) {
            for (double z = -2.0; z <= 2.0; z += 1.0) {
                t3.setTranslation(new Vector3d(-10.0 + 2.0 * x, 0.0 + 2.0 * y, -20.0 + 2.0 * z));
                TransformGroup objTrans = new TransformGroup(t3);

                objRoot.addChild(objTrans);

                PointArray pa = new PointArray(1, PointArray.COORDINATES | PointArray.COLOR_3);

                pa.setCoordinate(0, new Point3d(0.0, 0.0, 0.0));
                pa.setColor(0, grey);

                Shape3D shape = new Shape3D();
                shape.setGeometry(pa);

                // use the utility method to set the capabilities
                PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);

                objTrans.addChild(shape);
            }
        }
    }

    return objRoot;
}

From source file:ExTransform.java

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

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