Contents

PerspectiveCameraComponent

A component that defines a virtual camera and its controls.

Declaration

struct PerspectiveCameraComponent

Overview

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.

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 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.

Topics

Creating a camera component

Setting focal points

Setting the field of view

See Also

Cameras