Represents a camera for viewing the 3D scene.
More...
#include <camera.hpp>
|
| enum class | ProjectionMode { Perspective
, Orthographic
} |
| | Projection mode for the camera.
|
| |
|
| | Camera (float fov=45.0f, float aspect=16.0f/9.0f, float near=0.1f, float far=100.0f) |
| | Constructor for the Camera class.
|
| |
| void | set_perspective (float fov, float aspect, float near, float far) |
| | Set the camera to perspective projection mode.
|
| |
| void | set_orthographic (float left, float right, float bottom, float top, float near, float far) |
| | Set the camera to orthographic projection mode.
|
| |
| void | set_position (const glm::vec3 &position) |
| | Set the camera position.
|
| |
| void | set_target (const glm::vec3 &target) |
| | Set the camera target/look-at point.
|
| |
| void | set_up (const glm::vec3 &up) |
| | Set the camera's up vector.
|
| |
| const glm::vec3 & | get_position () const |
| | Get the camera position.
|
| |
| const glm::vec3 & | get_target () const |
| | Get the camera target.
|
| |
| const glm::vec3 & | get_up () const |
| | Get the camera up vector.
|
| |
| const glm::mat4 & | get_view_matrix () const |
| | Get the view matrix.
|
| |
| const glm::mat4 & | get_projection_matrix () const |
| | Get the projection matrix.
|
| |
| glm::mat4 | get_view_projection_matrix () const |
| | Get the combined view-projection matrix.
|
| |
| glm::vec3 | unproject (float screen_x, float screen_y, float screen_width, float screen_height) const |
| | Unproject screen coordinates to world space.
|
| |
| ProjectionMode | get_projection_mode () const |
| | Get the current projection mode.
|
| |
| float | get_aspect () const |
| | Get the current aspect ratio.
|
| |
| void | set_aspect (float aspect) |
| | Set a new aspect ratio.
|
| |
Represents a camera for viewing the 3D scene.
The Camera class provides methods to configure perspective or orthographic projection, compute view matrices, and perform screen-to-world unprojection for tasks like mouse picking.
◆ Camera()
| lmgl::scene::Camera::Camera |
( |
float | fov = 45.0f, |
|
|
float | aspect = 16.0f / 9.0f, |
|
|
float | near = 0.1f, |
|
|
float | far = 100.0f ) |
Constructor for the Camera class.
Initializes the camera with default perspective settings.
- Parameters
-
| fov | Field of view in degrees (default: 45.0). |
| aspect | Aspect ratio (width/height) (default: 16.0/9.0). |
| near | Near clipping plane (default: 0.1). |
| far | Far clipping plane (default: 100.0). |
◆ get_aspect()
| float lmgl::scene::Camera::get_aspect |
( |
| ) |
const |
|
inline |
Get the current aspect ratio.
- Returns
- The current aspect ratio.
◆ get_position()
| const glm::vec3 & lmgl::scene::Camera::get_position |
( |
| ) |
const |
|
inline |
Get the camera position.
- Returns
- Current position of the camera.
◆ get_projection_matrix()
| const glm::mat4 & lmgl::scene::Camera::get_projection_matrix |
( |
| ) |
const |
|
inline |
Get the projection matrix.
Returns the current projection matrix (perspective or orthographic).
- Returns
- Projection matrix.
◆ get_projection_mode()
Get the current projection mode.
- Returns
- Current projection mode (Perspective or Orthographic).
◆ get_target()
| const glm::vec3 & lmgl::scene::Camera::get_target |
( |
| ) |
const |
|
inline |
Get the camera target.
- Returns
- Current target/look-at point.
◆ get_up()
| const glm::vec3 & lmgl::scene::Camera::get_up |
( |
| ) |
const |
|
inline |
Get the camera up vector.
- Returns
- Current up direction vector.
◆ get_view_matrix()
| const glm::mat4 & lmgl::scene::Camera::get_view_matrix |
( |
| ) |
const |
Get the view matrix.
Returns the view matrix computed using glm::lookAt. The matrix is cached and only recomputed when necessary.
- Returns
- View matrix.
◆ get_view_projection_matrix()
| glm::mat4 lmgl::scene::Camera::get_view_projection_matrix |
( |
| ) |
const |
Get the combined view-projection matrix.
Returns the product of projection and view matrices.
- Returns
- View-projection matrix.
◆ set_aspect()
| void lmgl::scene::Camera::set_aspect |
( |
float | aspect | ) |
|
Set a new aspect ratio.
Updates the aspect ratio and recalculates the projection matrix if the camera is in perspective mode.
- Parameters
-
| aspect | The new aspect ratio |
◆ set_orthographic()
| void lmgl::scene::Camera::set_orthographic |
( |
float | left, |
|
|
float | right, |
|
|
float | bottom, |
|
|
float | top, |
|
|
float | near, |
|
|
float | far ) |
Set the camera to orthographic projection mode.
Configures the camera to use orthographic projection with the specified bounds.
- Parameters
-
| left | Left boundary. |
| right | Right boundary. |
| bottom | Bottom boundary. |
| top | Top boundary. |
| near | Near clipping plane. |
| far | Far clipping plane. |
◆ set_perspective()
| void lmgl::scene::Camera::set_perspective |
( |
float | fov, |
|
|
float | aspect, |
|
|
float | near, |
|
|
float | far ) |
Set the camera to perspective projection mode.
Configures the camera to use perspective projection with the specified parameters.
- Parameters
-
| fov | Field of view in degrees. |
| aspect | Aspect ratio (width/height). |
| near | Near clipping plane. |
| far | Far clipping plane. |
◆ set_position()
| void lmgl::scene::Camera::set_position |
( |
const glm::vec3 & | position | ) |
|
|
inline |
Set the camera position.
Updates the position of the camera in world space.
- Parameters
-
| position | New position vector. |
◆ set_target()
| void lmgl::scene::Camera::set_target |
( |
const glm::vec3 & | target | ) |
|
|
inline |
Set the camera target/look-at point.
Updates the point the camera is looking at.
- Parameters
-
| target | Target position vector. |
◆ set_up()
| void lmgl::scene::Camera::set_up |
( |
const glm::vec3 & | up | ) |
|
|
inline |
Set the camera's up vector.
Updates the up direction for the camera orientation.
- Parameters
-
| up | Up direction vector (default: (0, 1, 0)). |
◆ unproject()
| glm::vec3 lmgl::scene::Camera::unproject |
( |
float | screen_x, |
|
|
float | screen_y, |
|
|
float | screen_width, |
|
|
float | screen_height ) const |
Unproject screen coordinates to world space.
Converts 2D screen coordinates to a 3D ray in world space, useful for mouse picking and raycasting.
- Parameters
-
| screen_x | Screen X coordinate. |
| screen_y | Screen Y coordinate. |
| screen_width | Width of the viewport. |
| screen_height | Height of the viewport. |
- Returns
- Ray direction in world space (normalized).
The documentation for this class was generated from the following files:
- include/lmgl/scene/camera.hpp
- src/scene/camera.cpp