… | |
… | |
52 | inline const GLfloat abs (const vec3 &v) |
52 | inline const GLfloat abs (const vec3 &v) |
53 | { |
53 | { |
54 | return sqrtf (dot (v, v)); |
54 | return sqrtf (dot (v, v)); |
55 | } |
55 | } |
56 | |
56 | |
57 | struct gl_matrix { |
57 | struct matrix { |
58 | GLfloat data[4][4]; |
58 | GLfloat data[4][4]; |
59 | |
59 | |
60 | const GLfloat operator ()(int i, int j) const { return data[j][i]; }; |
60 | const GLfloat operator ()(int i, int j) const { return data[j][i]; }; |
61 | GLfloat &operator ()(int i, int j) { return data[j][i]; }; |
61 | GLfloat &operator ()(int i, int j) { return data[j][i]; }; |
62 | |
62 | |
… | |
… | |
64 | void clear () { diagonal (0.); }; |
64 | void clear () { diagonal (0.); }; |
65 | void identity () { diagonal (1.); }; |
65 | void identity () { diagonal (1.); }; |
66 | |
66 | |
67 | void print (); // ugly |
67 | void print (); // ugly |
68 | |
68 | |
69 | static const gl_matrix translation (const vec3 &v); |
69 | static const matrix translation (const vec3 &v); |
70 | static const gl_matrix rotation (GLfloat degrees, const vec3 &axis); |
70 | static const matrix rotation (GLfloat degrees, const vec3 &axis); |
71 | |
71 | |
72 | gl_matrix () { }; |
72 | matrix () { }; |
73 | gl_matrix (GLfloat diag) { diagonal (diag); }; |
73 | matrix (GLfloat diag) { diagonal (diag); }; |
74 | }; |
|
|
75 | |
74 | |
|
|
75 | operator ShMatrix4x4f() const |
|
|
76 | { |
|
|
77 | ShMatrix4x4f r; |
|
|
78 | |
|
|
79 | for (int i = 0; i < 4; i++) |
|
|
80 | for (int j = 0; j < 4 ; j++) |
|
|
81 | r[i][j] = data[j][i]; |
|
|
82 | |
|
|
83 | return r; |
|
|
84 | } |
|
|
85 | }; |
|
|
86 | |
76 | const gl_matrix operator *(const gl_matrix &a, const gl_matrix &b); |
87 | const matrix operator *(const matrix &a, const matrix &b); |
77 | const vec3 operator *(const gl_matrix &a, const vec3 &v); |
88 | const vec3 operator *(const matrix &a, const vec3 &v); |
78 | |
89 | |
79 | typedef vec3 point; |
90 | typedef vec3 point; |
80 | |
91 | |
81 | // a generic plane |
92 | // a generic plane |
82 | struct plane { |
93 | struct plane { |