Eye
public final class Eye implements Trackable
A representation of a user's eye.
An Eye instance provides the state of the eye (shut or gazing), as well as a Pose indicating where the user is currently looking.
Summary
Nested types |
|---|
public final class Eye.State implements Trackable.StateThe representation of the current state of an |
Public methods |
|
|---|---|
@NonNull StateFlow<@NonNull Eye.State> |
getState() |
static final @NonNull Eye |
Returns the left eye. |
static final @NonNull Eye |
Returns the right eye. |
Public methods
left
Added in 1.0.0-beta01
public static final @NonNull Eye left(@NonNull Session session)
Returns the left eye.
import androidx.xr.arcore.ArDevice import androidx.xr.arcore.Eye import androidx.xr.arcore.TrackingState import androidx.xr.arcore.hitTest import androidx.xr.runtime.Session import androidx.xr.runtime.math.Ray import androidx.xr.scenecore.scene // We need the ArDevice object to properly transform the eye pose coordinate space into // something we can use. val arDevice = ArDevice.getInstance(session) // Obtain the left eye from the Session object. Eye.left(session)?.let { // The left eye is available; launch a coroutine // to respond to changes in the eye's state. yourCoroutineScope.launch { it.state.collect { eyeState -> // Early out if the eye is not reported as tracking if (eyeState.trackingState != TrackingState.TRACKING) return@collect // We are only interested in the eye pose if it is open, so early out if it is // closed as well. if (!eyeState.isOpen) return@collect // The pose we get from the eye is the actual pose of the eye. We want to turn that // into something we can use for interacting with other objects in the scene (for // example, a hit test). To do that, we need to convert the eye pose into the // correct coordinate space, and then use it to create a `Ray` we can pass to the // `hitTest()` function. // // Unlike most other objects, which are reported in the perception coordinate space, // the eye pose is reported in the device coordinate space. So we'll first need to // convert the device pose into the activity space (via the perception space), and // then we can use that to convert the eye pose in to the activity space. val transformedPose = eyeState.pose.let { pose -> val headPose = session.scene.perceptionSpace.getScenePoseFromPerceptionPose( arDevice.state.value.devicePose ) headPose.transformPoseTo(pose, session.scene.activitySpace) } val gazeRay = Ray(transformedPose.translation, transformedPose.backward) val hits = hitTest(session, gazeRay) yourHitTestHandler(hits) } } }
| Throws | |
|---|---|
IllegalStateException |
if |
right
Added in 1.0.0-beta01
public static final @NonNull Eye right(@NonNull Session session)
Returns the right eye.
import androidx.xr.arcore.ArDevice import androidx.xr.arcore.Eye import androidx.xr.arcore.TrackingState import androidx.xr.arcore.hitTest import androidx.xr.runtime.Session import androidx.xr.runtime.math.Ray import androidx.xr.scenecore.scene // We need the ArDevice object to properly transform the eye pose coordinate space into // something we can use. val arDevice = ArDevice.getInstance(session) // Obtain the right eye from the Session object. Eye.right(session)?.let { // The left eye is available; launch a coroutine // to respond to changes in the eye's state. yourCoroutineScope.launch { it.state.collect { eyeState -> // Early out if the eye is not reported as tracking if (eyeState.trackingState != TrackingState.TRACKING) return@collect // We are only interested in the eye pose if it is open, so early out if it is // closed as well. if (!eyeState.isOpen) return@collect // The pose we get from the eye is the actual pose of the eye. We want to turn that // into something we can use for interacting with other objects in the scene (for // example, a hit test). To do that, we need to convert the eye pose into the // correct coordinate space, and then use it to create a `Ray` we can pass to the // `hitTest()` function. // // Unlike most other objects, which are reported in the perception coordinate space, // the eye pose is reported in the device coordinate space. So we'll first need to // convert the device pose into the activity space (via the perception space), and // then we can use that to convert the eye pose in to the activity space. val transformedPose = eyeState.pose.let { pose -> val headPose = session.scene.perceptionSpace.getScenePoseFromPerceptionPose( arDevice.state.value.devicePose ) headPose.transformPoseTo(pose, session.scene.activitySpace) } val gazeRay = Ray(transformedPose.translation, transformedPose.backward) val hits = hitTest(session, gazeRay) yourHitTestHandler(hits) } } }
| Throws | |
|---|---|
IllegalStateException |
if |