Camera management

Managing cameras (even multiple) with the VkCV framework is quite easy. You can create a camera manager instance for your window, add a new camera with its individual controller type. Then you get all benefits of adjusting the camera during runtime with input as well as switching between multiple cameras.

The individual cameras will be identified via their handle related to their manager. So don't use these handles with different managers and such. It's probably best to use only one camera manager per application anyway.

Just notice that cameras, camera controllers and their manager are not part of the core VkCV framework but another module. So you need to add the ${vkcv_camera_include} as include directory and vkcv_camera as library for linkage in the "CMakeLists.txt" file of your project.

#include <vkcv/camera/CameraManager.hpp>
vkcv::camera::CameraManager cameraManager (window);

// add a new camera to the application with a pilot controller
auto camHandle = cameraManager.addCamera(vkcv::camera::ControllerType::PILOT);

// change the initial position of the new camera (selected via its handle)
cameraManager.getCamera(camHandle).setPosition(glm::vec3(0, 0, 2));

With the camera manager and at least one camera you can adjust the code from the previous step to pass the model-view-projection matrix from the active camera to the push constants instead of the identity matrix. This camera matrix will be adjustable during runtime via keyboard, mouse and gamepad input.

glm::mat4 mvp = cameraManager.getActiveCamera().getMVP();

core.recordDrawcallsToCmdStream(
  cmdStream,                   // command stream
  gfxPipeline,                 // graphics pipeline
  
  // push constants with the camera's model-view-projection matrix
  vkcv::pushConstants<glm::mat4>(mvp),
  
  { drawcall },                // vector of instance drawcalls to record
  { swapchainInput },          // render targets to attach as image handles
  windowHandle                 // window handle to select the surface
);

Previous

Next

Popular posts from this blog

Introduction

Application development

First setup