ARKit: ARCameraのシーン内座標はcamera.transform.columns.3から得られるのはなぜか

p0dee
Jun 19, 2021

--

調べるとよくそう書かれている。

let col3 = frame.camera.transform.columns.3
let cameraPosition = SCNVector3(col3.x, col3.y, col3.z)

このtransform.columns.3とは一体何なのか、、

ARCamera.transformは世界座標系における回転/移動を表した変換行列である。

The position and orientation of the camera in world coordinate space.
ARCamera / transform

ちなみに、このtranslationはもちろんSCNNodeも持っており、ARCameraと異なるのはスケール成分も含んでいる点だ。

The transformation is the combination of the node’s rotation, position, and scale properties.
SCNNode / transform

ARCameraSCNNodetransformの違いはこの他にも型にあり、前者がsimd_float4x4、後者がSCNMatrix4によって表現されるが、どちらも4x4の行列を表す。

ARCamera.transformの場合、この行列が次のように回転成分と移動成分を含んでいるから、このうち(0…2, 3)要素がシーン空間におけるカメラ座標(x, y, z)に対応している。だからcamera.transform.coulmns.3を用いるのだ。

参考: Geometric Transformations

ちなみに、ARKitを触っていると、SCNMatrix4SCNVector3に混じってsimd_float4x4が入り乱れてややこしい。SCN接頭辞は名前の通りSceneKit由来、いっぽう後者のsimd接頭辞は、Accelerateという大規模数理計算や画像処理を扱うフレームワーク由来で、ARKit内ではこちらを用いているようだ。

--

--