List of usage examples for javax.media.j3d TransformGroup TransformGroup
public TransformGroup()
From source file:SimpleGame.java
/** * This builds the ball that acts as the bullet for our gun. The ball is * created from a sphere primitive, and a transform group and interpolator * are added so that we can 'fire' the bullet. * /* w w w. j a v a 2s . c o m*/ * @return BranchGroup that is the root of the ball branch. */ protected BranchGroup buildBall() { BranchGroup theBall = new BranchGroup(); Appearance ballApp = 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; ballApp.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess)); Sphere ball = new Sphere(0.2f, ballApp); TransformGroup ballMovXfmGrp = new TransformGroup(); ballMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); ballMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); ballMovXfmGrp.addChild(ball); theBall.addChild(ballMovXfmGrp); ballAlpha = new Alpha(1, 0, 0, 500, 0, 0); Transform3D axis = new Transform3D(); axis.rotY(Math.PI / 2); moveBall = new PositionInterpolator(ballAlpha, ballMovXfmGrp, axis, 0.0f, 50.0f); moveBall.setSchedulingBounds(bounds); theBall.addChild(moveBall); return theBall; }
From source file:HiResCoordTest.java
public TransformGroup[] getViewTransformGroupArray(int nIndex) { TransformGroup[] tgArray = new TransformGroup[1]; tgArray[0] = new TransformGroup(); Vector3d vTrans = null;/*from w w w.j a va 2 s .c om*/ if (nIndex == 1) vTrans = new Vector3d(0.0, 0.0, -m_TranslateEarthZ); else vTrans = new Vector3d(0.0, 0.0, -m_TranslateHouseZ); // move the camera BACK so we can view the scene // note that the coordinate directions are // reversed as we are moving the view Transform3D t3d = new Transform3D(); t3d.setTranslation(vTrans); t3d.invert(); tgArray[0].setTransform(t3d); return tgArray; }
From source file:SwingTest.java
/** * Create the scene side of the scenegraph *//* w ww .j av a 2 s.c om*/ protected BranchGroup createSceneBranchGroup() { // create the root of the scene side scenegraph BranchGroup objRoot = new BranchGroup(); // create a TransformGroup to rotate the objects in the scene // set the capability bits on the TransformGroup so that it // can be modified at runtime TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create a spherical bounding volume BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // create a 4x4 transformation matrix Transform3D yAxis = new Transform3D(); // create an Alpha interpolator to automatically generate // modifications to the rotation component of the transformation matrix Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); // create a RotationInterpolator behavior to effect the TransformGroup rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); // set the scheduling bounds on the behavior rotator.setSchedulingBounds(bounds); // add the behavior to the scenegraph objTrans.addChild(rotator); // create the BranchGroup which contains the objects // we add/remove to and from the scenegraph sceneBranchGroup = new BranchGroup(); // allow the BranchGroup to have children added at runtime sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND); sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ); sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE); // add both the cube and the sphere to the scenegraph sceneBranchGroup.addChild(createCube()); sceneBranchGroup.addChild(createSphere()); // create the colors for the lights Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); // create the ambient light AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); // create the directional light DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); // add the lights to the scenegraph objRoot.addChild(aLgt); objRoot.addChild(lgt1); // wire the scenegraph together objTrans.addChild(sceneBranchGroup); objRoot.addChild(objTrans); // return the root of the scene side of the scenegraph return objRoot; }
From source file:PlatformTest.java
public BranchGroup createSceneGraph() { final int LAND_WIDTH = 12; final float LAND_HEIGHT = -1.0f; final int LAND_LENGTH = 12; final int nTileSize = 2; // calculate how many vertices we need to store all the "tiles" // that compose the QuadArray. final int nNumTiles = ((LAND_LENGTH / nTileSize) * 2) * ((LAND_WIDTH / nTileSize) * 2); final int nVertexCount = 4 * nNumTiles; Point3f[] coordArray = new Point3f[nVertexCount]; Point2f[] texCoordArray = new Point2f[nVertexCount]; // create an Appearance and load a texture Appearance app = new Appearance(); Texture tex = new TextureLoader("land.jpg", this).getTexture(); app.setTexture(tex);/*from w ww. j a v a 2 s .c o m*/ // create the parent BranchGroup BranchGroup bg = new BranchGroup(); int nItem = 0; // loop over all the tiles in the environment for (int x = -LAND_WIDTH; x <= LAND_WIDTH; x += nTileSize) { for (int z = -LAND_LENGTH; z <= LAND_LENGTH; z += nTileSize) { // if we are on the border of the environment create a // TransformGroup to position a ColorCube to create a "wall" if (x == -LAND_WIDTH || x == LAND_WIDTH || z == -LAND_LENGTH || z == LAND_LENGTH) { TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, 0, z)); tg.setTransform(t3d); tg.addChild(new ColorCube(nTileSize / 2)); bg.addChild(tg); } // if we are not on the last row or column create a "tile" // and add to the QuadArray. Use CCW winding and assign texture // coordinates. if (z < LAND_LENGTH && x < LAND_WIDTH) { coordArray[nItem] = new Point3f(x, LAND_HEIGHT, z); texCoordArray[nItem++] = new Point2f(0, 0); coordArray[nItem] = new Point3f(x, LAND_HEIGHT, z + nTileSize); texCoordArray[nItem++] = new Point2f(1, 0); coordArray[nItem] = new Point3f(x + nTileSize, LAND_HEIGHT, z + nTileSize); texCoordArray[nItem++] = new Point2f(1, 1); coordArray[nItem] = new Point3f(x + nTileSize, LAND_HEIGHT, z); texCoordArray[nItem++] = new Point2f(0, 1); } } } // create a GeometryInfo and generate Normal vectors // for the QuadArray that was populated. GeometryInfo gi = new GeometryInfo(GeometryInfo.QUAD_ARRAY); gi.setCoordinates(coordArray); gi.setTextureCoordinates(texCoordArray); NormalGenerator normalGenerator = new NormalGenerator(); normalGenerator.generateNormals(gi); // wrap the GeometryArray in a Shape3D Shape3D shape = new Shape3D(gi.getGeometryArray(), app); // add the Shape3D to the parent BranchGroup bg.addChild(shape); // create some lights for the scene Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(m_Bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(m_Bounds); // add the lights to the parent BranchGroup bg.addChild(aLgt); bg.addChild(lgt1); // create a light gray background Background back = new Background(new Color3f(0.9f, 0.9f, 0.9f)); back.setApplicationBounds(m_Bounds); bg.addChild(back); // compile the whole scene //bg.compile(); return bg; }
From source file:InterpolatorTest.java
private TransformGroup createSharedGroup(Appearance app) { TransformGroup tg = new TransformGroup(); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); tg.addChild(createGeometry(app, -0.5, -0.5, 0)); tg.addChild(createGeometry(app, -0.5, 0.5, 0)); tg.addChild(createGeometry(app, 0.5, 0.5, 0)); tg.addChild(createGeometry(app, 0.5, -0.5, 0)); return tg;//from ww w . j av a 2s. c o m }
From source file:ExSpotLight.java
private Group buildArrows() { // Create a switch group to hold the different arrow fan // spread angle choices. Enable child choice writing. arrowSpreadAngleSwitch = new Switch(); arrowSpreadAngleSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); // Create a set of arrow fans, one per spread angle // shown on the menu. AnnotationArrowFan af = null;/*from w w w. j a va 2s. c om*/ float spread = 0.0f; for (int i = 0; i < spreads.length; i++) { spread = ((Double) spreads[i].value).floatValue(); af = new AnnotationArrowFan(0.0f, 0.0f, 0.0f, // center position 2.5f, // arrow length -spread, // start angle spread, // end angle 5); // number of arrows arrowSpreadAngleSwitch.addChild(af); } // Select the current fan. arrowSpreadAngleSwitch.setWhichChild(currentSpread); // Create an outer transform group used to change the fan // position. Enable writing of its transform. arrowPositionTransformGroup = new TransformGroup(); arrowPositionTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // Create a set of Transform3Ds for the different arrow positions. arrowPositionTransforms = new Transform3D[positions.length]; Point3f pos; Vector3f v = new Vector3f(); for (int i = 0; i < positions.length; i++) { // Create a Transform3D, setting its translation. arrowPositionTransforms[i] = new Transform3D(); pos = (Point3f) positions[i].value; v.set(pos); arrowPositionTransforms[i].setTranslation(v); } // Set the initial transform to be the current position arrowPositionTransformGroup.setTransform(arrowPositionTransforms[currentPosition]); // Create an inner transform group surrounding the arrows, // used to set the aim direction. Enable writing of its transform. arrowDirectionTransformGroup = new TransformGroup(); arrowDirectionTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // Add the switch group to the direction-change transform group, // and add the direction-change transform group to the // position-change transform gorup. arrowDirectionTransformGroup.addChild(arrowSpreadAngleSwitch); arrowPositionTransformGroup.addChild(arrowDirectionTransformGroup); // Create a set of Transform3Ds for the different // arrow directions. arrowDirectionTransforms = new Transform3D[directions.length]; Vector3f dir = new Vector3f(); Vector3f positiveX = new Vector3f(1.0f, 0.0f, 0.0f); Vector3f axis = new Vector3f(); float angle; float dot; for (int i = 0; i < directions.length; i++) { // Normalize the direction vector dir.normalize((Vector3f) directions[i].value); // Cross the direction vector with the arrow's // +X aim direction to get a vector orthogonal // to both. This is the rotation axis. axis.cross(positiveX, dir); if (axis.x == 0.0f && axis.y == 0.0f && axis.z == 0.0f) { // New direction is parallel to current // arrow direction. Default to a Y axis. axis.y = 1.0f; } // Compute the angle between the direction and +X // vectors, where: // // cos(angle) = (dir dot positiveX) // ------------------------------- // (positiveX.length * dir.length) // // but since positiveX is normalized (as created // above) and dir has been normalized, both have // a length of 1. So, the angle between the // vectors is: // // angle = arccos(dir dot positiveX) dot = dir.dot(positiveX); angle = (float) Math.acos(dot); // Create a Transform3D, setting its rotation using // an AxisAngle4f, which takes an XYZ rotation vector // and an angle to rotate by around that vector. arrowDirectionTransforms[i] = new Transform3D(); arrowDirectionTransforms[i].setRotation(new AxisAngle4f(axis.x, axis.y, axis.z, angle)); } // Set the initial transform to be the current aim direction. arrowDirectionTransformGroup.setTransform(arrowDirectionTransforms[currentDirection]); return arrowPositionTransformGroup; }
From source file:ExSound.java
private Group buildForeground() { ///*from w w w . j av a2 s . c om*/ // Create a group for the foreground, and move // everything up a bit. // TransformGroup group = new TransformGroup(); Transform3D tr = new Transform3D(); tr.setTranslation(new Vector3f(0.0f, -1.6f, 0.0f)); group.setTransform(tr); // // Load textures // if (debug) System.err.println(" textures..."); Texture groundTex = null; Texture spurTex = null; Texture domeTex = null; TextureLoader texLoader = null; ImageComponent image = null; texLoader = new TextureLoader("flooring.jpg", this); image = texLoader.getImage(); if (image == null) System.err.println("Cannot load flooring.jpg texture"); else { groundTex = texLoader.getTexture(); groundTex.setBoundaryModeS(Texture.WRAP); groundTex.setBoundaryModeT(Texture.WRAP); groundTex.setMinFilter(Texture.NICEST); groundTex.setMagFilter(Texture.NICEST); groundTex.setMipMapMode(Texture.BASE_LEVEL); groundTex.setEnable(true); } texLoader = new TextureLoader("granite07rev.jpg", this); Texture 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); } texLoader = new TextureLoader("brtsky.jpg", this); Texture boxTex = texLoader.getTexture(); if (boxTex == null) System.err.println("Cannot load brtsky.jpg texture"); else { boxTex.setBoundaryModeS(Texture.WRAP); boxTex.setBoundaryModeT(Texture.WRAP); boxTex.setMinFilter(Texture.NICEST); boxTex.setMagFilter(Texture.NICEST); boxTex.setMipMapMode(Texture.BASE_LEVEL); boxTex.setEnable(true); } // // Build the ground // if (debug) System.err.println(" ground..."); Appearance groundApp = new Appearance(); Material groundMat = new Material(); groundMat.setAmbientColor(0.3f, 0.3f, 0.3f); groundMat.setDiffuseColor(0.7f, 0.7f, 0.7f); groundMat.setSpecularColor(0.0f, 0.0f, 0.0f); groundApp.setMaterial(groundMat); tr = new Transform3D(); tr.setScale(new Vector3d(16.0, 4.0, 1.0)); TextureAttributes groundTexAtt = new TextureAttributes(); groundTexAtt.setTextureMode(TextureAttributes.MODULATE); groundTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); groundTexAtt.setTextureTransform(tr); groundApp.setTextureAttributes(groundTexAtt); if (groundTex != null) groundApp.setTexture(groundTex); ElevationGrid ground = new ElevationGrid(11, // X dimension 11, // Z dimension 2.0f, // X spacing 2.0f, // Z spacing // Automatically use zero heights groundApp); // Appearance group.addChild(ground); // // Create a column appearance used for both columns. // Appearance columnApp = new Appearance(); Material columnMat = new Material(); columnMat.setAmbientColor(0.6f, 0.6f, 0.6f); columnMat.setDiffuseColor(1.0f, 1.0f, 1.0f); columnMat.setSpecularColor(0.0f, 0.0f, 0.0f); columnApp.setMaterial(columnMat); TextureAttributes columnTexAtt = new TextureAttributes(); columnTexAtt.setTextureMode(TextureAttributes.MODULATE); columnTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); columnApp.setTextureAttributes(columnTexAtt); if (columnTex != null) columnApp.setTexture(columnTex); // // To give the point sound an apparent location, // build a column and a set of three co-located // tumbling boxes hovering above the column. // TransformGroup pointGroup = new TransformGroup(); tr.setIdentity(); tr.setTranslation(new Vector3f(pointX, 0.0f, 0.0f)); pointGroup.setTransform(tr); GothicColumn column = new GothicColumn(1.0f, // height 0.2f, // radius GothicColumn.BUILD_TOP, // flags columnApp); // appearance pointGroup.addChild(column); TransformGroup rotThing = new TransformGroup(); tr.setIdentity(); tr.setTranslation(new Vector3f(0.0f, soundHeight, 0.0f)); rotThing.setTransform(tr); Appearance boxApp = new Appearance(); // No material -- make it emissive TextureAttributes boxTexAtt = new TextureAttributes(); boxTexAtt.setTextureMode(TextureAttributes.REPLACE); boxTexAtt.setPerspectiveCorrectionMode(TextureAttributes.NICEST); boxApp.setTextureAttributes(boxTexAtt); if (boxTex != null) boxApp.setTexture(boxTex); rotThing.addChild(buildTumblingBox(0.4f, 0.4f, 0.4f, // width, height, // depth boxApp, // Appearance 40000, 32000, 26000));// XYZ tumble durations rotThing.addChild(buildTumblingBox(0.4f, 0.4f, 0.4f, // width, height, // depth boxApp, // Appearance 38000, 30000, 28000));// XYZ tumble durations rotThing.addChild(buildTumblingBox(0.4f, 0.4f, 0.4f, // width, height, // depth boxApp, // Appearance 30000, 26000, 34000));// XYZ tumble durations pointGroup.addChild(rotThing); group.addChild(pointGroup); return group; }
From source file:SplineInterpolatorTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create a root TG in case we need to scale the scene TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Transform3D t3d = new Transform3D(); objTrans.setTransform(t3d);/* ww w . ja v a 2 s . c o m*/ Group hiResGroup = createLodLand(objTrans); createBuildings(objTrans); createHelicopters(objTrans); // connect objRoot.addChild(objTrans); return objRoot; }
From source file:LightTest.java
protected Group createSphere(float x, float y, float z, float radius) { TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, y, z)); tg.setTransform(t3d);/*w w w. j a v a 2 s . co m*/ // create an Appearance and Material Appearance app = new Appearance(); Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); app.setMaterial(new Material(objColor, black, objColor, black, 80.0f)); tg.addChild(new Sphere(radius, Primitive.GENERATE_NORMALS, app)); return tg; }
From source file:SplineInterpolatorTest.java
public TransformGroup[] getViewTransformGroupArray() { TransformGroup[] tgArray = new TransformGroup[2]; tgArray[0] = new TransformGroup(); tgArray[1] = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(getScale());// w w w . j a v a2s. co m t3d.invert(); tgArray[0].setTransform(t3d); // create an Alpha object for the Interpolator Alpha alpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 25000, 4000, 100, 20000, 5000, 50); // ensure the Interpolator can access the TG tgArray[1].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); try { // create the Interpolator and load the keyframes from disk RotPosScaleTCBSplinePathInterpolator splineInterpolator = Utils.createSplinePathInterpolator( new UiAlpha(alpha), tgArray[1], new Transform3D(), new URL(getWorkingDirectory(), "rotate_viewer_spline.xls")); // set the scheduling bounds and attach to the scenegraph splineInterpolator.setSchedulingBounds(getApplicationBounds()); tgArray[1].addChild(splineInterpolator); } catch (Exception e) { System.err.println(e.toString()); } return tgArray; }