… | |
… | |
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 | sector orig; |
15 | vector<octant *> o; |
17 | vector<octant *> o; |
16 | box bbox; |
18 | box bbox; |
17 | |
19 | |
18 | virtual void update_bbox (); |
20 | virtual void update_bbox (); |
19 | virtual void show (const sector &sec) { }; |
21 | virtual void show () { world.add (this); }; |
20 | void hide (); |
22 | void hide (); |
|
|
23 | void display (draw_context &ctx); |
21 | virtual void draw (const draw_context &ctx) = 0; |
24 | virtual void draw (draw_context &ctx) = 0; |
|
|
25 | |
|
|
26 | entity_base (); |
22 | virtual ~entity_base () |
27 | virtual ~entity_base (); |
23 | { |
|
|
24 | hide (); |
|
|
25 | }; |
|
|
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 (); |
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: |
… | |
… | |
51 | } |
53 | } |
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 (); |
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; |
|
|
63 | |
|
|
64 | void show (const sector &sec); |
|
|
65 | void show (); |
|
|
66 | void draw (const draw_context &ctx); |
|
|
67 | }; |
64 | }; |
68 | |
|
|
69 | #if 0 |
|
|
70 | struct entity_affine : entity_filter { |
|
|
71 | GLfloat m[4][4]; |
|
|
72 | |
|
|
73 | void draw (const draw_context &ctx); |
|
|
74 | }; |
|
|
75 | #endif |
|
|
76 | |
65 | |
77 | struct vertex1d { |
66 | struct vertex1d { |
78 | colour c; // colour |
67 | colour c; // colour |
79 | point p; // vertex |
68 | point p; // vertex |
80 | }; |
69 | }; |
… | |
… | |
92 | }; |
81 | }; |
93 | |
82 | |
94 | template<GLenum type> |
83 | template<GLenum type> |
95 | struct entity_opengl1d : entity_opengl, vector<vertex1d> { |
84 | struct entity_opengl1d : entity_opengl, vector<vertex1d> { |
96 | void update_bbox (); |
85 | void update_bbox (); |
97 | void show (const sector &sec); |
|
|
98 | void draw (const draw_context &ctx); |
86 | void draw (draw_context &ctx); |
99 | }; |
87 | }; |
100 | |
88 | |
101 | template<GLenum type> |
89 | template<GLenum type> |
102 | struct entity_opengl2d : entity_opengl, vector<vertex2d> { |
90 | struct entity_opengl2d : entity_opengl, vector<vertex2d> { |
103 | material m; |
91 | material m; |
|
|
92 | GLuint list; |
104 | |
93 | |
105 | void update_bbox (); |
94 | void update_bbox (); |
106 | void show (const sector &sec); |
|
|
107 | void draw (const 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 | } |
108 | }; |
107 | }; |
109 | |
108 | |
110 | typedef entity_opengl1d<GL_POINTS> entity_points; |
109 | typedef entity_opengl1d<GL_POINTS> entity_points; |
111 | typedef entity_opengl1d<GL_LINES> entity_lines; |
110 | typedef entity_opengl1d<GL_LINES> entity_lines; |
112 | typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
111 | typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
… | |
… | |
116 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
115 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
117 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
116 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
118 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
117 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
119 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
118 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
120 | |
119 | |
121 | struct view { |
120 | struct entity_transform : entity_filter { |
122 | point p; |
121 | gl_matrix m; |
123 | vec3 d, u; |
|
|
124 | float fov; |
|
|
125 | int w, h; |
|
|
126 | |
122 | |
|
|
123 | entity_transform (); |
|
|
124 | |
|
|
125 | void update_bbox (); |
|
|
126 | void show (); |
127 | void draw (const draw_context &ctx); |
127 | void draw (draw_context &ctx); |
|
|
128 | }; |
|
|
129 | |
|
|
130 | struct entity_anim : entity_transform { |
|
|
131 | GLfloat vx, vy, vz; |
|
|
132 | void draw (draw_context &ctx); |
128 | }; |
133 | }; |
129 | |
134 | |
130 | #endif |
135 | #endif |
131 | |
136 | |
132 | |
137 | |