… | |
… | |
49 | } |
49 | } |
50 | |
50 | |
51 | struct gl_matrix { |
51 | struct gl_matrix { |
52 | GLfloat data[4][4]; |
52 | GLfloat data[4][4]; |
53 | |
53 | |
54 | const GLfloat operator ()(int i, int j) const { return data[i][j]; }; |
54 | const GLfloat operator ()(int i, int j) const { return data[j][i]; }; |
55 | GLfloat &operator ()(int i, int j) { return data[i][j]; }; |
55 | GLfloat &operator ()(int i, int j) { return data[j][i]; }; |
56 | |
56 | |
57 | void diagonal (GLfloat v); |
57 | void diagonal (GLfloat v); |
58 | void clear () { diagonal (0.); }; |
58 | void clear () { diagonal (0.); }; |
59 | void identity () { diagonal (1.); }; |
59 | void identity () { diagonal (1.); }; |
60 | |
60 | |
61 | void print (); // ugly |
61 | void print (); // ugly |
62 | |
62 | |
63 | void translate (const vec3 &v); |
63 | static const gl_matrix translation (const vec3 &v); |
64 | void rotate (GLfloat degrees, const vec3 &axis); |
64 | static const gl_matrix rotation (GLfloat degrees, const vec3 &axis); |
65 | |
65 | |
66 | gl_matrix () { }; |
66 | gl_matrix () { }; |
67 | gl_matrix (GLfloat diag) { diagonal (diag); }; |
67 | gl_matrix (GLfloat diag) { diagonal (diag); }; |
68 | }; |
68 | }; |
69 | |
69 | |
… | |
… | |
71 | const vec3 operator *(const gl_matrix &a, const vec3 &v); |
71 | const vec3 operator *(const gl_matrix &a, const vec3 &v); |
72 | |
72 | |
73 | typedef vec3 point; |
73 | typedef vec3 point; |
74 | |
74 | |
75 | // a generic plane |
75 | // a generic plane |
76 | class plane { |
76 | struct plane { |
77 | vec3 n; |
77 | vec3 n; |
78 | GLfloat d; |
78 | GLfloat d; |
79 | public: |
|
|
80 | |
79 | |
81 | GLfloat distance (const point &p) const |
80 | GLfloat distance (const point &p) const |
82 | { |
81 | { |
83 | return dot (n, p) + d; |
82 | return dot (n, p) + d; |
84 | } |
83 | } |