83 return vertex * scalar; |
83 return vertex * scalar; |
84 } |
84 } |
85 |
85 |
86 Q_DECLARE_METATYPE(Vertex) |
86 Q_DECLARE_METATYPE(Vertex) |
87 |
87 |
88 // |
88 /* |
89 // A mathematical 3 x 3 matrix |
89 * A mathematical 3 x 3 matrix |
90 // |
90 */ |
91 class Matrix |
91 class Matrix |
92 { |
92 { |
93 public: |
93 public: |
94 Matrix() {} |
94 Matrix(); |
95 Matrix(const std::initializer_list<double>& vals); |
95 Matrix(std::initializer_list<double> values); |
96 |
96 |
97 // Constructs a matrix all 9 elements initialized to the same value. |
97 double determinant() const; |
98 Matrix(double fillval); |
98 QString toString() const; |
99 |
99 void zero(); |
100 // Constructs a matrix with a C-array. |
100 Matrix& operator=(const Matrix& other); |
101 // note: @vals is expected to have exactly 9 elements. |
101 Matrix operator*(const Matrix& other) const; |
102 Matrix(double vals[]); |
102 double& operator[](int idx); |
103 |
103 const double& operator[](int idx) const; |
104 // Calculates the matrix's determinant. |
104 double& operator()(int row, int column); |
105 double getDeterminant() const; |
105 const double& operator()(int row, int column) const; |
106 |
106 bool operator==(const Matrix& other) const; |
107 // Multiplies this matrix with @other |
|
108 // note: a.mult(b) is not equivalent to b.mult(a)! |
|
109 Matrix mult(const Matrix& other) const; |
|
110 |
|
111 // Prints the matrix to stdout. |
|
112 void dump() const; |
|
113 |
|
114 // Yields a string representation of the matrix. |
|
115 QString toString() const; |
|
116 |
|
117 // Zeroes the matrix out. |
|
118 void zero(); |
|
119 |
|
120 // Assigns the matrix values to the values of @other. |
|
121 Matrix& operator= (const Matrix& other); |
|
122 |
|
123 // Returns a mutable reference to a value by @idx |
|
124 inline double& value(int idx) |
|
125 { |
|
126 return m_vals[idx]; |
|
127 } |
|
128 |
|
129 // An overload of value() for const matrices. |
|
130 inline const double& value(int idx) const |
|
131 { |
|
132 return m_vals[idx]; |
|
133 } |
|
134 |
|
135 // An operator overload for mult(). |
|
136 inline Matrix operator*(const Matrix& other) const |
|
137 { |
|
138 return mult(other); |
|
139 } |
|
140 |
|
141 // An operator overload for value(). |
|
142 inline double& operator[](int idx) |
|
143 { |
|
144 return value(idx); |
|
145 } |
|
146 |
|
147 // An operator overload for value() const. |
|
148 inline const double& operator[](int idx) const |
|
149 { |
|
150 return value(idx); |
|
151 } |
|
152 |
|
153 // Checks whether the two matrices have the same values. |
|
154 bool operator== (const Matrix& other) const; |
|
155 |
107 |
156 private: |
108 private: |
157 double m_vals[9]; |
109 double coefficients[9]; |
158 }; |
110 }; |
|
111 |
|
112 inline double& Matrix::operator[](int idx) |
|
113 { |
|
114 return coefficients[idx]; |
|
115 } |
|
116 |
|
117 inline const double& Matrix::operator[](int idx) const |
|
118 { |
|
119 return coefficients[idx]; |
|
120 } |
|
121 |
|
122 inline double& Matrix::operator()(int row, int column) |
|
123 { |
|
124 return coefficients[row * 3 + column]; |
|
125 } |
|
126 |
|
127 inline const double& Matrix::operator()(int row, int column) const |
|
128 { |
|
129 return coefficients[row * 3 + column]; |
|
130 } |
|
131 |
159 |
132 |
160 // |
133 // |
161 // Defines a bounding box that encompasses a given set of objects. |
134 // Defines a bounding box that encompasses a given set of objects. |
162 // vertex0 is the minimum vertex, vertex1 is the maximum vertex. |
135 // vertex0 is the minimum vertex, vertex1 is the maximum vertex. |
163 // |
136 // |