ARCore for Jetpack XR を使用すると、アプリはデバイスのポーズ(デバイスの向き(ピッチ、ヨー、ロール)と、ワールド原点を基準としたデバイスの位置(X、Y、Z))を取得できます。
この情報を使用して、現実世界にデジタル コンテンツをレンダリングしたり、デバイスのポーズを地理空間ポーズに変換して位置認識データを生成したりできます。
セッションにアクセスする
Jetpack XR ランタイム Session を介してデバイスのポーズ情報にアクセスします。これはアプリで作成する必要があります。
セッションを構成する
デバイスのポーズ情報は、XR セッションではデフォルトで有効になっていません。アプリでデバイスのポーズ情報を取得できるようにするには、セッションを構成し、DeviceTrackingMode.SPATIAL モードを設定します。
// Define the configuration object to enable tracking device pose. val newConfig = Config.Builder(session.config) .setDeviceTracking(DeviceTrackingMode.SPATIAL) .build() // 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 モードをサポートしているわけではありません。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. */) }