List of usage examples for javax.media.j3d BoundingSphere BoundingSphere
public BoundingSphere(Point3d center, double radius)
From source file:Demo3D.java
/** * Create the subgraph #3/*ww w . j a v a 2 s . com*/ * * @return javax.media.j3d.BranchGroup brGr3 - the root of the subgraph #3 */ public BranchGroup mySubGraph3() { // Create the BranchGroup node brGr3, in other words the root of // the subgraph31 and subgraph32. brGr3 = new BranchGroup(); // To allow the detach/add process of the subgraph 32 from the // BranchGroup node brGr3. brGr3.setCapability(Group.ALLOW_CHILDREN_READ); brGr3.setCapability(Group.ALLOW_CHILDREN_WRITE); brGr3.setCapability(Group.ALLOW_CHILDREN_EXTEND); // A BoundingSphere instance as picking bound region. pickBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 5.0); // A BoundingSphere instance as general bounding region. boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Create and attach the subgraph31 with the tetrahedron // to the BranchGroup node brGr3. tetrahedron = new Tetrahedron(1.0f); sceneBuilder31 = new SceneBuilder31(tetrahedron.myTetrahedron()); brGr3.addChild(sceneBuilder31.mySubGraph31()); // Picking of the tetrahedron // Note:It's the instruction: // trGr31.setCapability(TransformGroup.ENABLE_PICK_REPORTING) // in the class SceneBuilder31 that determines if the // tetrahedron is pickable or not. // Pick and translate the tetrahedron parallel to the z-axis if the // mouse pointer is over it. pickZoomBehavior = new PickZoomBehavior(brGr3, canvas3D, pickBounds); // pickZoomBehavior.setEnable(ctrlDown); brGr3.addChild(pickZoomBehavior); // Pick and translate the tetrahedron in the (x-y)-plane if the // mouse pointer is over it. pickTransBehavior = new PickTranslateBehavior(brGr3, canvas3D, pickBounds); // pickTransBehavior.setEnable(ctrlDown); brGr3.addChild(pickTransBehavior); // Pick and rotate the tetrahedron if the mouse pointer is over it. pickRotBehavior = new PickRotateBehavior(brGr3, canvas3D, pickBounds); // pickRotBehavior.setEnable(ctrlDown); brGr3.addChild(pickRotBehavior); // Create the subgraph32 ===> the earth in double rotation. sceneBuilder32 = new SceneBuilder32(); brGr3.addChild(sceneBuilder32.mySubGraph32()); // Create an instance of the AddDetachEarthBehavior class to // allow the detach/add process of the subgraph32. addDetachEarthBehavior = new AddDetachEarthBehavior(this, sceneBuilder32); addDetachEarthBehavior.setSchedulingBounds(boundsGen); brGr3.addChild(addDetachEarthBehavior); // Compile the subgraph to optimize the performances. brGr3.compile(); // Return the final version of the BranchGroup node brGr3 return brGr3; }
From source file:FourByFour.java
/** * Create the scenegraph for the 3D view. *//* w w w . ja v a2s.c om*/ public BranchGroup createScene3D() { // Define colors Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f red = new Color3f(0.80f, 0.20f, 0.2f); Color3f ambient = new Color3f(0.25f, 0.25f, 0.25f); Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f); Color3f specular = new Color3f(0.9f, 0.9f, 0.9f); Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); // Create the branch group BranchGroup branchGroup = new BranchGroup(); // Create the bounding leaf node BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0); BoundingLeaf boundingLeaf = new BoundingLeaf(bounds); branchGroup.addChild(boundingLeaf); // Create the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); branchGroup.addChild(bg); // Create the ambient light AmbientLight ambLight = new AmbientLight(white); ambLight.setInfluencingBounds(bounds); branchGroup.addChild(ambLight); // Create the directional light Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight dirLight = new DirectionalLight(white, dir); dirLight.setInfluencingBounds(bounds); branchGroup.addChild(dirLight); // Create the pole appearance Material poleMaterial = new Material(ambient, black, diffuse, specular, 110.f); poleMaterial.setLightingEnable(true); Appearance poleAppearance = new Appearance(); poleAppearance.setMaterial(poleMaterial); // Create the transform group node TransformGroup transformGroup = new TransformGroup(); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); branchGroup.addChild(transformGroup); // Create the poles Poles poles = new Poles(poleAppearance); transformGroup.addChild(poles.getChild()); // Add the position markers to the transform group transformGroup.addChild(positions.getChild()); // Let the positions object know about the transform group positions.setTransformGroup(transformGroup); // Create the mouse pick and drag behavior node PickDragBehavior behavior = new PickDragBehavior(canvas2D, canvas3D, positions, branchGroup, transformGroup); behavior.setSchedulingBounds(bounds); transformGroup.addChild(behavior); return branchGroup; }
From source file:GearTest.java
BranchGroup createBranchEnvironment() { // Create the root of the branch graph BranchGroup branchRoot = new BranchGroup(); // 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.5f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); branchRoot.addChild(bgNode);// www . j a v a2 s.com // Set up the ambient light Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); branchRoot.addChild(ambientLightNode); // Set up the directional lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); branchRoot.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); branchRoot.addChild(light2); return branchRoot; }
From source file:Demo3D.java
/** * Create the subgraph #32/* w w w. j a v a 2 s . co m*/ * * @return javax.media.j3d.TransformGroup trGr32_3 - the root of the * subgraph #32 */ public BranchGroup mySubGraph32() { // A BoundingSphere instance as general bounding region. boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Create the first TransformGroup node trGr32_1 to: // 1) attach the Switch node with the five different earth's // representations to the subgraph32 // 2) attach a coordinate system to each earth's representation // 3) rotate each earth about its own y-axis. trGr32_1 = new TransformGroup(); // With the ALLOW_TRANSFORM_WRITE capability, we allow the // modification of the TransformGroup's code by the behavior's // code at run time. trGr32_1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // SwitchBehavior is the class which controls the fonctioning of // the switchEarths node. switchBehavior = new SwitchBehavior(this); switchBehavior.setSchedulingBounds(boundsGen); trGr32_1.addChild(switchBehavior); // The Switch which allows the rendering of the five different // earth's representations. switchEarths = new Switch(); // With the ALLOW_TRANSFORM_WRITE, ALLOW_SWITCH_WRITE and // ALLOW_CHILDREN_READ // capabilities we allow to get or set new capabilities. switchEarths.setCapability(Switch.ALLOW_SWITCH_READ); switchEarths.setCapability(Switch.ALLOW_SWITCH_WRITE); switchEarths.setCapability(Switch.ALLOW_CHILDREN_READ); // Attach the different earth's representations to the Switch node. // Increasing earth_Points = new Earth("points", 0.4f); switchEarths.addChild(earth_Points.myEarth()); // # 0 earth_Lines = new Earth("lines", 0.4f); switchEarths.addChild(earth_Lines.myEarth()); // # 1 earth_Polygons = new Earth("polygons", 0.4f); switchEarths.addChild(earth_Polygons.myEarth()); // # 2 earth_Gouraud = new Earth("gouraud", 0.4f); switchEarths.addChild(earth_Gouraud.myEarth()); // # 3 earth_Texture = new Earth("texture", 0.4f); switchEarths.addChild(earth_Texture.myEarth()); // # 4 // Decreasing switchEarths.addChild(earth_Texture.myEarth()); // # 4 switchEarths.addChild(earth_Gouraud.myEarth()); // # 3 switchEarths.addChild(earth_Polygons.myEarth()); // # 2 switchEarths.addChild(earth_Lines.myEarth()); // # 1 switchEarths.addChild(earth_Points.myEarth()); // # 0 // Attach the Switch node with the five different earth's // representations to the TransformGroup node trGr32_1. trGr32_1.addChild(switchEarths); // Create and attach a coordinate system to the TransformGroup node // trGr32_1, that is to each earth's representation. coordSyst = new CoordSyst(1.0f, 1.0f, 0.0f, // Color of the x-axis 0.0f, 0.0f, 1.0f, // Color of the y-axis 1.0f, 0.0f, 0.0f, // Color of the z-axis 0.6f); // Lenght of the 3 axes trGr32_1.addChild(coordSyst); // Create the alpha(t) function for the earth's rotation about // its own y-axis. rotationAlpha_1 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 10000, 0, 0, 0, 0, 0); // Create the earth's rotation about its own y-axis. rotator_1 = new RotationInterpolator(rotationAlpha_1, trGr32_1, new Transform3D(), 0.0f, (float) Math.PI * 2.0f); rotator_1.setSchedulingBounds(boundsGen); trGr32_1.addChild(rotator_1); // Create a Transform3D instance to execute the desired "static // translation" of the earth, that is the rotation radius around // the sun. transl = new Transform3D(); vectTransl = new Vector3d(2.5, 0.0, 0.0); transl.set(vectTransl); // Create the second TransformGroup node trGr32_2 and attach the // "static translation" transl to it. trGr32_2 = new TransformGroup(transl); // Attach the trGr32_1 node to the trGr32_2 node. trGr32_2.addChild(trGr32_1); // Create the third TransformGroup node trGr32_3 for the earth's // rotation around the sun. trGr32_3 = new TransformGroup(); // With the ALLOW_TRANSFORM_WRITE capability, we allow the // modification of the TransformGroup's code by the behavior's // code at run time. trGr32_3.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // Attach the trGr32_2 node to the trGr32_3 node. trGr32_3.addChild(trGr32_2); // Create the alpha(t) function for the earth's rotation around the sun. rotationAlpha_2 = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 20000, 0, 0, 0, 0, 0); // To restart correctly the rotation of the earth around the // sun after a detach/add process of the subgraph32 from the // BranchGroup node brGr3. rotationAlpha_2.setStartTime(System.currentTimeMillis()); // Create the earth's rotation around the sun. rotator_2 = new RotationInterpolator(rotationAlpha_2, trGr32_3, new Transform3D(), 0.0f, (float) Math.PI * 2.0f); rotator_2.setSchedulingBounds(boundsGen); trGr32_3.addChild(rotator_2); // To allow the detaching of this subgraph32 from the // BranchGroup node brGr3. brGr32 = new BranchGroup(); brGr32.setCapability(BranchGroup.ALLOW_DETACH); brGr32.addChild(trGr32_3); // Return the final version of the BranchGroup node brGr32. return brGr32; }
From source file:GearTest.java
public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); Canvas3D c = new Canvas3D(config); add("Center", c); // Create the gearbox and attach it to the virtual universe BranchGroup scene = createGearBox(toothCount); u = new SimpleUniverse(c); // add mouse behaviors to the ViewingPlatform ViewingPlatform viewingPlatform = u.getViewingPlatform(); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. viewingPlatform.setNominalViewingTransform(); // add orbit behavior to the ViewingPlatform OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ALL); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds);//from w w w. j av a 2 s . co m viewingPlatform.setViewPlatformBehavior(orbit); u.addBranchGraph(scene); }
From source file:AppearanceExplorer.java
Group setupLights() { Group group = new Group(); // set up the BoundingSphere for all the lights BoundingSphere bounds = new BoundingSphere(new Point3d(), 100.0); // Set up the ambient light AmbientLight lightAmbient = new AmbientLight(medGrey); lightAmbient.setInfluencingBounds(bounds); lightAmbient.setCapability(Light.ALLOW_STATE_WRITE); group.addChild(lightAmbient);//from w w w . j a v a 2s. c o m lightSwitch = new Switch(); lightSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); group.addChild(lightSwitch); // Set up the directional light Vector3f lightDirection1 = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lightDirectional1 = new DirectionalLight(white, lightDirection1); lightDirectional1.setInfluencingBounds(bounds); lightDirectional1.setCapability(Light.ALLOW_STATE_WRITE); lightSwitch.addChild(lightDirectional1); Point3f lightPos1 = new Point3f(-4.0f, 8.0f, 16.0f); Point3f lightAttenuation1 = new Point3f(1.0f, 0.0f, 0.0f); PointLight pointLight1 = new PointLight(brightWhite, lightPos1, lightAttenuation1); pointLight1.setInfluencingBounds(bounds); lightSwitch.addChild(pointLight1); Point3f lightPos2 = new Point3f(-16.0f, 8.0f, 4.0f); //Point3f lightPos = new Point3f(-4.0f, 2.0f, 1.0f); Point3f lightAttenuation2 = new Point3f(1.0f, 0.0f, 0.0f); PointLight pointLight2 = new PointLight(white, lightPos2, lightAttenuation2); pointLight2.setInfluencingBounds(bounds); lightSwitch.addChild(pointLight2); return group; }
From source file:KeyNavigateTest.java
public Bounds getGeometryBounds() { return new BoundingSphere(new Point3d(0, 0, 0), 100); }
From source file:KeyNavigateTest.java
protected Bounds getSoundSchedulingBounds(boolean bCollide) { return new BoundingSphere(new Point3d(0, 0, 0), 1.0); }
From source file:AppearanceExplorer.java
public void init() { // initialize the code base try {//from w w w. j a va 2 s .c o m java.net.URL codeBase = getCodeBase(); codeBaseString = codeBase.toString(); } catch (Exception e) { // probably running as an application, try the application // code base codeBaseString = "file:./"; } // set up a NumFormat object to print out float with only 3 fraction // digits nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(3); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); canvas = new Canvas3D(config); canvas.setSize(600, 600); u = new SimpleUniverse(canvas); if (isApplication) { offScreenCanvas = new OffScreenCanvas3D(config, true); // set the size of the off-screen canvas based on a scale // of the on-screen size Screen3D sOn = canvas.getScreen3D(); Screen3D sOff = offScreenCanvas.getScreen3D(); Dimension dim = sOn.getSize(); dim.width *= offScreenScale; dim.height *= offScreenScale; sOff.setSize(dim); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth() * offScreenScale); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight() * offScreenScale); // attach the offscreen canvas to the view u.getViewer().getView().addCanvas3D(offScreenCanvas); } contentPane.add("Center", canvas); BackgroundTool bgTool = new BackgroundTool(codeBaseString); bgSwitch = bgTool.getSwitch(); bgChooser = bgTool.getChooser(); // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); // set up sound u.getViewer().createAudioDevice(); // get the view view = u.getViewer().getView(); // Get the viewing platform ViewingPlatform viewingPlatform = u.getViewingPlatform(); // Move the viewing platform back to enclose the -2 -> 2 range double viewRadius = 2.0; // want to be able to see circle // of viewRadius size around origin // get the field of view double fov = u.getViewer().getView().getFieldOfView(); // calc view distance to make circle view in fov float viewDistance = (float) (viewRadius / Math.tan(fov / 2.0)); tmpVector.set(0.0f, 0.0f, viewDistance);// setup offset tmpTrans.set(tmpVector); // set trans to translate // move the view platform viewingPlatform.getViewPlatformTransform().setTransform(tmpTrans); // add an orbit behavior to move the viewing platform OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.PROPORTIONAL_ZOOM | OrbitBehavior.REVERSE_ROTATE | OrbitBehavior.REVERSE_TRANSLATE); orbit.setZoomFactor(0.25); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit); u.addBranchGraph(scene); contentPane.add("East", guiPanel()); }
From source file:SplineInterpolatorTest.java
protected Bounds getSoundSchedulingBounds(boolean bCollide) { return new BoundingSphere(new Point3d(0, 0, 0), 20); }