Jetpack XR 用 ARCore を使用してデバイスのポーズをトラッキングする

対応する XR デバイス
このガイダンスは、次のようなタイプの XR デバイス向けのエクスペリエンスを構築する際に役立ちます。
[
XR Headsets
]
有線 XR グラス

Jetpack XR 用の ARCore を使用すると、アプリはデバイスの ポーズを取得できます。これは、デバイスの 向き(ピッチ、ヨー、ロール)と、ワールド原点に対するデバイスの位置(X、Y、Z)です。

この情報を使用して、現実世界にデジタル コンテンツをレンダリングしたり、デバイスのポーズを地理空間ポーズに変換して位置情報対応データを生成したりできます。

セッションにアクセスする

デバイスのポーズ情報にアクセスするには、アプリで作成する必要がある Jetpack XR ランタイム Session, を使用します。

セッションを構成する

XR セッションでは、デバイスのポーズ情報はデフォルトで有効になっていません。アプリでデバイスのポーズ情報を取得できるようにするには、セッションを構成して 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.
}

すべての XR デバイスが DeviceTrackingMode.SPATIAL モードをサポートしているわけではありません。 Session.configure() が成功した場合、デバイスはこのモードをサポートしています。

デバイスのポーズを取得する

セッションを構成したら、 AR 座標系内のデバイスのポーズを 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. */)
}