Jetpack XR के लिए ARCore की मदद से, आपका ऐप्लिकेशन किसी डिवाइस की पोज़ को वापस पा सकता है. इसमें, डिवाइस का ओरिएंटेशन (पिच, यॉ, रोल) और दुनिया के ऑरिजन के हिसाब से डिवाइस की पोज़िशन (X, Y, Z) शामिल है.
इस जानकारी का इस्तेमाल, असल दुनिया में डिजिटल कॉन्टेंट दिखाने के लिए करें. इसके अलावा, डिवाइस की पोज़ को जियोस्पेशल पोज़ में बदलकर, जगह की जानकारी देने वाला डेटा जनरेट करें.
सेशन ऐक्सेस करना
Jetpack XR Runtime Session के ज़रिए, डिवाइस की पोज़ की जानकारी ऐक्सेस करें.
यह सेशन, आपके ऐप्लिकेशन को बनाना होगा.
सेशन कॉन्फ़िगर करना
एक्सआर सेशन में, डिवाइस की पोज़ की जानकारी डिफ़ॉल्ट रूप से चालू नहीं होती. अपने
ऐप्लिकेशन को डिवाइस की पोज़ की जानकारी वापस पाने की अनुमति देने के लिए, सेशन को कॉन्फ़िगर करें और
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. }
सभी एक्सआर डिवाइसों पर, DeviceTrackingMode.SPATIAL मोड काम नहीं करता. अगर
Session.configure() काम करता है, तो इसका मतलब है कि डिवाइस पर यह मोड काम करता है.
डिवाइस की पोज़ पाना
सेशन को कॉन्फ़िगर करने के बाद,
एआर कोऑर्डिनेट सिस्टम में डिवाइस की पोज़ पाई जा सकती है, जिसके लिए 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) }
डिवाइस की पोज़ का ट्रांसलेशन और रोटेशन पाना
डिवाइस की Pose, ट्रैकिंग ऑरिजन के हिसाब से डिवाइस की पोज़िशन (ट्रांसलेशन) और ओरिएंटेशन (रोटेशन) को दिखाती है. अपने ऐप्लिकेशन के अनुभव को बेहतर बनाने के लिए, इस जानकारी का इस्तेमाल करें:
- पोज़िशन के हिसाब से सटीक नेविगेशन के निर्देश देना: पोज़िशन से जुड़े डेटा का इस्तेमाल करके, उपयोगकर्ता को अपनी जगह का पता लगाने और डिजिटल कॉन्टेंट की मदद से अपने आस-पास की जगह पर नेविगेट करने में मदद करें.
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. */) }