List of usage examples for javax.media.j3d BoundingSphere BoundingSphere
public BoundingSphere(Point3d center, double radius)
From source file:SimpleSpotLights.java
/** * This creates some lights and adds them to the BranchGroup. * /* w w w. j a v a 2 s .com*/ * @param b * BranchGroup that the lights are added to. */ protected void addLights(BranchGroup b) { // Create a bounds for the lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); //Set up the ambient light Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight ambientLight = new AmbientLight(ambientColour); ambientLight.setInfluencingBounds(bounds); Color3f blueColour = new Color3f(0.0f, 0.0f, 1.0f); Point3f bluePosition = new Point3f(1.8f, 1.8f, 1.8f); Point3f blueAtten = new Point3f(1.0f, 0.0f, 0.0f); Vector3f blueDir = new Vector3f(-1.0f, -1.0f, -1.0f); SpotLight blueLight = new SpotLight(blueColour, bluePosition, blueAtten, blueDir, (float) (Math.PI / 2.0), 0.0f); blueLight.setInfluencingBounds(bounds); Color3f greenColour = new Color3f(0.0f, 1.0f, 0.0f); Point3f greenPosition = new Point3f(0.0f, 0.0f, 3.0f); Point3f greenAtten = new Point3f(1.0f, 0.0f, 0.0f); Vector3f greenDir = new Vector3f(0.0f, 0.0f, -1.0f); SpotLight greenLight = new SpotLight(greenColour, greenPosition, greenAtten, greenDir, (float) (Math.PI / 2.0), 0.0f); greenLight.setInfluencingBounds(bounds); //Add the lights to the BranchGroup b.addChild(ambientLight); b.addChild(greenLight); b.addChild(blueLight); }
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);//from w ww . j av a 2 s . 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:MouseNavigatorApp.java
public BranchGroup createSceneGraph(SimpleUniverse su) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup vpTrans = null;//from www . j a v a 2 s. co m BoundingSphere mouseBounds = null; vpTrans = su.getViewingPlatform().getViewPlatformTransform(); objRoot.addChild(new ColorCube(0.4)); objRoot.addChild(new Axis()); mouseBounds = new BoundingSphere(new Point3d(), 1000.0); MouseRotate myMouseRotate = new MouseRotate(MouseBehavior.INVERT_INPUT); myMouseRotate.setTransformGroup(vpTrans); myMouseRotate.setSchedulingBounds(mouseBounds); objRoot.addChild(myMouseRotate); MouseTranslate myMouseTranslate = new MouseTranslate(MouseBehavior.INVERT_INPUT); myMouseTranslate.setTransformGroup(vpTrans); myMouseTranslate.setSchedulingBounds(mouseBounds); objRoot.addChild(myMouseTranslate); MouseZoom myMouseZoom = new MouseZoom(MouseBehavior.INVERT_INPUT); myMouseZoom.setTransformGroup(vpTrans); myMouseZoom.setSchedulingBounds(mouseBounds); objRoot.addChild(myMouseZoom); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:ModelClipTest.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // 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 w w w. j a v a 2s . c o m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // This Transformgroup is used by the mouse manipulators to // move the CYlinder. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); objScale.addChild(objTrans); //Create Model Clip ModelClip mc = new ModelClip(); boolean enables[] = { false, false, false, false, false, false }; Vector4d eqn1 = new Vector4d(0.0, 1.0, 0.0, 0.0); Vector4d eqn2 = new Vector4d(1.0, 1.0, 0.0, 0.0); mc.setEnables(enables); mc.setPlane(1, eqn1); mc.setPlane(2, eqn2); mc.setEnable(1, true); mc.setEnable(2, true); mc.setInfluencingBounds(bounds); objTrans.addChild(mc); //Create a cylinder PolygonAttributes attr = new PolygonAttributes(); attr.setCullFace(PolygonAttributes.CULL_NONE); Appearance ap = new Appearance(); Material mat = new Material(); mat.setLightingEnable(true); ap.setMaterial(mat); ap.setPolygonAttributes(attr); Cylinder CylinderObj = new Cylinder(1.0f, 2.0f, ap); objTrans.addChild(CylinderObj); // Create the rotate behavior node MouseRotate behavior = new MouseRotate(objTrans); objTrans.addChild(behavior); behavior.setSchedulingBounds(bounds); // Create the zoom behavior node MouseZoom behavior2 = new MouseZoom(objTrans); objTrans.addChild(behavior2); behavior2.setSchedulingBounds(bounds); //Shine it with two colored lights. Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f); Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f); Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); objScale.addChild(lgt1); objScale.addChild(lgt2); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SimpleMorph.java
/** * Add some lights to the scene graph//from w w w . j a v a2s. c o m * * @param b * BranchGroup that the lights are added to */ protected void addLights(BranchGroup b) { BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f ambLightColour = new Color3f(0.5f, 0.5f, 0.5f); AmbientLight ambLight = new AmbientLight(ambLightColour); ambLight.setInfluencingBounds(bounds); Color3f dirLightColour = new Color3f(1.0f, 1.0f, 1.0f); Vector3f dirLightDir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight dirLight = new DirectionalLight(dirLightColour, dirLightDir); dirLight.setInfluencingBounds(bounds); b.addChild(ambLight); b.addChild(dirLight); }
From source file:SimpleTextureGen.java
/** * Add some lights so that we can illuminate the scene. This adds one * ambient light to bring up the overall lighting level and one directional * shape to show the shape of the objects in the scene. * //from www.j av a 2s .c o m * @param b * BranchGroup that the lights are to be added to. */ protected void addLights(BranchGroup b) { BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f lightColour1 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f lightColour2 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir2 = new Vector3f(0.0f, 0.0f, -1.0f); Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight ambientLight1 = new AmbientLight(ambientColour); ambientLight1.setInfluencingBounds(bounds); DirectionalLight directionalLight1 = new DirectionalLight(lightColour1, lightDir1); directionalLight1.setInfluencingBounds(bounds); b.addChild(ambientLight1); b.addChild(directionalLight1); }
From source file:SimpleCombine.java
/** * Add some lights so that we can illuminate the scene. This adds one * ambient light to bring up the overall lighting level and one directional * shape to show the shape of the objects in the scene. * //from w w w. j a v a 2s . c o m * @param b * BranchGroup that the lights are to be added to. */ protected void addLights(BranchGroup b) { BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f lightColour1 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f lightColour2 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir2 = new Vector3f(1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1); light1.setInfluencingBounds(bounds); DirectionalLight light2 = new DirectionalLight(lightColour2, lightDir2); light2.setInfluencingBounds(bounds); b.addChild(light1); b.addChild(light2); }
From source file:SimpleIndexedQuadSmooth.java
/** * Add some lights so that we can illuminate the scene. This adds one * ambient light to bring up the overall lighting level and one directional * shape to show the shape of the objects in the scene. * /*from ww w . ja v a 2 s . co m*/ * @param b * BranchGroup that the lights are to be added to. */ protected void addLights(BranchGroup b) { //Create a bounding sphere to act as the active bounds //of the lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); //Create the colours and directions Color3f lightColour = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f); //Create the lights AmbientLight ambientLight = new AmbientLight(ambientColour); ambientLight.setInfluencingBounds(bounds); DirectionalLight directionalLight = new DirectionalLight(lightColour, lightDir); directionalLight.setInfluencingBounds(bounds); //Add the lights to the branch b.addChild(ambientLight); b.addChild(directionalLight); }
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. * /*w w w . j av a 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:SimpleSwitch.java
/** * Add some lights so that we can illuminate the scene. This adds one * ambient light to bring up the overall lighting level and one directional * shape to show the shape of the objects in the scene. * // ww w. j ava 2s . c o m * @param b * BranchGroup that the lights are to be added to. */ protected void addLights(BranchGroup b) { BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Color3f lightColour1 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir1 = new Vector3f(0.0f, -1.0f, 0.0f); Color3f lightColour2 = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir2 = new Vector3f(0.0f, 1.0f, 0.0f); DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1); light1.setInfluencingBounds(bounds); DirectionalLight light2 = new DirectionalLight(lightColour2, lightDir2); light2.setInfluencingBounds(bounds); b.addChild(light1); b.addChild(light2); }