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

private static BranchGroup createSceneGraph() {
    // Make a scene graph branch
    BranchGroup branch = new BranchGroup();

    // Make a changeable 3D transform
    TransformGroup trans = new TransformGroup();
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    branch.addChild(trans);/*from  w  w  w  . j  av a2s  .  co  m*/

    // Make a shape
    ColorCube demo = new ColorCube(0.4);
    trans.addChild(demo);

    // Make a behavor to spin the shape
    Alpha spinAlpha = new Alpha(-1, 4000);
    RotationInterpolator spinner = new RotationInterpolator(spinAlpha, trans);
    spinner.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
    trans.addChild(spinner);

    return branch;
}

From source file:BouncingBall.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);//from w ww  .  j  a  v a 2s . c o m

    // Create a simple shape leaf node, add it to the scene graph.
    Sphere sphere = new Sphere(0.25f);
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D pos1 = new Transform3D();
    pos1.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
    objTrans.setTransform(pos1);
    objTrans.addChild(sphere);
    objRoot.addChild(objTrans);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Color3f light1Color = new Color3f(1.0f, 0.0f, 0.2f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(1.0f, 1.0f, 1.0f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    return objRoot;
}

From source file:MouseBehaviorApp.java

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

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

    objRoot.addChild(objTransform);/*from w ww .j  a  v  a  2  s .c  om*/
    objTransform.addChild(new ColorCube(0.4));
    objRoot.addChild(new Axis());

    MouseRotate myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objTransform);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseRotate);

    MouseTranslate myMouseTranslate = new MouseTranslate();
    myMouseTranslate.setTransformGroup(objTransform);
    myMouseTranslate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseTranslate);

    MouseZoom myMouseZoom = new MouseZoom();
    myMouseZoom.setTransformGroup(objTransform);
    myMouseZoom.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseZoom);

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

    return objRoot;
}

From source file:HelloJava3Dc.java

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

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objSpin);/*from  w w  w.j av  a2 s.  c  o m*/

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

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

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 100
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    return objRoot;
}

From source file:StereoCube.java

public BranchGroup createSceneGraph(int i) {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D t = new Transform3D();
    TransformGroup tg = new TransformGroup(t);
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.addChild(tg);//from  w  w  w  .  j av a  2  s  .  c  o m
    tg.addChild(new ColorCube(0.4));
    MouseRotate behavior = new MouseRotate();
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    behavior.setTransformGroup(tg);
    objTrans.addChild(behavior);
    // Create the translate behavior node
    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(tg);
    objTrans.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

    KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg);
    keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
    objTrans.addChild(keyNavBeh);

    behavior.setSchedulingBounds(bounds);
    objRoot.addChild(objTrans);
    return objRoot;
}

From source file:MouseRotateApp.java

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

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

    objRoot.addChild(objRotate);/*from  w w  w  .  j a  v a  2 s  . c  o m*/
    objRotate.addChild(new ColorCube(0.4));
    objRoot.addChild(new Axis());

    MouseRotate myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objRotate);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseRotate);

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

    return objRoot;
}

From source file:HelloUniverse1.java

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

    // Create the TransformGroup node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at run time. Add it to
    // the root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);// w ww.j av a 2s  . c om

    // Create a simple Shape3D node; add it to the scene graph.
    objTrans.addChild(new ColorCube(0.4));

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

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, 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);
    objRoot.addChild(rotator);

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

    return objRoot;
}

From source file:Text2DApp.java

