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