Java Reference
In-Depth Information
used in tracing our way to the desired node from the picked node. Also, as the light sources
will be modified, all the relevant capabilities must be set to prevent getting Capability Not
Set exceptions. With these points in mind, Figure 15 and 16 shows the code segments for
creating the scene in this application.
To incorporate the picking behavior for this scene in the manner described, Figure
17 shows the structure of the customized picking behavior class needed. Again, as in the
example in the last section, the code structure includes declaration for a set of variables, a
constructor, an initialize and a processStimulus method.
Note that in the code segment for the constructor in Figure 17, the mode of picking is
set to be bounds rather than geometry based as has been done in earlier examples. This will
save time needed for intersection checking in the picking process, and will be satisfactory
in this application where the only picking operation is just to turn something on and off
through the smaller spheres. Since only mouse click will be used, the initialize method sets
up an initial wakeup criterion to correspond to MOUSE_CLICKED only.
Figure 16. Second code segment for PickConeRayBehavior.java
36.
Sphere small_sphere2 = new Sphere( 0.005f, createAppearance1() );
37.
objTrans2.addChild( small_sphere2 );
38.
PointLight pointlight2 = new PointLight();
39.
light_colour.set( 1.0f, 1.0f, 1.0f );
40.
pointlight2.setColor( light_colour );
41.
pointlight2.setInfluencingBounds( bounds );
42.
pointlight2.setCapability ( Light.ALLOW_STATE_WRITE );
43.
pointlight2.setCapability ( Light.ALLOW_STATE_READ );
44.
pointlight2.setCapability ( Light.ALLOW_COLOR_READ );
45.
pointlight2.setCapability ( Light.ALLOW_COLOR_WRITE );
46.
objTrans2.addChild( pointlight2 );
47.
translate.set( new Vector3f( -0.5f, -0.5f, 0.0f ) );
48.
objTrans2.setTransform( translate );
49.
50.
// creating a big sphere at the origin. Note that this sphere is not pickable
51.
Sphere big_sphere = new Sphere( 0.3f, createAppearance2() );
52.
big_sphere.setPickable( false ); //setting the sphere to be unpickable
53.
objRoot.addChild( big_sphere );
54.
PickingBehaviour behave = new PickingBehaviour( objRoot );
55.
behave.setSchedulingBounds( bounds );
56.
objRoot.addChild( behave );
57.
objRoot.compile();
58.
return objRoot;
59. }
Search WWH ::




Custom Search