List of usage examples for javax.media.j3d TransformGroup setTransform
public void setTransform(Transform3D t1)
From source file:TexCoordTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objPosition = new TransformGroup(); objPosition.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); TransformGroup objRotate = new TransformGroup(); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D axisTranslate = new Transform3D(); axisTranslate.rotZ(Math.toRadians(90)); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 6000, 0, 0, 0, 0, 0); m_PositionInterpolator = new PositionInterpolator(rotationAlpha, objPosition, axisTranslate, 0, 70); m_PositionInterpolator.setSchedulingBounds(createApplicationBounds()); objPosition.addChild(m_PositionInterpolator); m_PositionInterpolator.setEnable(false); m_RotationInterpolator = new RotationInterpolator(rotationAlpha, objRotate, new Transform3D(), 0.0f, (float) Math.PI * 2.0f); m_RotationInterpolator.setSchedulingBounds(getApplicationBounds()); objRotate.addChild(m_RotationInterpolator); m_RotationInterpolator.setEnable(true); TransformGroup tgLand = new TransformGroup(); Transform3D t3dLand = new Transform3D(); t3dLand.setTranslation(new Vector3d(0, -30, 0)); tgLand.setTransform(t3dLand); tgLand.addChild(createDemLandscape()); objRotate.addChild(tgLand);/*from ww w . j a v a2 s . c o m*/ objPosition.addChild(objRotate); objRoot.addChild(objPosition); // create some lights for the scene Color3f lColor1 = new Color3f(0.3f, 0.3f, 0.3f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(getApplicationBounds()); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(getApplicationBounds()); // add the lights to the parent BranchGroup objRoot.addChild(aLgt); objRoot.addChild(lgt1); return objRoot; }
From source file:NodesTest.java
TransformGroup createLabel(String szText, double scale) { Color3f colorText = new Color3f(); int nFontSizeText = 10; Text2D label3D = new Text2D(szText, colorText, "SansSerif", nFontSizeText, Font.PLAIN); TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(-8, 0.5 * (1 - m_nLabelNumber), 0)); t3d.setScale(scale);//from w w w . ja v a2 s. c om tg.setTransform(t3d); tg.addChild(label3D); m_nLabelNumber++; return tg; }
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 ww w. j a v a 2s .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:LightScopeApp.java
BranchGroup createScene() { BranchGroup scene = new BranchGroup(); TransformGroup tableTG = new TransformGroup(); TransformGroup lampTG = new TransformGroup(); TransformGroup litBoxTG = new TransformGroup(); TransformGroup unLitBoxTG = new TransformGroup(); scene.addChild(tableTG);/* www .j ava 2s . c om*/ tableTG.addChild(lampTG); tableTG.addChild(litBoxTG); tableTG.addChild(unLitBoxTG); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f blue = new Color3f(0.0f, 1.0f, 0.0f); Color3f green = new Color3f(0.0f, 0.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Vector3f transVector = new Vector3f(); Transform3D transTransform = new Transform3D(); transVector.set(0.0f, -0.4f, 0.5f); transTransform.setTranslation(transVector); tableTG.setTransform(transTransform); transVector.set(-0.4f, 0.001f, 0.1f); transTransform.setTranslation(transVector); lampTG.setTransform(transTransform); transVector.set(-0.2f, 0.1f, 0.2f); transTransform.setTranslation(transVector); litBoxTG.setTransform(transTransform); transVector.set(0.3f, 0.1f, -0.4f); transTransform.setTranslation(transVector); unLitBoxTG.setTransform(transTransform); Shape3D tablePlane = createXZPlane(new Point3f(-1.0f, 0.0f, -1.0f), new Point3f(-1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, 1.0f), new Point3f(1.0f, 0.0f, -1.0f)); tablePlane.setAppearance(createMaterialAppearance(white)); tableTG.addChild(tablePlane); litBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, createMaterialAppearance(red))); Shape3D shadowPlane = createXZPlane(new Point3f(0.1f, -0.095f, -0.1f), new Point3f(0.1f, -0.095f, 0.1f), new Point3f(0.2f, -0.095f, 0.15f), new Point3f(0.2f, -0.095f, -0.15f)); shadowPlane.setAppearance(createMaterialAppearance(black)); litBoxTG.addChild(shadowPlane); Appearance redGlowMat = createMaterialAppearance(red); // redGlowMat.getMaterial().setEmissiveColor(0.5f, 0.5f, 0.5f); unLitBoxTG.addChild(new Box(0.1f, 0.1f, 0.1f, Box.GENERATE_NORMALS, redGlowMat)); Shape3D lamp = createLampShape(); Appearance lampAppearance = createMaterialAppearance(blue); PolygonAttributes polyAttrib = new PolygonAttributes(); polyAttrib.setCullFace(PolygonAttributes.CULL_NONE); polyAttrib.setBackFaceNormalFlip(true); lampAppearance.setPolygonAttributes(polyAttrib); lamp.setAppearance(lampAppearance); lampTG.addChild(lamp); PointLight lampLight = new PointLight(); lampLight.setPosition(0.1f, 0.5f, -0.1f); lampLight.setInfluencingBounds(new BoundingSphere()); lampTG.addChild(lampLight); Shape3D litPlane = createXZPlane(new Point3f(-0.4f, 0.0f, -0.4f), new Point3f(-0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, 0.4f), new Point3f(0.4f, 0.0f, -0.4f)); litPlane.setAppearance(createMaterialAppearance(white)); lampTG.addChild(litPlane); lampLight.addScope(lampTG); lampLight.addScope(litBoxTG); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); lightD1.setColor(new Color3f(0.4f, 0.4f, 0.4f)); Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f); lightDir.normalize(); lightD1.setDirection(lightDir); scene.addChild(lightD1); DirectionalLight lightD2 = new DirectionalLight(); lightD2.setInfluencingBounds(new BoundingSphere()); lightD2.setColor(new Color3f(0.2f, 0.2f, 0.2f)); lightDir.set(1.0f, -1.0f, -1.0f); lightDir.normalize(); lightD2.setDirection(lightDir); scene.addChild(lightD2); Background bg = new Background(); bg.setColor(1.0f, 1.0f, 1.0f); bg.setApplicationBounds(new BoundingSphere()); scene.addChild(bg); return scene; }
From source file:KeyNavigatorApp.java
public BranchGroup createSceneGraph(SimpleUniverse su) { // Create the root of the branch graph TransformGroup vpTrans = null; BranchGroup objRoot = new BranchGroup(); Vector3f translate = new Vector3f(); Transform3D T3D = new Transform3D(); TransformGroup TG = null;/*from w ww . j a va 2s.co m*/ objRoot.addChild(createLand()); SharedGroup share = new SharedGroup(); share.addChild(createPyramid()); float[][] position = { { 0.0f, 0.0f, -3.0f }, { 6.0f, 0.0f, 0.0f }, { 6.0f, 0.0f, 6.0f }, { 3.0f, 0.0f, -10.0f }, { 13.0f, 0.0f, -30.0f }, { -13.0f, 0.0f, 30.0f }, { -13.0f, 0.0f, 23.0f }, { 13.0f, 0.0f, 3.0f } }; for (int i = 0; i < position.length; i++) { translate.set(position[i]); T3D.setTranslation(translate); TG = new TransformGroup(T3D); TG.addChild(new Link(share)); objRoot.addChild(TG); } vpTrans = su.getViewingPlatform().getViewPlatformTransform(); translate.set(0.0f, 0.3f, 0.0f); T3D.setTranslation(translate); vpTrans.setTransform(T3D); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans); keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); objRoot.addChild(keyNavBeh); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); 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); // 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;/* w w w.j ava 2 s. c om*/ }
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);/* www . j a va 2s .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:LoaderTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create a TransformGroup to flip the hand onto its end and enlarge it. TransformGroup objTrans1 = new TransformGroup(); Transform3D tr = new Transform3D(); objTrans1.getTransform(tr);/*w w w . j a v a 2 s .co m*/ tr.rotX(90.0 * Math.PI / 180.0); tr.setScale(10.0); objTrans1.setTransform(tr); // create a TransformGroup to rotate the hand TransformGroup objTrans2 = new TransformGroup(); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // create a RotationInterpolator behavior to rotate the hand Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans2, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans2.addChild(rotator); // Set up the global 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); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // load the object file Scene scene = null; Shape3D shape = null; // read in the geometry information from the data file ObjectFile objFileloader = new ObjectFile(ObjectFile.RESIZE); try { scene = objFileloader.load("hand1.obj"); } catch (Exception e) { scene = null; System.err.println(e); } if (scene == null) System.exit(1); // retrieve the Shape3D object from the scene BranchGroup branchGroup = scene.getSceneGroup(); shape = (Shape3D) branchGroup.getChild(0); // 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)); // assign the appearance to the Shape shape.setAppearance(app); // connect the scenegraph objTrans2.addChild(scene.getSceneGroup()); objTrans1.addChild(objTrans2); objRoot.addChild(objTrans1); return objRoot; }
From source file:ViewProj.java
public BranchGroup createProjViewSG() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objRoot.setCapability(BranchGroup.ALLOW_DETACH); // setup a transform group to hold the scaled scene TransformGroup objTrans = new TransformGroup(); Transform3D scale = new Transform3D(); scale.set(0.9);//from www . jav a2 s .c om objTrans.setTransform(scale); objRoot.addChild(objTrans); // create the clip limits line Point3f[] cpPoints = new Point3f[5]; cpPoints[0] = new Point3f(-1, -1, 0.1f); cpPoints[1] = new Point3f(1, -1, 0.1f); cpPoints[2] = new Point3f(1, 1, 0.1f); cpPoints[3] = new Point3f(-1, 1, 0.1f); cpPoints[4] = cpPoints[0]; int[] cpLength = new int[1]; cpLength[0] = 5; LineStripArray cpLines = new LineStripArray(5, LineArray.COORDINATES, cpLength); cpLines.setCoordinates(0, cpPoints); Appearance cpApp = new Appearance(); ColoringAttributes cpCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); cpApp.setColoringAttributes(cpCa); LineAttributes cpLa = new LineAttributes(); Shape3D cpShape = new Shape3D(cpLines, cpApp); objTrans.addChild(cpShape); // transform and render the clip grid points updateProjTrans(); if (numClipGridPts > 0) { // transform the clipGridPts for (int i = 0; i < numClipGridPts; i++) { projectPoint(clipGridPtsVW[i], clipGridPtsProj[i]); } LineArray clipLn = new LineArray(numClipGridPts, LineArray.COORDINATES); clipLn.setCoordinates(0, clipGridPtsProj, 0, numClipGridPts); Appearance clipGridApp = new Appearance(); ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT); clipGridApp.setColoringAttributes(clipCa); LineAttributes clipLa = new LineAttributes(); Shape3D clipShape = new Shape3D(clipLn, clipGridApp); objTrans.addChild(clipShape); } // set up the circle Appearance circleApp = new Appearance(); ColoringAttributes circleCa = new ColoringAttributes(); circleCa.setColor(red); circleApp.setColoringAttributes(circleCa); PolygonAttributes pa = new PolygonAttributes(); pa.setCullFace(PolygonAttributes.CULL_NONE); circleApp.setPolygonAttributes(pa); // transform the circlePts for (int i = 0; i < numCirclePts; i++) { projectPoint(circlePtsVW[i], circlePtsProj[i]); } int[] lineStripLength = new int[1]; lineStripLength[0] = numCirclePts; //LineStripArray circleLineStrip = new LineStripArray(numCirclePts, // LineArray.COORDINATES, lineStripLength); TriangleFanArray circleLineStrip = new TriangleFanArray(numCirclePts, LineArray.COORDINATES, lineStripLength); circleLineStrip.setCoordinates(0, circlePtsProj); Shape3D circleShape = new Shape3D(circleLineStrip, circleApp); objTrans.addChild(circleShape); return objRoot; }
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);//w ww.j a v a2 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(); }