Example usage for javax.media.j3d Switch ALLOW_SWITCH_WRITE

List of usage examples for javax.media.j3d Switch ALLOW_SWITCH_WRITE

Introduction

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

Prototype

int ALLOW_SWITCH_WRITE

To view the source code for javax.media.j3d Switch ALLOW_SWITCH_WRITE.

Click Source Link

Document

Specifies that this node allows writing its child selection and mask values.

Usage

From source file:EnvironmentExplorer.java

void setupSpheres() {

    // create a Switch for the spheres, allow switch changes
    spheresSwitch = new Switch(Switch.CHILD_ALL);
    spheresSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Set up an appearance to make the Sphere with objColor ambient,
    // black emmissive, objColor diffuse and white specular coloring
    Material material = new Material(objColor, black, objColor, white, 32);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);//from  ww  w . j av a2s . co m

    // create a sphere and put it into a shared group
    Sphere sphere = new Sphere(0.5f, appearance);
    SharedGroup sphereSG = new SharedGroup();
    sphereSG.addChild(sphere);

    // create a grid of spheres in the z=0 plane
    // each has a TransformGroup to position the sphere which contains
    // a link to the shared group for the sphere
    for (int y = -2; y <= 2; y++) {
        for (int x = -2; x <= 2; x++) {
            TransformGroup tg = new TransformGroup();
            tmpVector.set(x * 1.2f, y * 1.2f, -0.1f);
            tmpTrans.set(tmpVector);
            tg.setTransform(tmpTrans);
            tg.addChild(new Link(sphereSG));
            spheresSwitch.addChild(tg);
        }
    }
}

From source file:EnvironmentExplorer.java

void setupGrid() {

    // create a Switch for the spheres, allow switch changes
    gridSwitch = new Switch(Switch.CHILD_NONE);
    gridSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Set up an appearance to make the square3s with red ambient,
    // black emmissive, red diffuse and black specular coloring
    Material material = new Material(red, black, red, black, 64);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);/* w  w w  .j a v  a2 s  . com*/

    // create a grid of quads
    int gridSize = 20; // grid is gridSize quads along each side
    int numQuads = gridSize * gridSize;
    int numVerts = numQuads * 4; // 4 verts per quad
    // there will be 3 floats per coord and 4 coords per quad
    float[] coords = new float[3 * numVerts];
    // All the quads will use the same normal at each vertex, so
    // allocate an array to hold references to the same normal
    Vector3f[] normals = new Vector3f[numVerts];
    Vector3f vertNormal = new Vector3f(0.0f, 0.0f, 1.0f);
    float edgeLength = 5.0f; // length of each edge of the grid
    float gridGap = 0.03f; // the gap between each quad
    // length of each quad is (total length - sum of the gaps) / gridSize
    float quadLength = (edgeLength - gridGap * (gridSize - 1)) / gridSize;

    // create a grid of quads in the z=0 plane
    // each has a TransformGroup to position the sphere which contains
    // a link to the shared group for the sphere
    float curX, curY;
    for (int y = 0; y < gridSize; y++) {
        curY = y * (quadLength + gridGap); // offset to lower left corner
        curY -= edgeLength / 2; // center on 0,0
        for (int x = 0; x < gridSize; x++) {
            // this is the offset into the vertex array for the first
            // vertex of the quad
            int vertexOffset = (y * gridSize + x) * 4;
            // this is the offset into the coord array for the first
            // vertex of the quad, where there are 3 floats per vertex
            int coordOffset = vertexOffset * 3;
            curX = x * (quadLength + gridGap); // offset to ll corner
            curX -= edgeLength / 2; // center on 0,0
            // lower left corner
            coords[coordOffset + 0] = curX;
            coords[coordOffset + 1] = curY;
            coords[coordOffset + 2] = 0.0f; // z
            // lower right corner
            coords[coordOffset + 3] = curX + quadLength;
            coords[coordOffset + 4] = curY;
            coords[coordOffset + 5] = 0.0f; // z
            // upper right corner
            coords[coordOffset + 6] = curX + quadLength;
            coords[coordOffset + 7] = curY + quadLength;
            coords[coordOffset + 8] = 0.0f; // z
            // upper left corner
            coords[coordOffset + 9] = curX;
            coords[coordOffset + 10] = curY + quadLength;
            coords[coordOffset + 11] = 0.0f; // z
            for (int i = 0; i < 4; i++) {
                normals[vertexOffset + i] = vertNormal;
            }
        }
    }
    // now that we have the data, create the QuadArray
    QuadArray quads = new QuadArray(numVerts, QuadArray.COORDINATES | QuadArray.NORMALS);
    quads.setCoordinates(0, coords);
    quads.setNormals(0, normals);

    // create the shape
    Shape3D shape = new Shape3D(quads, appearance);

    // add it to the switch
    gridSwitch.addChild(shape);
}

