public class SensorEvent extends Object
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.
SensorEventAgent
,
SensorButtonListener
,
SensorReadListener
Modifier and Type | Field and Description |
---|---|
static int |
DRAGGED
A button dragged event.
|
static int |
NOBUTTON
The value that is returned by
getButton 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 and Description |
---|
SensorEvent()
Creates a new ephemeral
SensorEvent . |
SensorEvent(Object source,
int id,
Sensor sensor,
Transform3D sensorRead,
int[] buttonState,
int button,
long time,
long lastTime)
Creates a new
SensorEvent . |
SensorEvent(SensorEvent e)
Creates a copy of the given
SensorEvent . |
Modifier and Type | Method and Description |
---|---|
int |
getButton()
Gets the index of the button that changed state when passed to a
pressed or released 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 the
dispatchEvents method of SensorEventAgent
was last called to generate events, usually from the
processStimulus method of a Behavior ; 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
given
Transform3D . |
Object |
getSource()
Gets a reference to the originating object which instantiated the
SensorEventAgent , usually a Behavior ; may
be null. |
long |
getTime()
Gets the time in nanoseconds at which the
dispatchEvents method of SensorEventAgent
was called to generate this event, usually from the
processStimulus method of a Behavior . |
boolean |
isEphemeral()
Returns true if this event is ephemeral and is valid only
until the listener returns.
|
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.
|
public static final int PRESSED
public static final int RELEASED
public static final int DRAGGED
public static final int READ
public static final int NOBUTTON
getButton
when no
buttons have changed state.public SensorEvent(Object source, int id, Sensor sensor, Transform3D sensorRead, int[] buttonState, int button, long time, long lastTime)
SensorEvent
.source
- a reference to the originating object which
instantiated the SensorEventAgent
, usually a
Behavior
; 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 value NOBUTTON
time
- the time in nanoseconds at which the
dispatchEvents
method of
SensorEventAgent
was called to generate this event,
usually from the processStimulus
method of a BehaviorlastTime
- the time in nanoseconds at which the
dispatchEvents
method of
SensorEventAgent
was last called to generate
events, usually from the processStimulus
method of a
Behavior
; may be used to measure frame time in
behaviors that wake up every framepublic SensorEvent()
SensorEvent
. In order
to avoid creating large numbers of sensor event objects, the events
passed to the button and read listeners by the
dispatchEvents
method of SensorEventAgent
are valid only until the listener returns. If the event needs to
be retained then they must be copied with the
SensorEvent(SensorEvent)
constructor.public SensorEvent(SensorEvent e)
SensorEvent
. Listeners
must use this constructor to copy events that need to be retained.
NOTE: The Sensor
and Object
references
returned by getSensor
and getSource
remain references to the original objects.e
- the event to be copiedpublic void set(Object source, int id, Sensor sensor, Transform3D sensorRead, int[] buttonState, int button, long time, long lastTime)
IllegalStateException
will be thrown if this event
is not ephemeral.source
- a reference to the originating object which
instantiated the SensorEventAgent
, usually a
Behavior
; 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 value NOBUTTON
time
- the time in nanoseconds at which the
dispatchEvents
method of
SensorEventAgent
was called to generate this event,
usually from the processStimulus
method of a BehaviorlastTime
- the time in nanoseconds at which the
dispatchEvents
method of
SensorEventAgent
was last called to generate
events, usually from the processStimulus
method of a
Behavior
; may be used to measure frame time in
behaviors that wake up every framepublic Object getSource()
SensorEventAgent
, usually a Behavior
; may
be null.public int getID()
public Sensor getSensor()
public long getTime()
dispatchEvents
method of SensorEventAgent
was called to generate this event, usually from the
processStimulus
method of a Behavior
.public long getLastTime()
dispatchEvents
method of SensorEventAgent
was last called to generate events, usually from the
processStimulus
method of a Behavior
; may
be used to measure frame time in behaviors that wake up every
frame.public void getSensorRead(Transform3D t)
Transform3D
.t
- the transform to receive the sensor readpublic int getButton()
pressed
or released
callback. The index
may range from 0 to (sensor.getSensorButtonCount() -
1)
. The value returned is NOBUTTON
for events
passed to a read
or dragged
callback.public void getButtonState(int[] buttonState)
buttonState
- the state of the sensor buttonspublic boolean isEphemeral()
SensorEvent(SensorEvent)
constructor.Copyright © 2016–2022 SciJava. All rights reserved.