A component that defines a virtual camera and its controls.
Each scene requires a camera that defines the viewpoint from
which RealityKit renders the scene.
In RealityKit, the default camera is a *perspective camera*,
which simulates the way real cameras and human vision work.
Entities that are farther away from the camera render smaller.
For an alternative camera solution, see ``OrthographicCameraComponent``.
To create a perspective camera, add this component to an entity.
```swift
let cameraEntity = Entity()
// Place the camera 2 meters along the z-axis,
// looking at the scene origin.
let cameraPosition: SIMD3<Float> = [0, 0, 2]
cameraEntity.look(at: .zero, from: cameraPosition, relativeTo: nil)
cameraEntity.components.set(PerspectiveCameraComponent())
```
A `PerspectiveCameraComponent` defines the camera settings for a
perspective camera, such as the ``fieldOfViewInDegrees``.
The entity’s ``HasTransform/transform`` defines the camera entity’s viewpoint and direction.
The direction it points is along the entity's negative z-axis.
In AR scenarios, the system provides the camera automatically;
however, in non-AR scenarios, the app needs to set the camera.
If the app doesn't provide a camera, the system uses the default perspective camera.
Members (10)
get · iOS 13.0+
fieldOfViewInDegrees
TypeScript
get fieldOfViewInDegrees(): number
Swift declaration
var fieldOfViewInDegrees: Float
The camera's total field of view in degrees.
This property contains the entire field of view for the
camera in degrees.
When you set ``fieldOfViewOrientation`` to
``CameraFieldOfViewOrientation/vertical``,
this value sets the vertical field of view for the camera in degrees,
and the system automatically calculates the horizontal field of view
to fit the aspect ratio of the device's screen.
This property defaults to `60` degrees.
set · iOS 13.0+
fieldOfViewInDegrees
TypeScript
set fieldOfViewInDegrees(value: number)
Swift declaration
var fieldOfViewInDegrees: Float
The camera's total field of view in degrees.
This property contains the entire field of view for the
camera in degrees.
When you set ``fieldOfViewOrientation`` to
``CameraFieldOfViewOrientation/vertical``,
this value sets the vertical field of view for the camera in degrees,
and the system automatically calculates the horizontal field of view
to fit the aspect ratio of the device's screen.
This property defaults to `60` degrees.
get · iOS 18.0+
fieldOfViewOrientation
TypeScript
get fieldOfViewOrientation(): CameraFieldOfViewOrientation
Swift declaration
var fieldOfViewOrientation: CameraFieldOfViewOrientation
The orientation with which the system uses to apply the field-of-view degrees.
The value of this property determines the orientation that
the system uses to apply the ``fieldOfViewInDegrees`` value.
This property defaults to ``CameraFieldOfViewOrientation/vertical``.
set · iOS 18.0+
fieldOfViewOrientation
TypeScript
set fieldOfViewOrientation(value: CameraFieldOfViewOrientation)
Swift declaration
var fieldOfViewOrientation: CameraFieldOfViewOrientation
The orientation with which the system uses to apply the field-of-view degrees.
The value of this property determines the orientation that
the system uses to apply the ``fieldOfViewInDegrees`` value.
This property defaults to ``CameraFieldOfViewOrientation/vertical``.
get · iOS 13.0+
far
TypeScript
get far(): number
Swift declaration
var far: Float
The maximum distance in meters from the camera that the camera can see.
The value defaults to `infinity`. Use a value greater than the
value of ``PerspectiveCameraComponent/near``.
The renderer clips any surface beyond the `far` point.
set · iOS 13.0+
far
TypeScript
set far(value: number)
Swift declaration
var far: Float
The maximum distance in meters from the camera that the camera can see.
The value defaults to `infinity`. Use a value greater than the
value of ``PerspectiveCameraComponent/near``.
The renderer clips any surface beyond the `far` point.
Creates a perspective camera component from near and far clipping planes,
a field of view, and an orientation.
- Parameters:
- near: The minimum distance in meters from the camera that the camera can see.
- far: The maximum distance in meters from the camera that the camera can see.
- fieldOfViewInDegrees: The camera's field of view in degrees.
- fieldOfViewOrientation: The orientation of the field of view.
Creates a perspective camera component from near and far clipping planes and a field of view.
- Parameters:
- near: The minimum distance in meters from the camera that the camera
can see.
- far: The maximum distance in meters from the camera that the camera
can see.
- fieldOfViewInDegrees: The camera's field of view, in degrees.
get · iOS 13.0+
near
TypeScript
get near(): number
Swift declaration
var near: Float
The minimum distance in meters from the camera that the camera can see.
The value defaults to `1.0` centimeter. Use a value greater than `0.0`
and less than the value of ``PerspectiveCameraComponent/far``.
The renderer clips any surface closer than the `near` point.
set · iOS 13.0+
near
TypeScript
set near(value: number)
Swift declaration
var near: Float
The minimum distance in meters from the camera that the camera can see.
The value defaults to `1.0` centimeter. Use a value greater than `0.0`
and less than the value of ``PerspectiveCameraComponent/far``.
The renderer clips any surface closer than the `near` point.