From source file:ffx.potential.MolecularAssembly.java

/**
 * The MolecularAssembly BranchGroup has two TransformGroups between it and
 * the "base" node where geometry is attached. If the point between the two
 * transformations is where user rotation occurs. For example, if rotating
 * about the center of mass of the system, the RotToCOM transformation will
 * be an identity transformation (ie. none). If rotation is about some atom
 * or group of atoms within the system, then the RotToCOM transformation
 * will be a translation from that point to the COM.
 *
 * @param zero boolean/*from  ww  w. j a  v  a 2  s. c  o m*/
 * @return BranchGroup
 */
public BranchGroup createScene(boolean zero) {
    originToRotT3D = new Transform3D();
    originToRotV3D = new Vector3d();
    originToRot = new TransformGroup(originToRotT3D);
    branchGroup = new BranchGroup();
    rotToCOM = new TransformGroup();
    rotToCOMT3D = new Transform3D();
    rotToCOMV3D = new Vector3d();
    // Set capabilities needed for picking and moving the MolecularAssembly
    branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
    originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    originToRot.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    originToRot.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    rotToCOM.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    // Put the MolecularAssembly in the middle of the scene
    if (zero) {
        originToRotV3D.set(0.0, 0.0, 0.0);
        originToRotT3D.set(originToRotV3D);
        originToRot.setTransform(originToRotT3D);
    }
    wire = renderWire();
    switchGroup = new Switch(Switch.CHILD_NONE);
    switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE);
    base = new BranchGroup();
    base.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    base.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    childNodes = new BranchGroup();
    childNodes.setCapability(BranchGroup.ALLOW_DETACH);
    childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    childNodes.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
    switchGroup.addChild(base);
    if (wire != null) {
        base.addChild(wire);
    }
    vrml = loadVRML();
    if (vrml != null) {
        vrmlTG = new TransformGroup();
        vrmlTd = new Transform3D();
        vrmlTG.setTransform(vrmlTd);
        vrmlTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        vrmlTG.addChild(vrml);
        switchGroup.addChild(vrmlTG);
        setView(RendererCache.ViewModel.INVISIBLE, null);
    }
    switchGroup.setWhichChild(Switch.CHILD_ALL);
    rotToCOM.addChild(switchGroup);
    originToRot.addChild(rotToCOM);
    branchGroup.addChild(originToRot);
    branchGroup.compile();
    return branchGroup;
}

From source file:Demo3D.java

/**
 * Create the subgraph #32//from  w  w w  . jav  a2 s  . com
 * 
 * @return javax.media.j3d.TransformGroup trGr32_3 - the root of the
 *         subgraph #32
 */
