-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.cpp
40 lines (36 loc) · 950 Bytes
/
camera.cpp
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
#include "camera.h"
#include <math.h>
Matrix4x4 camera_calc_view_matrix(const Camera& c)
{
return matrix4x4_inverse(matrix4x4_from_rotation_and_translation(c.rotation, c.position));
}
Camera camera_create_projection()
{
float near_plane = 0.01f;
float far_plane = 1000.0f;
float fov = 90.0f;
float aspect = 1.0f;
float y_scale = 1.0f / tanf((3.14f / 180.0f) * fov / 2);
float x_scale = y_scale / aspect;
Camera c = {};
c.projection_matrix = {
x_scale, 0, 0, 0,
0, y_scale, 0, 0,
0, 0, far_plane/(far_plane-near_plane), 1,
0, 0, (-far_plane * near_plane) / (far_plane - near_plane), 0
};
c.rotation = quaternion_identity();
return c;
}
Camera camera_create_uv_rendering()
{
Camera c = {};
c.projection_matrix = {
-2, 0, 0, 0,
0, 2, 0, 0,
0, 0, 1, 0,
1, -1, 0, 1
};
c.rotation = quaternion_identity();
return c;
}