65 lines
1.8 KiB
Markdown
65 lines
1.8 KiB
Markdown
# 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.
|
||
|
||

|
||
|
||
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
|
||
|
||

|
||
|
||
The camera can also move back and forwards, making the sphere bigger or smaller.
|
||
|
||

|
||
|
||
$$
|
||
\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
|
||
```
|