List of usage examples for javax.media.j3d Group addChild
public void addChild(Node child)
From source file:AvatarTest.java
public TransformGroup addBehaviors(Group bgRoot) { // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D zAxis = new Transform3D(); zAxis.rotY(Math.toRadians(90.0)); Alpha zoomAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 20000, 0, 0, 0, 0, 0); PositionInterpolator posInt = new PositionInterpolator(zoomAlpha, objTrans, zAxis, 0, -160); posInt.setSchedulingBounds(getBoundingSphere()); objTrans.addChild(posInt);/*from w w w .jav a 2 s .c om*/ bgRoot.addChild(objTrans); return objTrans; }
From source file:ScenegraphTest.java
private TransformGroup addLimb(Group parentGroup, String szName, double radius, double length, double rotMin, double rotMax) { // create the rotator TransformGroup tgJoint = new TransformGroup(); tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // add a rotator if necessary if (rotMin != rotMax) { Transform3D xAxis = new Transform3D(); xAxis.rotX(Math.PI / 2.0); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, tgJoint, xAxis, (float) rotMin, (float) rotMax); rotator.setSchedulingBounds(createApplicationBounds()); tgJoint.addChild(rotator);/*w w w .j a v a 2s . c o m*/ } // create a cylinder using length and radius tgJoint.addChild(createLimb(radius, length)); // create the joint (the *next* TG should // be offset by the length of this limb) TransformGroup tgOffset = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(0, length, 0)); tgOffset.setTransform(t3d); tgJoint.addChild(tgOffset); parentGroup.addChild(tgJoint); // return the offset TG, so any child TG's will be added // in the correct position. return tgOffset; }
From source file:AvatarTest.java
public Group createBuildings(Group g) { BranchGroup bg = new BranchGroup(); for (int n = (int) Road.ROAD_LENGTH; n < 0; n = n + 10) { Building building = new Building(this, bg, ComplexObject.GEOMETRY | ComplexObject.TEXTURE | ComplexObject.COLLISION); building.createObject(new Appearance(), new Vector3d(getRandomNumber(-4.0f, 0.25f), getRandomNumber(1.0f, 0.5f), getRandomNumber(n, 0.5f)), new Vector3d(1, 1, 1), "house.jpg", null, null);// ww w . j ava 2 s .co m building = new Building(this, bg, ComplexObject.GEOMETRY | ComplexObject.TEXTURE | ComplexObject.COLLISION); building.createObject(new Appearance(), new Vector3d(getRandomNumber(4.0f, 0.25f), getRandomNumber(1.0f, 0.5f), getRandomNumber(n, 0.5f)), new Vector3d(1, 1, 1), "house.jpg", null, null); } g.addChild(bg); return bg; }
From source file:KeyNavigateTest.java
public Group createMap(Group g) { System.out.println("Creating map items"); Group mapGroup = new Group(); g.addChild(mapGroup); Texture tex = new TextureLoader(m_szMapName, this).getTexture(); m_MapImage = ((ImageComponent2D) tex.getImage(0)).getImage(); float imageWidth = m_MapImage.getWidth(); float imageHeight = m_MapImage.getHeight(); FLOOR_WIDTH = imageWidth * 8;// ww w. j a v a2 s. c o m FLOOR_LENGTH = imageHeight * 8; for (int nPixelX = 1; nPixelX < imageWidth - 1; nPixelX++) { for (int nPixelY = 1; nPixelY < imageWidth - 1; nPixelY++) createMapItem(mapGroup, nPixelX, nPixelY); float percentDone = 100 * (float) nPixelX / (float) (imageWidth - 2); System.out.println(" " + (int) (percentDone) + "%"); } createExternalWall(mapGroup); return mapGroup; }
From source file:KeyNavigateTest.java
public Group createFloor(Group g) { System.out.println("Creating floor"); Group floorGroup = new Group(); Land floorTile = null;/*from ww w. j a v a 2s.co m*/ // use a shared Appearance so we only store 1 copy of the texture Appearance app = new Appearance(); g.addChild(floorGroup); final double kNumTiles = 6; for (double x = -FLOOR_WIDTH + FLOOR_WIDTH / (2 * kNumTiles); x < FLOOR_WIDTH; x = x + FLOOR_WIDTH / kNumTiles) { for (double z = -FLOOR_LENGTH + FLOOR_LENGTH / (2 * kNumTiles); z < FLOOR_LENGTH; z = z + FLOOR_LENGTH / kNumTiles) { floorTile = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); floorTile.createObject(app, new Vector3d(x, m_kFloorLevel, z), new Vector3d(FLOOR_WIDTH / (2 * kNumTiles), 1, FLOOR_LENGTH / (2 * kNumTiles)), "floor.gif", null, null); } } return floorGroup; }
From source file:KeyNavigateTest.java
public Group createCeiling(Group g) { System.out.println("Creating ceiling"); Group ceilingGroup = new Group(); Land ceilingTile = null;// www . ja v a2 s . co m // because we are technically viewing the ceiling from below // we want to switch the normals using a PolygonAttributes. Appearance app = new Appearance(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false)); g.addChild(ceilingGroup); final double kNumTiles = 6; for (double x = -FLOOR_WIDTH + FLOOR_WIDTH / (2 * kNumTiles); x < FLOOR_WIDTH; x = x + FLOOR_WIDTH / kNumTiles) { for (double z = -FLOOR_LENGTH + FLOOR_LENGTH / (2 * kNumTiles); z < FLOOR_LENGTH; z = z + FLOOR_LENGTH / kNumTiles) { ceilingTile = new Land(this, g, ComplexObject.GEOMETRY | ComplexObject.TEXTURE); ceilingTile.createObject(app, new Vector3d(x, m_kCeilingLevel, z), new Vector3d(FLOOR_WIDTH / (2 * kNumTiles), 1, FLOOR_LENGTH / (2 * kNumTiles)), "ceiling.gif", null, null); } } return ceilingGroup; }
From source file:KeyNavigateTest.java
protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile, String szSoundFile) {/*from www . j a va 2 s .c o m*/ Group g = new Group(); app.setPolygonAttributes( new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0, false)); app.setTransparencyAttributes(new TransparencyAttributes(TransparencyAttributes.BLENDED, 1.0f)); m_TextureAttributes = new TextureAttributes(TextureAttributes.REPLACE, new Transform3D(), new Color4f(0, 0, 0, 1), TextureAttributes.FASTEST); app.setTextureAttributes(m_TextureAttributes); if ((m_nFlags & ComplexObject.TEXTURE) == ComplexObject.TEXTURE) setTexture(app, szTextureFile); Cone cone = new Cone(1, 1, Primitive.GENERATE_TEXTURE_COORDS, app); g.addChild(cone); attachBehavior(new TextureAnimationBehavior(m_TextureAttributes)); return g; }
From source file:ExDepthCue.java
public Group buildIsoline() { Group group = new Group(); // alpha theta radius r g b group.addChild(buildSurface(3.0, 5.0, 2.194, 1.0f, 0.0f, 0.0f)); group.addChild(buildSurface(2.0, 4.0, 1.181, 1.0f, 0.5f, 0.0f)); group.addChild(buildSurface(1.0, 3.0, 0.506, 1.0f, 1.0f, 0.0f)); return group; }
From source file:ExAmbientLight.java
public Group buildScene() { // Get the current color Color3f color = (Color3f) colors[currentColor].value; // Turn off the example headlight setHeadlightEnable(false);/*from w ww.ja v a 2 s .c o m*/ // Build the scene group Group scene = new Group(); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Set the light color and its influencing bounds light = new AmbientLight(); light.setEnable(lightOnOff); light.setColor(color); light.setCapability(AmbientLight.ALLOW_STATE_WRITE); light.setCapability(AmbientLight.ALLOW_COLOR_WRITE); light.setInfluencingBounds(worldBounds); scene.addChild(light); // END EXAMPLE TOPIC // Build foreground geometry scene.addChild(new SphereGroup()); return scene; }
From source file:ExLightScope.java
public Group buildScene() { // Turn off the example headlight setHeadlightEnable(false);//from www . ja v a 2 s .c o m // Build the scene group Group scene = new Group(); // Build foreground geometry into two groups. We'll // create three directional lights below, one each with // scope to cover the first geometry group only, the // second geometry group only, or both geometry groups. content1 = new SphereGroup(0.25f, // radius of spheres 1.5f, // x spacing 0.75f, // y spacing 3, // number of spheres in X 5, // number of spheres in Y null); // appearance scene.addChild(content1); content2 = new SphereGroup(0.25f, // radius of spheres 1.5f, // x spacing 0.75f, // y spacing 2, // number of spheres in X 5, // number of spheres in Y null); // appearance scene.addChild(content2); // BEGIN EXAMPLE TOPIC // Create influencing bounds BoundingSphere worldBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), // Center 1000.0); // Extent // Add three directional lights whose scopes are set // to cover one, the other, or both of the shape groups // above. Also set the lights' color and aim direction. // Light #1 with content1 scope light1 = new DirectionalLight(); light1.setEnable(light1OnOff); light1.setColor(Red); light1.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light1.setInfluencingBounds(worldBounds); light1.addScope(content1); light1.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(light1); // Light #2 with content2 scope light2 = new DirectionalLight(); light2.setEnable(light2OnOff); light2.setColor(Blue); light2.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light2.setInfluencingBounds(worldBounds); light2.addScope(content2); light2.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(light2); // Light #3 with universal scope (the default) light3 = new DirectionalLight(); light3.setEnable(light3OnOff); light3.setColor(White); light3.setDirection(new Vector3f(1.0f, 0.0f, -1.0f)); light3.setInfluencingBounds(worldBounds); light3.setCapability(Light.ALLOW_STATE_WRITE); scene.addChild(light3); // Add an ambient light to dimly illuminate the rest of // the shapes in the scene to help illustrate that the // directional lights are being scoped... otherwise it looks // like we're just removing shapes from the scene AmbientLight ambient = new AmbientLight(); ambient.setEnable(true); ambient.setColor(White); ambient.setInfluencingBounds(worldBounds); scene.addChild(ambient); // END EXAMPLE TOPIC return scene; }