… | |
… | |
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 (); |
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) |
|
|
32 | { |
|
|
33 | push_back (e); |
|
|
34 | e->parent = this; |
|
|
35 | update (); |
|
|
36 | } |
|
|
37 | |
30 | void update_bbox (); |
38 | void update (); |
31 | void show (const sector &sec); |
39 | void show (); |
32 | void draw (const draw_context &ctx); |
40 | void draw (draw_context &ctx); |
33 | ~entity_container (); |
41 | ~entity_container (); |
34 | }; |
42 | }; |
35 | |
43 | |
36 | struct entity_filter : entity_base { |
44 | struct entity_filter : entity_base { |
37 | protected: |
45 | protected: |
… | |
… | |
40 | |
48 | |
41 | void set (entity_base *e) |
49 | void set (entity_base *e) |
42 | { |
50 | { |
43 | this->e = e; |
51 | this->e = e; |
44 | e->parent = this; |
52 | e->parent = this; |
|
|
53 | update (); |
45 | } |
54 | } |
46 | |
55 | |
47 | void remove () |
56 | void remove () |
48 | { |
57 | { |
49 | this->e->parent = 0; |
58 | this->e->parent = 0; |
50 | this->e = 0; |
59 | this->e = 0; |
51 | } |
60 | } |
52 | |
61 | |
53 | entity_base *content () { return e; }; |
62 | entity_base *content () { return e; }; |
54 | |
63 | |
55 | void update_bbox (); |
64 | void update (); |
56 | void show (const sector &sec); |
65 | void show (); |
57 | void draw (const draw_context &ctx); |
66 | void draw (draw_context &ctx); |
58 | ~entity_filter (); |
67 | ~entity_filter (); |
59 | }; |
68 | }; |
60 | |
69 | |
61 | struct entity : entity_filter { |
70 | 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 | }; |
71 | }; |
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 | |
72 | |
77 | struct vertex1d { |
73 | struct vertex1d { |
78 | colour c; // colour |
74 | colour c; // colour |
79 | point p; // vertex |
75 | point p; // vertex |
80 | }; |
76 | }; |
… | |
… | |
87 | vertex2d () { }; |
83 | vertex2d () { }; |
88 | vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; |
84 | vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; |
89 | }; |
85 | }; |
90 | |
86 | |
91 | struct entity_opengl : entity_base { |
87 | struct entity_opengl : entity_base { |
|
|
88 | GLuint list; |
|
|
89 | |
|
|
90 | entity_opengl (); |
|
|
91 | ~entity_opengl (); |
92 | }; |
92 | }; |
93 | |
93 | |
94 | template<GLenum type> |
94 | template<GLenum type> |
95 | struct entity_opengl1d : entity_opengl, vector<vertex1d> { |
95 | struct entity_opengl1d : entity_opengl, vector<vertex1d> { |
96 | void update_bbox (); |
96 | void update (); |
97 | void show (const sector &sec); |
|
|
98 | void draw (const draw_context &ctx); |
97 | void draw (draw_context &ctx); |
99 | }; |
98 | }; |
100 | |
99 | |
101 | template<GLenum type> |
100 | template<GLenum type> |
102 | struct entity_opengl2d : entity_opengl, vector<vertex2d> { |
101 | struct entity_opengl2d : entity_opengl { |
103 | material m; |
102 | material m; |
104 | |
103 | |
105 | void update_bbox (); |
104 | void set (const vector<vertex2d> &v); |
106 | void show (const sector &sec); |
|
|
107 | void draw (const draw_context &ctx); |
105 | void draw (draw_context &ctx); |
108 | }; |
106 | }; |
109 | |
107 | |
110 | typedef entity_opengl1d<GL_POINTS> entity_points; |
108 | typedef entity_opengl1d<GL_POINTS> entity_points; |
111 | typedef entity_opengl1d<GL_LINES> entity_lines; |
109 | typedef entity_opengl1d<GL_LINES> entity_lines; |
112 | typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
110 | typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
… | |
… | |
116 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
114 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
117 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
115 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
118 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
116 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
119 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
117 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
120 | |
118 | |
121 | struct view { |
119 | struct entity_transform : entity_filter { |
122 | point p; |
120 | protected: |
123 | vec3 d, u; |
121 | matrix m; |
124 | float fov; |
122 | void renormalize (); |
125 | int w, h; |
123 | public: |
126 | |
124 | |
|
|
125 | entity_transform (); |
|
|
126 | |
|
|
127 | void update (); |
|
|
128 | void show (); |
127 | void draw (const draw_context &ctx); |
129 | void draw (draw_context &ctx); |
|
|
130 | void set_matrix (const matrix &xfrm); |
|
|
131 | void update (const matrix &xfrm); |
|
|
132 | }; |
|
|
133 | |
|
|
134 | struct entity_anim : entity_transform { |
|
|
135 | GLfloat vx, vy, vz; |
|
|
136 | void draw (draw_context &ctx); |
128 | }; |
137 | }; |
129 | |
138 | |
130 | #endif |
139 | #endif |
131 | |
140 | |
132 | |
141 | |