List of usage examples for javax.media.j3d Transform3D rotX
public void rotX(double angle)
From source file:TickTockPicking.java
public BranchGroup createSceneGraph(Canvas3D c) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4);/*from www .j a va2 s .c o m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and behaviors BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // 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); objScale.addChild(aLgt); objScale.addChild(lgt1); // Create a pair of transform group nodes and initialize them to // identity. Enable the TRANSFORM_WRITE capability so that // our behaviors can modify them at runtime. Add them to the // root of the subgraph. TransformGroup objTrans1 = new TransformGroup(); objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(objTrans1); TransformGroup objTrans2 = new TransformGroup(); objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans1.addChild(objTrans2); // Create the positioning and scaling transform group node. Transform3D t = new Transform3D(); t.set(0.3, new Vector3d(0.0, -1.5, 0.0)); TransformGroup objTrans3 = new TransformGroup(t); objTrans2.addChild(objTrans3); // Create a simple shape leaf node, set it's appearance, and // add it to the scene graph. Shape3D shape = new Cube(); Appearance a = new Appearance(); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.8f, 0.0f, 0.0f); a.setMaterial(new Material(objColor, black, objColor, white, 80.0f)); shape.setAppearance(a); shape.setCapability(shape.ALLOW_APPEARANCE_READ); shape.setCapability(shape.ALLOW_APPEARANCE_WRITE); objTrans3.addChild(shape); // Create a new Behavior object that will perform the desired // rotation on the specified transform object and add it into // the scene graph. Transform3D yAxis1 = new Transform3D(); yAxis1.rotX(Math.PI / 2.0); Alpha tickTockAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 2500, 200, 5000, 2500, 200); RotationInterpolator tickTock = new RotationInterpolator(tickTockAlpha, objTrans1, yAxis1, -(float) Math.PI / 2.0f, (float) Math.PI / 2.0f); tickTock.setSchedulingBounds(bounds); objTrans2.addChild(tickTock); // Create a new Behavior object that will perform the desired // rotation on the specified transform object and add it into // the scene graph. Transform3D yAxis2 = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans2, yAxis2, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans2.addChild(rotator); // Now create the simple picking behavior PickHighlightBehavior pickBeh = new PickHighlightBehavior(c, objRoot, bounds); // Create a bunch of objects with a behavior and add them // into the scene graph. int row, col; Appearance[][] app = new Appearance[3][3]; for (row = 0; row < 3; row++) for (col = 0; col < 3; col++) app[row][col] = createAppearance(row * 3 + col); for (int i = 0; i < 3; i++) { double ypos = (double) (i - 1) * 1.5; for (int j = 0; j < 3; j++) { double xpos = (double) (j - 1) * 1.5; objScale.addChild(createObject(app[i][j], 0.3, xpos, ypos)); } } // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
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); t3d.setScale(getScale());/*from ww w. j a va 2 s . com*/ t3d.setTranslation(new Vector3d(0.0, 0, -20.0)); t3d.invert(); 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);//from w w w . j a va 2s. c om 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:HiResCoordTest.java
protected BranchGroup createSceneBranchGroupHouse() { BranchGroup objRoot = super.createSceneBranchGroup(); Transform3D t3dTilt = new Transform3D(); t3dTilt.rotX(0.3); TransformGroup subTg = new TransformGroup(t3dTilt); subTg.addChild(new ColorCube(50.0)); subTg.addChild(createLabel("House", 60, 60, 0)); objRoot.addChild(subTg);//from www .j ava2s.c o m return objRoot; }
From source file:HiResCoordTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); Transform3D t3dTilt = new Transform3D(); t3dTilt.rotX(0.3); TransformGroup objTrans = new TransformGroup(t3dTilt); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); TransformGroup objTransPlanets = new TransformGroup(); objTransPlanets.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); 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, objTransPlanets, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), m_TranslateSunZ); rotator.setSchedulingBounds(bounds); objTransPlanets.addChild(rotator);/*from w w w . j av a 2 s .com*/ // create the sun TransformGroup sunTg = createSun(); // create Earth Transform3D t3dEarth = new Transform3D(); t3dEarth.setScale(m_EarthRadius); t3dEarth.setTranslation(new Vector3d(m_EarthOrbit, 0, 0)); objTransPlanets.addChild(createPlanet("Earth", new Color3f(0, 0.1f, 1.0f), t3dEarth, null)); // create Mars Transform3D t3dMars = new Transform3D(); t3dMars.setTranslation( new Vector3d(Math.sin(Math.PI * 1.5) * m_MarsOrbit, 0, Math.cos(Math.PI * 0.5) * m_MarsOrbit)); t3dMars.setScale(m_MarsRadius); objTransPlanets.addChild(createPlanet("Mars", new Color3f(1, 0, 0), t3dMars, null)); // create Mercury Transform3D t3dMercury = new Transform3D(); t3dMercury.setTranslation( new Vector3d(Math.sin(Math.PI) * m_MercuryOrbit, 0, Math.cos(Math.PI) * m_MercuryOrbit)); t3dMercury.setScale(m_MercuryRadius); objTransPlanets.addChild(createPlanet("Mercury", new Color3f(0.5f, 0.5f, 0.5f), t3dMercury, null)); sunTg.addChild(objTransPlanets); objTrans.addChild(sunTg); objRoot.addChild(objTrans); return objRoot; }
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);/*from w w w. ja v a2s . c o 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:KeyNavigateTest.java
protected void doRotateX(double radians) { transformGroup.getTransform(transform3D); Transform3D toMove = new Transform3D(); toMove.rotX(radians); transform3D.mul(toMove);//from w ww . j a v a 2 s . c o m updateTransform(); }
From source file:AppearanceTest.java
public void onX_30_degrees() { Transform3D t3d = new Transform3D(); t3d.rotX(Math.toRadians(30)); getTextureAttributes().setTextureTransform(t3d); }
From source file:Morphing.java
private BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(0.4);// ww w . j a v a 2 s . c o m objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // 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); objScale.addChild(aLgt); objScale.addChild(lgt1); // // Create the transform group nodes for the 3 original objects // and the morphed object. Add them to the root of the // branch graph. // TransformGroup objTrans[] = new TransformGroup[4]; for (int i = 0; i < 4; i++) { objTrans[i] = new TransformGroup(); objScale.addChild(objTrans[i]); } Transform3D tr = new Transform3D(); Transform3D rotX90 = new Transform3D(); rotX90.rotX(90.0 * Math.PI / 180.0); objTrans[0].getTransform(tr); tr.setTranslation(new Vector3d(-2.0, 1.5, -2.0)); tr.mul(rotX90); objTrans[0].setTransform(tr); objTrans[1].getTransform(tr); tr.setTranslation(new Vector3d(0.0, 1.5, -2.0)); tr.mul(rotX90); objTrans[1].setTransform(tr); objTrans[2].getTransform(tr); tr.setTranslation(new Vector3d(2.0, 1.5, -2.0)); tr.mul(rotX90); objTrans[2].setTransform(tr); objTrans[3].getTransform(tr); tr.setTranslation(new Vector3d(0.0, -2.0, -2.0)); tr.mul(rotX90); objTrans[3].setTransform(tr); // Now load the object files Scene s[] = new Scene[3]; GeometryArray g[] = new GeometryArray[3]; Shape3D shape[] = new Shape3D[3]; ObjectFile loader = new ObjectFile(ObjectFile.RESIZE); for (int i = 0; i < 3; i++) { s[i] = null; g[i] = null; shape[i] = null; } for (int i = 0; i < 3; i++) { try { s[i] = loader.load(objFiles[i]); } catch (FileNotFoundException e) { System.err.println(e); System.exit(1); } catch (ParsingErrorException e) { System.err.println(e); System.exit(1); } catch (IncorrectFormatException e) { System.err.println(e); System.exit(1); } BranchGroup b = s[i].getSceneGroup(); shape[i] = (Shape3D) b.getChild(0); g[i] = (GeometryArray) shape[i].getGeometry(); shape[i].setGeometry(g[i]); objTrans[i].addChild(b); } // // Create a Morph node, and set the appearance and input geometry // arrays. Set the Morph node's capability bits to allow the weights // to be modified at runtime. // 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)); Morph morph = new Morph(g, app); morph.setCapability(Morph.ALLOW_WEIGHTS_READ); morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE); objTrans[3].addChild(morph); // Now create the Alpha object that controls the speed of the // morphing operation. Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 2000, 1000, 200, 2000, 1000, 200); // Finally, create the morphing behavior MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph); mBeh.setSchedulingBounds(bounds); objScale.addChild(mBeh); return objRoot; }
From source file:Gouraud.java
/** * Erstellt den Szenegraphen/* www. j av a 2 s .co m*/ * * @return BranchGroup */ public BranchGroup macheSzene() { BranchGroup objWurzel = new BranchGroup(); // Transformation, 2 Rotationen: Transform3D drehung = new Transform3D(); Transform3D drehung2 = new Transform3D(); drehung.rotX(Math.PI / 4.0d); drehung2.rotY(Math.PI / 5.0d); drehung.mul(drehung2); TransformGroup objDreh = new TransformGroup(drehung); //Loader ObjectFile file = new ObjectFile(ObjectFile.RESIZE); Scene scene = null; try { // Laden der Obj Datei mittels jar scene = file.load(ClassLoader.getSystemResource("teapot.obj")); } catch (Exception e) { System.err.println(e); System.exit(1); } objDreh.addChild(scene.getSceneGroup()); DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 1.0f, 1.0f), new Vector3f(-1.0f, -1.0f, -1.0f)); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d)); objDreh.addChild(d_Licht); objWurzel.addChild(objDreh); return objWurzel; }