public BranchGroup mySubGraph32() {
    // A BoundingSphere instance as general bounding region.
    boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Create the first TransformGroup node trGr32_1 to:
    // 1) attach the Switch node with the five different earth's
    //    representations to the subgraph32
    // 2) attach a coordinate system to each earth's representation
    // 3) rotate each earth about its own y-axis.
    trGr32_1 = new TransformGroup();

    // With the ALLOW_TRANSFORM_WRITE capability, we allow the
    // modification of the TransformGroup's code by the behavior's
    // code at run time.
    trGr32_1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // SwitchBehavior is the class which controls the fonctioning of
    // the switchEarths node.

    switchBehavior = new SwitchBehavior(this);
    switchBehavior.setSchedulingBounds(boundsGen);
    trGr32_1.addChild(switchBehavior);

    // The Switch which allows the rendering of the five different
    // earth's representations.
    switchEarths = new Switch();
    // With the ALLOW_TRANSFORM_WRITE, ALLOW_SWITCH_WRITE and
    // ALLOW_CHILDREN_READ
    // capabilities we allow to get or set new capabilities.
    switchEarths.setCapability(Switch.ALLOW_SWITCH_READ);
    switchEarths.setCapability(Switch.ALLOW_SWITCH_WRITE);
    switchEarths.setCapability(Switch.ALLOW_CHILDREN_READ);

    // Attach the different earth's representations to the Switch node.
    // Increasing
    earth_Points = new Earth("points", 0.4f);
    switchEarths.addChild(earth_Points.myEarth()); // # 0

    earth_Lines = new Earth("lines", 0.4f);
    switchEarths.addChild(earth_Lines.myEarth()); // # 1

    earth_Polygons = new Earth("polygons", 0.4f);
    switchEarths.addChild(earth_Polygons.myEarth()); // # 2

    earth_Gouraud = new Earth("gouraud", 0.4f);
    switchEarths.addChild(earth_Gouraud.myEarth()); // # 3

    earth_Texture = new Earth("texture", 0.4f);
    switchEarths.addChild(earth_Texture.myEarth()); // # 4

    // Decreasing
    switchEarths.addChild(earth_Texture.myEarth()); // # 4
    switchEarths.addChild(earth_Gouraud.myEarth()); // # 3
    switchEarths.addChild(earth_Polygons.myEarth()); // # 2
    switchEarths.addChild(earth_Lines.myEarth()); // # 1
    switchEarths.addChild(earth_Points.myEarth()); // # 0

    // Attach the Switch node with the five different earth's
    // representations to the TransformGroup node trGr32_1.
    trGr32_1.addChild(switchEarths);

    // Create and attach a coordinate system to the TransformGroup node
    // trGr32_1, that is to each earth's representation.
    coordSyst = new CoordSyst(1.0f, 1.0f, 0.0f, // Color of the x-axis
            0.0f, 0.0f, 1.0f, // Color of the y-axis
            1.0f, 0.0f, 0.0f, // Color of the z-axis
            0.6f); // Lenght of the 3 axes
    trGr32_1.addChild(coordSyst);

    // Create the alpha(t) function for the earth's rotation about
    // its own y-axis.
    rotationAlpha_1 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0);
    // Create the earth's rotation about its own y-axis.
    rotator_1 = new RotationInterpolator(rotationAlpha_1, trGr32_1, new Transform3D(), 0.0f,
            (float) Math.PI * 2.0f);
    rotator_1.setSchedulingBounds(boundsGen);
    trGr32_1.addChild(rotator_1);

    // Create a Transform3D instance to execute the desired "static
    // translation" of the earth, that is the rotation radius around
    // the sun.
    transl = new Transform3D();
    vectTransl = new Vector3d(2.5, 0.0, 0.0);
    transl.set(vectTransl);

    // Create the second TransformGroup node trGr32_2 and attach the
    // "static translation" transl to it.
    trGr32_2 = new TransformGroup(transl);

    // Attach the trGr32_1 node to the trGr32_2 node.
    trGr32_2.addChild(trGr32_1);

    // Create the third TransformGroup node trGr32_3 for the earth's
    // rotation around the sun.
    trGr32_3 = new TransformGroup();

    // With the ALLOW_TRANSFORM_WRITE capability, we allow the
    // modification of the TransformGroup's code by the behavior's
    // code at run time.
    trGr32_3.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Attach the trGr32_2 node to the trGr32_3 node.
    trGr32_3.addChild(trGr32_2);

    // Create the alpha(t) function for the earth's rotation around the sun.
    rotationAlpha_2 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 20000, 0, 0, 0, 0, 0);

    // To restart correctly the rotation of the earth around the
    // sun after a detach/add process of the subgraph32 from the
    // BranchGroup node brGr3.
    rotationAlpha_2.setStartTime(System.currentTimeMillis());

    // Create the earth's rotation around the sun.
    rotator_2 = new RotationInterpolator(rotationAlpha_2, trGr32_3, new Transform3D(), 0.0f,
            (float) Math.PI * 2.0f);
    rotator_2.setSchedulingBounds(boundsGen);
    trGr32_3.addChild(rotator_2);

    // To allow the detaching of this subgraph32 from the
    // BranchGroup node brGr3.
    brGr32 = new BranchGroup();
    brGr32.setCapability(BranchGroup.ALLOW_DETACH);
    brGr32.addChild(trGr32_3);

    // Return the final version of the BranchGroup node brGr32.
    return brGr32;
}

From source file:AppearanceExplorer.java

