08-ARCamera介绍

8.1概述###

ARCamera是一个相机,它是连接虚拟场景与现实场景之间的枢纽。在ARKit中,它是捕捉现实图像的相机,在SceneKit中它又是3D虚拟世界中的相机。(一般第一人称3D游戏,主角其实就是一个3D相机,我们电脑屏幕看到的画面就是这个相机捕捉的画面)。
一般我们无需去创建一个相机,因为当我们初始化一个AR视图时,他会为我们默认创建一个相机,而且这个相机就是摄像头的位置,同时也是3D世界中的原点所在(x=0,y=0,z=0)ARCamera的API一般我们无需关心,因为ARKit会默认帮助我们配置好。

8.2 ARCamera API截图###

08-ARCamera介绍_第1张图片
image.png
08-ARCamera介绍_第2张图片
image.png

8.3 ARCamera API源码


/**
描述相机追踪的状态
A value describing the camera's tracking state.
*/
@available(iOS 11.0, *)
public enum __ARTrackingState : Int {

/** Tracking is not available.追踪不被允许 */
case notAvailable


/** Tracking is limited. See tracking reason for details.追踪有限,查看追踪原因的详细信息 */
case limited


/** Tracking is Normal. 正常*/
case normal

}

/**说明为什么相机的追踪状态有限的原因
A reason describing why the camera's tracking state is limited.
*/
@available(iOS 11.0, *)
public enum __ARTrackingStateReason : Int {

/** Tracking is not limited. 追踪不受限制*/
case none


/** Tracking is limited due to a excessive motion of the camera.由于相机的过度运动,追踪受到限制 */
case excessiveMotion


/** Tracking is limited due to a lack of features visible to the camera.由于缺少相机可见的功能,追踪受到限制 */
case insufficientFeatures

}

/**
A model representing the camera and its parameters.
*/
@available(iOS 11.0, *)
open class ARCamera : NSObject, NSCopying {

/**4*4矩阵表示相机位置,同ARAnchor
 The transformation matrix that defines the camera's rotation and translation in world coordinates.

在世界坐标系中定义相机旋转和平移的变换矩阵。
*/
open var transform: matrix_float4x4 { get }

/**相机方向(旋转)的矢量欧拉角
   分别是x/y/z
 The camera's orientation defined as Euler angles.
 
 @dicussion The order of components in this vector matches the axes of rotation:
               1. Pitch (the x component) is the rotation about the node's x-axis (in radians)
               2. Yaw   (the y component) is the rotation about the node's y-axis (in radians)
               3. Roll  (the z component) is the rotation about the node's z-axis (in radians)
            ARKit applies these rotations in the reverse order of the components:
               1. first roll
               2. then yaw
               3. then pitch
 */
open var eulerAngles: vector_float3 { get }


/**追踪运动类型
 The tracking state of the camera.
 */
open var __trackingState: __ARTrackingState { get }


/**
 The reason for the camera's current tracking state.
 */
open var __trackingStateReason: __ARTrackingStateReason { get }


/**相机曲率(笔者有点费解,反复揣摩应该是与焦距相关参数)
 The camera intrinsics.
 @discussion The matrix has the following contents:
 fx 0   px
 0  fy  py
 0  0   1
 fx and fy are the focal length in pixels.
 px and py are the coordinates of the principal point in pixels.
 The origin is at the center of the upper-left pixel.
 */
open var intrinsics: matrix_float3x3 { get }


/**摄像头分辨率
 The camera image resolution in pixels.
 */
open var imageResolution: CGSize { get }


/**投影矩阵
 The projection matrix of the camera.
*/
open var projectionMatrix: matrix_float4x4 { get }


/**创建相机投影矩阵
 Creates a projection matrix for the camera given rendering parameters.
 
 @discussion The projection matrix returned provides an aspect fill and rotation for the provided viewport size and orientation.
 @param viewportSize Viewport size.
 @param orientation Viewport orientation.
 @param zNear Near depth limit.
 @param zFar Far depth limit.
 */
open func projectionMatrix(withViewportSize viewportSize: CGSize, orientation: UIInterfaceOrientation, zNear: CGFloat, zFar: CGFloat) -> matrix_float4x4

}

你可能感兴趣的:(08-ARCamera介绍)