# Eye

Artifact: [androidx.xr.arcore:arcore](https://developer.android.com/jetpack/androidx/releases/xr-arcore) [View Source](https://cs.android.com/search?q=file:androidx/xr/arcore/Eye.kt+class:androidx.xr.arcore.Eye) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-arcore#1.0.0)

*** ** * ** ***


```
class Eye : Trackable<Eye.State>
```

<br />

*** ** * ** ***

A representation of a user's eye.

An `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye` instance provides the state of the eye (shut or gazing), as well as a `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` indicating where the user is currently looking.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye.State : https://developer.android.com/reference/kotlin/androidx/xr/arcore/Trackable.State` The representation of the current state of an `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye`. |

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye` | `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye#left(androidx.xr.runtime.Session)(session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session)` Returns the left eye. |
| `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye` | `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye#right(androidx.xr.runtime.Session)(session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session)` Returns the right eye. |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye#toString()()` Returns a string representation of `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye` for debugging. |

| ### Public properties |
|---|---|
| `open https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html<https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye.State>` | `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye#state()` A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html` that contains the latest `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye.State` of an `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye`. |

## Public companion functions

### left

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-arcore#1.0.0)

```
fun left(session: Session): Eye
```

Returns the left eye.

```kotlin
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)
        }
    }
}
```

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` to retrieve the eye from |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Config#eyeTracking()` is set to `https://developer.android.com/reference/kotlin/androidx/xr/runtime/EyeTrackingMode#DISABLED()` |

### right

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-arcore#1.0.0)

```
fun right(session: Session): Eye
```

Returns the right eye.

```kotlin
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)
        }
    }
}
```

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` to retrieve the eye from |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Config#eyeTracking()` is set to `https://developer.android.com/reference/kotlin/androidx/xr/runtime/EyeTrackingMode#DISABLED()` |

## Public functions

### toString

```
open fun toString(): String
```

Returns a string representation of `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye` for debugging.

Note: Not intended for production use.

## Public properties

### state

```
open val state: StateFlow<Eye.State>
```

A `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-state-flow/index.html` that contains the latest `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye.State` of an `https://developer.android.com/reference/kotlin/androidx/xr/arcore/Eye`.