void setupSceneSwitch() {

    // create a Switch for the scene, allow switch changes
    sceneSwitch = new Switch();
    sceneSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    sceneSwitch.setCapability(Switch.ALLOW_CHILDREN_READ);
    sceneSwitch.setCapability(Switch.ALLOW_CHILDREN_WRITE);
    sceneSwitch.setCapability(Switch.ALLOW_CHILDREN_EXTEND);

    Shape3D pointArray = createPointArray();
    sceneSwitch.addChild(pointArray);// w  ww.j a v  a2s. com

    Shape3D lineArray = createLineArray();
    sceneSwitch.addChild(lineArray);

    Shape3D triangleArray = createTriangleArray();
    sceneSwitch.addChild(triangleArray);

    Shape3D lineStripArray = createLineStripArray();
    sceneSwitch.addChild(lineStripArray);

    Shape3D triangleStripArray = createTriangleStripArray();
    sceneSwitch.addChild(triangleStripArray);

    Shape3D triangleFanArray = createTriangleFanArray();
    sceneSwitch.addChild(triangleFanArray);

    Shape3D texTris = createTexTris();
    sceneSwitch.addChild(texTris);

    Shape3D texSquare = createTexSquare();
    sceneSwitch.addChild(texSquare);

    Shape3D largeTexSquare = createLargeTexSquare();
    sceneSwitch.addChild(largeTexSquare);

    Shape3D colorCube = createColorCube();
    sceneSwitch.addChild(colorCube);

    Shape3D ngCreaseCube = createNGCube(45);
    sceneSwitch.addChild(ngCreaseCube);

    Shape3D ngSmoothCube = createNGCube(100);
    sceneSwitch.addChild(ngSmoothCube);

    Shape3D triWithHole = createTriWithHole();
    sceneSwitch.addChild(triWithHole);

    // create a sphere with the shared appearance
    Sphere sphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, appearance);
    sceneSwitch.addChild(sphere);

    // create a sphere with the shared appearance
    Sphere lrSphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, 10,
            appearance);
    sceneSwitch.addChild(lrSphere);

    // create a sphere with the shared appearance
    Sphere hrSphere = new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, 45,
            appearance);
    sceneSwitch.addChild(hrSphere);

    // Text3D
    Shape3D text3D = createText3D();
    sceneSwitch.addChild(text3D);

    // galleon -- use a placeholder to indicate it hasn't been loaded yet
    // then load it the first time it gets asked for
    //was:
    //Group galleon = createGalleon();
    //sceneSwitch.addChild(galleon);
    galleonIndex = sceneSwitch.numChildren();
    galleonPlaceholder = new BranchGroup();
    galleonPlaceholder.setCapability(BranchGroup.ALLOW_DETACH);
    sceneSwitch.addChild(galleonPlaceholder);

    // beethoven -- use a placeholder to indicate it hasn't been loaded yet
    // then load it the first time it gets asked for
    //was:
    //Group beethoven = createBeethoven();
    //sceneSwitch.addChild(beethoven);
    beethovenIndex = sceneSwitch.numChildren();
    beethovenPlaceholder = new BranchGroup();
    beethovenPlaceholder.setCapability(BranchGroup.ALLOW_DETACH);
    sceneSwitch.addChild(beethovenPlaceholder);
}

From source file:AppearanceExplorer.java

Group setupLights() {

    Group group = new Group();

    // set up the BoundingSphere for all the lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0);

    // Set up the ambient light
    AmbientLight lightAmbient = new AmbientLight(medGrey);
    lightAmbient.setInfluencingBounds(bounds);
    lightAmbient.setCapability(Light.ALLOW_STATE_WRITE);
    group.addChild(lightAmbient);/*  w  w  w.  j av  a  2  s. c om*/

    lightSwitch = new Switch();
    lightSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
    group.addChild(lightSwitch);

    // Set up the directional light
    Vector3f lightDirection1 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lightDirectional1 = new DirectionalLight(white, lightDirection1);
    lightDirectional1.setInfluencingBounds(bounds);
    lightDirectional1.setCapability(Light.ALLOW_STATE_WRITE);
    lightSwitch.addChild(lightDirectional1);

    Point3f lightPos1 = new Point3f(-4.0f, 8.0f, 16.0f);
    Point3f lightAttenuation1 = new Point3f(1.0f, 0.0f, 0.0f);
    PointLight pointLight1 = new PointLight(brightWhite, lightPos1, lightAttenuation1);
    pointLight1.setInfluencingBounds(bounds);
    lightSwitch.addChild(pointLight1);

    Point3f lightPos2 = new Point3f(-16.0f, 8.0f, 4.0f);
    //Point3f lightPos = new Point3f(-4.0f, 2.0f, 1.0f);
    Point3f lightAttenuation2 = new Point3f(1.0f, 0.0f, 0.0f);
    PointLight pointLight2 = new PointLight(white, lightPos2, lightAttenuation2);
    pointLight2.setInfluencingBounds(bounds);
    lightSwitch.addChild(pointLight2);

    return group;
}

From source file:TransformExplorer.java

