-
Notifications
You must be signed in to change notification settings - Fork 15
/
view.c
60 lines (51 loc) · 902 Bytes
/
view.c
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
50
51
52
53
54
55
56
57
58
59
60
#include "matrix.h"
static struct {
float matrix[16];
float width;
float height;
float z;
}
state = {
.z = 2.0f,
};
const float *
view_matrix (void)
{
return state.matrix;
}
static void
view_recalc (void)
{
float aspect_ratio = state.width / state.height;
float matrix_frustum[16];
float matrix_translate[16];
// Create frustum matrix:
mat_frustum(matrix_frustum, 0.7, aspect_ratio, 0.5, 6);
// Create frustum translation matrix:
mat_translate(matrix_translate, 0, 0, state.z);
// Combine into perspective matrix:
mat_multiply(state.matrix, matrix_frustum, matrix_translate);
}
void
view_set_window (int width, int height)
{
state.width = width;
state.height = height;
view_recalc();
}
void
view_z_decrease (void)
{
if (state.z > 1.5f) {
state.z -= 0.1f;
view_recalc();
}
}
void
view_z_increase (void)
{
if (state.z < 5.0f) {
state.z += 0.1f;
view_recalc();
}
}