ARCamera的transform

    /**
     The transformation matrix that defines the camera’s rotation and translation in world coordinates.
     轉換矩陣,用於定義相機在世界座標系中的旋轉和平移。
     */
    open var transform: simd_float4x4 { get }

介紹: 轉換矩陣,用於定義相機在世界座標系中的旋轉和平移。

transform 是一個 4x4 矩陣。關於矩陣中信息的介紹,推薦看這個matrix

        0  1  2  3
     ┌              ┐ 
     |  1  0  0  0  |   X
     |  0  1  0  0  |   Y
     |  0  0  1  0  |   Z
     |  0  0  0  1  |   W
     └              ┘
        X  Y  Z  W

這裏還是記錄下 camera.transform 的介紹

World coordinate space in ARKit always follows a right-handed convention, but is oriented based on the session configuration. For details, see Understanding World Tracking.
This transform creates a local coordinate space for the camera that is constant with respect to device orientation. In camera space, the x-axis points to the right when the device is in UIDeviceOrientation.landscapeRight orientation—that is, the x-axis always points along the long axis of the device, from the front-facing camera toward the Home button. The y-axis points upward (with respect to UIDeviceOrientation.landscapeRight orientation), and the z-axis points away from the device on the screen side.

在攝像頭空間中,當設備處於 UIDeviceOrientation.landscapeRight 方向時,x 軸指向右側,即,x 軸始終沿設備的長軸指向,從前置攝像頭指向 **Home** 按鈕。 y軸指向上方(相對於UIDeviceOrientation.landscapeRight 方向),z 軸指向遠離屏幕側設備的位置。

在所有 AR 體驗中,ARKit 都遵循 右手習慣 使用世界和相機座標系:y 軸指向上方,z 軸指向觀看者,x 軸指向觀看者的右邊。

根據 camera.transform 的介紹可知,在 landscapeRight 時的座標系。ARKit 會話的座標系將取決於 session configuration

    /**
     Determines how the coordinate system should be aligned with the world.
     @discussion The default is ARWorldAlignmentGravity.
     */
    open var worldAlignment: ARConfiguration.WorldAlignment

    /**
     Enum constants for indicating the world alignment.
     */
    @available(iOS 11.0, *)
    public enum WorldAlignment : Int {
        /** Aligns the world with gravity that is defined by vector (0, -1, 0). */
        case gravity = 0

        /** Aligns the world with gravity that is defined by the vector (0, -1, 0)
         and heading (w.r.t. True North) that is given by the vector (0, 0, -1). */
        case gravityAndHeading = 1

        /** Aligns the world with the camera’s orientation. */
        case camera = 2
    }
  • gravity:座標系的y軸與重力平行,其原點和 x-z 方向是設備的初始位置和方向。

  • gravityAndHeading:與重力相同,增加的 x 軸指向東方,z 軸指向南方。

  • camera: 鎖定座標系以匹配攝像機位置和方向,並在攝像機移動時跟隨。

ARConfigurationopen var worldAlignment: ARConfiguration.WorldAlignment 的默認值是 ARWorldAlignmentGravity,也即是 gravity

也就是說,如無指定 worldAlignmentcameratransform 中的數據是相對於開始的原點和座標系的位移和旋轉。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章