CoordSys(float axisLength) {
    super(Switch.CHILD_ALL);

    float coordSysLength = axisLength;
    float labelOffset = axisLength / 20.0f;
    float axisRadius = axisLength / 500.0f;
    float arrowRadius = axisLength / 125.0f;
    float arrowHeight = axisLength / 50.0f;
    float tickRadius = axisLength / 125.0f;
    float tickHeight = axisLength / 250.0f;

    // Set the Switch to allow changes
    setCapability(Switch.ALLOW_SWITCH_READ);
    setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Set up an appearance to make the Axis have
    // grey ambient, black emmissive, grey diffuse and grey specular
    // coloring.//from   www  .  ja v  a2  s  .com
    //Material material = new Material(grey, black, grey, white, 64);
    Material material = new Material(white, black, white, white, 64);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);

    // Create a shared group to hold one axis of the coord sys
    SharedGroup coordAxisSG = new SharedGroup();

    // create a cylinder for the central line of the axis
    Cylinder cylinder = new Cylinder(axisRadius, coordSysLength, appearance);
    // cylinder goes from -coordSysLength/2 to coordSysLength in y
    coordAxisSG.addChild(cylinder);

    // create the shared arrowhead
    Cone arrowHead = new Cone(arrowRadius, arrowHeight, appearance);
    SharedGroup arrowHeadSG = new SharedGroup();
    arrowHeadSG.addChild(arrowHead);

    // Create a TransformGroup to move the arrowhead to the top of the
    // axis
    // The arrowhead goes from -arrowHeight/2 to arrowHeight/2 in y.
    // Put it at the top of the axis, coordSysLength / 2
    tmpVector.set(0.0f, coordSysLength / 2 + arrowHeight / 2, 0.0f);
    tmpTrans.set(tmpVector);
    TransformGroup topTG = new TransformGroup();
    topTG.setTransform(tmpTrans);
    topTG.addChild(new Link(arrowHeadSG));
    coordAxisSG.addChild(topTG);

    // create the minus arrowhead
    // Create a TransformGroup to turn the cone upside down:
    // Rotate 180 degrees around Z axis
    tmpAxisAngle.set(0.0f, 0.0f, 1.0f, (float) Math.toRadians(180));
    tmpTrans.set(tmpAxisAngle);

    // Put the arrowhead at the bottom of the axis
    tmpVector.set(0.0f, -coordSysLength / 2 - arrowHeight / 2, 0.0f);
    tmpTrans.setTranslation(tmpVector);
    TransformGroup bottomTG = new TransformGroup();
    bottomTG.setTransform(tmpTrans);
    bottomTG.addChild(new Link(arrowHeadSG));
    coordAxisSG.addChild(bottomTG);

    // Now add "ticks" at 1, 2, 3, etc.

    // create a shared group for the tick
    Cylinder tick = new Cylinder(tickRadius, tickHeight, appearance);
    SharedGroup tickSG = new SharedGroup();
    tickSG.addChild(tick);

    // transform each instance and add it to the coord axis group
    int maxTick = (int) (coordSysLength / 2);
    int minTick = -maxTick;
    for (int i = minTick; i <= maxTick; i++) {
        if (i == 0)
            continue; // no tick at 0

        // use a TransformGroup to offset to the tick location
        TransformGroup tickTG = new TransformGroup();
        tmpVector.set(0.0f, (float) i, 0.0f);
        tmpTrans.set(tmpVector);
        tickTG.setTransform(tmpTrans);
        // then link to an instance of the Tick shared group
        tickTG.addChild(new Link(tickSG));
        // add the TransformGroup to the coord axis
        coordAxisSG.addChild(tickTG);
    }

    // add a Link to the axis SharedGroup to the coordSys
    addChild(new Link(coordAxisSG)); // Y axis

    // Create TransformGroups for the X and Z axes
    TransformGroup xAxisTG = new TransformGroup();
    // rotate 90 degrees around Z axis
    tmpAxisAngle.set(0.0f, 0.0f, 1.0f, (float) Math.toRadians(90));
    tmpTrans.set(tmpAxisAngle);
    xAxisTG.setTransform(tmpTrans);
    xAxisTG.addChild(new Link(coordAxisSG));
    addChild(xAxisTG); // X axis

    TransformGroup zAxisTG = new TransformGroup();
    // rotate 90 degrees around X axis
    tmpAxisAngle.set(1.0f, 0.0f, 0.0f, (float) Math.toRadians(90));
    tmpTrans.set(tmpAxisAngle);
    zAxisTG.setTransform(tmpTrans);
    zAxisTG.addChild(new Link(coordAxisSG));
    addChild(zAxisTG); // Z axis

    // Add the labels. First we need a Font3D for the Text3Ds
    // select the default font, plain style, 0.5 tall. Use null for
    // the extrusion so we get "flat" text since we will be putting it
    // into an oriented Shape3D
    Font3D f3d = new Font3D(new Font("Default", Font.PLAIN, 1), null);

    // set up the +X label
    Text3D plusXText = new Text3D(f3d, "+X", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT);
    // orient around the local origin
    OrientedShape3D plusXTextShape = new OrientedShape3D(plusXText, appearance,
            OrientedShape3D.ROTATE_ABOUT_POINT, origin);
    // transform to scale down to 0.15 in height, locate at end of axis
    TransformGroup plusXTG = new TransformGroup();
    tmpVector.set(coordSysLength / 2 + labelOffset, 0.0f, 0.0f);
    tmpTrans.set(0.15f, tmpVector);
    plusXTG.setTransform(tmpTrans);
    plusXTG.addChild(plusXTextShape);
    addChild(plusXTG);

    // set up the -X label
    Text3D minusXText = new Text3D(f3d, "-X", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT);
    // orient around the local origin
    OrientedShape3D minusXTextShape = new OrientedShape3D(minusXText, appearance,
            OrientedShape3D.ROTATE_ABOUT_POINT, origin);
    // transform to scale down to 0.15 in height, locate at end of axis
    TransformGroup minusXTG = new TransformGroup();
    tmpVector.set(-coordSysLength / 2 - labelOffset, 0.0f, 0.0f);
    tmpTrans.set(0.15f, tmpVector);
    minusXTG.setTransform(tmpTrans);
    minusXTG.addChild(minusXTextShape);
    addChild(minusXTG);

    // set up the +Y label
    Text3D plusYText = new Text3D(f3d, "+Y", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT);
    // orient around the local origin
    OrientedShape3D plusYTextShape = new OrientedShape3D(plusYText, appearance,
            OrientedShape3D.ROTATE_ABOUT_POINT, origin);
    // transform to scale down to 0.15 in height, locate at end of axis
    TransformGroup plusYTG = new TransformGroup();
    tmpVector.set(0.0f, coordSysLength / 2 + labelOffset, 0.0f);
    tmpTrans.set(0.15f, tmpVector);
    plusYTG.setTransform(tmpTrans);
    plusYTG.addChild(plusYTextShape);
    addChild(plusYTG);

    // set up the -Y label
    Text3D minusYText = new Text3D(f3d, "-Y", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT);
    // orient around the local origin
    OrientedShape3D minusYTextShape = new OrientedShape3D(minusYText, appearance,
            OrientedShape3D.ROTATE_ABOUT_POINT, origin);
    // transform to scale down to 0.15 in height, locate at end of axis
    TransformGroup minusYTG = new TransformGroup();
    tmpVector.set(0.0f, -coordSysLength / 2 - labelOffset, 0.0f);
    tmpTrans.set(0.15f, tmpVector);
    minusYTG.setTransform(tmpTrans);
    minusYTG.addChild(minusYTextShape);
    addChild(minusYTG);

    // set up the +Z label
    Text3D plusZText = new Text3D(f3d, "+Z", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT);
    // orient around the local origin
    OrientedShape3D plusZTextShape = new OrientedShape3D(plusZText, appearance,
            OrientedShape3D.ROTATE_ABOUT_POINT, origin);
    // transform to scale down to 0.15 in height, locate at end of axis
    TransformGroup plusZTG = new TransformGroup();
    tmpVector.set(0.0f, 0.0f, coordSysLength / 2 + labelOffset);
    tmpTrans.set(0.15f, tmpVector);
    plusZTG.setTransform(tmpTrans);
    plusZTG.addChild(plusZTextShape);
    addChild(plusZTG);

    // set up the -Z label
    Text3D minusZText = new Text3D(f3d, "-Z", origin, Text3D.ALIGN_CENTER, Text3D.PATH_RIGHT);
    // orient around the local origin
    OrientedShape3D minusZTextShape = new OrientedShape3D(minusZText, appearance,
            OrientedShape3D.ROTATE_ABOUT_POINT, origin);
    // transform to scale down to 0.15 in height, locate at end of axis
    TransformGroup minusZTG = new TransformGroup();
    tmpVector.set(0.0f, 0.0f, -coordSysLength / 2 - labelOffset);
    tmpTrans.set(0.15f, tmpVector);
    minusZTG.setTransform(tmpTrans);
    minusZTG.addChild(minusZTextShape);
    addChild(minusZTG);
}

