Jetpack XR için ARCore ile uygulamanız, cihazın pozunu (dünyanın başlangıç noktasına göre cihazın yönü [eğim, sapma, yuvarlanma] ve konumu [X, Y, Z]) alabilir.
Bu bilgileri, dijital içeriği gerçek dünyada oluşturmak veya konuma duyarlı veriler oluşturmak için cihaz pozunu coğrafi uzamsal poza dönüştürmek amacıyla kullanın.
Bir oturuma erişme
Cihaz duruşu bilgilerine, Session Jetpack XR Runtime üzerinden erişin.
Bu uygulamanız tarafından oluşturulmalıdır.
Oturumu yapılandırma
Cihaz duruşu bilgileri, XR oturumlarında varsayılan olarak etkin değildir. Uygulamanızın cihaz duruşu bilgilerini almasını sağlamak için oturumu yapılandırın ve DeviceTrackingMode.SPATIAL_LAST_KNOWN modunu ayarlayın:
// 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. }
DeviceTrackingMode.SPATIAL_LAST_KNOWN modu tüm XR cihazlarda desteklenmez. Session.configure() başarılı olursa cihaz bu modu destekler.
Cihaz pozunu elde etme
Oturumu yapılandırdıktan sonra, ArDevice nesnesini kullanarak cihazın AR koordinat sistemindeki duruşunu elde edebilirsiniz:
// 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) }
Cihaz pozunun çevirisini ve dönüşünü alma
Cihaz Pose, cihazın izleme başlangıcına göre konumunu (öteleme) ve yönünü (dönme) temsil eder. Uygulamanızın deneyimini iyileştirmek için bu bilgileri kullanın:
- Konum açısından doğru gezinme talimatları sağlama: Kullanıcının yönünü bulmasına ve yer paylaşımlı dijital içerik yardımıyla çevresinde gezinmesine yardımcı olmak için konum verilerini kullanın.
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. */) }