Skip to content

Vp::AbstractCamera

Abstract camera base class. More...

#include "Viewport/camera/AbstractCamera.h"

Inherited by Vp::AbstractOrbitCamera, Vp::AggregateCamera

Public Types

Name
enum classViewpoint { LEFT, RIGHT, TOP, BOTTOM, FRONT, BACK}

Public Functions

Name
virtual~AbstractCamera() =default
virtual voidcenterOnBox(glm::vec3 boxMin, glm::vec3 boxMax, bool interpolate)<br>Moves camera so that the specified axis aligned bounding box is visible.
virtual voidcenterOnObjects(const std::vector< const GameObject * > objects)<br>Moves camera so that the specified objects are visible.
virtual voidcenterOnScene(const Scene & scene)<br>Moves camera so that all objects in the scene are visible.
virtual voidcenterOnSelection(const Scene & scene)<br>Moves camera so that all selected objects in the scene are visible.
virtual glm::vec3getDirection() const
virtual floatgetFov() const
virtual intgetHeight() const
virtual glm::vec3getPosition() const
virtual glm::mat4getProjection() const
virtual glm::vec3getRight() const
virtual glm::vec3getUp() const
virtual glm::mat4getView() const
virtual intgetWidth() const
virtual floatgetZFar() const
virtual floatgetZNear() const
voidinterpolate(glm::mat4 from, glm::mat4 to)<br>Begin interpolation from one view matrix to another, the interpolation will take m_interpolationPeriod seconds in realtime.
boolisInterpolating(float & progress) const<br>Checks whether interpolation between view matrices is currently happening.
virtual voidprocessInput(double dt, glm::vec2 mousePos, glm::ivec2 windowSize) =0<br>Updates the internal camera state with user input.
virtual voidsetFov(float fov)
virtual voidsetZFar(float zFar)
virtual voidsetZNear(float zNear)
virtual voidsize(int width, int height)<br>Sets the camera resolution in pixels.
virtual voidupdate() =0<br>Recalculates the view and projection matrices based on the internal camera state.
virtual voidviewpoint(AbstractCamera::Viewpoint viewpoint)<br>Moves the camera to the specified viewpoint.

Protected Functions

Name
std::vector< glm::vec3 >createBoundingBoxWorldPoints(glm::vec3 boxMin, glm::vec3 boxMax, glm::mat4 modelMatrix)
glm::mat4createProjectionMatrix(bool nonShrinking) const

Protected Attributes

Name
glm::mat4interpolationFrom
doubleinterpolationPeriod
std::chrono::time_point< std::chrono::steady_clock, std::chrono::duration< double > >interpolationStart
glm::mat4interpolationTo
glm::vec3m_direction
floatm_fov <br>Vertical field of vision in degrees.
intm_height <br>Camera resolution height in pixels.
glm::vec3m_position
glm::mat4m_projection
glm::vec3m_right
glm::vec3m_up
glm::mat4m_view
intm_width <br>Camera resolution width in pixels.
floatm_zFar <br>Distance to the far clipping pane.
floatm_zNear <br>Distance to the near clipping pane.

Detailed Description

cpp
class Vp::AbstractCamera;
class Vp::AbstractCamera;

Abstract camera base class.

Holds a view matrix and projection information. Also contains further information about its view space (position, direction, up and right vectors)

Public Types Documentation

enum Viewpoint

EnumeratorValueDescription
LEFT
RIGHT
TOP
BOTTOM
FRONT
BACK

Public Functions Documentation

function ~AbstractCamera

cpp
virtual ~AbstractCamera() =default
virtual ~AbstractCamera() =default

function centerOnBox

cpp
virtual void centerOnBox(
    glm::vec3 boxMin,
    glm::vec3 boxMax,
    bool interpolate
)
virtual void centerOnBox(
    glm::vec3 boxMin,
    glm::vec3 boxMax,
    bool interpolate
)

Moves camera so that the specified axis aligned bounding box is visible.

Reimplemented by: Vp::AbstractOrbitCamera::centerOnBox, Vp::AggregateCamera::centerOnBox

function centerOnObjects

cpp
virtual void centerOnObjects(
    const std::vector< const GameObject * > objects
)
virtual void centerOnObjects(
    const std::vector< const GameObject * > objects
)

