VkCV Framework  0.0.1
CV Vulkan framework
vkcv::camera::CameraManager Class Reference

Used for managing an arbitrary amount of camera controllers. More...

#include <CameraManager.hpp>

Collaboration diagram for vkcv::camera::CameraManager:

Public Member Functions

 CameraManager (Window &window)
 The constructor of the CameraManager. More...
 
 ~CameraManager ()
 The destructor of the CameraManager. Destroying the CameraManager leads to deletion of all stored camera objects and camera controller objects.
 
uint32_t addCamera (ControllerType controllerType=ControllerType::NONE)
 Adds a new camera object to the CameraManager and binds it to a camera controller object of specified controllerType. More...
 
uint32_t addCamera (ControllerType controllerType, const Camera &camera)
 Adds a new camera object to the CameraManager and binds it to a camera controller object of specified controllerType. More...
 
CameragetCamera (uint32_t cameraIndex)
 Gets the stored camera object located at cameraIndex. More...
 
CameragetActiveCamera ()
 Gets the stored camera object set as the active camera. More...
 
void setActiveCamera (uint32_t cameraIndex)
 Sets the stored camera object located at cameraIndex as the active camera. More...
 
uint32_t getActiveCameraIndex () const
 Gets the index of the stored active camera object. More...
 
void setControllerType (uint32_t cameraIndex, ControllerType controllerType)
 Binds a stored camera object located at cameraIndex to a camera controller of specified controllerType. More...
 
ControllerType getControllerType (uint32_t cameraIndex)
 Gets the currently bound camera controller type of the stored camera object located at cameraIndex. More...
 
void update (double deltaTime)
 Updates all stored camera controllers in respect to deltaTime. More...
 

Private Member Functions

void bindCameraToEvents ()
 Binds the camera object to the window event handles.
 
void keyCallback (int key, int scancode, int action, int mods)
 A callback function for key events. Currently, cycling between all existing camera controllers via Tab, window closure via Esc and polling key events from the active camera controller are supported. More...
 
void scrollCallback (double offsetX, double offsetY)
 A callback function for mouse scrolling events. More...
 
void mouseMoveCallback (double x, double y)
 A callback function for mouse movement events. More...
 
void mouseButtonCallback (int button, int action, int mods)
 A callback function for mouse button events. More...
 
void resizeCallback (int width, int height)
 A callback function for handling the window resizing event. Each existing camera is resized in respect of the window size. More...
 
void gamepadCallback (int gamepadIndex)
 A callback function for gamepad input events. Currently, inputs are handled only for the first connected gamepad! More...
 
CameraControllergetControllerByType (ControllerType controllerType)
 Gets a camera controller object of specified controllerType. More...
 
CameraControllergetActiveController ()
 

Private Attributes

event_handle< int, int, int, int > m_keyHandle
 
event_handle< double, double > m_mouseMoveHandle
 
event_handle< double, double > m_mouseScrollHandle
 
event_handle< int, int, int > m_mouseButtonHandle
 
event_handle< int, int > m_resizeHandle
 
event_handle< int > m_gamepadHandle
 
Windowm_window
 
std::vector< Cameram_cameras
 
std::vector< ControllerType > m_cameraControllerTypes
 
uint32_t m_activeCameraIndex
 
PilotCameraController m_pilotController
 
TrackballCameraController m_trackController
 
double m_lastX
 
double m_lastY
 
double m_inputDelayTimer
 
double m_frameTime
 

Detailed Description

Used for managing an arbitrary amount of camera controllers.

Constructor & Destructor Documentation

◆ CameraManager()

vkcv::camera::CameraManager::CameraManager ( Window window)
explicit

The constructor of the CameraManager.

Parameters
[in]windowThe window.

References bindCameraToEvents(), vkcv::Window::getHeight(), and vkcv::Window::getWidth().

Here is the call graph for this function:

Member Function Documentation

◆ addCamera() [1/2]

uint32_t vkcv::camera::CameraManager::addCamera ( ControllerType  controllerType,
const Camera camera 
)

Adds a new camera object to the CameraManager and binds it to a camera controller object of specified controllerType.

Parameters
[in]controllerTypeThe type of the camera controller.
[in]cameraThe new camera object.
Returns
The index of the newly bound camera object.

◆ addCamera() [2/2]

uint32_t vkcv::camera::CameraManager::addCamera ( ControllerType  controllerType = ControllerType::NONE)

Adds a new camera object to the CameraManager and binds it to a camera controller object of specified controllerType.

Parameters
[in]controllerTypeThe type of the camera controller.
Returns
The index of the newly created camera object.

References vkcv::Window::getHeight(), vkcv::Window::getWidth(), and vkcv::camera::Camera::setPerspective().

Here is the call graph for this function:

◆ gamepadCallback()

void vkcv::camera::CameraManager::gamepadCallback ( int  gamepadIndex)
private

A callback function for gamepad input events. Currently, inputs are handled only for the first connected gamepad!

Parameters
gamepadIndexThe gamepad index.

References vkcv::camera::CameraController::gamepadCallback(), getActiveCamera(), and getActiveController().

Referenced by bindCameraToEvents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getActiveCamera()

Camera & vkcv::camera::CameraManager::getActiveCamera ( )

Gets the stored camera object set as the active camera.

Returns
The active camera.

References getActiveCameraIndex().

