List of usage examples for javax.media.j3d Transform3D Transform3D
public Transform3D()
From source file:SimpleCylinder.java
/** * This builds the content branch of our scene graph. It uses the Cylinder * utility class to create the actual shape, adding to to the transform * group so that the shape is slightly tilted to reveal its 3D shape. * //from www .j ava2s.c o m * @param shape * Node that represents the geometry for the content * @return BranchGroup that is the root of the content branch */ protected BranchGroup buildContentBranch() { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); //Create the shape and add it to the branch rotationGroup.addChild(new Cylinder(1.0f, 1.0f, new Appearance())); return contentBranch; }
From source file:SimpleCone.java
/** * This builds the content branch of our scene graph. It uses the buildShape * function to create the actual shape, adding to to the transform group so * that the shape is slightly tilted to reveal its 3D shape. * /*w w w. j a v a2 s.c om*/ * @param shape * Node that represents the geometry for the content * @return BranchGroup that is the root of the content branch */ protected BranchGroup buildContentBranch() { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); rotationGroup.addChild(new Cone(1.0f, 2.0f, 0, new Appearance())); return contentBranch; }
From source file:BouncingBall.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);/* ww w. j a v a 2s . c om*/ // Create a simple shape leaf node, add it to the scene graph. Sphere sphere = new Sphere(0.25f); objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D pos1 = new Transform3D(); pos1.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f)); objTrans.setTransform(pos1); objTrans.addChild(sphere); objRoot.addChild(objTrans); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f light1Color = new Color3f(1.0f, 0.0f, 0.2f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objRoot.addChild(light1); // Set up the ambient light Color3f ambientColor = new Color3f(1.0f, 1.0f, 1.0f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objRoot.addChild(ambientLightNode); return objRoot; }
From source file:PickCallbackApp.java
public BranchGroup createSceneGraph(Canvas3D canvas) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objRotate = null;/*w w w.j ava 2 s .c om*/ PickRotateBehavior pickRotate = null; Transform3D transform = new Transform3D(); BoundingSphere behaveBounds = new BoundingSphere(); // create ColorCube and PickRotateBehavior objects transform.setTranslation(new Vector3f(-0.6f, 0.0f, -0.6f)); objRotate = new TransformGroup(transform); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objRoot.addChild(objRotate); objRotate.addChild(new ColorCube(0.4)); pickRotate = new PickRotateBehavior(objRoot, canvas, behaveBounds); objRoot.addChild(pickRotate); PickingCallback myCallback = new MyCallbackClass(); // Register the class callback to be called pickRotate.setupCallback(myCallback); // add a second ColorCube object to the scene graph transform.setTranslation(new Vector3f(0.6f, 0.0f, -0.6f)); objRotate = new TransformGroup(transform); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objRotate.setCapability(TransformGroup.ENABLE_PICK_REPORTING); objRoot.addChild(objRotate); objRotate.addChild(new ColorCube(0.4)); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:Text3DApp.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); Transform3D t3D = new Transform3D(); t3D.setTranslation(new Vector3f(0.0f, 0.0f, -3.0f)); TransformGroup objMove = new TransformGroup(t3D); objRoot.addChild(objMove);// w w w. j a v a2s . c o m // Create the transform group node and initialize it to the // identity. Add it to the root of the subgraph. TransformGroup objSpin = new TransformGroup(); objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objMove.addChild(objSpin); Appearance textAppear = new Appearance(); ColoringAttributes textColor = new ColoringAttributes(); textColor.setColor(1.0f, 0.0f, 0.0f); textAppear.setColoringAttributes(textColor); textAppear.setMaterial(new Material()); // Create a simple shape leaf node, add it to the scene graph. Font3D font3D = new Font3D(new Font("Helvetica", Font.PLAIN, 1), new FontExtrusion()); Text3D textGeom = new Text3D(font3D, new String("3DText")); textGeom.setAlignment(Text3D.ALIGN_CENTER); Shape3D textShape = new Shape3D(); textShape.setGeometry(textGeom); textShape.setAppearance(textAppear); objSpin.addChild(textShape); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Alpha rotationAlpha = new Alpha(-1, 10000); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin); // a bounding sphere specifies a region a behavior is active // create a sphere centered at the origin with radius of 100 BoundingSphere bounds = new BoundingSphere(); rotator.setSchedulingBounds(bounds); objSpin.addChild(rotator); DirectionalLight lightD = new DirectionalLight(); lightD.setInfluencingBounds(bounds); lightD.setDirection(new Vector3f(0.0f, 0.0f, -1.0f)); lightD.setColor(new Color3f(1.0f, 0.0f, 1.0f)); objMove.addChild(lightD); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(bounds); objMove.addChild(lightA); return objRoot; }
From source file:SimpleWire.java
/** * This builds the content branch of our scene graph. It uses the buildCube * function to create the actual shape, adding to to the transform group so * that the shape is slightly tilted to reveal its 3D shape. * /*from ww w . ja va2s. c o m*/ * @param shape * Node that represents the geometry for the content * @return BranchGroup that is the root of the content branch */ protected BranchGroup buildContentBranch(Node shape) { BranchGroup contentBranch = new BranchGroup(); Transform3D rotateCube = new Transform3D(); rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0)); TransformGroup rotationGroup = new TransformGroup(rotateCube); contentBranch.addChild(rotationGroup); rotationGroup.addChild(shape); return contentBranch; }
From source file:SimpleSounds.java
/** * Build the view branch of the scene graph. In this case a key navigation * utility object is created and associated with the view transform so that * the view can be changed via the keyboard. * // ww w . j a va 2 s . c om * @return BranchGroup that is the root of the view branch */ protected BranchGroup buildViewBranch(Canvas3D c) { BranchGroup viewBranch = new BranchGroup(); Transform3D viewXfm = new Transform3D(); viewXfm.set(new Vector3f(0.0f, 0.0f, 30.0f)); TransformGroup viewXfmGroup = new TransformGroup(viewXfm); viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); ViewPlatform myViewPlatform = new ViewPlatform(); BoundingSphere movingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); BoundingLeaf boundLeaf = new BoundingLeaf(movingBounds); PhysicalBody myBody = new PhysicalBody(); PhysicalEnvironment myEnvironment = new PhysicalEnvironment(); viewXfmGroup.addChild(myViewPlatform); viewBranch.addChild(viewXfmGroup); View myView = new View(); myView.addCanvas3D(c); myView.attachViewPlatform(myViewPlatform); myView.setPhysicalBody(myBody); myView.setPhysicalEnvironment(myEnvironment); KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(viewXfmGroup); keyNav.setSchedulingBounds(movingBounds); viewBranch.addChild(keyNav); //Create a sounds mixer to use our sounds with //and initialise it JavaSoundMixer myMixer = new JavaSoundMixer(myEnvironment); myMixer.initialize(); return viewBranch; }
From source file:Position.java
public Position() { SimpleUniverse universe = new SimpleUniverse(); BranchGroup group = new BranchGroup(); // X axis made of spheres for (float x = -1.0f; x <= 1.0f; x = x + 0.1f) { Sphere sphere = new Sphere(0.05f); TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Vector3f vector = new Vector3f(x, .0f, .0f); transform.setTranslation(vector); tg.setTransform(transform);// w w w . jav a 2 s . c om tg.addChild(sphere); group.addChild(tg); } // Y axis made of cones for (float y = -1.0f; y <= 1.0f; y = y + 0.1f) { TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Cone cone = new Cone(0.05f, 0.1f); Vector3f vector = new Vector3f(.0f, y, .0f); transform.setTranslation(vector); tg.setTransform(transform); tg.addChild(cone); group.addChild(tg); } // Z axis made of cylinders for (float z = -1.0f; z <= 1.0f; z = z + 0.1f) { TransformGroup tg = new TransformGroup(); Transform3D transform = new Transform3D(); Cylinder cylinder = new Cylinder(0.05f, 0.1f); Vector3f vector = new Vector3f(.0f, .0f, z); transform.setTranslation(vector); tg.setTransform(transform); tg.addChild(cylinder); group.addChild(tg); } Color3f light1Color = new Color3f(.1f, 1.4f, .1f); // green light BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); group.addChild(light1); universe.getViewingPlatform().setNominalViewingTransform(); // add the group of objects to the Universe universe.addBranchGraph(group); }
From source file:StereoGirl.java
public BranchGroup createSceneGraph(int i) { System.out.println("Creating scene for: " + URLString); // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); try {//from ww w. j a v a 2s . c o m Transform3D myTransform3D = new Transform3D(); myTransform3D.setTranslation(new Vector3f(+0.0f, -0.1f, -1.2f)); TransformGroup objTrans = new TransformGroup(myTransform3D); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D t = new Transform3D(); TransformGroup tg = new TransformGroup(t); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.addChild(tg); URL url = new URL(URLString); ObjectFile f = new ObjectFile(); f.setFlags(ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY); System.out.println("About to load"); Scene s = f.load(url); tg.addChild(s.getSceneGroup()); System.out.println("Finished Loading"); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f light1Color = new Color3f(.9f, 0.8f, 0.8f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objTrans.addChild(light1); // Set up the ambient light Color3f ambientColor = new Color3f(1.0f, .4f, 0.3f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objTrans.addChild(ambientLightNode); MouseRotate behavior = new MouseRotate(); behavior.setTransformGroup(tg); objTrans.addChild(behavior); // Create the translate behavior node MouseTranslate behavior3 = new MouseTranslate(); behavior3.setTransformGroup(tg); objTrans.addChild(behavior3); behavior3.setSchedulingBounds(bounds); KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(tg); keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); objTrans.addChild(keyNavBeh); behavior.setSchedulingBounds(bounds); objRoot.addChild(objTrans); } catch (Throwable t) { System.out.println("Error: " + t); } return objRoot; }
From source file:OffScreenTest.java
public BranchGroup createSceneGraph(Raster drawRaster) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // spin object has composited transformation matrix Transform3D spin = new Transform3D(); Transform3D tempspin = new Transform3D(); spin.rotX(Math.PI / 4.0d);/* w w w .ja v a 2 s . co m*/ tempspin.rotY(Math.PI / 5.0d); spin.mul(tempspin); spin.setScale(0.7); spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0)); TransformGroup objTrans = new TransformGroup(spin); objRoot.addChild(objTrans); // Create a simple shape leaf node, add it to the scene graph. // ColorCube is a Convenience Utility class objTrans.addChild(new ColorCube(0.4)); //Create a raster Shape3D shape = new Shape3D(drawRaster); objRoot.addChild(shape); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }