List of usage examples for javax.media.j3d TransformGroup TransformGroup
public TransformGroup(Transform3D t1)
From source file:ExLinearFog.java
private Group buildColumns(SharedGroup column) { Group group = new Group(); // Place columns float x = -ColumnSideOffset; float y = -1.6f; float z = ColumnDepthSpacing; float xSpacing = 2.0f * ColumnSideOffset; float zSpacing = -ColumnDepthSpacing; // BEGIN EXAMPLE TOPIC Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg;//from w ww. j a v a 2 s . com for (int i = 0; i < NumberOfColumns; i++) { // Left link trans.set(x, y, z); tr.set(trans); tg = new TransformGroup(tr); tg.addChild(new Link(column)); group.addChild(tg); // Right link trans.set(x + xSpacing, y, z); tr.set(trans); tg = new TransformGroup(tr); tg.addChild(new Link(column)); group.addChild(tg); z += zSpacing; } // END EXAMPLE TOPIC return group; }
From source file:AlternateAppearanceScopeTest.java
public SphereGroup(float radius, float xSpacing, float ySpacing, int xCount, int yCount, Appearance app, boolean overrideflag) { if (app == null) { app = new Appearance(); Material material = new Material(); material.setDiffuseColor(new Color3f(0.8f, 0.8f, 0.8f)); material.setSpecularColor(new Color3f(0.0f, 0.0f, 0.0f)); material.setShininess(0.0f);/* w w w . j a v a 2 s. c o m*/ app.setMaterial(material); } double xStart = -xSpacing * (double) (xCount - 1) / 2.0; double yStart = -ySpacing * (double) (yCount - 1) / 2.0; Sphere sphere = null; TransformGroup trans = null; Transform3D t3d = new Transform3D(); Vector3d vec = new Vector3d(); double x, y = yStart, z = 0.0; shapes = new Shape3D[xCount * yCount]; for (int i = 0; i < yCount; i++) { x = xStart; for (int j = 0; j < xCount; j++) { vec.set(x, y, z); t3d.setTranslation(vec); trans = new TransformGroup(t3d); addChild(trans); sphere = new Sphere(radius, // sphere radius Primitive.GENERATE_NORMALS, // generate normals 16, // 16 divisions radially app); // it's appearance trans.addChild(sphere); x += xSpacing; shapes[numShapes] = sphere.getShape(); if (overrideflag) shapes[numShapes].setCapability(Shape3D.ALLOW_APPEARANCE_OVERRIDE_WRITE); numShapes++; } y += ySpacing; } }
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 w ww . j ava 2 s .com*/ * @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:ExLinearFog.java
public ColumnScene(Component observer) { BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Add a few lights AmbientLight ambient = new AmbientLight(); ambient.setEnable(true);//from w w w. ja v a2s .co m ambient.setColor(new Color3f(0.2f, 0.2f, 0.2f)); ambient.setInfluencingBounds(worldBounds); addChild(ambient); DirectionalLight dir1 = new DirectionalLight(); dir1.setEnable(true); dir1.setColor(new Color3f(1.0f, 1.0f, 1.0f)); dir1.setDirection(new Vector3f(0.8f, -0.35f, 0.5f)); dir1.setInfluencingBounds(worldBounds); addChild(dir1); DirectionalLight dir2 = new DirectionalLight(); dir2.setEnable(true); dir2.setColor(new Color3f(0.75f, 0.75f, 1.0f)); dir2.setDirection(new Vector3f(-0.7f, -0.35f, -0.5f)); dir2.setInfluencingBounds(worldBounds); addChild(dir2); // Load textures TextureLoader texLoader = new TextureLoader("grass06.jpg", observer); Texture grassTex = texLoader.getTexture(); if (grassTex == null) System.err.println("Cannot load grass06.jpg texture"); else { grassTex.setBoundaryModeS(Texture.WRAP); grassTex.setBoundaryModeT(Texture.WRAP); grassTex.setMinFilter(Texture.NICEST); grassTex.setMagFilter(Texture.NICEST); grassTex.setMipMapMode(Texture.BASE_LEVEL); grassTex.setEnable(true); } texLoader = new TextureLoader("marble10.jpg", observer); Texture walkTex = texLoader.getTexture(); if (walkTex == null) System.err.println("Cannot load marble10.jpg texture"); else { walkTex.setBoundaryModeS(Texture.WRAP); walkTex.setBoundaryModeT(Texture.WRAP); walkTex.setMinFilter(Texture.NICEST); walkTex.setMagFilter(Texture.NICEST); walkTex.setMipMapMode(Texture.BASE_LEVEL); walkTex.setEnable(true); } texLoader = new TextureLoader("granite07rev.jpg", observer); columnTex = texLoader.getTexture(); if (columnTex == null) System.err.println("Cannot load granite07rev.jpg texture"); else { columnTex.setBoundaryModeS(Texture.WRAP); columnTex.setBoundaryModeT(Texture.WRAP); columnTex.setMinFilter(Texture.NICEST); columnTex.setMagFilter(Texture.NICEST); columnTex.setMipMapMode(Texture.BASE_LEVEL); columnTex.setEnable(true); } // // Build the ground // +-----+---+-----+ // | | | | // | G | W | G | // | | | | // +-----+---+-----+ // // where "G" is grass, and "W" is a walkway between columns // Vector3f trans = new Vector3f(); Transform3D tr = new Transform3D(); TransformGroup tg; // Walkway appearance Appearance walkApp = new Appearance(); Material walkMat = new Material(); walkMat.setAmbientColor(0.5f, 0.5f, 0.5f); walkMat.setDiffuseColor(1.0f, 1.0f, 1.0f); walkMat.setSpecularColor(0.0f, 0.0f, 0.0f); walkApp.setMaterial(walkMat); TextureAttributes walkTexAtt = new TextureAttributes(); walkTexAtt.setTextureMode(TextureAttributes.MODULATE); walkTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); tr.setIdentity(); tr.setScale(new Vector3d(1.0, 6.0, 1.0)); walkTexAtt.setTextureTransform(tr); walkApp.setTextureAttributes(walkTexAtt); if (walkTex != null) walkApp.setTexture(walkTex); // Grass appearance Appearance grassApp = new Appearance(); Material grassMat = new Material(); grassMat.setAmbientColor(0.5f, 0.5f, 0.5f); grassMat.setDiffuseColor(1.0f, 1.0f, 1.0f); grassMat.setSpecularColor(0.0f, 0.0f, 0.0f); grassApp.setMaterial(grassMat); TextureAttributes grassTexAtt = new TextureAttributes(); grassTexAtt.setTextureMode(TextureAttributes.MODULATE); grassTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); tr.setIdentity(); tr.setScale(new Vector3d(2.0, 8.0, 1.0)); grassTexAtt.setTextureTransform(tr); grassApp.setTextureAttributes(grassTexAtt); if (grassTex != null) grassApp.setTexture(grassTex); // Left grass trans.set(-LawnWidth / 2.0f - WalkwayWidth / 2.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid grass1 = new ElevationGrid(2, // X dimension 2, // Z dimension LawnWidth, // X spacing LawnDepth, // Z spacing grassApp); // appearance tg.addChild(grass1); addChild(tg); // Right grass trans.set(LawnWidth / 2.0f + WalkwayWidth / 2.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid grass2 = new ElevationGrid(2, // X dimension 2, // Z dimension LawnWidth, // X spacing LawnDepth, // Z spacing grassApp); // appearance tg.addChild(grass2); addChild(tg); // Walkway trans.set(0.0f, -1.6f, 0.0f); tr.set(trans); tg = new TransformGroup(tr); ElevationGrid walk = new ElevationGrid(2, // X dimension 2, // Z dimension WalkwayWidth, // X spacing WalkwayDepth, // Z spacing walkApp); // appearance tg.addChild(walk); addChild(tg); // // Build several columns on the floor // SharedGroup column = buildSharedColumn(); Group columns = buildColumns(column); addChild(columns); }
From source file:Demo3D.java
/** * Create the subgraph #2/* w w w . jav a 2 s . co m*/ * * @return javax.media.j3d.BranchGroup brGr2 - the root of the subgraph #2 */ public BranchGroup mySubGraph2() { // Create the BranchGroup node brGr2 of the second subgraph. brGr2 = new BranchGroup(); // A BoundingSphere instance as general bounding region. boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Create a Transform3D instance rot1 to perform the necessary // "static rotation" for the desired cube's position. rot1 = new Transform3D(); // Rotation of Pi/2 - arctan(1/sqrt(2)) = 0.955 rad about the // (1,0,-1)-axis passing through the origin. axe_rot = new AxisAngle4f(1.0f, 0.0f, -1.0f, 0.955f); rot1.setRotation(axe_rot); // Create the first TransformGroup node trGr2_1 and attach the // "static rotation" rot1 instance to it. trGr2_1 = new TransformGroup(rot1); // Create and attach a coordinate system to the TransformGroup node // trGr2_1 of the subgraph #2, that is to the cube. 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.4f); // Lenght of the 3 axes trGr2_1.addChild(coordSyst); // Create the ColorCube (Shape3D) and attach it to the // TransformGroup node trGr2_1 of the subgraph #2. colorCube = new ColorCube(0.5f); trGr2_1.addChild(colorCube); // Create the second TransformGroup node trGr2_2. trGr2_2 = 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. trGr2_2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // Attach the first node trGr2_1 to the second node trGr2_2. trGr2_2.addChild(trGr2_1); // Prepare the RotationInterpolator (Behavior) for the // cube's rotation about the y-axis. trans1 = new Transform3D(); // Create the alpha(t) function. rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0); // Create the cube's rotation about the y-axis. rotator = new RotationInterpolator(rotationAlpha, trGr2_2, trans1, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(boundsGen); trGr2_2.addChild(rotator); brGr2.addChild(trGr2_2); // Compile the subgraph to optimize the performances. brGr2.compile(); // Return the final version of the BranchGroup node brGr2 return brGr2; }
From source file:Demo3D.java
/** * Create the subgraph #31 and prepare the TransformGroup node trGr31 for * the tetrahedron's picking.// w w w .j a v a2 s. co m * * @return javax.media.j3d.TransformGroup trGr31_2 - the root of the * subgraph #31 */ public TransformGroup mySubGraph31() { // Create a Transform3D node to execute the desired "static translation" // of the tetrahedron ===> start position. transl = new Transform3D(); vectransl = new Vector3d(0.0, -2.0, 0.0); // translation transl.set(vectransl); // Create the TransformGroup node trGr31, attach into it the "static // translation" instance and prepare it for the picking. trGr31 = new TransformGroup(transl); trGr31.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); trGr31.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); trGr31.setCapability(TransformGroup.ENABLE_PICK_REPORTING); // Attach myObject (Shape3D leaf) to the TransformGroup node trGr31. trGr31.addChild(myObject); // Return the final version of the TransformGroup node trGr31. return trGr31; }
From source file:ExLinearFog.java
private void addBox(float width, float height, float depth, float y, float width2, float depth2, int flags) { float[] coordinates = { // around the bottom -width / 2.0f, -height / 2.0f, depth / 2.0f, width / 2.0f, -height / 2.0f, depth / 2.0f, width / 2.0f, -height / 2.0f, -depth / 2.0f, -width / 2.0f, -height / 2.0f, -depth / 2.0f, // around the top -width2 / 2.0f, height / 2.0f, depth2 / 2.0f, width2 / 2.0f, height / 2.0f, depth2 / 2.0f, width2 / 2.0f, height / 2.0f, -depth2 / 2.0f, -width2 / 2.0f, height / 2.0f, -depth2 / 2.0f, }; int[] fullCoordinateIndexes = { 0, 1, 5, 4, // front 1, 2, 6, 5, // right 2, 3, 7, 6, // back 3, 0, 4, 7, // left 4, 5, 6, 7, // top 3, 2, 1, 0, // bottom };/*from ww w. java 2 s . c o m*/ float v = -(width2 - width) / height; float[] normals = { 0.0f, v, 1.0f, // front 1.0f, v, 0.0f, // right 0.0f, v, -1.0f, // back -1.0f, v, 0.0f, // left 0.0f, 1.0f, 0.0f, // top 0.0f, -1.0f, 0.0f, // bottom }; int[] fullNormalIndexes = { 0, 0, 0, 0, // front 1, 1, 1, 1, // right 2, 2, 2, 2, // back 3, 3, 3, 3, // left 4, 4, 4, 4, // top 5, 5, 5, 5, // bottom }; float[] textureCoordinates = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, }; int[] fullTextureCoordinateIndexes = { 0, 1, 2, 3, // front 0, 1, 2, 3, // right 0, 1, 2, 3, // back 0, 1, 2, 3, // left 0, 1, 2, 3, // top 0, 1, 2, 3, // bottom }; // Select indexes needed int[] coordinateIndexes; int[] normalIndexes; int[] textureCoordinateIndexes; if (flags == 0) { // build neither top or bottom coordinateIndexes = new int[4 * 4]; textureCoordinateIndexes = new int[4 * 4]; normalIndexes = new int[4 * 4]; for (int i = 0; i < 4 * 4; i++) { coordinateIndexes[i] = fullCoordinateIndexes[i]; textureCoordinateIndexes[i] = fullTextureCoordinateIndexes[i]; normalIndexes[i] = fullNormalIndexes[i]; } } else if ((flags & (BUILD_TOP | BUILD_BOTTOM)) == (BUILD_TOP | BUILD_BOTTOM)) { // build top and bottom coordinateIndexes = fullCoordinateIndexes; textureCoordinateIndexes = fullTextureCoordinateIndexes; normalIndexes = fullNormalIndexes; } else if ((flags & BUILD_TOP) != 0) { // build top but not bottom coordinateIndexes = new int[5 * 4]; textureCoordinateIndexes = new int[5 * 4]; normalIndexes = new int[5 * 4]; for (int i = 0; i < 5 * 4; i++) { coordinateIndexes[i] = fullCoordinateIndexes[i]; textureCoordinateIndexes[i] = fullTextureCoordinateIndexes[i]; normalIndexes[i] = fullNormalIndexes[i]; } } else { // build bottom but not top coordinateIndexes = new int[5 * 4]; textureCoordinateIndexes = new int[5 * 4]; normalIndexes = new int[5 * 4]; for (int i = 0; i < 4 * 4; i++) { coordinateIndexes[i] = fullCoordinateIndexes[i]; textureCoordinateIndexes[i] = fullTextureCoordinateIndexes[i]; normalIndexes[i] = fullNormalIndexes[i]; } for (int i = 5 * 4; i < 6 * 4; i++) { coordinateIndexes[i - 4] = fullCoordinateIndexes[i]; textureCoordinateIndexes[i - 4] = fullTextureCoordinateIndexes[i]; normalIndexes[i - 4] = fullNormalIndexes[i]; } } IndexedQuadArray quads = new IndexedQuadArray(coordinates.length, // number // of // vertexes GeometryArray.COORDINATES | // vertex coordinates given GeometryArray.NORMALS | // normals given GeometryArray.TEXTURE_COORDINATE_2, // texture // coordinates given coordinateIndexes.length); // number of coordinate indexes quads.setCoordinates(0, coordinates); quads.setCoordinateIndices(0, coordinateIndexes); quads.setNormals(0, normals); quads.setNormalIndices(0, normalIndexes); quads.setTextureCoordinates(0, textureCoordinates); quads.setTextureCoordinateIndices(0, textureCoordinateIndexes); Shape3D box = new Shape3D(quads, mainAppearance); Vector3f trans = new Vector3f(0.0f, y, 0.0f); Transform3D tr = new Transform3D(); tr.set(trans); // translate TransformGroup tg = new TransformGroup(tr); tg.addChild(box); addChild(tg); }
From source file:ExLinearFog.java
private void addCylinder(float radius, float height, float y) { ///* w ww. ja v a 2s.c o m*/ // Compute coordinates, normals, and texture coordinates // around the top and bottom of a cylinder // float[] coordinates = new float[NSTEPS * 2 * 3]; // xyz float[] normals = new float[NSTEPS * 2 * 3]; // xyz vector float[] textureCoordinates = new float[NSTEPS * 2 * 2]; // st float angle = 0.0f; float deltaAngle = 2.0f * (float) Math.PI / ((float) NSTEPS - 1); float s = 0.0f; float deltaS = 1.0f / ((float) NSTEPS - 1); int n = 0; int tn = 0; float h2 = height / 2.0f; for (int i = 0; i < NSTEPS; i++) { // bottom normals[n + 0] = (float) Math.cos(angle); normals[n + 1] = 0.0f; normals[n + 2] = -(float) Math.sin(angle); coordinates[n + 0] = radius * normals[n + 0]; coordinates[n + 1] = -h2; coordinates[n + 2] = radius * normals[n + 2]; textureCoordinates[tn + 0] = s; textureCoordinates[tn + 1] = 0.0f; n += 3; tn += 2; // top normals[n + 0] = normals[n - 3]; normals[n + 1] = 0.0f; normals[n + 2] = normals[n - 1]; coordinates[n + 0] = coordinates[n - 3]; coordinates[n + 1] = h2; coordinates[n + 2] = coordinates[n - 1]; textureCoordinates[tn + 0] = s; textureCoordinates[tn + 1] = 1.0f; n += 3; tn += 2; angle += deltaAngle; s += deltaS; } // // Compute coordinate indexes, normal indexes, and texture // coordinate indexes awround the sides of a cylinder. // For this application, we don't need top or bottom, so // skip them. // int[] indexes = new int[NSTEPS * 4]; n = 0; int p = 0; // panel count for (int i = 0; i < NSTEPS - 1; i++) { indexes[n + 0] = p; // bottom left indexes[n + 1] = p + 2; // bottom right (next panel) indexes[n + 2] = p + 3; // top right (next panel) indexes[n + 3] = p + 1; // top left n += 4; p += 2; } indexes[n + 0] = p; // bottom left indexes[n + 1] = 0; // bottom right (next panel) indexes[n + 2] = 1; // top right (next panel) indexes[n + 3] = p + 1; // top left IndexedQuadArray quads = new IndexedQuadArray(coordinates.length / 3, // number // of // vertexes GeometryArray.COORDINATES | // format GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, indexes.length); // number // of // indexes quads.setCoordinates(0, coordinates); quads.setTextureCoordinates(0, textureCoordinates); quads.setNormals(0, normals); quads.setCoordinateIndices(0, indexes); quads.setTextureCoordinateIndices(0, indexes); quads.setNormalIndices(0, indexes); Shape3D shape = new Shape3D(quads, mainAppearance); Vector3f trans = new Vector3f(0.0f, y, 0.0f); Transform3D tr = new Transform3D(); tr.set(trans); // translate TransformGroup tg = new TransformGroup(tr); tg.addChild(shape); addChild(tg); }
From source file:ExSpotLight.java
public SphereGroup(float radius, float xSpacing, float ySpacing, int xCount, int yCount, Appearance app) { if (app == null) { app = new Appearance(); Material material = new Material(); material.setDiffuseColor(new Color3f(0.8f, 0.8f, 0.8f)); material.setSpecularColor(new Color3f(0.0f, 0.0f, 0.0f)); material.setShininess(0.0f);/*from w ww . j a v a 2 s . c o m*/ app.setMaterial(material); } double xStart = -xSpacing * (double) (xCount - 1) / 2.0; double yStart = -ySpacing * (double) (yCount - 1) / 2.0; Sphere sphere = null; TransformGroup trans = null; Transform3D t3d = new Transform3D(); Vector3d vec = new Vector3d(); double x, y = yStart, z = 0.0; for (int i = 0; i < yCount; i++) { x = xStart; for (int j = 0; j < xCount; j++) { vec.set(x, y, z); t3d.setTranslation(vec); trans = new TransformGroup(t3d); addChild(trans); sphere = new Sphere(radius, // sphere radius Primitive.GENERATE_NORMALS, // generate normals 16, // 16 divisions radially app); // it's appearance trans.addChild(sphere); x += xSpacing; } y += ySpacing; } }
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 ww . j a va 2 s . c om*/ 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); }