Moves camera so that the specified objects are visible.

Reimplemented by: Vp::AggregateCamera::centerOnObjects

function centerOnScene

cpp
virtual void centerOnScene(
    const Scene & scene
)
virtual void centerOnScene(
    const Scene & scene
)

Moves camera so that all objects in the scene are visible.

Reimplemented by: Vp::AggregateCamera::centerOnScene

function centerOnSelection

cpp
virtual void centerOnSelection(
    const Scene & scene
)
virtual void centerOnSelection(
    const Scene & scene
)

Moves camera so that all selected objects in the scene are visible.

Reimplemented by: Vp::AggregateCamera::centerOnSelection

function getDirection

cpp
virtual glm::vec3 getDirection() const
virtual glm::vec3 getDirection() const

Reimplemented by: Vp::AggregateCamera::getDirection

function getFov

cpp
virtual float getFov() const
virtual float getFov() const

Reimplemented by: Vp::AggregateCamera::getFov

function getHeight

cpp
virtual int getHeight() const
virtual int getHeight() const

Reimplemented by: Vp::AggregateCamera::getHeight

function getPosition

cpp
virtual glm::vec3 getPosition() const
virtual glm::vec3 getPosition() const

Reimplemented by: Vp::AggregateCamera::getPosition

function getProjection

cpp
virtual glm::mat4 getProjection() const
virtual glm::mat4 getProjection() const

Return: The camera projection matrix

Reimplemented by: Vp::AggregateCamera::getProjection

function getRight

cpp
virtual glm::vec3 getRight() const
virtual glm::vec3 getRight() const

Reimplemented by: Vp::AggregateCamera::getRight

function getUp

cpp
virtual glm::vec3 getUp() const
virtual glm::vec3 getUp() const

Reimplemented by: Vp::AggregateCamera::getUp

function getView

cpp
virtual glm::mat4 getView() const
virtual glm::mat4 getView() const

Return: The camera view matrix

Reimplemented by: Vp::AggregateCamera::getView

function getWidth

cpp
virtual int getWidth() const
virtual int getWidth() const

Reimplemented by: Vp::AggregateCamera::getWidth

function getZFar

cpp
virtual float getZFar() const
virtual float getZFar() const

Reimplemented by: Vp::AggregateCamera::getZFar

function getZNear

cpp
virtual float getZNear() const
virtual float getZNear() const

Reimplemented by: Vp::AggregateCamera::getZNear

function interpolate

cpp
void interpolate(
    glm::mat4 from,
    glm::mat4 to
)
void interpolate(
    glm::mat4 from,
    glm::mat4 to
)

Begin interpolation from one view matrix to another, the interpolation will take m_interpolationPeriod seconds in realtime.

Parameters:

  • from Start view matrix
  • to End view matrix

During that period the getView() method will be returning the interpolated view matrix rather than the one actually stored. This interpolation is independent from any internal parameters of the camera and does not modify it.

function isInterpolating

cpp
bool isInterpolating(
    float & progress
) const
bool isInterpolating(
    float & progress
) const

Checks whether interpolation between view matrices is currently happening.

Parameters:

  • progress Reference to which progress is written.

Return: true if interpolating, false otherwise

If interpolating, the progress argument is set to the current progress in range <0, 1>.

function processInput

cpp
virtual void processInput(
    double dt,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
) =0
virtual void processInput(
    double dt,
    glm::vec2 mousePos,
    glm::ivec2 windowSize
) =0

Updates the internal camera state with user input.

Parameters:

  • mousePos Mouse position relative to the window size.
  • windowSize The window size in pixels.

Reimplemented by: Vp::AggregateCamera::processInput, Vp::OrbitCamera::processInput, Vp::TrackballCamera::processInput

function setFov

cpp
virtual void setFov(
    float fov
)
virtual void setFov(
    float fov
)

Reimplemented by: Vp::AggregateCamera::setFov

function setZFar

cpp
virtual void setZFar(
    float zFar
)
virtual void setZFar(
    float zFar
)

Reimplemented by: Vp::AggregateCamera::setZFar

function setZNear

