Working with a 3D camera and basic user interaction
To debug a graphical application, it is very helpful to be able to navigate and move around within a 3D scene using a keyboard or mouse. Graphics APIs by themselves are not familiar with the concepts of camera and user interaction, so we have to implement a camera model that will convert user input into a view matrix usable by OpenGL or Vulkan. In this recipe, we will learn how to create a very simple yet extensible camera implementation and use it to enhance the functionality of examples from the previous chapter.
Getting ready
The source code for this recipe can be found in Chapter4/GL01_Camera
.
How to do it...
Our camera implementation will calculate a view matrix and a 3D position point based on the selected dynamic model. Let's look at the steps:
- First, let's implement the
Camera
class, which will represent our main API to work with the 3D camera. The class stores a reference to an instance of the...