View Javadoc

1   /* -------------------------------------------------------------------
2    * Java source file for the class SensorBehavior
3    * 
4    * Copyright (c), 2003, Masahiro Takatsuka.
5    * All Rights Researved.
6    * 
7    * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8    * $Author: takatsukam $
9    * 
10   * $Date: 2004/03/03 11:53:07 $
11   * 
12   * $Id: SensorBehavior.java,v 1.3 2004/03/03 11:53:07 takatsukam Exp $
13   * 
14   * Reference:		Document no:
15   * ___				___
16   * 
17   * To Do:
18   * ___
19   * 
20  ------------------------------------------------------------------- */
21  
22  /* --------------------------- Package ---------------------------- */
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                  Implementation of class SensorBehavior                
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  }