Jetpack XR용 ARCore를 사용하여 기기의 포즈 추적

적용 가능한 XR 기기
이 가이드에서는 이러한 유형의 XR 기기를 위한 환경을 빌드하는 방법을 설명합니다.
XR 헤드셋
유선 XR 안경

Jetpack XR용 ARCore를 사용하면 앱에서 기기의 포즈를 검색할 수 있습니다. 포즈는 세계 원점을 기준으로 기기의 방향 (피치, 요, 롤)과 위치 (X, Y, Z)입니다.

이 정보를 사용하여 실제 세계에서 디지털 콘텐츠를 렌더링하거나 기기 포즈를 지리공간 포즈로 변환하여 위치 인식 데이터를 생성합니다.

세션 액세스

앱에서 만들어야 하는 Jetpack XR 런타임 Session, 를 통해 기기 포즈 정보에 액세스합니다.

세션 구성

기기 포즈 정보는 XR 세션에서 기본적으로 사용 설정되지 않습니다. 앱에서 기기 포즈 정보를 검색할 수 있도록 세션을 구성하고 DeviceTrackingMode.SPATIAL_LAST_KNOWN 모드를 설정합니다.

// Define the configuration object to enable tracking device pose.
val newConfig = session.config.copy(
    deviceTracking = DeviceTrackingMode.SPATIAL_LAST_KNOWN
)
// Apply the configuration to the session.
try {
    when (val configResult = session.configure(newConfig)) {
        is SessionConfigureSuccess -> {
            // The session is now configured to track the device's pose.
        }
        else -> {
            // Catch-all for other configuration errors returned using the result class.
        }
    }
} catch (e: UnsupportedOperationException) {
    // Handle configuration failure. For example, if the specific mode is not supported on the current device or API version.
}

일부 XR 기기는 DeviceTrackingMode.SPATIAL_LAST_KNOWN 모드를 지원하지 않습니다. If Session.configure()가 성공하면 기기가 이 모드를 지원합니다.

기기 포즈 가져오기

세션을 구성한 후 AR 좌표계 내에서 기기의 포즈를 ArDevice 객체를 사용하여 가져올 수 있습니다.

// Get the ArDevice instance
val arDevice = ArDevice.getInstance(session)
// There are two ways to get the device pose.

// 1. Get the current device pose once.
// This is the device's position and orientation relative to the tracking origin.
val devicePose = arDevice.state.value.devicePose
processDevicePose(devicePose)

// 2. Continuously receive updates for the device pose.
// `collect` is a suspending function that will run indefinitely and process new poses.
arDevice.state.collect { state ->
    processDevicePose(state.devicePose)
}

기기 포즈의 변환 및 회전 가져오기

기기 Pose는 추적 원점을 기준으로 기기의 위치 (변환)와 방향(회전)을 나타냅니다. 앱에서 이 정보를 사용하여 앱 환경을 개선합니다.

  • 위치적으로 정확한 탐색 안내 제공: 위치 데이터를 사용하여 사용자가 디지털 콘텐츠를 오버레이하여 주변 환경을 파악하고 탐색하도록 지원합니다.

fun processDevicePose(pose: Pose) {
    // Extract Translation and Rotation
    val translation = pose.translation // Vector3(x, y, z)
    val rotation = pose.rotation // Quaternion (x, y, z, w)
    TODO(/* Use the translation and rotation in your app. */)
}