Class SensorEvent
java.lang.Object
com.sun.j3d.utils.behaviors.sensor.SensorEvent
This class defines the event object that is created by a
SensorEventAgent and passed to registered
SensorReadListener and SensorButtonListener
implementations.
The events passed to the listeners are ephemeral; they are only
valid until the listener has returned. This is done to avoid
allocating large numbers of mostly temporary objects, especially for
behaviors that wake up every frame. If a listener needs to retain the
event it must be copied using the SensorEvent(SensorEvent)
constructor.
- Since:
- Java 3D 1.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA button dragged event.static final intThe value that is returned bygetButtonwhen no buttons have changed state.static final intA button pressed event.static final intA sensor read event.static final intA button released event. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new ephemeralSensorEvent.Creates a copy of the givenSensorEvent.SensorEvent(Object source, int id, Sensor sensor, Transform3D sensorRead, int[] buttonState, int button, long time, long lastTime) Creates a newSensorEvent. -
Method Summary
Modifier and TypeMethodDescriptionintGets the index of the button that changed state when passed to apressedorreleasedcallback.voidgetButtonState(int[] buttonState) Copies the state of the sensor's buttons at the time of the event into the given array.intgetID()Gets the event type.longGets the time in nanoseconds at which thedispatchEventsmethod ofSensorEventAgentwas last called to generate events, usually from theprocessStimulusmethod of aBehavior; may be used to measure frame time in behaviors that wake up every frame.Gets a reference to the provoking sensor.voidCopies the sensor's read value at the time of the event into the givenTransform3D.Gets a reference to the originating object which instantiated theSensorEventAgent, usually aBehavior; may be null.longgetTime()Gets the time in nanoseconds at which thedispatchEventsmethod ofSensorEventAgentwas called to generate this event, usually from theprocessStimulusmethod of aBehavior.booleanReturns true if this event is ephemeral and is valid only until the listener returns.voidset(Object source, int id, Sensor sensor, Transform3D sensorRead, int[] buttonState, int button, long time, long lastTime) Sets the fields of an ephemeral event.
-
Field Details
-
PRESSED
public static final int PRESSEDA button pressed event.- See Also:
-
RELEASED
public static final int RELEASEDA button released event.- See Also:
-
DRAGGED
public static final int DRAGGEDA button dragged event.- See Also:
-
READ
public static final int READA sensor read event.- See Also:
-
NOBUTTON
public static final int NOBUTTONThe value that is returned bygetButtonwhen no buttons have changed state.- See Also:
-
-
Constructor Details
-
SensorEvent
public SensorEvent(Object source, int id, Sensor sensor, Transform3D sensorRead, int[] buttonState, int button, long time, long lastTime) Creates a newSensorEvent.- Parameters:
source- a reference to the originating object which instantiated theSensorEventAgent, usually aBehavior; may be nullid- event typesensor- a reference to the provoking sensorsensorRead- the sensor's read value at the time of the eventbuttonState- the state of the sensor's buttons at the time of the event, where a 1 in the array indicates that the button at that index is down, and a 0 indicates that button is up; may be nullbutton- index of the button that changed state, from 0 to(buttonCount - 1), or the valueNOBUTTONtime- the time in nanoseconds at which thedispatchEventsmethod ofSensorEventAgentwas called to generate this event, usually from theprocessStimulusmethod of a BehaviorlastTime- the time in nanoseconds at which thedispatchEventsmethod ofSensorEventAgentwas last called to generate events, usually from theprocessStimulusmethod of aBehavior; may be used to measure frame time in behaviors that wake up every frame
-
SensorEvent
public SensorEvent()Creates a new ephemeralSensorEvent. In order to avoid creating large numbers of sensor event objects, the events passed to the button and read listeners by thedispatchEventsmethod ofSensorEventAgentare valid only until the listener returns. If the event needs to be retained then they must be copied with theSensorEvent(SensorEvent)constructor. -
SensorEvent
Creates a copy of the givenSensorEvent. Listeners must use this constructor to copy events that need to be retained. NOTE: TheSensorandObjectreferences returned bygetSensorandgetSourceremain references to the original objects.- Parameters:
e- the event to be copied
-
-
Method Details
-
set
public void set(Object source, int id, Sensor sensor, Transform3D sensorRead, int[] buttonState, int button, long time, long lastTime) Sets the fields of an ephemeral event. No objects are copied. AnIllegalStateExceptionwill be thrown if this event is not ephemeral.- Parameters:
source- a reference to the originating object which instantiated theSensorEventAgent, usually aBehavior; may be nullid- event typesensor- a reference to the provoking sensorsensorRead- the sensor's read value at the time of the eventbuttonState- the state of the sensor's buttons at the time of the event; a 1 in the array indicates that the button at that index is down, while a 0 indicates that button is upbutton- index of the button that changed state, from 0 to(buttonCount - 1), or the valueNOBUTTONtime- the time in nanoseconds at which thedispatchEventsmethod ofSensorEventAgentwas called to generate this event, usually from theprocessStimulusmethod of a BehaviorlastTime- the time in nanoseconds at which thedispatchEventsmethod ofSensorEventAgentwas last called to generate events, usually from theprocessStimulusmethod of aBehavior; may be used to measure frame time in behaviors that wake up every frame
-
getSource
Gets a reference to the originating object which instantiated theSensorEventAgent, usually aBehavior; may be null.- Returns:
- the originating object
-
getID
public int getID()Gets the event type.- Returns:
- the event id
-
getSensor
Gets a reference to the provoking sensor.- Returns:
- the provoking sensor
-
getTime
public long getTime()Gets the time in nanoseconds at which thedispatchEventsmethod ofSensorEventAgentwas called to generate this event, usually from theprocessStimulusmethod of aBehavior.- Returns:
- time in nanoseconds
-
getLastTime
public long getLastTime()Gets the time in nanoseconds at which thedispatchEventsmethod ofSensorEventAgentwas last called to generate events, usually from theprocessStimulusmethod of aBehavior; may be used to measure frame time in behaviors that wake up every frame.- Returns:
- last time in nanoseconds
-
getSensorRead
Copies the sensor's read value at the time of the event into the givenTransform3D.- Parameters:
t- the transform to receive the sensor read
-
getButton
public int getButton()Gets the index of the button that changed state when passed to apressedorreleasedcallback. The index may range from 0 to(sensor.getSensorButtonCount() - 1). The value returned isNOBUTTONfor events passed to areadordraggedcallback.- Returns:
- the button index
-
getButtonState
public void getButtonState(int[] buttonState) Copies the state of the sensor's buttons at the time of the event into the given array. A 1 in the array indicates that the button at that index is down, while a 0 indicates that button is up.- Parameters:
buttonState- the state of the sensor buttons
-
isEphemeral
public boolean isEphemeral()Returns true if this event is ephemeral and is valid only until the listener returns. A copy of the event can be created by passing it to theSensorEvent(SensorEvent)constructor.
-