Jetpack XR 向け ARCore を使用すると、アプリはデバイスのポーズ(デバイスの向き(ピッチ、ヨー、ロール)と、ワールド原点に対するデバイスの位置(X、Y、Z))を取得できます。
この情報を使用して、現実世界にデジタル コンテンツをレンダリングしたり、デバイスのポーズを地理空間ポーズに変換して位置認識データを生成したりします。
セッションにアクセスする
デバイスのポーズ情報には、Jetpack XR Runtime の Session を通じてアクセスします。この Session は、アプリで作成する必要があります。
セッションを構成する
XR セッションでは、デバイスのポーズ情報はデフォルトで有効になっていません。アプリがデバイスのポーズ情報を取得できるようにするには、セッションを構成して DeviceTrackingMode.SPATIAL_LAST_KNOWN モードを設定します。
// 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. }
すべての XR デバイスが DeviceTrackingMode.SPATIAL_LAST_KNOWN モードをサポートしているわけではありません。Session.configure() が成功した場合、デバイスはこのモードをサポートしています。
デバイスのポーズを取得する
セッションを構成したら、ArDevice オブジェクトを使用して、AR 座標系内のデバイスのポーズを取得できます。
// 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. */) }