From source file:TransformExplorer.java

RotAxis(float axisLength) {
    super(Switch.CHILD_NONE);
    setCapability(Switch.ALLOW_SWITCH_READ);
    setCapability(Switch.ALLOW_SWITCH_WRITE);

    // set up the proportions for the arrow
    float axisRadius = axisLength / 120.0f;
    float arrowRadius = axisLength / 50.0f;
    float arrowHeight = axisLength / 30.0f;

    // create the TransformGroup which will be used to orient the axis
    axisTG = new TransformGroup();
    axisTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    axisTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    addChild(axisTG);/*from ww w  .j  av a  2 s. c  o m*/

    // Set up an appearance to make the Axis have 
    // blue ambient, black emmissive, blue diffuse and white specular 
    // coloring.  
    Material material = new Material(blue, black, blue, white, 64);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);

    // create a cylinder for the central line of the axis
    Cylinder cylinder = new Cylinder(axisRadius, axisLength, appearance);
    // cylinder goes from -length/2 to length/2 in y
    axisTG.addChild(cylinder);

    // create a SharedGroup for the arrowHead
    Cone arrowHead = new Cone(arrowRadius, arrowHeight, appearance);
    SharedGroup arrowHeadSG = new SharedGroup();
    arrowHeadSG.addChild(arrowHead);

    // Create a TransformGroup to move the cone to the top of the 
    // cylinder
    tmpVector.set(0.0f, axisLength / 2 + arrowHeight / 2, 0.0f);
    tmpTrans.set(tmpVector);
    TransformGroup topTG = new TransformGroup();
    topTG.setTransform(tmpTrans);
    topTG.addChild(new Link(arrowHeadSG));
    axisTG.addChild(topTG);

    // create the bottom of the arrow
    // Create a TransformGroup to move the cone to the bottom of the 
    // axis so that its pushes into the bottom of the cylinder
    tmpVector.set(0.0f, -(axisLength / 2), 0.0f);
    tmpTrans.set(tmpVector);
    TransformGroup bottomTG = new TransformGroup();
    bottomTG.setTransform(tmpTrans);
    bottomTG.addChild(new Link(arrowHeadSG));
    axisTG.addChild(bottomTG);

    updateAxisTransform();
}

