美文网首页
ARCamera的transform

ARCamera的transform

作者: loongod | 来源:发表于2020-12-08 10:51 被阅读0次
    /**
     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 中的数据是相对于开始的原点和坐标系的位移和旋转。

相关文章

网友评论

      本文标题:ARCamera的transform

      本文链接:https://www.haomeiwen.com/subject/xslfgktx.html