Magnum::Trade::CameraData class

Camera data.

Provides access to perspective and orthographic camera properties. Populated instances of this class are returned from AbstractImporter::camera() and can be passed to AbstractSceneConverter::add(const CameraData&, Containers::StringView). Similarly to other Trade types, the internal representation is fixed upon construction and doesn't allow any modification afterwards.

Constructors, destructors, conversion operators

CameraData(CameraType type, Rad fov, Float aspectRatio, Float near, Float far, const void* importerState = nullptr) explicit noexcept
Construct a camera using a field of view.
CameraData(CameraType type, const Vector2& size, Float near, Float far, const void* importerState = nullptr) explicit noexcept
Construct a camera using a projection size.
CameraData(const CameraData&) deleted
Copying is not allowed.
CameraData(CameraData&&) defaulted noexcept
Move constructor.

Public functions

auto operator=(const CameraData&) -> CameraData& deleted
Copying is not allowed.
auto operator=(CameraData&&) -> CameraData& defaulted noexcept
Move assignment.
auto type() const -> CameraType
Camera type.
auto size() const -> Vector2
Size of the near clipping plane.
auto fov() const -> Rad
Field-of-view angle.
auto aspectRatio() const -> Float
Aspect ratio.
auto near() const -> Float
Near clipping plane.
auto far() const -> Float
Far clipping plane.
auto importerState() const -> const void*
Importer-specific state.

Function documentation

Magnum::Trade::CameraData::CameraData(CameraType type, Rad fov, Float aspectRatio, Float near, Float far, const void* importerState = nullptr) explicit noexcept

Construct a camera using a field of view.

Parameters
type Camera type
fov Horizontal field-of-view angle $ \theta $
aspectRatio Horizontal:vertical aspect ratio $ a $
near Near clipping plane $ n $
far Far clipping plane $ f $ . Set to Constants::inf() for an infinite far plane.
importerState Importer-specific state

The constructor converts the fov and aspectRatio to near plane size using the following formula and stores that:

\[ \boldsymbol{s} = 2n \tan \left(\tfrac{\theta}{2} \right) \begin{pmatrix} 1 \\ \frac{1}{a} \end{pmatrix} \]

The type parameter has to be CameraType::Perspective3D, use CameraData(CameraType, const Vector2&, Float, Float, const void*) for orthographic and 2D cameras instead.

Magnum::Trade::CameraData::CameraData(CameraType type, const Vector2& size, Float near, Float far, const void* importerState = nullptr) explicit noexcept

Construct a camera using a projection size.

Parameters
type Camera type
size Size of the near clipping plane
near Near clipping plane
far Far clipping plane. Set to Constants::inf() for an infinite far plane.
importerState Importer-specific state

For CameraType::Orthographic2D, near and far is expected to be 0.0f.

Vector2 Magnum::Trade::CameraData::size() const

Size of the near clipping plane.

For CameraType::Perspective3D, this property is also available through fov() and aspectRatio().

Rad Magnum::Trade::CameraData::fov() const

Field-of-view angle.

Expects that type() is CameraType::Perspective3D. The value is calculated from size() using the following formula:

\[ \theta = 2 \arctan \left( \frac{s_x}{2n} \right) \]

Float Magnum::Trade::CameraData::aspectRatio() const

Aspect ratio.

Similarly to fov(), the value is calculated from size().

Float Magnum::Trade::CameraData::far() const

Far clipping plane.

Can be set to infinity, in which case it denotes a lack of far clipping plane.

const void* Magnum::Trade::CameraData::importerState() const

Importer-specific state.

See AbstractImporter::importerState() for more information.