1 | #ifndef GFXMATH_MAT3_INCLUDED // -*- C++ -*-
|
---|
2 | #define GFXMATH_MAT3_INCLUDED
|
---|
3 |
|
---|
4 | #include <gfx/math/Vec3.h>
|
---|
5 | #include <ostream>
|
---|
6 |
|
---|
7 | namespace simplif
|
---|
8 | {
|
---|
9 | class Mat3
|
---|
10 | {
|
---|
11 | private:
|
---|
12 | Vec3 row[3];
|
---|
13 |
|
---|
14 | protected:
|
---|
15 |
|
---|
16 | inline void copy(const Mat3& m);
|
---|
17 | inline Vec3 col(int i) const {return Vec3(row[0][i],row[1][i],row[2][i]);}
|
---|
18 |
|
---|
19 | public:
|
---|
20 | // Standard matrices
|
---|
21 | static Mat3 identity;
|
---|
22 | static Mat3 zero;
|
---|
23 | static Mat3 unit;
|
---|
24 | static Mat3 diag(const Vec3& v); // diagonal elements from v
|
---|
25 | static Mat3 extend(const Vec3& v); // each row becomes v
|
---|
26 |
|
---|
27 | // Standard constructors
|
---|
28 | Mat3() { copy(zero); }
|
---|
29 | Mat3(const Vec3& r0,const Vec3& r1,const Vec3& r2)
|
---|
30 | { row[0]=r0; row[1]=r1; row[2]=r2; }
|
---|
31 | Mat3(const Mat3& m) { copy(m); }
|
---|
32 |
|
---|
33 | // Access methods
|
---|
34 | // M(i, j) == row i;col j
|
---|
35 | real& operator()(int i, int j) { return row[i][j]; }
|
---|
36 | real operator()(int i, int j) const { return row[i][j]; }
|
---|
37 |
|
---|
38 | // Assignment methods
|
---|
39 | inline Mat3& operator=(const Mat3& m) { copy(m); return *this; }
|
---|
40 | inline Mat3& operator+=(const Mat3& m);
|
---|
41 | inline Mat3& operator-=(const Mat3& m);
|
---|
42 |
|
---|
43 | inline Mat3& operator*=(real s);
|
---|
44 | inline Mat3& operator/=(real s);
|
---|
45 |
|
---|
46 |
|
---|
47 | // Arithmetic methods
|
---|
48 | inline Mat3 operator+(const Mat3& m) const;
|
---|
49 | inline Mat3 operator-(const Mat3& m) const;
|
---|
50 | inline Mat3 operator-() const;
|
---|
51 |
|
---|
52 | inline Mat3 operator*(real s) const;
|
---|
53 | inline Mat3 operator/(real s) const;
|
---|
54 | Mat3 operator*(const Mat3& m) const;
|
---|
55 |
|
---|
56 | inline Vec3 operator*(const Vec3& v) const; // [x y z]
|
---|
57 |
|
---|
58 | // Matrix operations
|
---|
59 | real det();
|
---|
60 | Mat3 transpose();
|
---|
61 | Mat3 adjoint();
|
---|
62 | real inverse(Mat3&);
|
---|
63 |
|
---|
64 |
|
---|
65 | // // Input/Output methods
|
---|
66 | // friend std::ostream& operator<<(std::ostream&, const simplif::Mat3&);
|
---|
67 | // friend std::istream& operator>>(std::istream&, simplif::Mat3&);
|
---|
68 | };
|
---|
69 |
|
---|
70 |
|
---|
71 | inline void Mat3::copy(const Mat3& m)
|
---|
72 | {
|
---|
73 | row[0] = m.row[0]; row[1] = m.row[1]; row[2] = m.row[2];
|
---|
74 | }
|
---|
75 |
|
---|
76 | inline Mat3& Mat3::operator+=(const Mat3& m)
|
---|
77 | {
|
---|
78 | row[0] += m.row[0]; row[1] += m.row[1]; row[2] += m.row[2];
|
---|
79 | return *this;
|
---|
80 | }
|
---|
81 |
|
---|
82 | inline Mat3& Mat3::operator-=(const Mat3& m)
|
---|
83 | {
|
---|
84 | row[0] -= m.row[0]; row[1] -= m.row[1]; row[2] -= m.row[2];
|
---|
85 | return *this;
|
---|
86 | }
|
---|
87 |
|
---|
88 | inline Mat3& Mat3::operator*=(real s)
|
---|
89 | {
|
---|
90 | row[0] *= s; row[1] *= s; row[2] *= s;
|
---|
91 | return *this;
|
---|
92 | }
|
---|
93 |
|
---|
94 | inline Mat3& Mat3::operator/=(real s)
|
---|
95 | {
|
---|
96 | row[0] /= s; row[1] /= s; row[2] /= s;
|
---|
97 | return *this;
|
---|
98 | }
|
---|
99 |
|
---|
100 | inline Mat3 Mat3::operator+(const Mat3& m) const
|
---|
101 | {
|
---|
102 | return Mat3(row[0]+m.row[0],
|
---|
103 | row[1]+m.row[1],
|
---|
104 | row[2]+m.row[2]);
|
---|
105 | }
|
---|
106 |
|
---|
107 | inline Mat3 Mat3::operator-(const Mat3& m) const
|
---|
108 | {
|
---|
109 | return Mat3(row[0]-m.row[0],
|
---|
110 | row[1]-m.row[1],
|
---|
111 | row[2]-m.row[2]);
|
---|
112 | }
|
---|
113 |
|
---|
114 | inline Mat3 Mat3::operator-() const
|
---|
115 | {
|
---|
116 | return Mat3(-row[0], -row[1], -row[2]);
|
---|
117 | }
|
---|
118 |
|
---|
119 | inline Mat3 Mat3::operator*(real s) const
|
---|
120 | {
|
---|
121 | return Mat3(row[0]*s, row[1]*s, row[2]*s);
|
---|
122 | }
|
---|
123 |
|
---|
124 | inline Mat3 Mat3::operator/(real s) const
|
---|
125 | {
|
---|
126 | return Mat3(row[0]/s, row[1]/s, row[2]/s);
|
---|
127 | }
|
---|
128 |
|
---|
129 | inline Vec3 Mat3::operator*(const Vec3& v) const
|
---|
130 | {
|
---|
131 | return Vec3(row[0]*v, row[1]*v, row[2]*v);
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | /*
|
---|
136 | inline std::ostream& operator<<(std::ostream& out, const simplif::Mat3& M)
|
---|
137 | {
|
---|
138 | return out << M.row[0] << endl << M.row[1] << endl << M.row[2];
|
---|
139 | }
|
---|
140 |
|
---|
141 | inline istream& operator>>(istream& in, Mat3& M)
|
---|
142 | {
|
---|
143 | return in >> M.row[0] >> M.row[1] >> M.row[2];
|
---|
144 | }
|
---|
145 | */
|
---|
146 | extern bool jacobi(const simplif::Mat3& m, simplif::Vec3& vals, simplif::Vec3 vecs[3]);
|
---|
147 |
|
---|
148 |
|
---|
149 | // GFXMATH_MAT3_INCLUDED
|
---|
150 | #endif
|
---|