Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Camera Class Reference

This class represents a camera as used in real-time rendering APIs. It provides a view and projection matrices, and handles their proper update. More...

#include <Camera.hpp>

Public Member Functions

 Camera ()
 Constructor.
 
virtual void pose (const glm::vec3 &position, const glm::vec3 &center, const glm::vec3 &up)
 
virtual void projection (float ratio, float fov, float near, float far)
 
void frustum (float near, float far)
 
void ratio (float ratio)
 
void fov (float fov)
 
void pixelShifts (glm::vec3 &corner, glm::vec3 &dx, glm::vec3 &dy) const
 
float fov () const
 
float ratio () const
 
const glm::mat4 & view () const
 
const glm::mat4 & projection () const
 
const glm::vec3 & position () const
 
const glm::vec3 & up () const
 
const glm::vec3 & center () const
 
const glm::vec3 direction () const
 
const glm::vec2 & clippingPlanes () const
 
void apply (const Camera &camera)
 
bool decode (const KeyValues &params)
 
KeyValues encode () const
 
virtual ~Camera ()=default
 
 Camera (const Camera &)=default
 
Cameraoperator= (const Camera &)=default
 
 Camera (Camera &&)=default
 
Cameraoperator= (Camera &&)=default
 

Protected Member Functions

void updateProjection ()
 Update the projection matrix using the camera parameters.
 
void updateView ()
 Update the view matrix using the camera position and orientation.
 

Protected Attributes

glm::mat4 _view = glm::mat4(1.0f)
 The view matrix.
 
glm::mat4 _projection = glm::mat4(1.0f)
 The projection matrix.
 
glm::vec3 _eye = glm::vec3(0.0, 0.0, 1.0)
 The camera position.
 
glm::vec3 _center = glm::vec3(0.0, 0.0, 0.0)
 The camera center (look-at point)
 
glm::vec3 _up = glm::vec3(0.0, 1.0, 0.0)
 The camera up vector.
 
glm::vec3 _right = glm::vec3(1.0, 0.0, 0.0)
 The camera right vector.
 
glm::vec2 _clippingPlanes = glm::vec2(0.01f, 100.0f)
 The near and far plane distances.
 
float _fov = 1.3f
 The vertical field of view, in radians.
 
float _ratio = 1.0f
 The aspect ratio.
 

Detailed Description

This class represents a camera as used in real-time rendering APIs. It provides a view and projection matrices, and handles their proper update.

Inherited by ControllableCamera.

Constructor & Destructor Documentation

◆ ~Camera()

virtual Camera::~Camera ( )
virtualdefault

Destructor.

◆ Camera() [1/2]

Camera::Camera ( const Camera )
default

Copy constructor.

◆ Camera() [2/2]

Camera::Camera ( Camera &&  )
default

Move constructor.

Member Function Documentation

◆ apply()

void Camera::apply ( const Camera camera)

Apply the pose and parameters of another camera.

Parameters
camerathe camera to align with

◆ center()

const glm::vec3 & Camera::center ( ) const
inline

Obtain the current world space center position.

Returns
the current center

◆ clippingPlanes()

const glm::vec2 & Camera::clippingPlanes ( ) const
inline

Obtain the current world space camera position.

Returns
the current position

◆ decode()

bool Camera::decode ( const KeyValues params)

Setup a camera parameters from a list of key-value tuples. The following keywords will be searched for:

camera:
    position: X,Y,Z
    center: X,Y,Z
    up: X,Y,Z
    fov: F
    planes: N,F

where the field of view is given in radians.

Parameters
paramsthe parameters tuples list
Returns
decoding status

◆ direction()

const glm::vec3 Camera::direction ( ) const
inline

Obtain the current world space view direction.

Returns
the current direction

◆ encode()

KeyValues Camera::encode ( ) const

Encode a camera as a key-values representation.

Returns
the encoded camera parameters

◆ fov() [1/2]

float Camera::fov ( ) const
inline

Obtain the current vertical field of view, in radians.

Returns
the field of view

◆ fov() [2/2]

void Camera::fov ( float  fov)

Update the vertical field of view.

Parameters
fovthe new field of view, in radians

◆ frustum()

void Camera::frustum ( float  near,
float  far 
)

Update the frustum near and far planes.

Parameters
nearthe new near plane distance
farthe new far plane distance

◆ operator=() [1/2]

Camera & Camera::operator= ( Camera &&  )
default

Move assignment.

Returns
a reference to the object assigned to

◆ operator=() [2/2]

Camera & Camera::operator= ( const Camera )
default

Copy assignment.

Returns
a reference to the object assigned to

◆ pixelShifts()

void Camera::pixelShifts ( glm::vec3 &  corner,
glm::vec3 &  dx,
glm::vec3 &  dy 
) const

Compute world space position of the top-left corner of the image, and the shifts to move to the next pixel, horizontally and vertically.

Parameters
cornerwill contain the position of the top-left corner
dxwill contain the horizontal step
dywill contain the vertical step

◆ pose()

void Camera::pose ( const glm::vec3 &  position,
const glm::vec3 &  center,
const glm::vec3 &  up 
)
virtual

Update all view parameters

Parameters
positionthe camera position
centerthe camera center of interest
upthe camera vertical orientation

Reimplemented in ControllableCamera.

◆ position()

const glm::vec3 & Camera::position ( ) const
inline

Obtain the current world space camera position.

Returns
the current position

◆ projection() [1/2]

const glm::mat4 & Camera::projection ( ) const
inline

Obtain the current projection matrix.

Returns
the projection matrix

◆ projection() [2/2]

void Camera::projection ( float  ratio,
float  fov,
float  near,
float  far 
)
virtual

Update all projection parameters.

Parameters
ratiothe aspect ratio
fovthe vertical field of view in radians
nearthe near plane distance
farthe far plane distance

◆ ratio() [1/2]

float Camera::ratio ( ) const
inline

Obtain the current aspect ratio.

Returns
the aspect ratio

◆ ratio() [2/2]

void Camera::ratio ( float  ratio)

Update the aspect ratio.

Parameters
ratiothe new aspect ratio

◆ up()

const glm::vec3 & Camera::up ( ) const
inline

Obtain the current world space up direction.

Returns
the current direction

◆ view()

const glm::mat4 & Camera::view ( ) const
inline

Obtain the current view matrix.

Returns
the view matrix

The documentation for this class was generated from the following files: