1 | #ifndef VIEW_H |
1 | #ifndef VIEW_H |
2 | #define VIEW_H |
2 | #define VIEW_H |
3 | |
3 | |
4 | #include <set> |
4 | #include <set> |
|
|
5 | #include <map> |
5 | |
6 | |
6 | using namespace std; |
7 | using namespace std; |
7 | |
8 | |
8 | #include "util.h" |
9 | #include "util.h" |
9 | |
10 | |
10 | struct draw_context { |
|
|
11 | enum { DEPTH, LIGHTED } mode; |
|
|
12 | light *l; |
|
|
13 | set<entity_base *> drawn; |
|
|
14 | |
|
|
15 | bool may_draw (entity_base *e); |
|
|
16 | |
|
|
17 | draw_context (); |
|
|
18 | ~draw_context (); |
|
|
19 | }; |
|
|
20 | |
|
|
21 | struct view { |
11 | struct view { |
|
|
12 | sector orig; |
22 | point p; |
13 | point p; |
23 | vec3 d, u; |
14 | vec3 d, u; |
24 | float fov; |
15 | float fov; |
25 | int w, h; |
16 | int w, h; |
26 | |
17 | |
27 | void draw (draw_context &ctx); |
18 | void draw (draw_context &ctx); |
28 | }; |
19 | }; |
29 | |
20 | |
|
|
21 | struct visibility_state { |
|
|
22 | unsigned int generation; |
|
|
23 | enum { UNKNOWN, OCCLUDED, PARTIAL, FULL } visibility; |
|
|
24 | |
|
|
25 | visibility_state () : generation(0), visibility(UNKNOWN) { }; |
|
|
26 | }; |
|
|
27 | |
|
|
28 | struct draw_context { |
|
|
29 | view &v; |
|
|
30 | |
|
|
31 | gl_matrix projection; |
|
|
32 | struct { |
|
|
33 | plane l, r, t, b, n, f; |
|
|
34 | } frustum; |
|
|
35 | enum { DEPTH, LIGHTED } mode; |
|
|
36 | light *l; |
|
|
37 | set<entity_base *> drawn; |
|
|
38 | |
|
|
39 | unsigned int generation; |
|
|
40 | map<octant *, visibility_state> vismap; |
|
|
41 | vector<octant *> vislist; // octants partially or fully visible |
|
|
42 | vector<octant *> checklist; // octants possibly visible |
|
|
43 | |
|
|
44 | bool may_draw (entity_base *e); |
|
|
45 | |
|
|
46 | draw_context (view &v); |
|
|
47 | ~draw_context (); |
|
|
48 | }; |
|
|
49 | |
|
|
50 | inline void update_matrix (const draw_context &ctx) |
|
|
51 | { |
|
|
52 | gl_matrix m1 = ctx.projection; |
|
|
53 | gl_matrix m2; |
|
|
54 | |
|
|
55 | glGetFloatv (GL_MODELVIEW_MATRIX, (GLfloat *)&m2); |
|
|
56 | |
|
|
57 | m1 = m1 * m2; |
|
|
58 | |
|
|
59 | for (int i = 0; i < 4; i++) |
|
|
60 | for (int j = 0; j < 4 ; j++) |
|
|
61 | mvp[i][j] = m1(i,j); |
|
|
62 | } |
|
|
63 | |
30 | #endif |
64 | #endif |
31 | |
65 | |