Example usage for javax.media.j3d Material Material

List of usage examples for javax.media.j3d Material Material

Introduction

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

Prototype

public Material(Color3f ambientColor, Color3f emissiveColor, Color3f diffuseColor, Color3f specularColor,
        float shininess) 

Source Link

Document

Constructs and initializes a new material object using the specified parameters.

Usage

From source file:Text3DTest.java

TransformGroup createText3D(TornadoRotation rotator, String szText, int nSize, float scale, float trans,
        int nPath) {
    TransformGroup tg = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(scale);// www .j ava  2s .co  m
    t3d.setTranslation(new Vector3d(0.0, trans, -10.0));
    tg.setTransform(t3d);

    // use a customized FontExtrusion object to control the depth of the
    // text
    double X1 = 0;
    double Y1 = 0;
    double X2 = 3;
    double Y2 = 0;
    Shape extrusionShape = new java.awt.geom.Line2D.Double(X1, Y1, X2, Y2);

    FontExtrusion fontEx = new FontExtrusion(extrusionShape);

    Font3D f3d = new Font3D(new Font("TimesRoman", Font.PLAIN, nSize), fontEx);

    TornadoText3D text3D = new TornadoText3D(f3d, szText, new Point3f(0.0f, 0.0f, 0.0f), Text3D.ALIGN_CENTER,
            nPath);

    rotator.addTornadoText3D(text3D);

    // create an appearance
    Color3f black = new Color3f(0.1f, 0.1f, 0.1f);
    Color3f objColor = new Color3f(0.2f, 0.2f, 0.2f);

    Appearance app = new Appearance();
    app.setMaterial(new Material(objColor, black, objColor, black, 90.0f));

    // render as a wireframe
    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    app.setPolygonAttributes(polyAttrbutes);

    tg.addChild(new Shape3D(text3D, app));
    return tg;
}

From source file:ScenegraphTest.java

private void addHead(Group parentGroup) {
    // add a cylinder for the Neck
    TransformGroup tgNeck = addLimb(parentGroup, "Neck", 0.05, 0.2, 0.0, 0.0);

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

    // position a Sphere for the head itself
    Sphere headSphere = new Sphere((float) 0.12, Primitive.GENERATE_NORMALS, app);
    tgNeck.addChild(headSphere);/*  www. j a v a  2s  .  c om*/
}

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 w  ww.j  a va 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() {
    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:SimpleMorph2.java

/**
 * Build the content branch for the scene graph
 * //w  w w .  j a v  a2  s  . com
 * @return BranchGroup that is the root of the content
 */
protected BranchGroup buildContentBranch() {
    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 key shape
    IndexedQuadArray indexedCube = new IndexedQuadArray(8,
            IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24);
    Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f),
            new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f),
            new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f),
            new Point3f(1.0f, -1.0f, -1.0f) };
    Vector3f[] cubeNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f),
            new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f),
            new Vector3f(0.0f, -1.0f, 0.0f) };
    int cubeCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 };
    int cubeNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 };
    indexedCube.setCoordinates(0, cubeCoordinates);
    indexedCube.setNormals(0, cubeNormals);
    indexedCube.setCoordinateIndices(0, cubeCoordIndices);
    indexedCube.setNormalIndices(0, cubeNormalIndices);

    //Make the pyramid key shape. Although this needs
    //only five vertices to create the desired shape, we
    //need to use six vertices so that it has the same
    //number as the cube.
    IndexedQuadArray indexedPyramid = new IndexedQuadArray(8,
            IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24);
    Point3f[] pyramidCoordinates = { new Point3f(0.0f, 1.0f, 0.0f), new Point3f(0.0f, 1.0f, 0.0f),
            new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(0.0f, 1.0f, 0.0f),
            new Point3f(0.0f, 1.0f, 0.0f), new Point3f(-1.0f, -1.0f, -1.0f), new Point3f(1.0f, -1.0f, -1.0f) };
    Vector3f[] pyramidNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f),
            new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f),
            new Vector3f(0.0f, -1.0f, 0.0f) };
    int pyramidCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 };
    int pyramidNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 };
    indexedPyramid.setCoordinates(0, pyramidCoordinates);
    indexedPyramid.setNormals(0, pyramidNormals);
    indexedPyramid.setCoordinateIndices(0, pyramidCoordIndices);
    indexedPyramid.setNormalIndices(0, pyramidNormalIndices);
    //Set the contents of the array to the two shapes
    GeometryArray[] theShapes = new GeometryArray[2];
    theShapes[0] = indexedCube;
    theShapes[1] = indexedPyramid;
    BranchGroup contentBranch = new BranchGroup();
    //Create a transform to rotate the shape slightly
    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);
    addLights(contentBranch);
    //Call the function to build the morph
    rotationGroup.addChild(createMorph(theShapes, app));
    //Add the behaviour to the scene graph to activate it
    rotationGroup.addChild(myBehave);
    return contentBranch;

}

