3
3

More than 1 year has passed since last update.

デバイスの位置って重要

ARはユーザーとARコンテンツのインタラクションなので、ユーザーの視点の位置=デバイスの位置は大事です。

ARKitでデバイスの位置を取得できます

デバイス位置取得

func session(_ session: ARSession, didUpdate frame: ARFrame) {
    let transform = frame.camera.transform.columns.3
    let devicePosition = simd_float3(x: transform.x, y: transform.y, z: transform.z)
    print(devicePosition)
}

SIMD3(0.0, 0.0, 0.0)
SIMD3(9.0870006e-10, 4.1317643e-09, -3.1889111e-09)
SIMD3(-2.9535964e-05, -4.5597553e-06, -9.115785e-06)
SIMD3(-3.6674974e-05, -2.1950224e-05, -2.2978664e-05)

X軸Y軸Z軸の座標が得られます。

対象座標との距離

let objectPosition = node.simdWorldPosition
distance(devicePosition,objectPosition)

1.0562732

メートル単位です。

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

Core MLやARKitを使ったアプリを作っています。
機械学習/AR関連の情報を発信しています。

Twitter
Medium
GitHub

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3