Example usage for javax.media.j3d Transform3D set

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

Introduction

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

Prototype

public final void set(double scale) 

Source Link

Document

Sets the value of this transform to a uniform scale; all of the matrix values are modified.

Usage

From source file:SimpleLOD.java

/**
 * Build the view branch of the scene graph. In this case a key navigation
 * utility object is created and associated with the view transform so that
 * the view can be changed via the keyboard.
 * /*from   w  w  w  .j  a  v a 2  s .  c  o  m*/
 * @return BranchGroup that is the root of the view branch
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 10.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    BoundingSphere movingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    BoundingLeaf boundLeaf = new BoundingLeaf(movingBounds);
    ViewPlatform myViewPlatform = new ViewPlatform();
    viewXfmGroup.addChild(boundLeaf);
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);

    KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(viewXfmGroup);
    keyNav.setSchedulingBounds(movingBounds);
    viewBranch.addChild(keyNav);

    return viewBranch;
}

From source file:SimpleWorld.java

/**
 * This function builds the view branch of the scene graph. It creates a
 * branch group and then creates the necessary view elements to give a
 * useful view of our content.//from  w  w  w  . ja  v a 2 s . c o  m
 * 
 * @param c
 *            Canvas3D that will display the view
 * @return BranchGroup that is the root of the view elements
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    //This is the root of our view branch
    BranchGroup viewBranch = new BranchGroup();

    //The transform that will move our view
    //back 5 units along the z-axis
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 5.0f));

    //The transform group that will be the parent
    //of our view platform elements
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();

    //Next the physical elements are created
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();

    //Then we put it all together
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);

    return viewBranch;
}

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.
 * //w w  w . ja  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:SimpleIndexedQuadSmooth.java

/**
 * This function builds the view branch of the scene graph. It creates a
 * branch group and then creates the necessary view elements to give a
 * useful view of our content./*  www .  j ava 2 s  . co  m*/
 * 
 * @param c
 *            Canvas3D that will display the view
 * @return BranchGroup that is the root of the view elements
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 5.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    return viewBranch;
}

From source file:SimpleKeyNav.java

/**
 * Build the content branch for the scene graph
 * /* w  w w.  ja  v  a  2s.  c  om*/
 * @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: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./*  www.j a  va2s  . com*/
 * 
 * @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:SimpleBillboard.java

/**
 * Build the content branch for the scene graph. This creates two cubes and
 * uses a billboard node to keep one face of one of the cubes facing the
 * viewer./*from  w  ww.j  av  a  2 s .  c  o  m*/
 * 
 * @return BranchGroup that is the root of the content
 */
protected BranchGroup buildContentBranch() {
    //Create the appearance
    Appearance app = new Appearance();
    Color3f ambientColour = 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 diffuseColour = new Color3f(1.0f, 1.0f, 0.0f);
    float shininess = 20.0f;
    app.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    //Make the cubes
    Box leftCube = new Box(1.0f, 1.0f, 1.0f, app);
    ColorCube rightCube = new ColorCube();
    //Create the transformgroup used for the billboard
    TransformGroup billBoardGroup = new TransformGroup();
    //Set the access rights to the group
    billBoardGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    //Add the cube to the group
    billBoardGroup.addChild(rightCube);
    //Create and activate the billboard
    Billboard myBillboard = new Billboard(billBoardGroup, Billboard.ROTATE_ABOUT_AXIS,
            new Vector3f(0.0f, 1.0f, 0.0f));
    myBillboard.setSchedulingBounds(bounds);
    BranchGroup contentBranch = new BranchGroup();
    contentBranch.addChild(myBillboard);
    addLights(contentBranch);
    //Position the cubes
    TransformGroup bothGroup = new TransformGroup();
    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);
    //Put it all together
    bothGroup.addChild(leftGroup);
    leftGroup.addChild(leftCube);
    bothGroup.addChild(rightGroup);
    rightGroup.addChild(billBoardGroup);
    contentBranch.addChild(bothGroup);
    return contentBranch;

}

From source file:AxisClassDemoApp.java

public BranchGroup createSceneGraph() {

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

    // 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 objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

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

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    rotator.setSchedulingBounds(bounds);

    Transform3D trans = new Transform3D();
    trans.set(new Vector3f(0.5f, 0.0f, 0.0f));
    TransformGroup objTrans = new TransformGroup(trans);
    objRoot.addChild(objSpin);/*from  w w w.j  av a2 s .c  o m*/
    objSpin.addChild(objTrans);
    objSpin.addChild(rotator);
    objTrans.addChild(new ColorCube(0.1));

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

    return objRoot;
}

From source file:SimpleCombine.java

/**
 * This function builds the view branch of the scene graph. It creates a
 * branch group and then creates the necessary view elements to give a
 * useful view of our content.//  w w w  .j a v a 2  s  .com
 * 
 * @param c
 *            Canvas3D that will display the view
 * @return BranchGroup that is the root of the view elements
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 7.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    ViewPlatform myViewPlatform = new ViewPlatform();
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    return viewBranch;
}

From source file:SimpleSounds.java

/**
 * Build the view branch of the scene graph. In this case a key navigation
 * utility object is created and associated with the view transform so that
 * the view can be changed via the keyboard.
 * /*ww w  .  j  a  va  2  s. com*/
 * @return BranchGroup that is the root of the view branch
 */
protected BranchGroup buildViewBranch(Canvas3D c) {
    BranchGroup viewBranch = new BranchGroup();
    Transform3D viewXfm = new Transform3D();
    viewXfm.set(new Vector3f(0.0f, 0.0f, 30.0f));
    TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    ViewPlatform myViewPlatform = new ViewPlatform();
    BoundingSphere movingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    BoundingLeaf boundLeaf = new BoundingLeaf(movingBounds);
    PhysicalBody myBody = new PhysicalBody();
    PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
    viewXfmGroup.addChild(myViewPlatform);
    viewBranch.addChild(viewXfmGroup);
    View myView = new View();
    myView.addCanvas3D(c);
    myView.attachViewPlatform(myViewPlatform);
    myView.setPhysicalBody(myBody);
    myView.setPhysicalEnvironment(myEnvironment);
    KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(viewXfmGroup);
    keyNav.setSchedulingBounds(movingBounds);
    viewBranch.addChild(keyNav);
    //Create a sounds mixer to use our sounds with
    //and initialise it
    JavaSoundMixer myMixer = new JavaSoundMixer(myEnvironment);
    myMixer.initialize();
    return viewBranch;
}