From source file:AppearanceExplorer.java

BackgroundTool(String codeBaseString) {

    bgSwitch = new Switch(Switch.CHILD_NONE);
    bgSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // set up the dark grey BG color node
    Background bgDarkGrey = new Background(darkGrey);
    bgDarkGrey.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgDarkGrey);//www.  j  ava  2  s.  c  o  m

    // set up the grey BG color node
    Background bgGrey = new Background(grey);
    bgGrey.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgGrey);

    // set up the light grey BG color node
    Background bgLightGrey = new Background(lightGrey);
    bgLightGrey.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgLightGrey);

    // set up the white BG color node
    Background bgWhite = new Background(white);
    bgWhite.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgWhite);

    // set up the blue BG color node
    Background bgBlue = new Background(skyBlue);
    bgBlue.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgBlue);

    // set up the image
    java.net.URL bgImageURL = null;
    try {
        bgImageURL = new java.net.URL(codeBaseString + "bg.jpg");
    } catch (java.net.MalformedURLException ex) {
        System.out.println(ex.getMessage());
        System.exit(1);
    }
    if (bgImageURL == null) { // application, try file URL
        try {
            bgImageURL = new java.net.URL("file:./bg.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }
    TextureLoader bgTexture = new TextureLoader(bgImageURL, null);

    // Create a background with the static image
    Background bgImage = new Background(bgTexture.getImage());
    bgImage.setApplicationBounds(infiniteBounds);
    bgSwitch.addChild(bgImage);

    // create a background with the image mapped onto a sphere which
    // will enclose the world
    Background bgGeo = new Background();
    bgGeo.setApplicationBounds(infiniteBounds);
    BranchGroup bgGeoBG = new BranchGroup();
    Appearance bgGeoApp = new Appearance();
    bgGeoApp.setTexture(bgTexture.getTexture());
    Sphere sphereObj = new Sphere(1.0f,
            Sphere.GENERATE_NORMALS | Sphere.GENERATE_NORMALS_INWARD | Sphere.GENERATE_TEXTURE_COORDS, 45,
            bgGeoApp);
    bgGeoBG.addChild(sphereObj);
    bgGeo.setGeometry(bgGeoBG);
    bgSwitch.addChild(bgGeo);

    // Create the chooser GUI
    String[] bgNames = { "No Background (Black)", "Dark Grey", "Grey", "Light Grey", "White", "Blue",
            "Sky Image", "Sky Geometry", };
    int[] bgValues = { Switch.CHILD_NONE, 0, 1, 2, 3, 4, 5, 6 };

    bgChooser = new IntChooser("Background:", bgNames, bgValues, 0);
    bgChooser.addIntListener(new IntListener() {
        public void intChanged(IntEvent event) {
            int value = event.getValue();
            bgSwitch.setWhichChild(value);
        }
    });
    bgChooser.setValue(Switch.CHILD_NONE);
}

From source file:FourByFour.java

public Positions() {

    // Define colors for lighting
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f red = new Color3f(0.9f, 0.1f, 0.2f);
    Color3f blue = new Color3f(0.3f, 0.3f, 0.8f);
    Color3f yellow = new Color3f(1.0f, 1.0f, 0.0f);
    Color3f ambRed = new Color3f(0.3f, 0.03f, 0.03f);
    Color3f ambBlue = new Color3f(0.03f, 0.03f, 0.3f);
    Color3f ambYellow = new Color3f(0.3f, 0.3f, 0.03f);
    Color3f ambWhite = new Color3f(0.3f, 0.3f, 0.3f);
    Color3f specular = new Color3f(1.0f, 1.0f, 1.0f);

    // Create the red appearance node
    redMat = new Material(ambRed, black, red, specular, 100.f);
    redMat.setLightingEnable(true);/*from  w w  w  .  ja v  a 2  s  . co  m*/
    redApp = new Appearance();
    redApp.setMaterial(redMat);

    // Create the blue appearance node
    blueMat = new Material(ambBlue, black, blue, specular, 100.f);
    blueMat.setLightingEnable(true);
    blueApp = new Appearance();
    blueApp.setMaterial(blueMat);

    // Create the yellow appearance node
    yellowMat = new Material(ambYellow, black, yellow, specular, 100.f);
    yellowMat.setLightingEnable(true);
    yellowApp = new Appearance();
    yellowApp.setMaterial(yellowMat);

    // Create the white appearance node
    whiteMat = new Material(ambWhite, black, white, specular, 100.f);
    whiteMat.setLightingEnable(true);
    whiteApp = new Appearance();
    whiteApp.setMaterial(whiteMat);

    // Load the point array with the offset (coordinates) for each of
    // the 64 positions.
    point = new Vector3f[64];
    int count = 0;
    for (int i = -30; i < 40; i += 20) {
        for (int j = -30; j < 40; j += 20) {
            for (int k = -30; k < 40; k += 20) {
                point[count] = new Vector3f((float) k, (float) j, (float) i);
                count++;
            }
        }
    }

    // Create the switch nodes
    posSwitch = new Switch(Switch.CHILD_MASK);
    humanSwitch = new Switch(Switch.CHILD_MASK);
    machineSwitch = new Switch(Switch.CHILD_MASK);

    // Set the capability bits
    posSwitch.setCapability(Switch.ALLOW_SWITCH_READ);
    posSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    humanSwitch.setCapability(Switch.ALLOW_SWITCH_READ);
    humanSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    machineSwitch.setCapability(Switch.ALLOW_SWITCH_READ);
    machineSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Create the bit masks
    posMask = new BitSet();
    humanMask = new BitSet();
    machineMask = new BitSet();

    // Create the small white spheres that mark unoccupied
    // positions.
    posSphere = new Sphere[64];
    for (int i = 0; i < 64; i++) {
        Transform3D transform3D = new Transform3D();
        transform3D.set(point[i]);
        TransformGroup transformGroup = new TransformGroup(transform3D);
        posSphere[i] = new Sphere(2.0f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_APPEARANCE_MODIFY, 12,
                whiteApp);
        Shape3D shape = posSphere[i].getShape();
        ID id = new ID(i);
        shape.setUserData(id);
        transformGroup.addChild(posSphere[i]);
        posSwitch.addChild(transformGroup);
        posMask.set(i);
    }

    // Create the red spheres that mark the user's positions.
    for (int i = 0; i < 64; i++) {
        Transform3D transform3D = new Transform3D();
        transform3D.set(point[i]);
        TransformGroup transformGroup = new TransformGroup(transform3D);
        transformGroup.addChild(new Sphere(7.0f, redApp));
        humanSwitch.addChild(transformGroup);
        humanMask.clear(i);
    }

    // Create the blue cubes that mark the computer's positions.
    for (int i = 0; i < 64; i++) {
        Transform3D transform3D = new Transform3D();
        transform3D.set(point[i]);
        TransformGroup transformGroup = new TransformGroup(transform3D);
        BigCube cube = new BigCube(blueApp);
        transformGroup.addChild(cube.getChild());
        machineSwitch.addChild(transformGroup);
        machineMask.clear(i);
    }

    // Set the positions mask
    posSwitch.setChildMask(posMask);
    humanSwitch.setChildMask(humanMask);
    machineSwitch.setChildMask(machineMask);

    // Throw everything into a single group
    group = new Group();
    group.addChild(posSwitch);
    group.addChild(humanSwitch);
    group.addChild(machineSwitch);
}