PerspectiveCamera
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 is rendered at a time, the one passed to Renderer::Render. Construct the camera directly with the window's aspect ratio and pass it into the render call each frame.
auto camera = vglx::PerspectiveCamera::Create({
.fov = vglx::math::DegToRad(60.0f),
.aspect = window.AspectRatio(),
.near = 0.1f,
.far = 1000.0f
});
renderer.Render(scene.get(), camera.get());INFO
Derives from Camera and inherits all public properties and methods.
Construction
Constructors
PerspectiveCamera()
Constructs a perspective camera.
PerspectiveCamera::PerspectiveCamera(const Parameters& params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the camera. |
Factories preferred
PerspectiveCamera::Create() std::unique_ptr<PerspectiveCamera>
Creates an instance of PerspectiveCamera.
static std::unique_ptr<PerspectiveCamera> PerspectiveCamera::Create(const Parameters& params);| Parameter | Description |
|---|---|
| params | Initialization parameters for constructing the camera. |
Types
PerspectiveCamera::Parameters struct
Parameters for constructing a PerspectiveCamera object.
| Parameter | Description |
|---|---|
| fov float | Vertical field of view in radians. |
| aspect float | Aspect ratio. |
| near float | Distance to the near clipping plane. |
| far float | Distance to the far clipping plane. |
Functions
Resize() void virtual
Updates the projection transform to match the new viewport size.
void PerspectiveCamera::Resize(int width, int height) override;| Parameter | Description |
|---|---|
| width | Viewport width in pixels. |
| height | Viewport height in pixels. |
SetLens() void
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.
void PerspectiveCamera::SetLens(float fov, float near, float far);| Parameter | Description |
|---|---|
| fov | Vertical field of view in radians. |
| near | Distance to the near clipping plane. |
| far | Distance to the far clipping plane. |