1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.jbeans.j3d.util.behavior.sensor;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26 import javax.media.j3d.*;
27 import java.util.*;
28
29
30
31
32 /***
33 * SensorBehavior defines a Behavior object triggered by a Java3D sensor.
34 *
35 * @version $Revision: 1.3 $
36 * @author Masahiro Takatsuka (masa@jbeans.net)
37 * @see Behavior
38 */
39
40 public class SensorBehavior extends Behavior {
41 private WakeupOnElapsedFrames conditions = new WakeupOnElapsedFrames(0);
42 private TransformGroup transformGroup;
43 private Sensor sensor;
44 private Transform3D transform = new Transform3D();
45
46 /***
47 * Constructs a new SensorBehavior object with the specified
48 * TransformGroup and Sensor.
49 *
50 * @param tg a TransformGroup object.
51 * @param sensor a Sensor object which triggers this behavior.
52 */
53 public SensorBehavior( TransformGroup tg, Sensor sensor ) {
54 this.transformGroup = tg;
55 this.sensor = sensor;
56 }
57
58 /***
59 * Initialize this behavior.
60 */
61 public void initialize() {
62 wakeupOn( this.conditions );
63 }
64
65 /***
66 * Process a stimulus meant for this behavior. This method is invoked if
67 * the wakeup criteria are satisfied and the ViewPlatform's activation
68 * region intersect with the Behavior's scheduling region.
69 *
70 * @param criteria an enumeration of triggered wakeup criteria.
71 */
72 public void processStimulus( Enumeration criteria ) {
73 this.sensor.getRead( this.transform );
74 this.transformGroup.setTransform( this.transform );
75 wakeupOn( this.conditions );
76 }
77 }