List of usage examples for javax.media.j3d BoundingSphere BoundingSphere
public BoundingSphere(Point3d center, double radius)
From source file:HelloWorld.java
private static BranchGroup createSceneGraph() { // Make a scene graph branch BranchGroup branch = new BranchGroup(); // Make a changeable 3D transform TransformGroup trans = new TransformGroup(); trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); branch.addChild(trans);//from ww w . j av a2 s .c o m // Make a shape ColorCube demo = new ColorCube(0.4); trans.addChild(demo); // Make a behavor to spin the shape Alpha spinAlpha = new Alpha(-1, 4000); RotationInterpolator spinner = new RotationInterpolator(spinAlpha, trans); spinner.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0)); trans.addChild(spinner); return branch; }
From source file:Ball.java
public Ball() { // Create the universe SimpleUniverse universe = new SimpleUniverse(); // Create a structure to contain objects BranchGroup group = new BranchGroup(); // Create a ball and add it to the group of objects Sphere sphere = new Sphere(0.5f); group.addChild(sphere);//from ww w . jav a 2s.c o m // Create a red light that shines for 100m from the origin Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f); 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); // look towards the ball universe.getViewingPlatform().setNominalViewingTransform(); // add the group of objects to the Universe universe.addBranchGraph(group); }
From source file:Licht.java
/** * Erstellt den Szenegraphen//from w ww . j a v a 2s. c o 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); Sphere kugel = new Sphere(0.5f, Sphere.GENERATE_NORMALS, 50, makeAppearance()); objWurzel.addChild(kugel); objWurzel.addChild(objDreh); //directes Licht DirectionalLight d_Licht = new DirectionalLight(); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), Double.MAX_VALUE)); d_Licht.setColor(new Color3f(1.0f, 0.0f, 0.0f)); Vector3f dir = new Vector3f(1.0f, 2.0f, -1.0f); dir.normalize(); d_Licht.setDirection(dir); objWurzel.addChild(d_Licht); // ambient Licht AmbientLight a_licht = new AmbientLight(); a_licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0f, 0.0f, 0.0f), Double.MAX_VALUE)); a_licht.setColor(new Color3f(1.0f, 0.0f, 0.0f)); objWurzel.addChild(a_licht); return objWurzel; }
From source file:SimpleLOD.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. * /*from w w w .j a v 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, 10.0f)); TransformGroup viewXfmGroup = new TransformGroup(viewXfm); viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); viewXfmGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); BoundingSphere movingBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); BoundingLeaf boundLeaf = new BoundingLeaf(movingBounds); ViewPlatform myViewPlatform = new ViewPlatform(); viewXfmGroup.addChild(boundLeaf); 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); return viewBranch; }
From source file:ObjectLoader.java
/** * Erstellt den Szenegraphen/*w w w. j a v a 2 s .c o 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 { scene = file.load(ClassLoader.getSystemResource("teapot.obj")); } catch (Exception e) { } objDreh.addChild(scene.getSceneGroup()); DirectionalLight d_Licht = new DirectionalLight(new Color3f(1.0f, 0.5f, 0.3f), new Vector3f(-1.0f, -1.0f, -1.0f)); d_Licht.setInfluencingBounds(new BoundingSphere(new Point3d(0.0d, 0.0d, 0.0d), 100.0d)); // d_Licht.setColor(new Color3f(1.0f,0.5f,0.3f)); objDreh.addChild(d_Licht); objWurzel.addChild(objDreh); return objWurzel; }
From source file:Phong.java
/** * Erstellt den Szenegraphen/* w w w . ja v a 2s. c o 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 { 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; }
From source file:SimpleSphere.java
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 global lights 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); Point3f lightPosition2 = new Point3f(3.0f, 3.0f, 3.0f); Point3f lightAtten2 = new Point3f(0.0f, 0.0f, 1.0f); Vector3f lightDir2 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight ambientLight1 = new AmbientLight(ambientColour); ambientLight1.setInfluencingBounds(bounds); DirectionalLight light1 = new DirectionalLight(lightColour1, lightDir1); light1.setInfluencingBounds(bounds); PointLight light2 = new PointLight(lightColour2, lightPosition2, lightAtten2); light2.setInfluencingBounds(bounds); b.addChild(ambientLight1);//from w w w . ja v a2 s. c om b.addChild(light1); //b.addChild(light2); }
From source file:AppearanceTest.java
private BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = 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 TextureLoader bgTexture = new TextureLoader(bgImage, this); Background bg = new Background(bgTexture.getImage()); bg.setApplicationBounds(bounds);/* ww w .j a v a 2s .c o m*/ objRoot.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); objRoot.addChild(aLgt); objRoot.addChild(lgt1); // 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) * 0.6; for (int j = 0; j < 3; j++) { double xpos = (double) (j - 1) * 0.6; objRoot.addChild(createObject(app[i][j], 0.12, xpos, ypos)); } } // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:SimpleDirLight.java
/** * This creates some lights and adds them to the BranchGroup. * // w ww . j a v a 2 s. c o m * @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); //Set up the directional light Color3f lightColour = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lightDir = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light = new DirectionalLight(lightColour, lightDir); light.setInfluencingBounds(bounds); //Add the lights to the BranchGroup b.addChild(ambientLight); b.addChild(light); }
From source file:StereoCube.java
public BranchGroup createSceneGraph(int i) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); TransformGroup objTrans = new TransformGroup(); 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);/*from w ww .java 2 s . co m*/ tg.addChild(new ColorCube(0.4)); MouseRotate behavior = new MouseRotate(); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); 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); return objRoot; }