… | |
… | |
5 | |
5 | |
6 | #include <vector> |
6 | #include <vector> |
7 | |
7 | |
8 | #include "util.h" |
8 | #include "util.h" |
9 | #include "oct.h" |
9 | #include "oct.h" |
|
|
10 | #include "view.h" |
10 | |
11 | |
11 | using namespace std; |
12 | using namespace std; |
12 | |
13 | |
13 | struct entity_base { |
14 | struct entity_base { |
14 | struct entity_base *parent; |
15 | struct entity_base *parent; |
… | |
… | |
16 | box bbox; |
17 | box bbox; |
17 | |
18 | |
18 | virtual void update_bbox (); |
19 | virtual void update_bbox (); |
19 | virtual void show (const sector &sec) { }; |
20 | virtual void show (const sector &sec) { }; |
20 | void hide (); |
21 | void hide (); |
21 | virtual void draw (const draw_context &ctx) = 0; |
22 | virtual void draw (draw_context &ctx) = 0; |
|
|
23 | void try_draw (draw_context &ctx) { if (ctx.may_draw (this)) draw (ctx); } |
22 | virtual ~entity_base () |
24 | virtual ~entity_base () |
23 | { |
25 | { |
24 | hide (); |
26 | hide (); |
25 | }; |
27 | }; |
26 | }; |
28 | }; |
27 | |
29 | |
28 | struct entity_container : entity_base, protected vector<entity_base *> { |
30 | struct entity_container : entity_base, protected vector<entity_base *> { |
29 | void add (entity_base *e) { push_back (e); e->parent = this; } |
31 | void add (entity_base *e) { push_back (e); e->parent = this; } |
30 | void update_bbox (); |
32 | void update_bbox (); |
31 | void show (const sector &sec); |
33 | void show (const sector &sec); |
32 | void draw (const draw_context &ctx); |
34 | void draw (draw_context &ctx); |
33 | ~entity_container (); |
35 | ~entity_container (); |
34 | }; |
36 | }; |
35 | |
37 | |
36 | struct entity_filter : entity_base { |
38 | struct entity_filter : entity_base { |
37 | protected: |
39 | protected: |
… | |
… | |
52 | |
54 | |
53 | entity_base *content () { return e; }; |
55 | entity_base *content () { return e; }; |
54 | |
56 | |
55 | void update_bbox (); |
57 | void update_bbox (); |
56 | void show (const sector &sec); |
58 | void show (const sector &sec); |
57 | void draw (const draw_context &ctx); |
59 | void draw (draw_context &ctx); |
58 | ~entity_filter (); |
60 | ~entity_filter (); |
59 | }; |
61 | }; |
60 | |
62 | |
61 | struct entity : entity_filter { |
63 | struct entity : entity_filter { |
62 | sector sec; |
64 | sector sec; |
63 | |
65 | |
64 | void show (const sector &sec); |
66 | void show (const sector &sec); |
65 | void show (); |
67 | void show (); |
66 | void draw (const draw_context &ctx); |
68 | void draw (draw_context &ctx); |
67 | }; |
69 | }; |
68 | |
70 | |
|
|
71 | #if 0 |
69 | struct entity_affine : entity_filter { |
72 | struct entity_affine : entity_filter { |
70 | //matrix m; |
73 | GLfloat m[4][4]; |
|
|
74 | |
|
|
75 | void draw (draw_context &ctx); |
71 | }; |
76 | }; |
|
|
77 | #endif |
72 | |
78 | |
73 | struct vertex1d { |
79 | struct vertex1d { |
74 | colour c; // colour |
80 | colour c; // colour |
75 | point p; // vertex |
81 | point p; // vertex |
76 | }; |
82 | }; |
… | |
… | |
89 | |
95 | |
90 | template<GLenum type> |
96 | template<GLenum type> |
91 | struct entity_opengl1d : entity_opengl, vector<vertex1d> { |
97 | struct entity_opengl1d : entity_opengl, vector<vertex1d> { |
92 | void update_bbox (); |
98 | void update_bbox (); |
93 | void show (const sector &sec); |
99 | void show (const sector &sec); |
94 | void draw (const draw_context &ctx); |
100 | void draw (draw_context &ctx); |
95 | }; |
101 | }; |
96 | |
102 | |
97 | template<GLenum type> |
103 | template<GLenum type> |
98 | struct entity_opengl2d : entity_opengl, vector<vertex2d> { |
104 | struct entity_opengl2d : entity_opengl, vector<vertex2d> { |
99 | material m; |
105 | material m; |
100 | |
106 | |
101 | void update_bbox (); |
107 | void update_bbox (); |
102 | void show (const sector &sec); |
108 | void show (const sector &sec); |
103 | void draw (const draw_context &ctx); |
109 | void draw (draw_context &ctx); |
104 | }; |
110 | }; |
105 | |
111 | |
106 | typedef entity_opengl1d<GL_POINTS> entity_points; |
112 | typedef entity_opengl1d<GL_POINTS> entity_points; |
107 | typedef entity_opengl1d<GL_LINES> entity_lines; |
113 | typedef entity_opengl1d<GL_LINES> entity_lines; |
108 | typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
114 | typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
… | |
… | |
112 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
118 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
113 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
119 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
114 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
120 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
115 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
121 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
116 | |
122 | |
117 | struct view { |
|
|
118 | point p; |
|
|
119 | vec3 d, u; |
|
|
120 | float fov; |
|
|
121 | int w, h; |
|
|
122 | |
|
|
123 | void draw (const draw_context &ctx); |
|
|
124 | }; |
|
|
125 | |
|
|
126 | #endif |
123 | #endif |
127 | |
124 | |
128 | |
125 | |
129 | |
126 | |