Melacak pose perangkat menggunakan ARCore untuk Jetpack XR

Perangkat XR yang kompatibel
Panduan ini membantu Anda membangun pengalaman untuk jenis perangkat XR ini.
Headset XR
Kacamata XR Berkabel
Kacamata AI

Dengan ARCore untuk Jetpack XR, aplikasi Anda dapat mengambil pose perangkat: orientasi (pitch, yaw, roll) dan posisi (X, Y, Z) perangkat relatif terhadap asal dunia.

Gunakan informasi ini untuk merender konten digital di dunia nyata, atau mengonversi pose perangkat menjadi pose geospasial untuk menghasilkan data yang mengetahui lokasi.

Mengakses sesi

Akses informasi pose perangkat melalui Session Jetpack XR Runtime, yang harus dibuat oleh aplikasi Anda.

Mengonfigurasi sesi

Informasi pose perangkat tidak diaktifkan secara default pada sesi XR. Untuk mengaktifkan aplikasi Anda mengambil informasi pose perangkat, konfigurasi sesi dan tetapkan mode 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.
}

Tidak semua perangkat XR mendukung mode HeadTrackingMode.LAST_KNOWN. Jika Session.configure() berhasil, perangkat mendukung mode ini.

Mendapatkan pose perangkat

Setelah sesi dikonfigurasi, Anda dapat memperoleh pose perangkat dalam sistem koordinat AR menggunakan objek ArDevice:

// 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

Mendapatkan terjemahan dan rotasi pose perangkat

Perangkat Pose merepresentasikan posisi (terjemahan) dan orientasi (rotasi) perangkat relatif terhadap asal pelacakan. Gunakan informasi ini di aplikasi Anda untuk meningkatkan pengalaman aplikasi Anda:

  1. Memberikan petunjuk navigasi yang akurat secara posisi: Data posisi dapat digunakan untuk membantu pengguna mengorientasikan diri dan menavigasi lingkungan sekitar dengan bantuan konten digital yang ditumpuk.

  2. Penyelarasan dunia menengah: Pose ini digunakan oleh Geospatial API untuk menghitung lokasi dunia nyata.

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

Mengonversi pose perangkat menjadi pose geospasial

Setelah memiliki pose perangkat, Anda dapat memperoleh pose geospasial darinya. Mengonversi ke pose geospasial akan mengubah konten AR Anda dari pengalaman sementara dan terisolasi menjadi fitur permanen, yang dibagikan secara universal, dan sadar konteks di dunia nyata.

Pelajari cara mengonversi pose perangkat menjadi pose geospasial dalam dokumentasi Geospatial API kami.