1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include "camera.hpp"
void Camera::init(float vfov, const v3f& f, const v3f& p) {
fov = vfov;
forward = f;
position = p;
near = 0.1f;
far = 1000.0f;
asp = 1.0f;
}
void Camera::init_shadow(
const v3f& dir,
const v3f& mic,
const v3f& mac
) {
v3f up(0.0f, 1.0f, 0.0f);
AABB aabb = { mic, mac };
init(0.0f, dir, v3f(0.0f));
view = m4f::lookat(
dir,
v3f(0.0f),
up
);
aabb = m4f::transform(view, aabb);
proj = m4f::orth(
aabb.min.x,
aabb.max.x,
aabb.max.y,
aabb.min.y,
aabb.min.z,
aabb.max.z
);
}
void Camera::update() {
v3f up(0.0f, 1.0f, 0.0f);
view = m4f::lookat(position, position + forward, up);
proj = m4f::pers(fov, asp, near, far);
}
const m4f& Camera::get_view() const {
return view;
}
const m4f& Camera::get_proj() const {
return proj;
}
|