List of usage examples for javax.media.j3d DirectionalLight setInfluencingBounds
public void setInfluencingBounds(Bounds region)
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.java 2 s . c om // 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 w w . ja va2 s . c om * * @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:LitSphereApp.java
BranchGroup createScene() { BranchGroup scene = new BranchGroup(); scene.addChild(new Sphere(0.9f, Sphere.GENERATE_NORMALS, createAppearance())); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA);// w ww .ja v a 2 s.c o m DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere()); Vector3f direction1 = new Vector3f(-1.0f, -1.0f, -0.5f); direction1.normalize(); lightD1.setDirection(direction1); lightD1.setColor(new Color3f(0.0f, 0.0f, 1.0f)); scene.addChild(lightD1); DirectionalLight lightD2 = new DirectionalLight(); lightD2.setInfluencingBounds(new BoundingSphere()); Vector3f direction2 = new Vector3f(1.0f, -1.0f, -0.5f); direction2.normalize(); lightD2.setDirection(direction2); lightD2.setColor(new Color3f(1.0f, 0.0f, 0.0f)); scene.addChild(lightD2); Background bg = new Background(); bg.setColor(1.0f, 1.0f, 1.0f); bg.setApplicationBounds(new BoundingSphere()); scene.addChild(bg); return scene; }
From source file:LitPlaneApp.java
public LitPlaneApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); BranchGroup scene = new BranchGroup(); Shape3D plane = new LitPlane(); scene.addChild(new LitPlane()); scene.addChild(new Sphere(0.5f, Sphere.GENERATE_NORMALS, plane.getAppearance())); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA);//from w w w . j a v a 2 s . c o m DirectionalLight lightD1 = new DirectionalLight(); lightD1.setInfluencingBounds(new BoundingSphere(new Point3d(0.0, 0.5, 0.0), 0.1)); Vector3f direction = new Vector3f(-1.0f, -1.0f, -1.0f); direction.normalize(); lightD1.setDirection(direction); lightD1.setColor(new Color3f(1.0f, 1.0f, 1.0f)); scene.addChild(lightD1); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); }
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 ww w .j ava 2 s.c o m*/ b.addChild(light1); //b.addChild(light2); }
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);//from w w w . j av a2 s .c o m 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:PictureBall.java
public PictureBall() { // Create the universe SimpleUniverse universe = new SimpleUniverse(); // Create a structure to contain objects BranchGroup group = new BranchGroup(); // Set up colors Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(0.7f, .15f, .15f); // Set up the texture map TextureLoader loader = new TextureLoader("K:\\3d\\Arizona.jpg", "LUMINANCE", new Container()); Texture texture = loader.getTexture(); texture.setBoundaryModeS(Texture.WRAP); texture.setBoundaryModeT(Texture.WRAP); texture.setBoundaryColor(new Color4f(0.0f, 1.0f, 0.0f, 0.0f)); // Set up the texture attributes //could be REPLACE, BLEND or DECAL instead of MODULATE TextureAttributes texAttr = new TextureAttributes(); texAttr.setTextureMode(TextureAttributes.MODULATE); Appearance ap = new Appearance(); ap.setTexture(texture);/*w ww. ja v a 2s . c o m*/ ap.setTextureAttributes(texAttr); //set up the material ap.setMaterial(new Material(red, black, red, black, 1.0f)); // Create a ball to demonstrate textures int primflags = Primitive.GENERATE_NORMALS + Primitive.GENERATE_TEXTURE_COORDS; Sphere sphere = new Sphere(0.5f, primflags, ap); group.addChild(sphere); // Create lights Color3f light1Color = new Color3f(1f, 1f, 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); AmbientLight ambientLight = new AmbientLight(new Color3f(.5f, .5f, .5f)); ambientLight.setInfluencingBounds(bounds); group.addChild(ambientLight); // look towards the ball universe.getViewingPlatform().setNominalViewingTransform(); // add the group of objects to the Universe universe.addBranchGraph(group); }
From source file:LOD.java
private void createLights(BranchGroup graphRoot) { // Create a bounds for the light source influence BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the global, ambient light Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(bounds);// ww w . jav a2 s . c o m graphRoot.addChild(aLgt); // Set up the directional (infinite) light source Color3f lColor1 = new Color3f(0.9f, 0.9f, 0.9f); Vector3f lDir1 = new Vector3f(1.0f, 1.0f, -1.0f); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(bounds); graphRoot.addChild(lgt1); }
From source file:SimpleDirLight.java
/** * This creates some lights and adds them to the BranchGroup. * /* w ww . ja v a2s. co 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: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);//from w w w.ja v a 2 s .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; }