From source file:SimpleSwitch.java

/**
 * This creates the shapes used in the program. A switch node is created
 * that has its write capability set so that we can swap the rendered shape.
 * Then a box and a cone are created and added to the switch.
 * /*www .jav  a 2  s .  c  o m*/
 * @return Node that is the switch node
 */
protected Node buildShape() {
    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));
    //Set the capability so that we can change the switch value
    firstSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    //Add the two shapes to the switch
    firstSwitch.addChild(new Box(2.0f, 2.0f, 2.0f, Box.GENERATE_NORMALS, app));
    firstSwitch.addChild(new Cone(2.0f, 4.0f, Cone.GENERATE_NORMALS, app));
    return firstSwitch;
}

From source file:SimpleCollision.java

/**
 * Creates the content branch of the scene graph.
 * //from  ww  w .j a v a  2 s  .  c o m
 * @return BranchGroup with content attached.
 */
protected BranchGroup buildContentBranch() {
    //First create a different appearance for each cube
    Appearance app1 = new Appearance();
    Appearance app2 = new Appearance();
    Appearance app3 = new Appearance();
    Color3f ambientColour1 = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f ambientColour2 = new Color3f(1.0f, 1.0f, 0.0f);
    Color3f ambientColour3 = new Color3f(1.0f, 1.0f, 1.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);
    Color3f diffuseColour3 = new Color3f(1.0f, 1.0f, 1.0f);
    float shininess = 20.0f;
    app1.setMaterial(new Material(ambientColour1, emissiveColour, diffuseColour1, specularColour, shininess));
    app2.setMaterial(new Material(ambientColour2, emissiveColour, diffuseColour2, specularColour, shininess));
    app3.setMaterial(new Material(ambientColour3, emissiveColour, diffuseColour3, specularColour, shininess));

    //Create the vertex data for the cube. Since each shape is
    //a cube we can use the same vertex data for each cube
    IndexedQuadArray indexedCube = new IndexedQuadArray(8,
            IndexedQuadArray.COORDINATES | IndexedQuadArray.NORMALS, 24);
    Point3f[] cubeCoordinates = { new Point3f(1.0f, 1.0f, 1.0f), new Point3f(-1.0f, 1.0f, 1.0f),
            new Point3f(-1.0f, -1.0f, 1.0f), new Point3f(1.0f, -1.0f, 1.0f), new Point3f(1.0f, 1.0f, -1.0f),
            new Point3f(-1.0f, 1.0f, -1.0f), new Point3f(-1.0f, -1.0f, -1.0f),
            new Point3f(1.0f, -1.0f, -1.0f) };
    Vector3f[] cubeNormals = { new Vector3f(0.0f, 0.0f, 1.0f), new Vector3f(0.0f, 0.0f, -1.0f),
            new Vector3f(1.0f, 0.0f, 0.0f), new Vector3f(-1.0f, 0.0f, 0.0f), new Vector3f(0.0f, 1.0f, 0.0f),
            new Vector3f(0.0f, -1.0f, 0.0f) };
    int cubeCoordIndices[] = { 0, 1, 2, 3, 7, 6, 5, 4, 0, 3, 7, 4, 5, 6, 2, 1, 0, 4, 5, 1, 6, 7, 3, 2 };
    int cubeNormalIndices[] = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 };
    indexedCube.setCoordinates(0, cubeCoordinates);
    indexedCube.setNormals(0, cubeNormals);
    indexedCube.setCoordinateIndices(0, cubeCoordIndices);
    indexedCube.setNormalIndices(0, cubeNormalIndices);

    //Create the three cubes
    leftCube = new Shape3D(indexedCube, app1);
    rightCube = new Shape3D(indexedCube, app2);
    moveCube = new Shape3D(indexedCube, app3);

    //Define the user data so that we can print out the
    //name of the colliding cube.
    leftCube.setUserData(new String("left cube"));
    rightCube.setUserData(new String("right cube"));

    //Create the content branch and add the lights
    BranchGroup contentBranch = new BranchGroup();
    addLights(contentBranch);

    //Create and set up the movable cube's TransformGroup.
    //This scales and translates the cube and then sets the
    // read, write and pick reporting capabilities.
    Transform3D moveXfm = new Transform3D();
    moveXfm.set(0.7, new Vector3d(0.0, 2.0, 1.0));
    moveGroup = new TransformGroup(moveXfm);
    moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    moveGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    moveGroup.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    //Create the left cube's TransformGroup
    Transform3D leftGroupXfm = new Transform3D();
    leftGroupXfm.set(new Vector3d(-1.5, 0.0, 0.0));
    leftGroup = new TransformGroup(leftGroupXfm);

    //Create the right cube's TransformGroup
    Transform3D rightGroupXfm = new Transform3D();
    rightGroupXfm.set(new Vector3d(1.5, 0.0, 0.0));
    rightGroup = new TransformGroup(rightGroupXfm);

    //Add the behaviour to allow us to move the cube
    PickTranslateBehavior pickTranslate = new PickTranslateBehavior(contentBranch, myCanvas3D, bounds);
    contentBranch.addChild(pickTranslate);

    //Add our CollisionDetector class to detect collisions with
    //the movable cube.
    CollisionDetector myColDet = new CollisionDetector(moveCube, bounds);
    contentBranch.addChild(myColDet);

    //Create the content branch hierarchy.
    contentBranch.addChild(moveGroup);
    contentBranch.addChild(leftGroup);
    contentBranch.addChild(rightGroup);
    moveGroup.addChild(moveCube);
    leftGroup.addChild(leftCube);
    rightGroup.addChild(rightCube);

    return contentBranch;

}

