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

TransformGroup createConeTransformGroup() {

    // create a TransformGroup for the cone, allow tranform changes,
    coneTG = new TransformGroup();
    coneTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    coneTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // Set up an appearance to make the Cone with red ambient,
    // black emmissive, red diffuse and white specular coloring
    Material material = new Material(red, black, red, white, 64);
    // These are the colors used for the book figures:
    //Material material = new Material(white, black, white, black, 64);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);/*ww  w  .  j  ava2  s.c om*/

    // create the cone and add it to the coneTG
    Cone cone = new Cone(coneRadius, coneHeight, appearance);
    coneTG.addChild(cone);

    return coneTG;
}

From source file:SimpleSounds.java

protected BranchGroup buildContentBranch() {
    //Create the appearance
    Appearance app = new Appearance();
    Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f);
    float shininess = 20.0f;
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    //Make the cube
    Box myCube = new Box(1.0f, 1.0f, 1.0f, app);

    TransformGroup cubeGroup = new TransformGroup();

    BranchGroup contentBranch = new BranchGroup();
    addLights(contentBranch);/*w  w  w . j a va 2  s .c  om*/
    addObjectSound(cubeGroup, sound1, new String("file:./loop1.wav"), 10.0f);
    addObjectSound(cubeGroup, sound2, new String("file:./loop2.wav"), 20.0f);
    addBackgroundSound(contentBranch, new String("file:./loop3.wav"));

    cubeGroup.addChild(myCube);
    contentBranch.addChild(cubeGroup);
    return contentBranch;

}

From source file:KeyNavigateTest.java

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

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

    createMap(objTrans);/*  www.j a v  a2  s .com*/
    createFloor(objTrans);
    createCeiling(objTrans);

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:SwingTest.java

/**
 * Get the TransformGroup for the View side of the scenegraph
 *//* w w  w  . j a v a 2  s  .co m*/
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.setScale(getScale());
    t3d.setTranslation(new Vector3d(0.0, 0.0, -20.0));
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:AvatarTest.java

ViewerAvatar createAvatar() {
    ViewerAvatar va = new ViewerAvatar();
    TransformGroup tg = new TransformGroup();

    Car car = new Car(this, tg, ComplexObject.GEOMETRY | ComplexObject.TEXTURE | ComplexObject.COLLISION
            | ComplexObject.COLLISION_SOUND);

    car.createObject(new Appearance(), new Vector3d(0, -0.3, -0.3), new Vector3d(0.3, 0.3, 1), "platform.jpg",
            null, "collide.wav");

    tg.addChild(car);/* w ww.ja  v a  2 s.  com*/
    va.addChild(tg);

    return va;
}

From source file:ScenegraphTest.java

TransformGroup createLimb(double radius, double length) {
    // because the cylinder is centered at 0,0,0
    // we need to shift the cylinder so that the bottom of
    // the cylinder is at 0,0,0 and the top is at 0, length, 0

    TransformGroup tg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3d(0, length / 2, 0));
    tg.setTransform(t3d);// w  w w  . j  av  a  2s. c  o m

    Appearance app = new Appearance();
    Color3f black = new Color3f(0.4f, 0.2f, 0.1f);
    Color3f objColor = new Color3f(1, 0.8f, 0.6f);
    app.setMaterial(new Material(objColor, black, objColor, black, 90.0f));

    Cylinder cylinder = new Cylinder((float) radius, (float) length, Primitive.GENERATE_NORMALS, app);

    tg.addChild(cylinder);
    return tg;
}

From source file:J3dSwingFrame.java

public Camera() {
    hud_group = new Group();
    hud_group.setCapability(Group.ALLOW_CHILDREN_EXTEND);

    platform = new ViewPlatform();
    location = new Transform3D();

    root_tx_grp = new TransformGroup();
    root_tx_grp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    root_tx_grp.setTransform(location);//www  . ja  va 2 s.  c  om
    root_tx_grp.addChild(platform);
    root_tx_grp.addChild(hud_group);

    // now create the headlight
    headlight = new DirectionalLight();
    headlight.setCapability(Light.ALLOW_STATE_WRITE);
    headlight.setColor(White);
    headlight.setInfluencingBounds(LIGHT_BOUNDS);
    root_tx_grp.addChild(headlight);

    body = new PhysicalBody();
    env = new PhysicalEnvironment();

    view = new View();
    view.setBackClipDistance(BACK_CLIP_DISTANCE);
    view.setPhysicalBody(body);
    view.setPhysicalEnvironment(env);
    view.attachViewPlatform(platform);
}

