Class SensorEvent
- java.lang.Object
-
- com.sun.j3d.utils.behaviors.sensor.SensorEvent
-
public class SensorEvent extends java.lang.Object
This class defines the event object that is created by aSensorEventAgent
and passed to registeredSensorReadListener
andSensorButtonListener
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:
SensorEventAgent
,SensorButtonListener
,SensorReadListener
-
-
Field Summary
Fields Modifier and Type Field Description static int
DRAGGED
A button dragged event.static int
NOBUTTON
The value that is returned bygetButton
when no buttons have changed state.static int
PRESSED
A button pressed event.static int
READ
A sensor read event.static int
RELEASED
A button released event.
-
Constructor Summary
Constructors Constructor Description SensorEvent()
Creates a new ephemeralSensorEvent
.SensorEvent(SensorEvent e)
Creates a copy of the givenSensorEvent
.SensorEvent(java.lang.Object source, int id, Sensor sensor, Transform3D sensorRead, int[] buttonState, int button, long time, long lastTime)
Creates a newSensorEvent
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getButton()
Gets the index of the button that changed state when passed to apressed
orreleased
callback.void
getButtonState(int[] buttonState)
Copies the state of the sensor's buttons at the time of the event into the given array.int
getID()
Gets the event type.long
getLastTime()
Gets the time in nanoseconds at which thedispatchEvents
method ofSensorEventAgent
was last called to generate events, usually from theprocessStimulus
method of aBehavior
; may be used to measure frame time in behaviors that wake up every frame.Sensor
getSensor()
Gets a reference to the provoking sensor.void
getSensorRead(Transform3D t)
Copies the sensor's read value at the time of the event into the givenTransform3D
.java.lang.Object
getSource()
Gets a reference to the originating object which instantiated theSensorEventAgent
, usually aBehavior
; may be null.long
getTime()
Gets the time in nanoseconds at which thedispatchEvents
method ofSensorEventAgent
was called to generate this event, usually from theprocessStimulus
method of aBehavior
.boolean
isEphemeral()
Returns true if this event is ephemeral and is valid only until the listener returns.void
set(java.lang.Object source, int id, Sensor sensor, Transform3D sensorRead, int[] buttonState, int button, long time, long lastTime)
Sets the fields of an ephemeral event.
-
-
-
Field Detail
-
PRESSED
public static final int PRESSED
A button pressed event.- See Also:
- Constant Field Values
-
RELEASED
public static final int RELEASED
A button released event.- See Also:
- Constant Field Values
-
DRAGGED
public static final int DRAGGED
A button dragged event.- See Also:
- Constant Field Values
-
READ
public static final int READ
A sensor read event.- See Also:
- Constant Field Values
-
NOBUTTON
public static final int NOBUTTON
The value that is returned bygetButton
when no buttons have changed state.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SensorEvent
public SensorEvent(java.lang.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 valueNOBUTTON
time
- the time in nanoseconds at which thedispatchEvents
method ofSensorEventAgent
was called to generate this event, usually from theprocessStimulus
method of a BehaviorlastTime
- the time in nanoseconds at which thedispatchEvents
method ofSensorEventAgent
was last called to generate events, usually from theprocessStimulus
method 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 thedispatchEvents
method ofSensorEventAgent
are valid only until the listener returns. If the event needs to be retained then they must be copied with theSensorEvent(SensorEvent)
constructor.
-
SensorEvent
public SensorEvent(SensorEvent e)
Creates a copy of the givenSensorEvent
. Listeners must use this constructor to copy events that need to be retained. NOTE: TheSensor
andObject
references returned bygetSensor
andgetSource
remain references to the original objects.- Parameters:
e
- the event to be copied
-
-
Method Detail
-
set
public void set(java.lang.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. AnIllegalStateException
will 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 valueNOBUTTON
time
- the time in nanoseconds at which thedispatchEvents
method ofSensorEventAgent
was called to generate this event, usually from theprocessStimulus
method of a BehaviorlastTime
- the time in nanoseconds at which thedispatchEvents
method ofSensorEventAgent
was last called to generate events, usually from theprocessStimulus
method of aBehavior
; may be used to measure frame time in behaviors that wake up every frame
-
getSource
public java.lang.Object 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
public Sensor getSensor()
Gets a reference to the provoking sensor.- Returns:
- the provoking sensor
-
getTime
public long getTime()
Gets the time in nanoseconds at which thedispatchEvents
method ofSensorEventAgent
was called to generate this event, usually from theprocessStimulus
method of aBehavior
.- Returns:
- time in nanoseconds
-
getLastTime
public long getLastTime()
Gets the time in nanoseconds at which thedispatchEvents
method ofSensorEventAgent
was last called to generate events, usually from theprocessStimulus
method of aBehavior
; may be used to measure frame time in behaviors that wake up every frame.- Returns:
- last time in nanoseconds
-
getSensorRead
public void getSensorRead(Transform3D t)
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 apressed
orreleased
callback. The index may range from 0 to(sensor.getSensorButtonCount() - 1)
. The value returned isNOBUTTON
for events passed to aread
ordragged
callback.- 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.
-
-