public BranchGroup createSceneGraph() {

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

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objSpin);/*from  w w w.j a va2s . c  o  m*/

    // Create a simple Text2D leaf node, add it to the scene graph.
    Text2D text2d = new Text2D("2D text in Java 3D", new Color3f(0.9f, 1.0f, 1.0f), "Helvetica", 24,
            Font.ITALIC);

    objSpin.addChild(text2d);

    Appearance textAppear = text2d.getAppearance();

    // The following 4 lines of code (commented out) make the Text2D object
    // 2-sided.
    // This code depends on the line of code above that sets TextAppear.
    //         PolygonAttributes polyAttrib = new PolygonAttributes();
    //         polyAttrib.setCullFace(PolygonAttributes.CULL_NONE);
    //         polyAttrib.setBackFaceNormalFlip(true);
    //         textAppear.setPolygonAttributes(polyAttrib);

    // The following 12 lines of code (commented out) use the texture from
    // the previous Text2D object on another object.
    // This code depends on the line of code above that sets TextAppear.
    //         QuadArray qa = new QuadArray(4, QuadArray.COORDINATES |
    //                                         QuadArray.TEXTURE_COORDINATE_2);
    //         qa.setCoordinate(0, new Point3f(-10.0f, 1.0f, -5.0f));
    //         qa.setCoordinate(1, new Point3f(-10.0f, -1.0f, -5.0f));
    //         qa.setCoordinate(2, new Point3f(10.0f, -1.0f, -5.0f));
    //         qa.setCoordinate(3, new Point3f(10.0f, 1.0f, -5.0f));
    //         qa.setTextureCoordinate(0, new Point2f(0.0f, 1.0f));
    //         qa.setTextureCoordinate(1, new Point2f(0.0f, 0.0f));
    //         qa.setTextureCoordinate(2, new Point2f(1.0f, 0.0f));
    //         qa.setTextureCoordinate(3, new Point2f(1.0f, 1.0f));
    //
    //         objRoot.addChild(new Shape3D(qa, textAppear));

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

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 100
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    Background backg = new Background();
    backg.setColor(0.4f, 0.4f, 1.0f);
    backg.setApplicationBounds(new BoundingSphere());
    objRoot.addChild(backg);

    return objRoot;
}

From source file:Position.java

public Position() {
    SimpleUniverse universe = new SimpleUniverse();
    BranchGroup group = new BranchGroup();
    // X axis made of spheres
    for (float x = -1.0f; x <= 1.0f; x = x + 0.1f) {
        Sphere sphere = new Sphere(0.05f);
        TransformGroup tg = new TransformGroup();
        Transform3D transform = new Transform3D();
        Vector3f vector = new Vector3f(x, .0f, .0f);
        transform.setTranslation(vector);
        tg.setTransform(transform);/*from   www.j  av a2s.  com*/
        tg.addChild(sphere);
        group.addChild(tg);
    }
    // Y axis made of cones
    for (float y = -1.0f; y <= 1.0f; y = y + 0.1f) {
        TransformGroup tg = new TransformGroup();
        Transform3D transform = new Transform3D();
        Cone cone = new Cone(0.05f, 0.1f);
        Vector3f vector = new Vector3f(.0f, y, .0f);
        transform.setTranslation(vector);
        tg.setTransform(transform);
        tg.addChild(cone);
        group.addChild(tg);
    }
    // Z axis made of cylinders
    for (float z = -1.0f; z <= 1.0f; z = z + 0.1f) {
        TransformGroup tg = new TransformGroup();
        Transform3D transform = new Transform3D();
        Cylinder cylinder = new Cylinder(0.05f, 0.1f);
        Vector3f vector = new Vector3f(.0f, .0f, z);
        transform.setTranslation(vector);
        tg.setTransform(transform);
        tg.addChild(cylinder);
        group.addChild(tg);
    }

    Color3f light1Color = new Color3f(.1f, 1.4f, .1f); // green light
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    group.addChild(light1);
    universe.getViewingPlatform().setNominalViewingTransform();

    // add the group of objects to the Universe
    universe.addBranchGraph(group);
}

From source file:TextureImage.java

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

    // 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. Add it to the
    // root of the subgraph.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);//from w  w  w  . j av  a 2s .  c o m

    // Create appearance object for textured cube
    Appearance app = new Appearance();
    Texture tex = new TextureLoader(texImage, this).getTexture();
    app.setTexture(tex);
    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    app.setTextureAttributes(texAttr);

    // Create textured cube and add it to the scene graph.
    Box textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS, app);
    objTrans.addChild(textureCube);

    // 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, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, 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);
    objTrans.addChild(rotator);

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

    return objRoot;
}