… | |
… | |
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 | }; |
|
|
68 | |
|
|
69 | struct entity_affine : entity_filter { |
|
|
70 | //matrix m; |
|
|
71 | }; |
64 | }; |
72 | |
65 | |
73 | struct vertex1d { |
66 | struct vertex1d { |
74 | colour c; // colour |
67 | colour c; // colour |
75 | point p; // vertex |
68 | point p; // vertex |
76 | }; |
69 | }; |
77 | |
70 | |
78 | struct vertex2d { |
71 | struct vertex2d { |
79 | colour c; // colour |
|
|
80 | point p; // vertex |
72 | point p; // vertex |
81 | vec3 n; // normal |
73 | vec3 n; // normal |
82 | texc t; // texture |
74 | texc t; // texture |
83 | |
75 | |
84 | vertex2d () { }; |
76 | vertex2d () { }; |
85 | vertex2d (colour c, point p, vec3 n, texc t = texc()) : c(c), p(p), n(n), t(t) { }; |
77 | vertex2d (point p, vec3 n, texc t = texc()) : p(p), n(n), t(t) { }; |
|
|
78 | }; |
|
|
79 | |
|
|
80 | struct entity_opengl : entity_base { |
|
|
81 | GLuint list; |
|
|
82 | |
|
|
83 | entity_opengl (); |
|
|
84 | ~entity_opengl (); |
86 | }; |
85 | }; |
87 | |
86 | |
88 | template<GLenum type> |
87 | template<GLenum type> |
89 | struct entity_opengl1d : entity_base, vector<vertex1d> { |
88 | struct entity_opengl1d : entity_opengl, vector<vertex1d> { |
90 | void update_bbox (); |
89 | void update_bbox (); |
91 | void show (const sector &sec); |
|
|
92 | void draw (const draw_context &ctx); |
90 | void draw (draw_context &ctx); |
93 | }; |
91 | }; |
94 | |
92 | |
95 | template<GLenum type> |
93 | template<GLenum type> |
96 | struct entity_opengl2d : entity_base, vector<vertex2d> { |
94 | struct entity_opengl2d : entity_opengl { |
97 | void update_bbox (); |
95 | material m; |
98 | void show (const sector &sec); |
96 | |
|
|
97 | void set (const vector<vertex2d> &v); |
99 | void draw (const draw_context &ctx); |
98 | void draw (draw_context &ctx); |
|
|
99 | |
100 | }; |
100 | }; |
101 | |
101 | |
102 | typedef entity_opengl1d<GL_POINTS> entity_points; |
102 | typedef entity_opengl1d<GL_POINTS> entity_points; |
103 | typedef entity_opengl1d<GL_LINES> entity_lines; |
103 | typedef entity_opengl1d<GL_LINES> entity_lines; |
104 | typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
104 | typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
… | |
… | |
108 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
108 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
109 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
109 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
110 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
110 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
111 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
111 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
112 | |
112 | |
113 | struct view { |
113 | struct entity_transform : entity_filter { |
114 | point p; |
114 | gl_matrix m; |
115 | vec3 d, u; |
|
|
116 | float fov; |
|
|
117 | int w, h; |
|
|
118 | |
115 | |
|
|
116 | entity_transform (); |
|
|
117 | |
|
|
118 | void update_bbox (); |
|
|
119 | void show (); |
119 | void draw (const draw_context &ctx); |
120 | void draw (draw_context &ctx); |
|
|
121 | }; |
|
|
122 | |
|
|
123 | struct entity_anim : entity_transform { |
|
|
124 | GLfloat vx, vy, vz; |
|
|
125 | void draw (draw_context &ctx); |
120 | }; |
126 | }; |
121 | |
127 | |
122 | #endif |
128 | #endif |
123 | |
129 | |
124 | |
130 | |