cpp
virtual void setZNear(
    float zNear
)
virtual void setZNear(
    float zNear
)

Reimplemented by: Vp::AggregateCamera::setZNear

function size

cpp
virtual void size(
    int width,
    int height
)
virtual void size(
    int width,
    int height
)

Sets the camera resolution in pixels.

Parameters:

  • width Screen width in pixels
  • height Screen height in pixels

Reimplemented by: Vp::AggregateCamera::size

Should be called prior to the Camera::update() method.

function update

cpp
virtual void update() =0
virtual void update() =0

Recalculates the view and projection matrices based on the internal camera state.

Reimplemented by: Vp::AggregateCamera::update, Vp::OrbitCamera::update, Vp::TrackballCamera::update

Generally this method should build up a new view matrix from scratch using some arbitrary internal variables. From the calculated view matrix, direction, up, right and position information should be updated.

function viewpoint

cpp
virtual void viewpoint(
    AbstractCamera::Viewpoint viewpoint
)
virtual void viewpoint(
    AbstractCamera::Viewpoint viewpoint
)

Moves the camera to the specified viewpoint.

Parameters:

  • viewpoint

Reimplemented by: Vp::AggregateCamera::viewpoint, Vp::OrbitCamera::viewpoint, Vp::TrackballCamera::viewpoint

Subclasses need to provide their own implementations.

Protected Functions Documentation

function createBoundingBoxWorldPoints

cpp
std::vector< glm::vec3 > createBoundingBoxWorldPoints(
    glm::vec3 boxMin,
    glm::vec3 boxMax,
    glm::mat4 modelMatrix
)
std::vector< glm::vec3 > createBoundingBoxWorldPoints(
    glm::vec3 boxMin,
    glm::vec3 boxMax,
    glm::mat4 modelMatrix
)

function createProjectionMatrix

cpp
glm::mat4 createProjectionMatrix(
    bool nonShrinking
) const
glm::mat4 createProjectionMatrix(
    bool nonShrinking
) const

Protected Attributes Documentation

variable interpolationFrom

cpp
glm::mat4 interpolationFrom;
glm::mat4 interpolationFrom;

variable interpolationPeriod

cpp
double interpolationPeriod {0.14f};
double interpolationPeriod {0.14f};

variable interpolationStart

cpp
std::chrono::time_point< std::chrono::steady_clock, std::chrono::duration< double > > interpolationStart {};
std::chrono::time_point< std::chrono::steady_clock, std::chrono::duration< double > > interpolationStart {};

variable interpolationTo

cpp
glm::mat4 interpolationTo;
glm::mat4 interpolationTo;

variable m_direction

cpp
glm::vec3 m_direction = glm::vec3(1.0f, 0.0f, 0.0f);
glm::vec3 m_direction = glm::vec3(1.0f, 0.0f, 0.0f);

variable m_fov

cpp
float m_fov = 90.0f;
float m_fov = 90.0f;

Vertical field of vision in degrees.

variable m_height

cpp
int m_height {200};
int m_height {200};

Camera resolution height in pixels.

variable m_position

cpp
glm::vec3 m_position = glm::vec3(3.0f, 0.0f, 0.0f);
glm::vec3 m_position = glm::vec3(3.0f, 0.0f, 0.0f);

variable m_projection

cpp
glm::mat4 m_projection {1.0f};
glm::mat4 m_projection {1.0f};

variable m_right

cpp
glm::vec3 m_right = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 m_right = glm::vec3(0.0f, 1.0f, 0.0f);

variable m_up

cpp
glm::vec3 m_up = glm::vec3(0.0f, 0.0f, 1.0f);
glm::vec3 m_up = glm::vec3(0.0f, 0.0f, 1.0f);

variable m_view

cpp
glm::mat4 m_view {1.0f};
glm::mat4 m_view {1.0f};

variable m_width

cpp
int m_width {200};
int m_width {200};

Camera resolution width in pixels.

variable m_zFar

cpp
float m_zFar = 270.0f;
float m_zFar = 270.0f;

Distance to the far clipping pane.

variable m_zNear

cpp
float m_zNear = 0.2f;
float m_zNear = 0.2f;

Distance to the near clipping pane.


Updated on 2024-03-16 at 19:15:01 +0000