Files
notes/docs/lectures/graphics/07_camera.md
T

65 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Camera Essentials
There are two types of camera:
1. A model-viewer camera
2. A fly-through camera
A camera involves
1. A position in 3D space
2. A forward direction
3. A right direction
4. An up direction
Calculating a camera direction can be achieved using Euler angles, **pitch**, **yaw** and **roll** .
- Pitch rotates the camera on the x axis
- Think of a plane pointing its nose to the floor or to the sky
- Yaw rotates the camera on the y axis
- Think a plane moving the nose left to right keeping the wings parallel with the ground
- Roll rotates the camera on the z axis
- Think tilting the plane’s wings left and right, but not changing the direction of the nose
#### Model-Viewer Camera
This is a camera that can rotate around the model in a sphere.
![1648476699.png](img/1648476699.png)
Changing the pitch of the camera makes the camera move upwards and point downwards, here the camera moves around the sphere where the direction is always towards the model
![1648476784.png](img/1648476784.png)
The camera can also move back and forwards, making the sphere bigger or smaller.
![1648476819.png](img/1648476819.png)
$$
\begin{aligned}
p_x = &\cos\theta * \cos\alpha \\
p_y = &\sin\alpha \\
p_z = &\sin\theta * \cos\alpha
\end{aligned}
$$
#### Fly-Through Camera
The camera has a position in world space and a focus direction `front`, which can be focused on the model or not.
We can move this kind of camera, forward, backward, left and right along with pitch, roll and yaw.
The camera is at the center of the sphere, and the model moves around the edge of the sphere.
A unit vector points from the camera to the model as the front direction of the camera
We can move the camera forwards and backwards by
```c
pos += front //forwards
pos -= front //backwards
pos += right //move right
pos -= right //move left
```