Java Reference
In-Depth Information
Figure 5. First code segment for J3d.java
1. public BranchGroup createscenegraph() {
2. // background object
3. shape s = new shape();
4. BranchGroup root = new BranchGroup();
5. Transform3D rotation = new Transform3D(); Transform3D translation = new Transform3D();
6. translation.set(new Vector3d( 0.0,-0.3, 0.0)); rotation.rotY(Math.PI/-4.0); translation.mul(rotation);
7. TransformGroup platform=new TransformGroup(translation);
8. System.out.println("Enter the number of planes");
9. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
10. try { String userInput = in.readLine(); int res = Integer.parseInt(userInput); }
11. catch (IOException ioe) { System.out.println("IO error trying to read input!"); System.exit(1); }
12.
platform.addChild(s.plane(5f,res)); root.addChild(platform);
13.
14.
// create a sphere
15.
Transform3D sphereposition= new Transform3D();
16.
TransformGroup sphere1 = new TransformGroup(sphereposition);
17.
TransformGroup sphere2 = new TransformGroup(sphereposition);
18.
Primitive shape = new Sphere(0.1f);
19.
Shape3D sphere = shape.getShape(1);
20.
Appearance appearance = new Appearance();
21.
Material material =new Material(s.black,s.green,s.black,s.white,100f);
22.
appearance.setMaterial(material);
23.
shape.setAppearance(appearance);
24.
the sphere does emit a green color and this emission dominates what is being seen at the
position of the sphere.
dIrectIonal lIGht
As its name suggests, directional light corresponds to light arriving from a certain direction
in a uniform plane wave front (Lighting up the world, 2006). The intensity of the light is
uniform, and it is usually used to simulate sky light or light from a distant source.
Line 35 in Figure 6 gives an example for creating a directional light. The first argument
in the constructor DirectionalLight() corresponds to the color of the light, while the second
argument specifies the direction of arrival of the rays. The capabilities, directionallght.
setCapability(DirectionalLight.ALLOW_DIRECTION_WRITE) and directionallght.
setCapability(DirectionalLight.ALLOW_DIRECTION_READ), must also be set if the
Search WWH ::




Custom Search