Java Reference
In-Depth Information
Figure 7. Code segment for WakeupOnActivationAndDeactivation.java
1.
public class SimpleBehavior extends Behavior
2.
{
3.
private TransformGroup targetTG;
4.
private WakeupCriterion Activation = new WakeupOnActivation();
5.
private WakeupCriterion DeActivation = new WakeupOnDeactivation();
6.
private BoundingSphere bound = new BoundingSphere(new Point3d(100.0, 0.0, 0.0), 50.0);
7.
8. SimpleBehavior(TransformGroup TG)
9. {
10.
this.targetTG = TG;
11.
this.setSchedulingBounds(bound); // set SchedulingBounds - center (100, 0, 0), radius 50
12.
}
ViewingPlatform
r = 62
BoundingSphere
r = 50
x
0
50
10
0
62
13. public void initialize()
14. {
15.
this.wakeupOn(Activation); //set initial wakeup criterion as Activation
16.
}
17.
18. public void processStimulus(Enumeration criteria)
19. {
20.
bound.setRadius(20.0); // change the radius to 20.0
21.
this.setSchedulingBounds(bound); // reset the SchedulingBounds
ViewingPlatform
r = 62
BoundingSphere
r = 20
x
0
62 80
10
0
22.
if (DeActivation.hasTriggered()) // check for DeActivation
23.
System.out.println("Deactivation = True");
24.
else
25.
System.out.println("Deactivation = False");
26.
this.wakeupOn(DeActivation); // set the new wakeup criterion to DeActivation
27.
}
28. }
Search WWH ::




Custom Search