… | |
… | |
19 | soffs x, y, z; |
19 | soffs x, y, z; |
20 | }; |
20 | }; |
21 | |
21 | |
22 | struct point { |
22 | struct point { |
23 | GLfloat x, y, z; |
23 | GLfloat x, y, z; |
|
|
24 | |
|
|
25 | point () { }; |
|
|
26 | point (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; |
24 | }; |
27 | }; |
25 | |
28 | |
26 | struct colour { |
29 | struct colour { |
27 | GLfloat r, g, b; |
30 | GLfloat r, g, b; |
|
|
31 | colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1.) : r(r), g(g), b(b) { }; |
28 | }; |
32 | }; |
29 | |
33 | |
30 | struct vect { |
34 | struct vec3 { |
31 | GLfloat x, y, z; |
35 | GLfloat x, y, z; |
|
|
36 | vec3 () { }; |
|
|
37 | vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; |
|
|
38 | |
|
|
39 | const vec3 operator -() const |
|
|
40 | { return vec3 (-x, -y, -z); } |
32 | }; |
41 | }; |
33 | |
42 | |
|
|
43 | const vec3 cross (const vec3 &a, const vec3 &b); |
|
|
44 | GLfloat dot (const vec3 &a, const vec3 &b); |
|
|
45 | |
34 | struct texc { |
46 | struct texc { |
35 | GLfloat u, v; |
47 | GLfloat s, t; |
|
|
48 | texc () { }; |
|
|
49 | texc (GLfloat s, GLfloat t) : s(s), t(t) { }; |
36 | }; |
50 | }; |
37 | |
51 | |
38 | struct box { |
52 | struct box { |
39 | point a, b; |
53 | point a, b; |
40 | |
54 | |
41 | void reset () |
55 | void reset () |
42 | { |
56 | { |
43 | a.x = a.y = a.z = GLFLOAT_MAX; |
57 | a = point (GLFLOAT_MAX, GLFLOAT_MAX, GLFLOAT_MAX); |
44 | b.x = b.y = b.z = GLFLOAT_MIN; |
58 | b = point (GLFLOAT_MIN, GLFLOAT_MIN, GLFLOAT_MIN); |
45 | } |
59 | } |
46 | |
60 | |
47 | void add (const box &o); |
61 | void add (const box &o); |
48 | }; |
62 | }; |
49 | |
63 | |
… | |
… | |
61 | hide (); |
75 | hide (); |
62 | }; |
76 | }; |
63 | }; |
77 | }; |
64 | |
78 | |
65 | struct entity_container : entity_base, protected vector<entity_base *> { |
79 | struct entity_container : entity_base, protected vector<entity_base *> { |
|
|
80 | void add (entity_base *e) { push_back (e); e->parent = this; } |
66 | void update_bbox (); |
81 | void update_bbox (); |
67 | void show (const sector &sec); |
82 | void show (const sector &sec); |
68 | void draw (); |
83 | void draw (); |
69 | ~entity_container (); |
84 | ~entity_container (); |
70 | }; |
85 | }; |
… | |
… | |
96 | |
111 | |
97 | struct entity : entity_filter { |
112 | struct entity : entity_filter { |
98 | sector sec; |
113 | sector sec; |
99 | |
114 | |
100 | void show (const sector &sec); |
115 | void show (const sector &sec); |
|
|
116 | void show (); |
101 | void draw (); |
117 | void draw (); |
102 | }; |
118 | }; |
103 | |
119 | |
104 | struct entity_affine : entity_filter { |
120 | struct entity_affine : entity_filter { |
105 | //matrix m; |
121 | //matrix m; |
106 | }; |
122 | }; |
107 | |
123 | |
108 | struct vertex1d { |
124 | struct vertex1d { |
109 | point v; // vertex |
|
|
110 | colour c; // colour |
125 | colour c; // colour |
|
|
126 | point p; // vertex |
111 | }; |
127 | }; |
112 | |
128 | |
113 | struct vertex2d { |
129 | struct vertex2d { |
114 | point v; // vertex |
|
|
115 | colour c; // colour |
130 | colour c; // colour |
|
|
131 | point p; // vertex |
116 | vect n; // normal |
132 | vec3 n; // normal |
117 | texc t; // texture |
133 | texc t; // texture |
|
|
134 | |
|
|
135 | vertex2d () { }; |
|
|
136 | vertex2d (colour c, point p, vec3 n, texc t = texc()) : c(c), p(p), n(n), t(t) { }; |
118 | }; |
137 | }; |
119 | |
138 | |
120 | template<GLenum type> |
139 | template<GLenum type> |
121 | struct entity_opengl1d : entity_base, vector<vertex1d> { |
140 | struct entity_opengl1d : entity_base, vector<vertex1d> { |
122 | void update_bbox (); |
141 | void update_bbox (); |
… | |
… | |
131 | void draw (); |
150 | void draw (); |
132 | }; |
151 | }; |
133 | |
152 | |
134 | typedef entity_opengl1d<GL_POINTS> entity_points; |
153 | typedef entity_opengl1d<GL_POINTS> entity_points; |
135 | typedef entity_opengl1d<GL_LINES> entity_lines; |
154 | typedef entity_opengl1d<GL_LINES> entity_lines; |
136 | typedef entity_opengl1d<GL_LINE_STRIP> entity_linestrip; |
155 | typedef entity_opengl1d<GL_LINE_STRIP> entity_line_strip; |
137 | typedef entity_opengl1d<GL_LINE_LOOP> entity_lineloop; |
156 | typedef entity_opengl1d<GL_LINE_LOOP> entity_line_loop; |
138 | typedef entity_opengl2d<GL_TRIANGLES> entity_triangles; |
157 | typedef entity_opengl2d<GL_TRIANGLES> entity_triangles; |
139 | typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_trianglestrip; |
158 | typedef entity_opengl2d<GL_TRIANGLE_STRIP> entity_triangle_strip; |
140 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_trianglefan; |
159 | typedef entity_opengl2d<GL_TRIANGLE_FAN> entity_triangle_fan; |
141 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
160 | typedef entity_opengl2d<GL_QUADS> entity_quads; |
142 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
161 | typedef entity_opengl2d<GL_QUAD_STRIP> entity_quad_strip; |
143 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
162 | typedef entity_opengl2d<GL_POLYGON> entity_polygon; |
|
|
163 | |
|
|
164 | struct light { |
|
|
165 | point p; |
|
|
166 | colour c; |
|
|
167 | GLfloat intensity; |
|
|
168 | GLfloat radius; |
|
|
169 | }; |
|
|
170 | |
|
|
171 | struct draw_context { |
|
|
172 | enum { DEPTH, AMBIENT, LIGHTED } mode; |
|
|
173 | light *l; |
|
|
174 | }; |
|
|
175 | |
|
|
176 | struct view { |
|
|
177 | point p; |
|
|
178 | vec3 d, u; |
|
|
179 | float fov; |
|
|
180 | int w, h; |
|
|
181 | |
|
|
182 | void draw (const draw_context &c); |
|
|
183 | }; |
144 | |
184 | |
145 | #endif |
185 | #endif |
146 | |
186 | |
147 | |
187 | |
148 | |
188 | |