19/21

9. Camera

3D scene are often conceived as containing shapes, lights, and observed from a camera in space. Technically, there is no difference between moving forward a camera, or moving backward all objects of the scene. Camera can therefore be implemented as applying the opposite transform to all objects of the scene.

We commonly encounter three types of transformation applied to vertices in the following order

  • Model transformation: Applied to a specific shape to set its position and orientation in space (possibly animated). All shapes may have their own associated model transformation.

  • View transformation: Corresponds to the inverse transform of the camera position and orientation in space. Typically, the same View matrix is applied to all shapes of the scene.

  • Perspective projection: Models the perspective transform. This matrix is applied at last once vertices have been placed in the local frame of the camera.

Interactive camera model

The following code implements a possible model of camera controlled by the mouse.

[ source ]

interactive

Note the following addition

  • Files vec_mat (hpp, cpp) contain helper math 3D vector and \(3\times 3\) matrix to model conveniently transformations.

  • Files camera_scene (hpp, cpp) contain the implementation of the camera operations (change of orientation, zoom, spanning, etc).

  • Files camera_control_helper (hpp, cpp) handle the conversion between motion of the mouse received by GLFW, and transformation to apply on the camera.

Shaders have been updated to handle camera transform (called view), and camera position to compute illumination. The aspect ratio of the perspective projection is also updated when the window is resized.