… | |
… | |
120 | |
120 | |
121 | inline const GLfloat norm (const vec3 &v) |
121 | inline const GLfloat norm (const vec3 &v) |
122 | { |
122 | { |
123 | return sqrtf (dot (v, v)); |
123 | return sqrtf (dot (v, v)); |
124 | } |
124 | } |
125 | |
|
|
126 | struct matrix |
|
|
127 | { |
|
|
128 | GLfloat data[4][4]; |
|
|
129 | |
|
|
130 | const GLfloat operator ()(int i, int j) const { return data[j][i]; }; |
|
|
131 | GLfloat &operator ()(int i, int j) { return data[j][i]; }; |
|
|
132 | |
|
|
133 | operator GLfloat *() { return &data[0][0]; } |
|
|
134 | |
|
|
135 | void diagonal (GLfloat v); |
|
|
136 | void clear () { diagonal (0.F); }; |
|
|
137 | void identity () { diagonal (1.F); }; |
|
|
138 | |
|
|
139 | void print (); // ugly |
|
|
140 | |
|
|
141 | static const matrix translation (const vec3 &v); |
|
|
142 | static const matrix rotation (GLfloat degrees, const vec3 &axis); |
|
|
143 | |
|
|
144 | matrix () { }; |
|
|
145 | matrix (GLfloat diag) { diagonal (diag); }; |
|
|
146 | }; |
|
|
147 | |
|
|
148 | const matrix operator *(const matrix &a, const matrix &b); |
|
|
149 | const vec3 operator *(const matrix &a, const vec3 &v); |
|
|
150 | |
125 | |
151 | typedef vec3 point; |
126 | typedef vec3 point; |
152 | |
127 | |
153 | // a generic plane |
128 | // a generic plane |
154 | struct plane |
129 | struct plane |
… | |
… | |
262 | extern skedjuhlar main_scheduler; |
237 | extern skedjuhlar main_scheduler; |
263 | */ |
238 | */ |
264 | |
239 | |
265 | namespace gl |
240 | namespace gl |
266 | { |
241 | { |
|
|
242 | #ifdef DEBUG |
|
|
243 | extern int nesting; |
|
|
244 | void errchk (const char *name, const char *args, const char *file, int line); |
|
|
245 | #endif |
|
|
246 | |
267 | struct vertex_v3f |
247 | struct vertex_v3f |
268 | { |
248 | { |
269 | point p; // vertex |
249 | point p; // vertex |
270 | |
250 | |
271 | vertex_v3f () { }; |
251 | vertex_v3f () { }; |
… | |
… | |
284 | vertex_t2f_n3f_v3f (point p, vec3 n, tex2 t = tex2()) : p(p), n(n), t(t) { }; |
264 | vertex_t2f_n3f_v3f (point p, vec3 n, tex2 t = tex2()) : p(p), n(n), t(t) { }; |
285 | |
265 | |
286 | GLenum gl_format () const { return GL_T2F_N3F_V3F; } |
266 | GLenum gl_format () const { return GL_T2F_N3F_V3F; } |
287 | }; |
267 | }; |
288 | |
268 | |
289 | extern int nesting; |
269 | struct matrix |
290 | void errchk (const char *name, const char *args, const char *file, int line); |
270 | { |
|
|
271 | GLfloat data[4][4]; |
|
|
272 | |
|
|
273 | const GLfloat operator ()(int i, int j) const { return data[j][i]; }; |
|
|
274 | GLfloat &operator ()(int i, int j) { return data[j][i]; }; |
|
|
275 | |
|
|
276 | operator GLfloat *() { return &data[0][0]; } |
|
|
277 | |
|
|
278 | void diagonal (GLfloat v); |
|
|
279 | void clear () { diagonal (0.F); }; |
|
|
280 | void identity () { diagonal (1.F); }; |
|
|
281 | |
|
|
282 | void print (); // ugly |
|
|
283 | |
|
|
284 | static const matrix translation (const vec3 &v); |
|
|
285 | static const matrix rotation (GLfloat degrees, const vec3 &axis); |
|
|
286 | |
|
|
287 | matrix () { }; |
|
|
288 | matrix (GLfloat diag) { diagonal (diag); }; |
|
|
289 | }; |
|
|
290 | |
|
|
291 | const matrix operator *(const matrix &a, const matrix &b); |
|
|
292 | const vec3 operator *(const matrix &a, const vec3 &v); |
291 | |
293 | |
292 | struct vertex_buffer_object { |
294 | struct vertex_buffer_object { |
293 | GLuint buffer; |
295 | GLuint buffer; |
294 | GLenum format; |
296 | GLenum format; |
295 | |
297 | |