glpp::core::render::camera_t class

Class for calulation of mvp-matricies.

The camera_t class is a data structure used to calculate model-view-projection matricies. It recrates a virtual camera that can be placed and oriented in global space. With its position, orientation and other state a mvp matrics can be calculated. The orientation is represented by a quaternion to prevent gimbal locking the camera.

Constructors, destructors, conversion operators

camera_t() defaulted noexcept
default constructor of camera_t
camera_t(camera_t&& mov) defaulted noexcept
move constructor
camera_t(const camera_t& cpy) defaulted noexcept
copy constructor
camera_t(glm::vec3 position, glm::quat orientation = glm::quat(glm::vec3(0.0, 0.0, 0.0)), float fov = 90, float near_plane = 0.1f, float far_plane = 100.0f, float aspect_ratio = 1.0f) noexcept
value intialisation constructor using position and orientation.
camera_t(glm::vec3 position, glm::vec3 look_at, glm::vec3 up, float fov = 90, float near_plane = 0.1f, float far_plane = 100.0f, float aspect_ratio = 1.0f) noexcept
value intialisation constructor using position, look_at and up vectors.

Public functions

auto mvp(const glm::mat4& model_matrix = glm::mat4(1.0f)) const -> glm::mat4
calculate model-view-projection matrix
auto operator=(camera_t&& mov) -> camera_t& defaulted noexcept
move assignment operator
auto operator=(const camera_t& cpy) -> camera_t& defaulted noexcept
copy assignment operator

Public variables

glm::vec3 position
position of the camera in global space
glm::quat orientation
orientation of the camera
float fov
field of view of the camera
float near_plane
near clipping plane of the view frustum
float far_plane
far clipping plane of the view frustum
float aspect_ratio
aspect ratio of the view frustum

Function documentation

glpp::core::render::camera_t::camera_t() defaulted noexcept

default constructor of camera_t

Constructs a camera_t object with sane default values for all parameters.

glpp::core::render::camera_t::camera_t(glm::vec3 position, glm::quat orientation = glm::quat(glm::vec3(0.0, 0.0, 0.0)), float fov = 90, float near_plane = 0.1f, float far_plane = 100.0f, float aspect_ratio = 1.0f) noexcept

value intialisation constructor using position and orientation.

Parameters
position [in] position of the origin of the view frustum. The origin is outside of the rendered frustum volume.
orientation [in] orientation of the frustum
fov [in] field of view
near_plane [in] distance of the near plane from the origin. Must be greater than zero.
far_plane [in] distance of the far plane from the origin. Must be greater than near_plane.
aspect_ratio [in] aspect ratio of the view frustum

Constructs a camera_t from a position, orientation and additional parameters.

glpp::core::render::camera_t::camera_t(glm::vec3 position, glm::vec3 look_at, glm::vec3 up, float fov = 90, float near_plane = 0.1f, float far_plane = 100.0f, float aspect_ratio = 1.0f) noexcept

value intialisation constructor using position, look_at and up vectors.

Parameters
position [in] position of the origin of the view frustum. The origin is outside of the rendered frustum volume.
look_at [in] vector from the position to the center of the view frustum. Must have a length greater than zero.
up [in] vector in the up direction of the view frustum. Must have a length greater than zero and orthogonal to look_at.
fov [in] field of view
near_plane [in] distance of the near plane from the origin. Must be greater than zero.
far_plane [in] distance of the far plane from the origin. Must be greater than near_plane.
aspect_ratio [in] aspect ratio of the view frustum

Constructs a camera_t from a position, look_at and up vector and additional parameters. The orientation of the camera is derived from the look_at and up vectors.

glm::mat4 glpp::core::render::camera_t::mvp(const glm::mat4& model_matrix = glm::mat4(1.0f)) const

calculate model-view-projection matrix

Parameters
model_matrix in transformation matrix of a mesh.
Returns Model-view-projection matrix to transform global space coordinations to clip space.

Calculate the model-view-projection matrix for a specific mesh. The model matrix of the mesh is passed as first parameter. The mvp matrix transform local space coordinates of the mesh to clip space. If no model matrix is passed global space will be transformed into clip space.

Variable documentation

glm::quat glpp::core::render::camera_t::orientation

orientation of the camera

Rotation of the camera from its native orientation. The native orientation is facing in the -z direction, with +y facing up.

float glpp::core::render::camera_t::fov

field of view of the camera

Field of view of the view frustum in degrees.

float glpp::core::render::camera_t::near_plane

near clipping plane of the view frustum

Distance of the near clipping plane from position in the direction of the view vector, measured in global units.

float glpp::core::render::camera_t::far_plane

far clipping plane of the view frustum

Distance of the far clipping plane from position in the direction of the view vector, measured in global units.

float glpp::core::render::camera_t::aspect_ratio

aspect ratio of the view frustum

Aspect ratio of the view frustum (width / height). Should be set equal to the aspect ratio of the active framebuffer to prevent distortion.