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 postur perangkat menjadi postur geospasial untuk menghasilkan data yang mengetahui lokasi.
Mengakses sesi
Akses informasi postur 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
DeviceTrackingMode.SPATIAL:
// Define the configuration object to enable tracking device pose. val newConfig = session.config.copy( deviceTracking = DeviceTrackingMode.SPATIAL ) // 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 DeviceTrackingMode.SPATIAL. Jika
Session.configure() berhasil, perangkat mendukung mode ini.
Mendapatkan pose perangkat
Setelah mengonfigurasi sesi, Anda dapat memperoleh pose perangkat dalam sistem koordinat AR menggunakan objek 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) }
Mendapatkan terjemahan dan rotasi pose perangkat
Pose perangkat merepresentasikan posisi (terjemahan) dan orientasi
(rotasi) perangkat relatif terhadap asal pelacakan. Gunakan informasi ini di aplikasi Anda untuk
meningkatkan pengalaman aplikasi Anda:
- Memberikan petunjuk navigasi yang akurat secara posisi: Gunakan data posisi untuk membantu pengguna memahami posisi mereka dan menavigasi lingkungan sekitar dengan bantuan konten digital yang ditampilkan di atasnya.
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. */) }