Java Reference
In-Depth Information
further limited by specifying a scope for the light object so that its influence is restricted
to only a portion of the scene graph or to visual objects lying below an interesting group
in the graph.
Figure 11 shows the code segment and result obtained from using this approach.
In this example, two crystals are illuminated by two spotlights and each spot light has
a light scope given by lines 30 and 35 such that only the respective crystal will be illumi-
Figure 11. Code segment and result for LightAttenApp.java
1.
public LightAttenApp extends Applet {
2.
public BranchGroup createSceneGraph(){
3.
BranchGroup objRoot = new BranchGroup();
4.
TransformGroup objPath = new TransformGroup();
5.
objPath.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
6.
objRoot.addChild(objPath);
7.
8.
Transform3D trans1 = new Transform3D(); // move crystal to left
9.
trans1.setTranslation(new Vector3f(-0.3f, 0.0f, 0.0f));
10.
TransformGroup light1G = new TransformGroup(trans1);
11.
light1G.addChild(new Crystal()); objPath.addChild(light1G);
12.
Transform3D trans2 = new Transform3D(); // move crystal to right
13.
trans2.setTranslation(new Vector3f(0.3f, 0.0f, 0.0f));
14.
TransformGroup light2G = new TransformGroup(trans2);
15.
light2G.addChild(new Crystal()); objPath.addChild(light2G);
16.
17.
Alpha pathAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE
18.
|Alpha.DECREASING_ENABLE, 0, 0, 2500, 0, 0, 2500, 0, 0);
19.
Transform3D pathAxis = new Transform3D();
20.
pathAxis.rotY(Math.PI/2.0f);
21.
PositionInterpolator path = new PositionInterpolator(pathAlpha, objPath, pathAxis, 0.8f, -0.8f);
22.
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
23.
path.setSchedulingBounds(bounds); objPath.addChild(path);
24.
Vector3f lightDirectionA = new Vector3f(-1.0f, 0.0f, -1.0f); lightDirectionA.normalize();
25.
26.
SpotLight lightS1 = new SpotLight(); // add spot light 1
27.
lightS1.setPosition(-0.3f, 0.0f, 1.2f); lightS1.setAttenuation(0.0f, 0.0f, 3.0f);
28.
lightS1.setConcentration(100.0f); lightS1.setSpreadAngle((float)Math.PI/5.0f);
29.
lightS1.setInfluencingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0), 5.0));
30.
lightS1.addScope(light1G); objRoot.addChild(lightS1);
31.
SpotLight lightS2 = new SpotLight(); // add spot light 2
32.
lightS2.setPosition(0.3f, 0.0f, 1.2f); lightS2.setAttenuation(0.0f, 3.0f, 0.0f);
33.
lightS2.setConcentration(100.0f); lightS2.setSpreadAngle((float)Math.PI/5.0f);
34.
lightS2.setInfluencingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0), 5.0));
35.
lightS2.addScope(light2G); objRoot.addChild(lightS2);
36.
DirectionalLight lightD = new DirectionalLight(new Color3f(0.5f, 0.5f, 0.5f), lightDirectionA);
37.
lightD.setInfluencingBounds(new BoundingSphere()); objRoot.addChild(lightD);
38.
AmbientLight lightA = new AmbientLight(new Color3f(1.0f, 1.0f, 1.0f));
39.
lightA.setInfluencingBounds(new BoundingSphere()); objRoot.addChild(lightA);
40.
objRoot.compile(); return objRoot; }
Search WWH ::




Custom Search