From source file:SimpleCombine.java

/**
 * This defines the shapes used in the scene. The function uses the utility
 * geometries sphere, box, cone and cylinder to build a simple scene. This
 * demonstrates the use of transformations to group and position items.
 * /*  w w w .  ja va 2 s .c  o m*/
 * @return Node that is the root of the shape hierarchy.
 */
protected Node buildShape() {
    //Create a root for the shapes in the scene
    BranchGroup theScene = new BranchGroup();
    //Create an appearance for the ground
    Appearance groundApp = new Appearance();
    Color3f groundColour = new Color3f(0.0f, 0.5f, 0.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(0.5f, 0.5f, 0.5f);
    float shininess = 10.0f;
    groundApp.setMaterial(new Material(groundColour, emissiveColour, groundColour, specularColour, shininess));
    //Create a box that will be the ground
    Box ground = new Box(100.0f, 0.1f, 100.0f, groundApp);
    //Create a transform and a transform group that
    //will position the ground
    Transform3D grndXfm = new Transform3D();
    grndXfm.set(new Vector3f(0.0f, -1.0f, 0.0f));
    TransformGroup grndXfmGrp = new TransformGroup(grndXfm);
    //Add the ground shape to the group
    grndXfmGrp.addChild(ground);
    //Add the ground group to the scene group
    theScene.addChild(grndXfmGrp);
    //Create an appearance for the wall of the house
    Appearance wallApp = new Appearance();
    Color3f wallColour = new Color3f(0.5f, 0.5f, 0.5f);
    wallApp.setMaterial(new Material(wallColour, emissiveColour, wallColour, specularColour, shininess));
    //Create a cylinder that is the wall of the house
    Cylinder walls = new Cylinder(1.0f, 1.0f, Primitive.GENERATE_NORMALS, wallApp);
    //Create a group that will be the root of the house
    TransformGroup house = new TransformGroup();
    //Add the walls to the house group
    house.addChild(walls);
    //Create an appearance for the roof
    Appearance roofApp = new Appearance();
    Color3f roofColour = new Color3f(0.5f, 0.0f, 0.0f);
    roofApp.setMaterial(new Material(roofColour, emissiveColour, roofColour, specularColour, shininess));
    //Create a cone that will be the roof
    Cone myRoof = new Cone(1.0f, 1.0f, Primitive.GENERATE_NORMALS, roofApp);
    //Create the transform and transform group that will position the
    //roof on the house
    Transform3D roofXfm = new Transform3D();
    roofXfm.set(new Vector3f(0.0f, 1.0f, 0.0f));
    TransformGroup roofXfmGrp = new TransformGroup(roofXfm);
    //Add the roof to the roof transform group
    roofXfmGrp.addChild(myRoof);
    //Add the roof group to the house
    house.addChild(roofXfmGrp);
    //Create an appearance for the tree trunks
    Appearance trunkApp = new Appearance();
    Color3f trunkColour = new Color3f(0.2f, 0.2f, 0.0f);
    trunkApp.setMaterial(new Material(trunkColour, emissiveColour, trunkColour, specularColour, shininess));
    //Create an appearance for the tree leaves
    Appearance leafApp = new Appearance();
    Color3f leafColour = new Color3f(0.0f, 0.2f, 0.0f);
    leafApp.setMaterial(new Material(leafColour, emissiveColour, leafColour, specularColour, shininess));
    //Create a transform and transform group for the tree
    Transform3D treeXfm = new Transform3D();
    treeXfm.set(new Vector3f(-2.0f, 0.0f, 0.5f));
    TransformGroup treeXfmGrp = new TransformGroup(treeXfm);
    //Create a cylinder for the tree trunk
    Cylinder myTrunk = new Cylinder(0.1f, 1.0f, trunkApp);
    //Add the trunk to the tree group
    treeXfmGrp.addChild(myTrunk);
    //Create a transform and transform group for the tree leaves
    Transform3D leafXfm = new Transform3D();
    leafXfm.set(new Vector3f(0.0f, 1.0f, 0.0f));
    TransformGroup leafXfmGrp = new TransformGroup(leafXfm);
    //Create the leaves
    Sphere myLeaf = new Sphere(0.5f, leafApp);
    //Add the leaves to the leaf group
    leafXfmGrp.addChild(myLeaf);
    //Add the leaf group to the tree group
    treeXfmGrp.addChild(leafXfmGrp);
    //Create another tree
    Transform3D tree1Xfm = new Transform3D();
    tree1Xfm.set(new Vector3f(1.4f, 0.0f, -0.5f));
    TransformGroup tree1XfmGrp = new TransformGroup(tree1Xfm);
    Cylinder myTrunk1 = new Cylinder(0.1f, 1.0f, trunkApp);
    tree1XfmGrp.addChild(myTrunk1);
    Transform3D leaf1Xfm = new Transform3D();
    leaf1Xfm.set(new Vector3f(0.0f, 1.0f, 0.0f));
    TransformGroup leaf1XfmGrp = new TransformGroup(leaf1Xfm);
    Sphere myLeaf1 = new Sphere(0.5f, leafApp);
    leaf1XfmGrp.addChild(myLeaf1);
    tree1XfmGrp.addChild(leaf1XfmGrp);
    //Create the final tree
    Transform3D tree2Xfm = new Transform3D();
    tree2Xfm.set(new Vector3f(1.2f, 0.0f, 1.0f));
    TransformGroup tree2XfmGrp = new TransformGroup(tree2Xfm);
    Cylinder myTrunk2 = new Cylinder(0.1f, 1.0f, trunkApp);
    tree2XfmGrp.addChild(myTrunk2);
    Transform3D leaf2Xfm = new Transform3D();
    leaf2Xfm.set(new Vector3f(0.0f, 1.0f, 0.0f));
    TransformGroup leaf2XfmGrp = new TransformGroup(leaf2Xfm);
    Sphere myLeaf2 = new Sphere(0.5f, leafApp);
    leaf2XfmGrp.addChild(myLeaf2);
    tree2XfmGrp.addChild(leaf2XfmGrp);
    //Put the scene together by adding all the groups
    //to the scene group
    theScene.addChild(house);
    theScene.addChild(treeXfmGrp);
    theScene.addChild(tree1XfmGrp);
    theScene.addChild(tree2XfmGrp);
    return theScene;
}

From source file:SimpleTransform.java

/**
 * This defines the shapes used in the scene. It creates a simple cube using
 * a Box utility class.//from   w ww. j av a 2s  .  c om
 * 
 * @return Node that is the root of the shape hierarchy.
 */
protected Node buildShape() {
    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));
    return new Box(2.0f, 2.0f, 2.0f, app);
}

