190 bool wasBlockingSignals = object->signalsBlocked(); |
190 bool wasBlockingSignals = object->signalsBlocked(); |
191 object->blockSignals(true); |
191 object->blockSignals(true); |
192 function(); |
192 function(); |
193 object->blockSignals(wasBlockingSignals); |
193 object->blockSignals(wasBlockingSignals); |
194 } |
194 } |
|
195 |
|
196 /* |
|
197 * Returns the angle between two vectors |
|
198 */ |
|
199 qreal vectorAngle(const QVector3D& vec_1, const QVector3D& vec_2) |
|
200 { |
|
201 return acos(QVector3D::dotProduct(vec_1, vec_2) / vec_1.length() / vec_2.length()); |
|
202 } |
|
203 |
|
204 /* |
|
205 * Computes the determinant of a 2×2 matrix with each variable passed in row-major order. |
|
206 */ |
|
207 qreal determinant(qreal a, qreal b, qreal c, qreal d) |
|
208 { |
|
209 return a * d - b * c; |
|
210 } |
|
211 |
|
212 /* |
|
213 * Computes the determinant of a 3×3 matrix with each variable passed in row-major order. |
|
214 */ |
|
215 qreal determinant(qreal a, qreal b, qreal c, qreal d, qreal e, qreal f, qreal g, qreal h, qreal i) |
|
216 { |
|
217 return a*e*i + b*f*g + c*d*h - a*f*h - b*d*i - c*e*g; |
|
218 } |
|
219 |
|
220 /* |
|
221 * Computes the determinant of a 2×2 matrix. |
|
222 */ |
|
223 qreal determinant(const QMatrix2x2& matrix) |
|
224 { |
|
225 return matrix(0, 0) * matrix(1, 1) - matrix(0, 1) * matrix(1, 0); |
|
226 } |
|
227 |
|
228 /* |
|
229 * Computes the determinant of a 3×3 matrix. |
|
230 */ |
|
231 qreal determinant(const QMatrix3x3& matrix) |
|
232 { |
|
233 return sum( |
|
234 +matrix(0, 0) * matrix(1, 1) * matrix(2, 2), |
|
235 -matrix(0, 0) * matrix(1, 2) * matrix(2, 1), |
|
236 -matrix(0, 1) * matrix(1, 0) * matrix(2, 2), |
|
237 +matrix(0, 1) * matrix(1, 2) * matrix(2, 0), |
|
238 +matrix(0, 2) * matrix(1, 0) * matrix(2, 1), |
|
239 -matrix(0, 2) * matrix(1, 1) * matrix(2, 0)); |
|
240 } |
|
241 |
|
242 /* |
|
243 * Computes the determinant of a 4×4 matrix. |
|
244 */ |
|
245 qreal determinant(const QMatrix4x4& matrix) |
|
246 { |
|
247 qreal sum = 0; |
|
248 |
|
249 for (int column : {0, 1, 2, 3}) |
|
250 { |
|
251 int column_1 = (column >= 1) ? 0 : 1; |
|
252 int column_2 = (column >= 2) ? 1 : 2; |
|
253 int column_3 = (column >= 3) ? 2 : 3; |
|
254 sum += ((column % 1) ? -1 : 1) * determinant( |
|
255 matrix(1, column_1), matrix(1, column_2), matrix(1, column_3), |
|
256 matrix(2, column_1), matrix(2, column_2), matrix(2, column_3), |
|
257 matrix(3, column_1), matrix(3, column_2), matrix(3, column_3)); |
|
258 } |
|
259 |
|
260 return sum; |
|
261 } |