Skip to content

PerspectiveCamera

Represents a camera that uses perspective projection.

This projection mode is designed to mimic the way the human eye sees. It is the most common projection mode used for rendering a 3D scene.

Although multiple cameras can be added to the scene graph and inherit transformations from their parent objects, only one camera can be active at a time. The active camera is managed by the application’s runtime object:

cpp
class MyApp : public vglx::Application {
public:
  auto Configure() -> void override {}

  auto Setup() -> void override {
    SetCamera(vglx::PerspectiveCamera::Create({
      .fov = vglx::math::DegToRad(60.0f),
      .aspect = Context()->Parameters().ratio,
      .near = 0.1f,
      .far = 1000.0f
    }));
  }

  auto Update(float delta) -> bool override {
    return true;
  }
}

INFO

Derives from Camera and inherits all public properties and methods.

Construction

Constructors


PerspectiveCamera()

cpp
vglx::PerspectiveCamera::PerspectiveCamera(const Parameters &params)
ParameterDescription
paramsPerspectiveCamera::Parameters

Constructs an PerspectiveCamera object.

Factories preferred


PerspectiveCamera::Create() std::shared_ptr<PerspectiveCamera>

cpp
static std::shared_ptr< PerspectiveCamera > vglx::PerspectiveCamera::Create(const Parameters &params)
ParameterDescription
paramsPerspectiveCamera::Parameters

Creates a shared pointer to PerspectiveCamera object.

Types

PerspectiveCamera::Parameters struct

Parameters for constructing an PerspectiveCamera object.

NameTypeDescription
aspectfloatAspect ratio.
farfloatDistance to the far clipping plane.
fovfloatVertical field of view in radians.
nearfloatDistance to the near clipping plane.

Functions

Resize() void virtual

cpp
void vglx::PerspectiveCamera::Resize(int width, int height) override
ParameterDescription
widthViewport width in pixels.
heightViewport height in pixels.

Updates the projection transform to match the new viewport size.

SetLens() void

cpp
void vglx::PerspectiveCamera::SetLens(float fov, float near, float far)
ParameterDescription
fovVertical field of view in radians.
nearDistance to the near clipping plane.
farDistance to the far clipping plane.

Configures perspective projection parameters. Updates the camera's vertical field of view, near plane, and far plane, and rebuilds the projection transform accordingly. The aspect ratio remains unchanged until Resize is called.

Released under the MIT License.