Jetpack XR için ARCore ile uygulamanız, cihazın pozunu (cihazın dünya başlangıcına göre 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.LAST_KNOWN modunu ayarlayın:
// Define the configuration object to enable tracking device pose. val newConfig = session.config.copy( deviceTracking = DeviceTrackingMode.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.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 kaynağına göre konumunu (çeviri) ve yönünü (dönüş) gösterir. Uygulamanızın deneyimini iyileştirmek için bu bilgileri kullanın:
Konum açısından doğru gezinme talimatları sağlama: Konum verileri, kullanıcının yönünü bulmasına ve yer paylaşımlı dijital içeriklerin yardımıyla çevresinde gezinmesine yardımcı olmak için kullanılabilir.
Ara dünya hizalamasını hesaplama: Bu duruş, gerçek dünya konumunu hesaplamak için Geospatial API tarafından kullanılır.
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. */) }
Cihaz pozunu coğrafi uzamsal poza dönüştürme
Cihaz pozunu aldıktan sonra bu pozdan coğrafi poz elde edebilirsiniz. Coğrafi uzamsal duruşa dönüştürme, AR içeriğinizi geçici ve izole bir deneyimden gerçek dünyada kalıcı, evrensel olarak paylaşılan ve bağlama duyarlı bir özelliğe dönüştürür.
Geospatial API dokümanlarından cihaz duruşunu coğrafi duruşa dönüştürmeyi öğrenin.