List of usage examples for javax.media.j3d Transform3D Transform3D
public Transform3D()
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);//from ww w. java2s. c om 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:AvatarTest.java
/** * Process a keyboard event/*ww w . j a v a2s .c om*/ */ private void processAWTEvent(AWTEvent[] events) { for (int n = 0; n < events.length; n++) { if (events[n] instanceof KeyEvent) { KeyEvent eventKey = (KeyEvent) events[n]; if (eventKey.getID() == KeyEvent.KEY_PRESSED) { int keyCode = eventKey.getKeyCode(); int keyChar = eventKey.getKeyChar(); Vector3f translate = new Vector3f(); Transform3D t3d = new Transform3D(); m_TransformGroup.getTransform(t3d); t3d.get(translate); switch (keyCode) { case KeyEvent.VK_LEFT: translate.x += TRANSLATE_LEFT; break; case KeyEvent.VK_RIGHT: translate.x += TRANSLATE_RIGHT; break; } // System.out.println( "Steering: " + translate.x ); translate.y = 0.5f; t3d.setTranslation(translate); m_TransformGroup.setTransform(t3d); } } } }
From source file:ExTexture.java
public void checkboxChanged(CheckboxMenu menu, int check) { if (menu == imageMenu) { // Change the texture image currentImage = check;//w ww.j a v a 2 s . c o m Texture tex = textureComponents[currentImage]; int mode = ((Integer) boundaries[currentBoundary].value).intValue(); Color3f color = (Color3f) colors[currentColor].value; int filter = ((Integer) filters[currentFilter].value).intValue(); shape.setAppearance(dummyApp); tex.setEnable(textureOnOff); tex.setBoundaryModeS(mode); tex.setBoundaryModeT(mode); tex.setBoundaryColor(color.x, color.y, color.z, 0.0f); tex.setMagFilter(filter); tex.setMinFilter(filter); app.setTexture(tex); shape.setAppearance(app); return; } if (menu == boundaryMenu) { // Change the texture boundary mode currentBoundary = check; Texture tex = textureComponents[currentImage]; int mode = ((Integer) boundaries[currentBoundary].value).intValue(); shape.setAppearance(dummyApp); tex.setBoundaryModeS(mode); tex.setBoundaryModeT(mode); app.setTexture(tex); shape.setAppearance(app); return; } if (menu == colorMenu) { // Change the boundary color currentColor = check; Color3f color = (Color3f) colors[currentColor].value; Texture tex = textureComponents[currentImage]; shape.setAppearance(dummyApp); tex.setBoundaryColor(color.x, color.y, color.z, 0.0f); app.setTexture(tex); shape.setAppearance(app); return; } if (menu == filterMenu) { // Change the filter mode currentFilter = check; int filter = ((Integer) filters[currentFilter].value).intValue(); Texture tex = textureComponents[currentImage]; shape.setAppearance(dummyApp); tex.setMagFilter(filter); tex.setMinFilter(filter); app.setTexture(tex); shape.setAppearance(app); return; } if (menu == modeMenu) { // Change the texture mode currentMode = check; int mode = ((Integer) modes[currentMode].value).intValue(); app.setTextureAttributes(dummyAtt); texatt.setTextureMode(mode); app.setTextureAttributes(texatt); return; } if (menu == blendColorMenu) { // Change the boundary color currentBlendColor = check; Color3f color = (Color3f) colors[currentBlendColor].value; app.setTextureAttributes(dummyAtt); texatt.setTextureBlendColor(color.x, color.y, color.z, 0.5f); app.setTextureAttributes(texatt); return; } if (menu == xformMenu) { // Change the texture transform currentXform = check; Transform3D tt = new Transform3D(); switch (currentXform) { default: case 0: // Identity texatt.setTextureTransform(tt); return; case 1: // Scale by 2 tt.setScale(2.0); texatt.setTextureTransform(tt); return; case 2: // Scale by 4 tt.setScale(4.0); texatt.setTextureTransform(tt); return; case 3: // Z rotate by 45 degrees tt.rotZ(Math.PI / 4.0); texatt.setTextureTransform(tt); return; case 4: // Translate by 0.25 tt.set(new Vector3f(0.25f, 0.0f, 0.0f)); texatt.setTextureTransform(tt); return; } } // Handle all other checkboxes super.checkboxChanged(menu, check); }
From source file:LightTest.java
public Group createGeometry() { Point3f pos = new Point3f(); ((PointLight) m_Light).getPosition(pos); m_TransformGroup = new TransformGroup(); m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3f(pos.x, pos.y, pos.z)); m_TransformGroup.setTransform(t3d);// www . ja v a 2 s.co m m_Sphere = new Sphere(0.2f, Primitive.ENABLE_APPEARANCE_MODIFY | Primitive.GENERATE_NORMALS, 16); m_TransformGroup.addChild(m_Sphere); m_TransformGroup.addChild(super.createGeometry()); return (Group) m_TransformGroup; }
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 w w .ja 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:AppearanceExplorer.java
void setupAppearance() { appearance = new Appearance(); // ColoringAttributes coloringColor = new Color3f(red); coloringAttr = new ColoringAttributes(coloringColor, coloringShadeModel); coloringAttr.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE); coloringAttr.setCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE); appearance.setColoringAttributes(coloringAttr); // set up the editor coloringAttrEditor = new ColoringAttributesEditor(coloringAttr); // PointAttributes pointAttr = new PointAttributes(pointSize, pointAAEnable); pointAttr.setCapability(PointAttributes.ALLOW_SIZE_WRITE); pointAttr.setCapability(PointAttributes.ALLOW_ANTIALIASING_WRITE); appearance.setPointAttributes(pointAttr); // set up the editor pointAttrEditor = new PointAttributesEditor(pointAttr); // LineAttributes lineAttr = new LineAttributes(lineWidth, linePattern, lineAAEnable); lineAttr.setCapability(LineAttributes.ALLOW_WIDTH_WRITE); lineAttr.setCapability(LineAttributes.ALLOW_PATTERN_WRITE); lineAttr.setCapability(LineAttributes.ALLOW_ANTIALIASING_WRITE); appearance.setLineAttributes(lineAttr); // set up the editor lineAttrEditor = new LineAttributesEditor(lineAttr); // PolygonAttributes polygonAttr = new PolygonAttributes(polygonMode, polygonCull, 0.0f); polygonAttr.setPolygonOffset(polygonOffsetBias); polygonAttr.setPolygonOffsetFactor(polygonOffsetFactor); polygonAttr.setCapability(PolygonAttributes.ALLOW_MODE_WRITE); polygonAttr.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE); polygonAttr.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE); appearance.setPolygonAttributes(polygonAttr); // set up the editor polygonAttrEditor = new PolygonAttributesEditor(polygonAttr); // Rendering attributes renderAttr = new RenderingAttributes(renderDepthBuffer, renderDepthBufferWrite, 0.0f, RenderingAttributes.ALWAYS, renderVisible, renderIgnoreVertexColor, renderRasterOpEnable, renderRasterOp);/* ww w . j a va 2 s . c o m*/ renderAttr.setCapability(RenderingAttributes.ALLOW_IGNORE_VERTEX_COLORS_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_VISIBLE_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_RASTER_OP_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_FUNCTION_WRITE); renderAttr.setCapability(RenderingAttributes.ALLOW_ALPHA_TEST_VALUE_WRITE); appearance.setRenderingAttributes(renderAttr); appearance.setCapability(Appearance.ALLOW_RENDERING_ATTRIBUTES_WRITE); // set up the editor renderAttrEditor = new RenderingAttributesEditor(renderAttr); // TransparencyAttributes transpAttr = new TransparencyAttributes(transpMode, transpValue); transpAttr.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE); transpAttr.setCapability(TransparencyAttributes.ALLOW_VALUE_WRITE); transpAttr.setCapability(TransparencyAttributes.ALLOW_BLEND_FUNCTION_WRITE); appearance.setTransparencyAttributes(transpAttr); // set up the editor transpAttrEditor = new TransparencyAttributesEditor(transpAttr); // Material material = new Material(red, black, red, white, 20.f); material.setLightingEnable(false); material.setCapability(Material.ALLOW_COMPONENT_WRITE); appearance.setMaterial(material); // material presets String[] materialNames = { "Red", "White", "Red Ambient", "Red Diffuse", "Grey Emissive", "White Specular", "Aluminium", "Blue Plastic", "Copper", "Gold", "Red Alloy", "Black Onyx" }; Material[] materialPresets = new Material[materialNames.length]; materialPresets[0] = new Material(red, black, red, white, 20.0f); materialPresets[1] = new Material(white, black, white, white, 20.0f); materialPresets[2] = new Material(red, black, black, black, 20.0f); materialPresets[3] = new Material(black, black, red, black, 20.0f); materialPresets[4] = new Material(black, grey, black, black, 20.0f); materialPresets[5] = new Material(black, black, black, white, 20.0f); Color3f alum = new Color3f(0.37f, 0.37f, 0.37f); Color3f alumSpec = new Color3f(0.89f, 0.89f, 0.89f); materialPresets[6] = new Material(alum, black, alum, alumSpec, 17); Color3f bluePlastic = new Color3f(0.20f, 0.20f, 0.70f); Color3f bluePlasticSpec = new Color3f(0.85f, 0.85f, 0.85f); materialPresets[7] = new Material(bluePlastic, black, bluePlastic, bluePlasticSpec, 22); Color3f copper = new Color3f(0.30f, 0.10f, 0.00f); ; Color3f copperSpec = new Color3f(0.75f, 0.30f, 0.00f); materialPresets[8] = new Material(copper, black, copper, copperSpec, 10); Color3f gold = new Color3f(0.49f, 0.34f, 0.00f); Color3f goldSpec = new Color3f(0.89f, 0.79f, 0.00f); materialPresets[9] = new Material(gold, black, gold, goldSpec, 15); Color3f redAlloy = new Color3f(0.34f, 0.00f, 0.34f); Color3f redAlloySpec = new Color3f(0.84f, 0.00f, 0.00f); materialPresets[10] = new Material(redAlloy, black, redAlloy, redAlloySpec, 15); Color3f blackOnyxSpec = new Color3f(0.72f, 0.72f, 0.72f); materialPresets[11] = new Material(black, black, black, blackOnyxSpec, 23); // set up the editor materialEditor = new MaterialPresetEditor(material, materialNames, materialPresets); // Texture2D // set the values to the defaults texEnable = false; texMipMapMode = Texture.BASE_LEVEL; texBoundaryModeS = Texture.WRAP; texBoundaryModeT = Texture.WRAP; texMinFilter = Texture.BASE_LEVEL_POINT; texMagFilter = Texture.BASE_LEVEL_POINT; texBoundaryColor = new Color4f(0.0f, 0.0f, 0.0f, 0.0f); // set up the image choices String[] texImageNames = { "Earth", "Fish", }; String[] texImageFileNames = { "earth.jpg", "fish1.gif", }; int texImageFileIndex = 0; // set up the appearance to allow the texture to be changed appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE); // set up the editor (this will create the initial Texture2D and // assign it to the appearance) texture2DEditor = new Texture2DEditor(appearance, codeBaseString, texImageNames, texImageFileNames, texImageFileIndex, texEnable, texBoundaryModeS, texBoundaryModeT, texMinFilter, texMagFilter, texMipMapMode, texBoundaryColor); // TextureAttributes texMode = TextureAttributes.REPLACE; texBlendColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f); texTransform = new Transform3D(); texPerspCorrect = TextureAttributes.NICEST; textureAttr = new TextureAttributes(texMode, texTransform, texBlendColor, texPerspCorrect); // set the capabilities to allow run time changes textureAttr.setCapability(TextureAttributes.ALLOW_MODE_WRITE); textureAttr.setCapability(TextureAttributes.ALLOW_BLEND_COLOR_WRITE); textureAttr.setCapability(TextureAttributes.ALLOW_TRANSFORM_WRITE); // connect it to the appearance appearance.setTextureAttributes(textureAttr); // setup the editor textureAttrEditor = new TextureAttributesEditor(textureAttr); // set up the tex coordinate generation texGenEnable = false; texGenMode = TexCoordGeneration.OBJECT_LINEAR; texGenPlaneS = new Vector4f(1.0f, 0.0f, 0.0f, 0.0f); texGenPlaneT = new Vector4f(0.0f, 1.0f, 0.0f, 0.0f); // set the appearance so that we can replace the tex gen when live appearance.setCapability(Appearance.ALLOW_TEXGEN_WRITE); // setup the editor texGenEditor = new TexCoordGenerationEditor(appearance, texGenEnable, texGenMode, texGenPlaneS, texGenPlaneT); }
From source file:ExHenge.java
public Group buildRing(SharedGroup sg) { Group g = new Group(); g.addChild(new Link(sg)); // 0 degrees TransformGroup tg = new TransformGroup(); Transform3D tr = new Transform3D(); tr.rotY(0.785); // 45 degrees tg.setTransform(tr);/* w w w . ja va2 s .c o m*/ tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(-0.785); // -45 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(1.571); // 90 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(-1.571); // -90 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(2.356); // 135 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(-2.356); // -135 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); tg = new TransformGroup(); tr = new Transform3D(); tr.rotY(Math.PI); // 180 degrees tg.setTransform(tr); tg.addChild(new Link(sg)); g.addChild(tg); return g; }
From source file:SplineAnim.java
private void setupAnimationData() { yAxis = new Transform3D(); animAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, duration, 0, 0, 0, 0, 0); }
From source file:ExSound.java
private Group buildTumblingBox(float width, float height, float depth, Appearance app, int xDur, int yDur, int zDur) { BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Build a box to tumble Shape3D box = buildBox(width, height, depth, app); // Build a set of nested transform groups. Attach // to each one a behavior that rotates around an X, // Y, or Z axis. Use different rotation speeds for // each axis to create a tumbling effect. TransformGroup outerGroup = new TransformGroup(); outerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D yAxis = new Transform3D(); Alpha alpha = new Alpha(-1, // loop count: -1 = forever Alpha.INCREASING_ENABLE, // increasing 0, // trigger time: 0 = now 0, // delay: 0 = none xDur, // increasing duration 0, // increasing ramp duration 0, // at one (sustain) duration 0, // decreasing duration 0, // decreasing ramp duration 0); // at zero duration RotationInterpolator rot = new RotationInterpolator(alpha, // Alpha // control outerGroup, // Target transform group yAxis, // Y axis rotation 0.0f, // Minimum angle 2.0f * (float) Math.PI);// Maximum angle rot.setSchedulingBounds(worldBounds); outerGroup.addChild(rot);//from ww w . jav a 2 s .co m TransformGroup middleGroup = new TransformGroup(); middleGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D xAxis = new Transform3D(); xAxis.rotZ(-1.571f); alpha = new Alpha(-1, // loop count: -1 = forever Alpha.INCREASING_ENABLE, // increasing 0, // trigger time: 0 = now 0, // delay: 0 = none yDur, // increasing duration 0, // increasing ramp duration 0, // at one (sustain) duration 0, // decreasing duration 0, // decreasing ramp duration 0); // at zero duration rot = new RotationInterpolator(alpha, // Alpha control middleGroup, // Target transform group xAxis, // Y axis rotation 0.0f, // Minimum angle 2.0f * (float) Math.PI);// Maximum angle rot.setSchedulingBounds(worldBounds); middleGroup.addChild(rot); outerGroup.addChild(middleGroup); TransformGroup innerGroup = new TransformGroup(); innerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D zAxis = new Transform3D(); zAxis.rotX(1.571f); alpha = new Alpha(-1, // loop count: -1 = forever Alpha.INCREASING_ENABLE, // increasing 0, // trigger time: 0 = now 0, // delay: 0 = none zDur, // increasing duration 0, // increasing ramp duration 0, // at one (sustain) duration 0, // decreasing duration 0, // decreasing ramp duration 0); // at zero duration rot = new RotationInterpolator(alpha, // Alpha control innerGroup, // Target transform group zAxis, // Y axis rotation 0.0f, // Minimum angle 2.0f * (float) Math.PI);// Maximum angle rot.setSchedulingBounds(worldBounds); innerGroup.addChild(rot); middleGroup.addChild(innerGroup); innerGroup.addChild(box); return outerGroup; }
From source file:KeyNavigateTest.java
void createWater(Group mapGroup, int nPixelX, int nPixelY) { Point3d point = convertToWorldCoordinatesPixelCenter(nPixelX, nPixelY); if (m_WaterAppearance == null) { m_WaterAppearance = new Appearance(); m_WaterAppearance.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false)); m_WaterAppearance// w ww . j ava 2s . c o m .setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f)); m_WaterAppearance.setTextureAttributes(new TextureAttributes(TextureAttributes.REPLACE, new Transform3D(), new Color4f(0, 0, 0, 1), TextureAttributes.FASTEST)); } Land water = new Land(this, mapGroup, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); water.createObject(m_WaterAppearance, new Vector3d(point.x, m_kFloorLevel + 0.1, point.z), new Vector3d(40, 1, 40), "water.gif", null, null); }