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

해당 XR 기기
이 안내는 이러한 유형의 XR 기기용 환경을 구축하는 데 도움이 됩니다.
XR 헤드셋
유선 XR 안경
AI 글래스

Jetpack XR용 ARCore를 사용하면 앱이 기기의 포즈, 즉 세계 원점에 대한 기기의 방향 (피치, 요, 롤)과 위치 (X, Y, Z)를 가져올 수 있습니다.

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

세션 액세스

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

세션 구성

기기 포즈 정보는 XR 세션에서 기본적으로 사용 설정되지 않습니다. 앱이 기기 포즈 정보를 가져올 수 있도록 세션을 구성하고 HeadTrackingMode.LAST_KNOWN 모드를 설정합니다.

// Define the configuration object to enable tracking device pose.
val newConfig = session.config.copy(
    headTrackingMode = Config.HeadTrackingMode.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 기기는 HeadTrackingMode.LAST_KNOWN 모드를 지원하지 않습니다. Session.configure()이 성공하면 기기는 이 모드를 지원합니다.

기기 포즈 가져오기

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

// Get the ArDevice instance
val arDevice = ArDevice.getInstance(session)

// Collect the state to process the device pose
arDevice.state.collect { state ->
      // processDevicePose gets called automatically when a new pose is available.
      processDevicePose(state.devicePose)
}

// Or, get the current device Pose from the AR Device's state.
// This is the device's position and orientation relative to the tracking origin.
val devicePose = ArDevice.getInstance(session).state.value.devicePose

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

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

  1. 위치적으로 정확한 탐색 안내 제공: 위치 데이터를 사용하면 사용자가 오버레이된 디지털 콘텐츠의 도움을 받아 주변 환경을 파악하고 탐색할 수 있습니다.

  2. 중간 세계 정렬: 이 포즈는 Geospatial API에서 실제 위치를 계산하는 데 사용됩니다.

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. */)
}

기기 포즈를 지리 공간적 포즈로 변환

기기 포즈가 있으면 이를 통해 지리 공간 포즈를 가져올 수 있습니다. 지리 공간 포즈로 변환하면 AR 콘텐츠가 일시적이고 고립된 경험에서 영구적이고 보편적으로 공유되며 실제 세계에서 컨텍스트를 인식하는 기능으로 바뀝니다.

지리 공간 API 문서에서 기기 포즈를 지리 공간적 포즈로 변환하는 방법을 알아보세요.