Referenced by gamepadCallback(), keyCallback(), mouseButtonCallback(), mouseMoveCallback(), scrollCallback(), and update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getActiveCameraIndex()

uint32_t vkcv::camera::CameraManager::getActiveCameraIndex ( ) const

Gets the index of the stored active camera object.

Returns
The active camera index.

Referenced by getActiveCamera(), and getActiveController().

Here is the caller graph for this function:

◆ getActiveController()

CameraController & vkcv::camera::CameraManager::getActiveController ( )
private

@briof A method to get the currently active controller for the active camera.

Returns
Reference to the active #CameraController

References getActiveCameraIndex(), getControllerByType(), and getControllerType().

Referenced by gamepadCallback(), keyCallback(), mouseButtonCallback(), mouseMoveCallback(), scrollCallback(), and update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCamera()

Camera & vkcv::camera::CameraManager::getCamera ( uint32_t  cameraIndex)

Gets the stored camera object located at cameraIndex.

Parameters
[in]cameraIndexThe camera index.
Returns
The camera object at cameraIndex.
Exceptions
std::runtime_errorIf cameraIndex is not a valid camera index.

Referenced by resizeCallback().

Here is the caller graph for this function:

◆ getControllerByType()

CameraController & vkcv::camera::CameraManager::getControllerByType ( ControllerType  controllerType)
private

Gets a camera controller object of specified controllerType.

Parameters
[in]controllerTypeThe type of the camera controller.
Returns
The specified camera controller object.

Referenced by getActiveController().

Here is the caller graph for this function:

◆ getControllerType()

ControllerType vkcv::camera::CameraManager::getControllerType ( uint32_t  cameraIndex)

Gets the currently bound camera controller type of the stored camera object located at cameraIndex.

Parameters
[in]cameraIndexThe camera index.
Returns
The type of the camera controller of the specified camera object.
Exceptions
std::runtime_errorIf cameraIndex is not a valid camera index.

Referenced by getActiveController().

Here is the caller graph for this function:

◆ keyCallback()

void vkcv::camera::CameraManager::keyCallback ( int  key,
int  scancode,
int  action,
int  mods 
)
private

A callback function for key events. Currently, cycling between all existing camera controllers via Tab, window closure via Esc and polling key events from the active camera controller are supported.

Parameters
[in]keyThe keyboard key.
[in]scancodeThe platform-specific scancode.
[in]actionThe key action.
[in]modsThe modifier bits.

References getActiveCamera(), getActiveController(), vkcv::Window::getWindow(), and vkcv::camera::CameraController::keyCallback().

Referenced by bindCameraToEvents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseButtonCallback()

void vkcv::camera::CameraManager::mouseButtonCallback ( int  button,
int  action,
int  mods 
)
private

A callback function for mouse button events.

Parameters
[in]buttonThe mouse button.
[in]actionThe button action.
[in]modsThe modifier bits.

References getActiveCamera(), getActiveController(), vkcv::Window::getWindow(), and vkcv::camera::CameraController::mouseButtonCallback().

Referenced by bindCameraToEvents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseMoveCallback()

void vkcv::camera::CameraManager::mouseMoveCallback ( double  x,
double  y 
)
private

A callback function for mouse movement events.

Parameters
[in]xThe horizontal mouse position.
[in]yThe vertical mouse position.

References getActiveCamera(), getActiveController(), vkcv::Window::getHeight(), vkcv::Window::getWidth(), and vkcv::camera::CameraController::mouseMoveCallback().

Referenced by bindCameraToEvents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resizeCallback()

void vkcv::camera::CameraManager::resizeCallback ( int  width,
int  height 
)
private

A callback function for handling the window resizing event. Each existing camera is resized in respect of the window size.

Parameters
[in]widthThe new width of the window.
[in]heightThe new height of the window.

References getCamera(), vkcv::Window::getWindow(), and vkcv::camera::Camera::setRatio().

Referenced by bindCameraToEvents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scrollCallback()

void vkcv::camera::CameraManager::scrollCallback ( double  offsetX,
double  offsetY 
)
private

A callback function for mouse scrolling events.

Parameters
[in]offsetXThe offset in horizontal direction.
[in]offsetYThe offset in vertical direction.

References getActiveCamera(), getActiveController(), and vkcv::camera::CameraController::scrollCallback().

Referenced by bindCameraToEvents().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setActiveCamera()

void vkcv::camera::CameraManager::setActiveCamera ( uint32_t  cameraIndex)

Sets the stored camera object located at cameraIndex as the active camera.

Parameters
[in]cameraIndexThe camera index.
Exceptions
std::runtime_errorIf cameraIndex is not a valid camera index.

◆ setControllerType()

void vkcv::camera::CameraManager::setControllerType ( uint32_t  cameraIndex,
ControllerType  controllerType 
)

Binds a stored camera object located at cameraIndex to a camera controller of specified controllerType.

Parameters
[in]cameraIndexThe camera index.
[in]controllerTypeThe type of the camera controller.
Exceptions
std::runtime_errorIf cameraIndex is not a valid camera index.

◆ update()

void vkcv::camera::CameraManager::update ( double  deltaTime)

Updates all stored camera controllers in respect to deltaTime.

Parameters
[in]deltaTimeThe time that has passed since last update.

References getActiveCamera(), getActiveController(), vkcv::Window::getWindow(), and vkcv::camera::CameraController::updateCamera().

Here is the call graph for this function:

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