Skip to content

Vp::TrackballCamera ​

Camera turning around a point using a virtual screen-space trackball.

#include "Viewport/camera/TrackballCamera.h"

Inherits from Vp::AbstractOrbitCamera, Vp::AbstractCamera

Public Functions ​

Name
floatgetRotateSpeed() const
glm::mat4getRotation() const
boolgetSmoothScroll() const
floatgetSmoothScrollDamping() const
floatgetTranslateSpeed() const
floatgetZoomSpeed() const
virtual voidprocessInput(double dt, glm::vec2 mousePos, glm::ivec2 windowSize) override<br>Updates the internal camera state with user input.
voidsetRotateSpeed(float rotateSpeed)
voidsetRotation(glm::mat4 rotation)
voidsetSmoothScroll(bool b)
voidsetSmoothScrollDamping(float val)
voidsetTranslateSpeed(float translateSpeed)
voidsetZoomSpeed(float zoomSpeed)
virtual voidupdate() override<br>Recalculates the view and projection matrices based on the internal camera state.
virtual voidviewpoint(AbstractCamera::Viewpoint viewpoint) override<br>Moves the camera to the specified viewpoint.

Protected Functions ​

Name
virtual voidmouseWheel(float scroll)

Protected Attributes ​

Name
glm::mat4m_accumulatedRotation
floatm_dScroll
floatm_rotateSpeed
boolm_smoothScroll
floatm_smoothScrollDamping
floatm_translateSpeed
floatm_zoomSpeed

Additional inherited members ​

Public Functions inherited from Vp::AbstractOrbitCamera

Name
virtual voidcenterOnBox(glm::vec3 boxMin, glm::vec3 boxMax, bool interpolate) override<br>Moves camera so that the specified axis aligned bounding box is visible.
glm::vec3getPivot() const
floatgetRadius() const
voidsetPivot(const glm::vec3 & pivot)
voidsetRadius(float radius)

Protected Attributes inherited from Vp::AbstractOrbitCamera

Name
glm::vec3m_pivot
floatm_radius

Public Types inherited from Vp::AbstractCamera

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

Public Functions inherited from Vp::AbstractCamera

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 voidsetFov(float fov)
virtual voidsetZFar(float zFar)
virtual voidsetZNear(float zNear)
virtual voidsize(int width, int height)<br>Sets the camera resolution in pixels.

Protected Functions inherited from Vp::AbstractCamera

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

Protected Attributes inherited from Vp::AbstractCamera

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.
boolrightHanded

Public Functions Documentation ​

function getRotateSpeed ​

cpp
float getRotateSpeed() const

function getRotation ​

cpp
glm::mat4 getRotation() const

function getSmoothScroll ​

cpp
bool getSmoothScroll() const

function getSmoothScrollDamping ​

cpp
float getSmoothScrollDamping() const

function getTranslateSpeed ​

cpp
float getTranslateSpeed() const

function getZoomSpeed ​

cpp
float getZoomSpeed() const

function processInput ​

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

Updates the internal camera state with user input.

Parameters:

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

Reimplements: Vp::AbstractCamera::processInput

function setRotateSpeed ​

cpp
void setRotateSpeed(
    float rotateSpeed
)

function setRotation ​

cpp
void setRotation(
    glm::mat4 rotation
)

function setSmoothScroll ​

cpp
void setSmoothScroll(
    bool b
)

function setSmoothScrollDamping ​

cpp
void setSmoothScrollDamping(
    float val
)

function setTranslateSpeed ​

cpp
void setTranslateSpeed(
    float translateSpeed
)

function setZoomSpeed ​

cpp
void setZoomSpeed(
    float zoomSpeed
)

function update ​

cpp
virtual void update() override

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

Reimplements: Vp::AbstractCamera::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
) override

Moves the camera to the specified viewpoint.

Parameters:

  • viewpoint

Reimplements: Vp::AbstractCamera::viewpoint

Subclasses need to provide their own implementations.

Protected Functions Documentation ​

function mouseWheel ​

cpp
virtual void mouseWheel(
    float scroll
)

Protected Attributes Documentation ​

variable m_accumulatedRotation ​

cpp
glm::mat4 m_accumulatedRotation = glm::mat4(1);

variable m_dScroll ​

cpp
float m_dScroll = 0.0f;

variable m_rotateSpeed ​

cpp
float m_rotateSpeed = 0.29f;

variable m_smoothScroll ​

cpp
bool m_smoothScroll = true;

variable m_smoothScrollDamping ​

cpp
float m_smoothScrollDamping = 0.85f;

variable m_translateSpeed ​

cpp
float m_translateSpeed = 0.02f;

variable m_zoomSpeed ​

cpp
float m_zoomSpeed = 0.8f;

Updated on 2026-09-11 at 21:24:25 +0000