From source file:SimpleGame.java

/**
 * This builds the gun geometry. It uses box and cylinder primitives and
 * sets up a transform group so that we can rotate the gun.
 *//*from  w  w  w .  ja  v a 2s . c om*/
protected BranchGroup buildGun() {
    BranchGroup theGun = new BranchGroup();
    Appearance gunApp = new Appearance();
    Color3f ambientColour = new Color3f(0.5f, 0.5f, 0.5f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f diffuseColour = new Color3f(0.5f, 0.5f, 0.5f);
    float shininess = 20.0f;
    gunApp.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));
    TransformGroup init = new TransformGroup();
    TransformGroup barrel = new TransformGroup();
    Transform3D gunXfm = new Transform3D();
    Transform3D barrelXfm = new Transform3D();
    barrelXfm.set(new Vector3d(0.0, -2.0, 0.0));
    barrel.setTransform(barrelXfm);
    Matrix3d gunXfmMat = new Matrix3d();
    gunXfmMat.rotX(Math.PI / 2);
    gunXfm.set(gunXfmMat, new Vector3d(0.0, 0.0, 0.0), 1.0);
    init.setTransform(gunXfm);
    gunXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    gunXfmGrp.addChild(new Box(1.0f, 1.0f, 0.5f, gunApp));
    barrel.addChild(new Cylinder(0.3f, 4.0f, gunApp));
    gunXfmGrp.addChild(barrel);
    theGun.addChild(init);
    init.addChild(gunXfmGrp);
    return theGun;
}

