T 4.3 Camera Control
The Camera Frame
The Camera's frame has its origin locate at the eye/camera position, looking towards the -Z direction. Its Y axis points to the up direction and X axis points to the right hand side.

In following sections, examples will be given to demonstrate how to achieve camera rotation along the Y (pan) and X axis (tilt) as well as translation along the camera Z axis (zoom in/out) and world axis.
At the beginning of key_callback() in main.cpp , we set the increment steps for our angles and translations. Also we use a tempory variable mat to present the step transformation applied to our view matrix.
Camera Control
Common camera control include pan, tilt and zoom. Among the three, pan and tilt can be interpreted as local rotations and zoom can be interpreted as translations along its Z axis. All of the three transforms are relative to the camera space.
Pan
A camera Pan is to rotate the camera in a leftward and rigthward way, which is a rotation of around Y axis (pan left is a CCW rotation with a positive angle and pan right is a CW rotation with a negavtive angle).
We have learned from the lecture that:
We write this in our key event processing code
Tilt
A camera Tilt is to rotate the camera in a upward and downward way, which is a rotation of (tilt up is a CCW rotation with a positive angle and tilt down is a CW rotation with a negavtive angle).
We have learned that, similar to the pan angle, we have:
Zoom In/Out
A camera zoom is not a rotation but a translation along its own Z axis. A zoom in is to move a negative distance along its camera frame Z axis. A zoom out is to move a posive distance along its camera frame Z axis.
From what we learned in the lecture, we know that a translation relative to the camera frame is:
Accodingly, we have the following code
Camera's Translation in the World Space
Camera's translation in the world space can be achieved via:
You can try it by yoursel.
Reset
Finally we need a reset function to reset the modelling and view matrices. I am choosing press "r" triggers that.
Result
Example: panning left followed by tilting up.

Last updated