List of usage examples for javax.media.j3d Transform3D setTranslation
public final void setTranslation(Vector3d trans)
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);/* w w w .ja va 2 s. c o m*/ tg.setTransform(t3d); tg.addChild(label3D); m_nLabelNumber++; return tg; }
From source file:KeyNavigatorApp.java
public BranchGroup createSceneGraph(SimpleUniverse su) { // Create the root of the branch graph TransformGroup vpTrans = null;//from w w w. j a va 2 s.c o m BranchGroup objRoot = new BranchGroup(); Vector3f translate = new Vector3f(); Transform3D T3D = new Transform3D(); TransformGroup TG = null; 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:PlatformTest.java
ViewingPlatform createViewer(Canvas3D c, String szName, Color3f objColor, double x, double z) { // create a Viewer and attach to its canvas // a Canvas3D can only be attached to a single Viewer Viewer viewer2 = new Viewer(c); // create a ViewingPlatform with 1 TransformGroups above the // ViewPlatform ViewingPlatform vp2 = new ViewingPlatform(1); // create and assign the PlatformGeometry to the Viewer vp2.setPlatformGeometry(createPlatformGeometry(szName)); // create and assign the ViewerAvatar to the Viewer viewer2.setAvatar(createViewerAvatar(szName, objColor)); // set the initial position for the Viewer Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(x, 0, z)); vp2.getViewPlatformTransform().setTransform(t3d); // set capabilities on the TransformGroup so that the // KeyNavigatorBehavior // can modify the Viewer's position vp2.getViewPlatformTransform().setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); vp2.getViewPlatformTransform().setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // attach a navigation behavior to the position of the viewer KeyNavigatorBehavior key = new KeyNavigatorBehavior(vp2.getViewPlatformTransform()); key.setSchedulingBounds(m_Bounds); key.setEnable(false);/*from ww w. j av a2 s .com*/ // add the KeyNavigatorBehavior to the ViewingPlatform vp2.addChild(key); // set the ViewingPlatform for the Viewer viewer2.setViewingPlatform(vp2); // associate the name of the Viewer with its KeyNavigatorBehavior m_KeyHashtable.put(szName, key); // create a button to switch the Viewer ON. Button button = new Button(szName); button.addActionListener(this); add(button); return vp2; }
From source file:NodesTest.java
protected void moveCollisionObject() { Transform3D t3d = new Transform3D(); positionVector.add(incrementVector); t3d.setTranslation(positionVector); collisionObject.setTransform(t3d);//from ww w . j a v a 2 s. c o m }
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);// ww w. jav a 2s .c om tgLand.addChild(createDemLandscape()); objRotate.addChild(tgLand); 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:HiResCoordTest.java
public TransformGroup[] getViewTransformGroupArray() { TransformGroup[] tgArray = new TransformGroup[1]; tgArray[0] = new TransformGroup(); Vector3d vTrans = new Vector3d(0.0, 0.0, -m_TranslateSunZ); // 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();//from w w w . java2 s . co m tgArray[0].setTransform(t3d); return tgArray; }
From source file:PlatformTest.java
public PlatformTest() { m_KeyHashtable = new Hashtable(); m_Bounds = new BoundingSphere(new Point3d(0, 0, 0), 100); // get the graphics configuration for the graphics device GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); // create the first canvas, this is the top-down view Canvas3D c = new Canvas3D(config); c.setSize(m_kWidth, m_kHeight);// ww w . j a v a2 s .co m add(c); // create the second canvas, this is used for "Jim's" Viewer Canvas3D c2 = new Canvas3D(config); c2.setSize(m_kWidth, m_kHeight); add(c2); // create the third canvas, this is used for "Dan's" Viewer Canvas3D c3 = new Canvas3D(config); c3.setSize(m_kWidth, m_kHeight); add(c3); // Create the simple environment BranchGroup scene = createSceneGraph(); // create the first Viewer, this is a static top-down view // create a ViewingPlatform with 2 TransformGroups above the // ViewPlatform ViewingPlatform vp = new ViewingPlatform(2); // create the Viewer and attach to the first canvas Viewer viewer = new Viewer(c); // rotate and position the first Viewer above the environment Transform3D t3d = new Transform3D(); t3d.rotX(Math.PI / 2.0); t3d.setTranslation(new Vector3d(0, 0, -40)); t3d.invert(); MultiTransformGroup mtg = vp.getMultiTransformGroup(); mtg.getTransformGroup(0).setTransform(t3d); // create a SimpleUniverse from the ViewingPlatform and Viewer SimpleUniverse u = new SimpleUniverse(vp, viewer); // add the geometry to the scenegraph u.addBranchGraph(scene); // add two more Viewers to the scenegraph u.getLocale().addBranchGraph(createViewer(c2, "Jim", new Color3f(0.1f, 1.0f, 1.0f), -5, 8)); u.getLocale().addBranchGraph(createViewer(c3, "Dan", new Color3f(1.0f, 0.1f, 0.1f), 2, -8)); }
From source file:TexCoordTest.java
public TransformGroup[] getViewTransformGroupArray() { TransformGroup[] tgArray = new TransformGroup[1]; tgArray[0] = new TransformGroup(); // move the camera BACK a little... // note that we have to invert the matrix as // we are moving the viewer Transform3D t3d = new Transform3D(); t3d.rotX(0.4);//from w ww . jav a 2 s . co m t3d.setScale(getScale()); t3d.setTranslation(new Vector3d(0.0, 0, -20.0)); t3d.invert(); tgArray[0].setTransform(t3d); return tgArray; }
From source file:HiResCoordTest.java
public TransformGroup[] getViewTransformGroupArray(int nIndex) { TransformGroup[] tgArray = new TransformGroup[1]; tgArray[0] = new TransformGroup(); Vector3d vTrans = null;/*from ww w . j a va 2 s. c o m*/ 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: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);/*ww w. j a v a 2s. com*/ 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; } }