From source file:MouseNavigateTest.java

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

    // note that we are creating a TG *above* the TG
    // the is being controlled by the mouse behaviors.
    // The SUN mouse translate behavior would fail in this
    // instance as all movement would be in the X-Y plane
    // irrespective of any TG above the object.
    // The TornadoMouseTranslate behavior always moves an object
    // parrallel to the image plane
    TransformGroup objTrans1 = new TransformGroup();
    Transform3D t3d = new Transform3D();
    objTrans1.getTransform(t3d);//from  w  w w.j a va  2  s .c  o  m
    t3d.setEuler(new Vector3d(0.9, 0.8, 0.3));
    objTrans1.setTransform(t3d);

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

    // create the mouse scale behavior and set limits
    TornadoMouseScale mouseScale = new TornadoMouseScale(5, 0.1f);
    mouseScale.setMinScale(new Point3d(0.5, 0.5, 0.5));
    mouseScale.setMaxScale(new Point3d(2, 2, 2));
    mouseScale.setObject(objTrans);
    mouseScale.setChangeListener(this);
    mouseScale.setSchedulingBounds(getApplicationBounds());
    objTrans.addChild(mouseScale);

    // create the mouse rotate behavior
    TornadoMouseRotate mouseRotate = new TornadoMouseRotate(0.001, 0.001);
    mouseRotate.setInvert(true);
    mouseRotate.setObject(objTrans);
    mouseRotate.setChangeListener(this);
    mouseRotate.setSchedulingBounds(getApplicationBounds());
    objTrans.addChild(mouseRotate);

    // create the mouse translate behavior and set limits
    TornadoMouseTranslate mouseTrans = new TornadoMouseTranslate(0.005f);
    mouseTrans.setObject(objTrans);
    mouseTrans.setChangeListener(this);
    mouseTrans.setMinTranslate(new Point3d(-4, -4, -4));
    mouseTrans.setMaxTranslate(new Point3d(4, 4, 4));
    mouseTrans.setSchedulingBounds(getApplicationBounds());
    objTrans.addChild(mouseTrans);

    objTrans.addChild(new ColorCube(0.5));

    // create some axis for the world to show it has been rotated
    ColorCube axis = new ColorCube(5.0);
    Appearance app = new Appearance();
    app.setPolygonAttributes(
            new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0));
    axis.setAppearance(app);
    objTrans1.addChild(axis);

    objTrans1.addChild(objTrans);
    objRoot.addChild(objTrans1);

    return objRoot;
}

From source file:HiResCoordTest.java

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

    Vector3d vTrans = new Vector3d(0.0, 0.0, -m_TranslateSunZ);

    // move the camera BACK so we can view the scene
    // note that the coordinate directions are
    // reversed as we are moving the view
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(vTrans);//from w w w  .  jav a  2s.c  om
    t3d.invert();
    tgArray[0].setTransform(t3d);

    return tgArray;
}

From source file:SimpleTest.java

public TransformGroup createBehaviors(BranchGroup bg) {
    // create a TransformGroup.
    ///* w  ww.  j a v  a2 s . com*/
    // A TransformGroup is a Group node (can have children)
    // and contains a Transform3D member.
    //
    // The Transform3D member contains a 4x4 transformation matrix
    // that is applied during rendering to all the TransformGroup's
    // child nodes. The 4x4 matrix can describe:
    // scaling, translation and rotation in one neat package!

    // enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // create a new Transform3D that will describe
    // the direction we want to move.
    Transform3D xAxis = new Transform3D();

    // create an Alpha object.
    // The Alpha object describes a function against time.
    // The Alpha will output a value that ranges between 0 and 1
    // using the time parameters (in milliseconds).
    Alpha xAlpha = new Alpha(-1, Alpha.DECREASING_ENABLE | Alpha.INCREASING_ENABLE, 1000, 1000, 5000, 1000,
            1000, 10000, 2000, 4000);

    // create a PositionInterpolator
    // The PositionInterpolator will modify the translation components
    // of a TransformGroup's Transform3D (objTrans) based on the output
    // from the Alpha. In this case the movement will range from
    // -0.8 along the X-axis with Alpha=0 to X=0.8 when Alpha=1.
    PositionInterpolator posInt = new PositionInterpolator(xAlpha, objTrans, xAxis, -0.8f, 0.8f);

    // set the range of influence of the PositionInterpolator
    posInt.setSchedulingBounds(getBoundingSphere());

    // wire the PositionInterpolator into its parent
    // TransformGroup. Just like rendering nodes behaviors
    // must be added to the scenegraph.
    objTrans.addChild(posInt);

    // add the TransformGroup to its parent BranchGroup
    bg.addChild(objTrans);

    // we return the TransformGroup with the
    // behavior attached so that we can add nodes to it
    // (which will be effected by the PositionInterpolator).
    return objTrans;
}