-
ARCamera是一个相机,它是连接虚拟场景与现实场景之间的枢纽。在ARKit中,它是捕捉现实图像的相机,在SceneKit中它又是3D虚拟世界中的相机。(一般第一人称3D游戏,主角其实就是一个3D相机,我们电脑屏幕看到的画面就是这个相机捕捉的画面)
- 一般我们无需去创建一个相机,因为当我们初始化一个AR试图时,他会为我们默认创建一个相机,而且这个相机就是摄像头的位置,同时也是3D世界中的原点所在(x=0,y=0,z=0)
- ARCamera的API一般我们无需关心,因为ARKit会默认帮助我们配置好
- 一般我们无需去创建一个相机,因为当我们初始化一个AR试图时,他会为我们默认创建一个相机,而且这个相机就是摄像头的位置,同时也是3D世界中的原点所在(x=0,y=0,z=0)
-
API介绍
@interface ARCamera : NSObject <NSCopying>
/**
4x4矩阵表示相机位置,同ARAnchor
*/
@property (nonatomic, readonly) matrix_float4x4 transform;
/**
相机方向(旋转)的矢量欧拉角
分别是x/y/z
*/
@property (nonatomic, readonly) vector_float3 eulerAngles;
/**
相机追踪状态(在下方会有枚举值介绍)
*/
@property (nonatomic, readonly) ARTrackingState trackingState NS_REFINED_FOR_SWIFT;
/**
追踪运动类型
*/
@property (nonatomic, readonly) ARTrackingStateReason trackingStateReason NS_REFINED_FOR_SWIFT;
/**
相机曲率(笔者有点费解,反复揣摩应该是与焦距相关参数)
3x3矩阵
fx 0 px
0 fy py
0 0 1
*/
@property (nonatomic, readonly) matrix_float3x3 intrinsics;
/**
摄像头分辨率
*/
@property (nonatomic, readonly) CGSize imageResolution;
/**
投影矩阵
*/
@property (nonatomic, readonly) matrix_float4x4 projectionMatrix;
/**
创建相机投影矩阵
*/
- (matrix_float4x4)projectionMatrixWithViewportSize:(CGSize)viewportSize orientation:(UIInterfaceOrientation)orientation zNear:(CGFloat)zNear zFar:(CGFloat)zFar;
@end
//相机追踪状态枚举
typedef NS_ENUM(NSInteger, ARTrackingState) {
/** 不被允许 */
ARTrackingStateNotAvailable,
/** 最小 */
ARTrackingStateLimited,
/** 正常. */
ARTrackingStateNormal,
} NS_REFINED_FOR_SWIFT;
/**
追踪运动类型
*/
API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(macos, watchos, tvos)
typedef NS_ENUM(NSInteger, ARTrackingStateReason) {
/** 无. */
ARTrackingStateReasonNone,
/** 运动. */
ARTrackingStateReasonExcessiveMotion,
/** 脸部捕捉. */
ARTrackingStateReasonInsufficientFeatures,
} NS_REFINED_FOR_SWIFT;
网友评论
typedef NS_ENUM(NSInteger, ARTrackingStateReason) {
/** Tracking is not limited. */
ARTrackingStateReasonNone,
/** Tracking is limited due to initialization in progress. */
ARTrackingStateReasonInitializing,
/** Tracking is limited due to a excessive motion of the camera. */
ARTrackingStateReasonExcessiveMotion,
/** Tracking is limited due to a lack of features visible to the camera. */
ARTrackingStateReasonInsufficientFeatures,
} NS_SWIFT_NAME(ARCamera.TrackingStateReason);