From source file:PureImmediateStereo.java

public void run() {
    // Set up Graphics context
    gc = canvas.getGraphicsContext3D();//from  w  w w  .  ja va2  s  .  c o  m

    // We always need to set this for PureImmediate
    // stereo mode
    gc.setBufferOverride(true);

    Color3f lightColor = new Color3f(1, 1, 1);
    Vector3f lightDir = new Vector3f(0, 0, -1);
    DirectionalLight light = new DirectionalLight(lightColor, lightDir);

    gc.addLight(light);

    Appearance redApp = new Appearance();
    Appearance greenApp = new Appearance();
    Color3f ambientColor = new Color3f(0, 0, 0);
    Color3f emissiveColor = new Color3f(0, 0, 0);
    Color3f diffuseColor = new Color3f(1, 0, 0);
    Color3f specularColor = new Color3f(1, 1, 1);
    redApp.setMaterial(new Material(ambientColor, emissiveColor, diffuseColor, specularColor, 5));
    diffuseColor = new Color3f(0, 1, 0);

    greenApp.setMaterial(new Material(ambientColor, emissiveColor, diffuseColor, specularColor, 5));

    // Set up geometry
    Cone leftCone = new Cone(0.4f, 0.6f, Primitive.GENERATE_NORMALS, redApp);
    Cone rightCone = new Cone(0.4f, 0.6f, Primitive.GENERATE_NORMALS, greenApp);
    leftConeBody = leftCone.getShape(Cone.BODY);
    leftConeCap = leftCone.getShape(Cone.CAP);

    rightConeBody = rightCone.getShape(Cone.BODY);
    rightConeCap = rightCone.getShape(Cone.CAP);
    leftTrans = new Vector3f(-0.6f, 0, 0);
    rightTrans = new Vector3f(0.6f, 0, 0);

    while (true) {
        // compute data which is can be used
        // for both left and right eye
        computeSharedData();

        if (stereoSupport) {
            if (!sharedStereoZbuffer) {
                gc.setStereoMode(GraphicsContext3D.STEREO_BOTH);
                // This clear both left and right buffers, we
                // must set STEREO_BOTH before it. Otherwise
                // it only clear LEFT or RIGHT buffer unless
                // this is invoke twice for each buffer.
                gc.clear();
            }

            gc.setStereoMode(GraphicsContext3D.STEREO_LEFT);
            renderLeft();

            gc.setStereoMode(GraphicsContext3D.STEREO_RIGHT);
            renderRight();
        } else {
            gc.clear();
            renderLeft();
        }

        // This swap both left and right buffers so
        // there is no need to set STEREO_BOTH before it
        canvas.swap();

        // Be polite to other threads !
        Thread.yield();
    }
}