Camera Class
Represents a camera for perspective or orthographic projection. More...
Declaration
Public Constructors Index
| Camera () noexcept | |
|
Constructs a camera with identity projection and view matrices. More... | |
Public Member Functions Index
| const helios::math::mat4f & | projectionMatrix () const noexcept |
|
Gets the current projection matrix. More... | |
| const helios::math::mat4f & | viewMatrix () const noexcept |
|
Gets the current view matrix. More... | |
| Camera & | setViewMatrix (const helios::math::mat4f &viewMatrix) noexcept |
|
Sets the view matrix for this camera. More... | |
| Camera & | setAspectRatio (float aspectRatio) noexcept |
|
Sets the aspect ratio used by the camera. More... | |
| void | onResize (const float width, const float height) noexcept |
|
Handles viewport resize events. More... | |
| Camera & | setPerspective (float fovY, float aspectRatio, float zNear, float zFar) noexcept |
|
Sets the perspective projection parameters. More... | |
| Camera & | setOrtho (const float left, const float right, const float bottom, const float top, const float zNear=-1.0f, const float zFar=100.0f) noexcept |
|
Sets the orthographic projection parameters. More... | |
| Camera & | setZNear (float zNear) noexcept |
|
Sets the near clipping plane distance. More... | |
| Camera & | setZFar (float zFar) noexcept |
|
Sets the far clipping plane distance. More... | |
| Camera & | setFovY (float fovY) noexcept |
|
Sets the vertical field of view. More... | |
| float | fovY () const noexcept |
|
Gets the current vertical field of view. More... | |
| float | aspectRatio () const noexcept |
|
Gets the current aspect ratio. More... | |
| float | zNear () const noexcept |
|
Gets the current near clipping plane distance. More... | |
| float | zFar () const noexcept |
|
Gets the current far clipping plane distance. More... | |
Protected Member Functions Index
| void | update () const |
|
Updates the view and projection matrices if needed. More... | |
Protected Member Attributes Index
| helios::math::mat4f | perspectiveMatrix_ |
|
The projection matrix of this camera. More... | |
| helios::math::mat4f | orthographicMatrix_ |
|
The orthographic projection matrix of this camera. More... | |
| helios::math::mat4f | viewMatrix_ |
|
The view matrix of this camera. More... | |
| float | aspectRatio_ = 1.0f |
|
The aspect ratio of the camera (width/height). More... | |
| float | zNear_ = 0.1f |
|
The near clipping plane distance. More... | |
| float | zFar_ = 1000.0f |
|
The far clipping plane distance. More... | |
| float | fovY_ = helios::math::radians(90) |
|
The vertical field of view in radians. More... | |
| bool | needsUpdate_ = true |
|
Flag indicating whether the matrices need to be updated. More... | |
| float | left_ |
|
Left boundary of the orthographic frustum. More... | |
| float | right_ |
|
Right boundary of the orthographic frustum. More... | |
| float | bottom_ |
|
Bottom boundary of the orthographic frustum. More... | |
| float | top_ |
|
Top boundary of the orthographic frustum. More... | |
| bool | usePerspective_ = true |
|
Flag indicating the projection mode. More... | |
Description
Represents a camera for perspective or orthographic projection.
The camera provides the view and projection matrices, whereas the view matrix is computed as the inverse of the camera's world transform.
The camera supports two projection modes:
- **Perspective projection:** Simulates how the human eye perceives depth, where distant objects appear smaller. Use `setPerspective()` to configure.
- **Orthographic projection:** Maintains parallel lines and uniform scaling regardless of distance, useful for 2D rendering, UI elements, or CAD-style views. Use `setOrtho()` to configure.
By default, the camera uses perspective projection.
Example usage: ```cpp helios::scene::Camera camera;
// Perspective projection camera.setPerspective(helios::math::radians(60.0f), 16.0f / 9.0f, 0.1f, 1000.0f);
// Orthographic projection camera.setOrtho(0.0f, 800.0f, 0.0f, 600.0f, -1.0f, 100.0f); ```
Definition at line 44 of file Camera.ixx.
Public Constructors
Camera()
| inline noexcept |
Constructs a camera with identity projection and view matrices.
Definition at line 150 of file Camera.ixx.
References orthographicMatrix_, perspectiveMatrix_ and viewMatrix_.
Referenced by setAspectRatio, setFovY, setOrtho, setPerspective, setViewMatrix, setZFar and setZNear.
Public Member Functions
aspectRatio()
| inline nodiscard noexcept |
Gets the current aspect ratio.
- Returns
The aspect ratio (width/height).
Definition at line 362 of file Camera.ixx.
Reference aspectRatio_.
Referenced by setAspectRatio and setPerspective.
fovY()
| inline nodiscard noexcept |
Gets the current vertical field of view.
- Returns
The vertical field of view in radians.
Definition at line 353 of file Camera.ixx.
Reference fovY_.
Referenced by setFovY and setPerspective.
onResize()
| inline noexcept |
Handles viewport resize events.
Adjusts the camera projection parameters when the viewport dimensions change.
- For perspective projection: Updates the aspect ratio.
- For orthographic projection: Adjusts the right and top boundaries to maintain the correct projection volume.
- Parameters
-
width The new viewport width in pixels.
height The new viewport height in pixels.
Definition at line 225 of file Camera.ixx.
References bottom_, left_, needsUpdate_, right_, setAspectRatio, top_ and usePerspective_.
projectionMatrix()
| inline nodiscard noexcept |
Gets the current projection matrix.
Typically set to a perspective or orthographic projection.
- Returns
A const reference to this camera's projection matrix.
Definition at line 163 of file Camera.ixx.
References orthographicMatrix_, perspectiveMatrix_, update and usePerspective_.
setAspectRatio()
| inline noexcept |
Sets the aspect ratio used by the camera.
- Parameters
-
aspectRatio The new aspect ratio (width/height).
- Returns
A reference to this camera instance.
Definition at line 208 of file Camera.ixx.
References aspectRatio, aspectRatio_, Camera and needsUpdate_.
Referenced by onResize.
setFovY()
| inline noexcept |
Sets the vertical field of view.
- Parameters
-
fovY The new vertical field of view in radians.
- Returns
A reference to this camera instance.
Definition at line 342 of file Camera.ixx.
References Camera, fovY, fovY_ and needsUpdate_.
setOrtho()
| inline noexcept |
Sets the orthographic projection parameters.
Configures the camera for orthographic projection, which is useful for 2D rendering, UI overlays, or scenes where parallel lines should remain parallel (no perspective distortion).
- Parameters
-
left The left boundary of the view volume.
right The right boundary of the view volume.
bottom The bottom boundary of the view volume.
top The top boundary of the view volume.
zNear The near clipping plane distance. Defaults to -1.0.
zFar The far clipping plane distance. Defaults to 100.0.
- Returns
A reference to this camera instance.
Calling this method switches the camera to orthographic projection mode.
Definition at line 286 of file Camera.ixx.
References aspectRatio_, bottom_, Camera, left_, needsUpdate_, right_, top_, usePerspective_, zFar, zFar_, zNear and zNear_.
setPerspective()
| inline noexcept |
Sets the perspective projection parameters.
- Parameters
-
fovY The vertical field of view in radians.
aspectRatio The aspect ratio (width/height).
zNear The near clipping plane distance.
zFar The far clipping plane distance.
- Returns
A reference to this camera instance.
Definition at line 256 of file Camera.ixx.
References aspectRatio, aspectRatio_, Camera, fovY, fovY_, needsUpdate_, usePerspective_, zFar, zFar_, zNear and zNear_.
setViewMatrix()
| inline noexcept |
Sets the view matrix for this camera.
This method is typically called by `CameraSceneNode::worldTransform()` to update the view matrix based on the camera node's position and orientation in the scene graph.
- Parameters
-
viewMatrix The new view matrix to assign.
- Returns
A const reference to this camera instance.
Definition at line 196 of file Camera.ixx.
References Camera, viewMatrix and viewMatrix_.
setZFar()
| inline noexcept |
Sets the far clipping plane distance.
- Parameters
-
zFar The new far clipping plane distance.
- Returns
A reference to this camera instance.
Definition at line 329 of file Camera.ixx.
References Camera, needsUpdate_, zFar and zFar_.
setZNear()
| inline noexcept |
Sets the near clipping plane distance.
- Parameters
-
zNear The new near clipping plane distance.
- Returns
A reference to this camera instance.
Definition at line 316 of file Camera.ixx.
References Camera, needsUpdate_, zNear and zNear_.
viewMatrix()
| inline nodiscard noexcept |
Gets the current view matrix.
The view matrix represents the inverse of the camera's world transform.
- Returns
A const reference to this camera's view matrix.
Definition at line 180 of file Camera.ixx.
Reference viewMatrix_.
Referenced by setViewMatrix.
zFar()
| inline nodiscard noexcept |
Gets the current far clipping plane distance.
- Returns
The far clipping plane distance.
Definition at line 380 of file Camera.ixx.
Reference zFar_.
Referenced by setOrtho, setPerspective and setZFar.
zNear()
| inline nodiscard noexcept |
Gets the current near clipping plane distance.
- Returns
The near clipping plane distance.
Definition at line 371 of file Camera.ixx.
Reference zNear_.
Referenced by setOrtho, setPerspective and setZNear.
Protected Member Functions
update()
| inline protected |
Updates the view and projection matrices if needed.
This function recalculates the view and projection matrices based on the current camera parameters.
Definition at line 131 of file Camera.ixx.
References aspectRatio_, bottom_, fovY_, left_, needsUpdate_, helios::math::ortho, orthographicMatrix_, helios::math::perspective, perspectiveMatrix_, right_, top_, usePerspective_, zFar_ and zNear_.
Referenced by projectionMatrix.
Protected Member Attributes
aspectRatio_
| protected |
The aspect ratio of the camera (width/height).
Defaults to 1.0.
Definition at line 69 of file Camera.ixx.
Referenced by aspectRatio, setAspectRatio, setOrtho, setPerspective and update.
bottom_
| protected |
fovY_
| protected |
The vertical field of view in radians.
Defaults to 90 degrees (converted to radians).
Definition at line 90 of file Camera.ixx.
Referenced by fovY, setFovY, setPerspective and update.
left_
| protected |
needsUpdate_
| protected mutable |
Flag indicating whether the matrices need to be updated.
Definition at line 95 of file Camera.ixx.
Referenced by onResize, setAspectRatio, setFovY, setOrtho, setPerspective, setZFar, setZNear and update.
orthographicMatrix_
| protected mutable |
The orthographic projection matrix of this camera.
Used when the camera is in orthographic mode (`usePerspective_ == false`).
Definition at line 57 of file Camera.ixx.
Referenced by Camera, projectionMatrix and update.
perspectiveMatrix_
| protected mutable |
The projection matrix of this camera.
Definition at line 50 of file Camera.ixx.
Referenced by Camera, projectionMatrix and update.
right_
| protected |
top_
| protected |
usePerspective_
| protected |
Flag indicating the projection mode.
When `true`, perspective projection is used. When `false`, orthographic projection is used. Defaults to `true`.
Definition at line 123 of file Camera.ixx.
Referenced by onResize, projectionMatrix, setOrtho, setPerspective and update.
viewMatrix_
| protected |
The view matrix of this camera.
Definition at line 62 of file Camera.ixx.
Referenced by Camera, setViewMatrix and viewMatrix.
zFar_
| protected |
The far clipping plane distance.
Defaults to 1000.0.
Definition at line 83 of file Camera.ixx.
Referenced by setOrtho, setPerspective, setZFar, update and zFar.
zNear_
| protected |
The near clipping plane distance.
Defaults to 0.1.
Definition at line 76 of file Camera.ixx.
Referenced by setOrtho, setPerspective, setZNear, update and zNear.
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.