Ocean
Loading...
Searching...
No Matches
HomogenousMatrix4.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_MATH_HOMOGENOUS_MATRIX_4_H
9#define META_OCEAN_MATH_HOMOGENOUS_MATRIX_4_H
10
11#include "ocean/math/Math.h"
12#include "ocean/math/Numeric.h"
14#include "ocean/math/Rotation.h"
16#include "ocean/math/Vector3.h"
17#include "ocean/math/Vector4.h"
18
19#include <vector>
20
21namespace Ocean
22{
23
24// Forward declaration.
25template <typename T> class EulerT;
26
27// Forward declaration.
28template <typename T> class RotationT;
29
30// Forward declaration.
31template <typename T> class SquareMatrixT4;
32
33// Forward declaration.
34template <typename T> class QuaternionT;
35
36// Forward declaration.
37template <typename T> class HomogenousMatrixT4;
38
39/**
40 * Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag either with single or double precision float data type.
41 * @see HomogenousMatrixT4
42 * @ingroup math
43 */
45
46/**
47 * Instantiation of the HomogenousMatrixT4 template class using a double precision float data type.
48 * @see HomogenousMatrixT4
49 * @ingroup math
50 */
52
53/**
54 * Instantiation of the HomogenousMatrixT4 template class using a float precision float data type.
55 * @see HomogenousMatrixT4
56 * @ingroup math
57 */
59
60/**
61 * Definition of a typename alias for vectors with HomogenousMatrixT4 objects.
62 * @see HomogenousMatrixT4
63 * @ingroup math
64 */
65template <typename T>
66using HomogenousMatricesT4 = std::vector<HomogenousMatrixT4<T>>;
67
68/**
69 * Definition of a vector holding HomogenousMatrix4 objects.
70 * @see HomogenousMatrix4
71 * @ingroup math
72 */
73using HomogenousMatrices4 = std::vector<HomogenousMatrix4>;
74
75/**
76 * Definition of a vector holding HomogenousMatrixD4 objects.
77 * @ingroup math
78 */
79using HomogenousMatricesD4 = std::vector<HomogenousMatrixD4>;
80
81/**
82 * Definition of a vector holding HomogenousMatrixF4 objects.
83 * @ingroup math
84 */
85using HomogenousMatricesF4 = std::vector<HomogenousMatrixF4>;
86
87
88/**
89 * This class implements a 4x4 homogeneous transformation matrix using floating point values with the precision specified by type T.
90 * <pre>
91 * The values are stored in a column major/aligned order with indices:
92 * | 0 4 8 12 |
93 * | 1 5 9 13 |
94 * | 2 6 10 14 |
95 * | 3 7 11 15 |
96 *
97 * This matrix allows homogeneous transformations only.
98 * With basis vectors (rx1, ry1, rz1), (rx2, ry2, rz2), (rx3, ry3, rz3), and translation vector (tx, ty, tz):
99 * | rx1 rx2 rx3 tx |
100 * | ry1 ry2 ry3 ty |
101 * | rz1 rz2 rz3 tz |
102 * | 0 0 0 1 |
103 * </pre>
104 * @tparam T Data type of matrix elements
105 * @see HomogenousMatrix4, HomogenousMatrixF4, HomogenousMatrixD4.
106 * @ingroup math
107 */
108template <typename T>
110{
111 template <typename U> friend class HomogenousMatrixT4;
112
113 public:
114
115 /**
116 * Definition of the used data type.
117 */
118 using Type = T;
119
120 public:
121
122 /**
123 * Creates a new default HomogenousMatrixT4 object with undefined elements.
124 * Beware: This matrix is neither a zero nor an entity matrix!
125 */
127
128 /**
129 * Copy constructor.
130 * @param matrix The matrix to copy
131 */
133
134 /**
135 * Copy constructor for a matrix with difference element data type than T.
136 * @param matrix The matrix to copy
137 * @tparam U The element data type of the second matrix
138 */
139 template <typename U>
140 inline explicit HomogenousMatrixT4(const HomogenousMatrixT4<U>& matrix);
141
142 /**
143 * Creates a new HomogenousMatrixT4.
144 * Beware: The zero matrix will hold a zero in the lower right corner which must be set explicitly later to create a valid matrix.<br>
145 * Only constructors explicitly set the lower right value to 1 like e.g., the constructor building a matrix from a rotation or translation and so on.
146 * @param setToIdentity True, to create a identity matrix; False, to set a zero matrix
147 */
148 inline explicit HomogenousMatrixT4(const bool setToIdentity);
149
150 /**
151 * Creates a new HomogenousMatrixT4 object by 16 given floating point values of type U.
152 * @param arrayValues The array with 16 matrix elements of type U
153 */
154 template <typename U>
155 explicit HomogenousMatrixT4(const U* arrayValues);
156
157 /**
158 * Creates a new HomogenousMatrixT4 object by 16 given floating point values.
159 * @param arrayValues The array with 16 matrix elements
160 */
161 explicit HomogenousMatrixT4(const T* arrayValues);
162
163 /**
164 * Creates a new HomogenousMatrixT4 object by an array of at least sixteen elements of float type U.
165 * @param arrayValues The sixteen matrix elements defining the new matrix, must be valid
166 * @param valuesRowAligned True, if the given values are stored in a row aligned order; False, if the values are stored in a column aligned order (which is the default case for this matrix)
167 * @tparam U The floating point type of the given elements
168 */
169 template <typename U>
170 HomogenousMatrixT4(const U* arrayValues, const bool valuesRowAligned);
171
172 /**
173 * Creates a new HomogenousMatrixT4 object by an array of at least sixteen elements.
174 * @param valuesRowAligned True, if the given values are stored in a row aligned order; False, if the values are stored in a column aligned order (which is the default case for this matrix)
175 * @param arrayValues The sixteen matrix elements defining the new matrix, must be valid
176 */
177 HomogenousMatrixT4(const T* arrayValues, const bool valuesRowAligned);
178
179 /**
180 * Creates a new HomogenousMatrixT4 object with only a translation.
181 * @param translation The translation of the resulting transformation
182 */
184
185 /**
186 * Creates a new HomogenousMatrixT4 object with only a rotation.
187 * @param rotation The angle-axis rotation of the resulting transformation
188 */
190
191 /**
192 * Creates a new HomogenousMatrixT4 object with only a rotation given as Euler rotation.
193 * @param euler The euler rotation of the resulting transformation
194 */
195 explicit HomogenousMatrixT4(const EulerT<T>& euler);
196
197 /**
198 * Creates a new HomogenousMatrixT4 object with only a rotation given as quaternion.
199 * @param rotation The rotation of the resulting transformation
200 */
202
203 /**
204 * Creates a new HomogenousMatrixT4 object with only a rotation given as 3x3 rotation matrix.
205 * @param rotation 3x3 rotation matrix
206 */
208
209 /**
210 * Creates a new HomogenousMatrixT4 object from a 4x4 square matrix.
211 * @param matrix The 4x4 square matrix
212 */
213 explicit HomogenousMatrixT4(const SquareMatrixT4<T>& matrix);
214
215 /**
216 * Creates a new HomogenousMatrixT4 object with a translation and rotation.
217 * The resulting transformation can be written as the following matrix multiplication:
218 * <pre>
219 * HomogenousMatrix4(translation, rotation) == HomogenousMatrix4(translation) * HomogenousMatrix4(rotation)
220 * </pre>
221 * @param translation The translation of the resulting transformation
222 * @param rotation The rotation of the resulting transformation, must be valid
223 */
225
226 /**
227 * Creates a new HomogenousMatrixT4 object with a translation and rotation.
228 * @param translationAndRotation The pair of translation and rotation of the resulting transformation
229 */
230 explicit HomogenousMatrixT4(const std::pair<VectorT3<T>, RotationT<T>>& translationAndRotation);
231
232 /**
233 * Creates a new HomogenousMatrixT4 object with a translation and rotation.
234 * The resulting transformation can be written as the following matrix multiplication:
235 * <pre>
236 * HomogenousMatrix4(translation, euler) == HomogenousMatrix4(translation) * HomogenousMatrix4(euler)
237 * </pre>
238 * @param translation The translation of the resulting transformation
239 * @param euler The euler rotation of the resulting transformation, must be valid
240 */
242
243 /**
244 * Creates a new HomogenousMatrixT4 object with a translation and rotation.
245 * The resulting transformation can be written as the following matrix multiplication:
246 * <pre>
247 * HomogenousMatrix4(translation, rotation) == HomogenousMatrix4(translation) * HomogenousMatrix4(rotation)
248 * </pre>
249 * @param translation The translation of the resulting transformation
250 * @param rotation The quaternion rotation of the resulting transformation, must be valid
251 */
253
254 /**
255 * Creates a new HomogenousMatrixT4 object with a translation and rotation.
256 * @param translationAndRotation The pair of translation and rotation of the resulting transformation
257 */
258 explicit HomogenousMatrixT4(const std::pair<VectorT3<T>, QuaternionT<T>>& translationAndRotation);
259
260 /**
261 * Creates a new HomogenousMatrixT4 object with a translation and rotation matrix.
262 * The resulting transformation can be written as the following matrix multiplication:
263 * <pre>
264 * HomogenousMatrix4(translation, rotation) == HomogenousMatrix4(translation) * HomogenousMatrix4(rotation)
265 * </pre>
266 * @param translation The translation of the resulting transformation
267 * @param rotation The rotation matrix of the resulting transformation, must be valid
268 */
270
271 /**
272 * Creates a new HomogenousMatrixT4 object by a translation and a scale.
273 * @param translation The translation of the resulting transformation
274 * @param scale The scale of the resulting transformation
275 */
277
278 /**
279 * Creates a new HomogenousMatrixT4 object by a translation, rotation and scale.
280 * @param translation The translation of the resulting transformation
281 * @param rotation The rotation of the resulting transformation, must be valid
282 * @param scale The scale of the resulting transformation
283 */
285
286 /**
287 * Creates a new HomogenousMatrixT4 object by a translation, rotation, scale and shear.
288 * @param translation The translation of the resulting transformation
289 * @param rotation The rotation of the resulting transformation as unit quaternion, must be valid
290 * @param scale The scale of the resulting transformation
291 * @param shear The shear of the resulting transformation with order (xy, xz, yz)
292 */
294
295 /**
296 * Creates a new HomogenousMatrixT4 object by a translation, rotation, scale and shear.
297 * @param translation The translation of the resulting transformation
298 * @param rotation The rotation of the resulting transformation, must be valid
299 * @param scale The scale of the resulting transformation
300 * @param shear The shear of the resulting transformation with order (xy, xz, yz)
301 */
303
304 /**
305 * Creates a new HomogenousMatrixT4 object by a translation, rotation and scale.
306 * @param translation The translation of the resulting transformation
307 * @param rotation The quaternion rotation of the resulting transformation, must be valid
308 * @param scale The scale of the resulting transformation
309 */
311
312 /**
313 * Creates a new HomogenousMatrixT4 object by three basis vectors.
314 * @param xAxis First basis vector
315 * @param yAxis Second basis vector
316 * @param zAxis Third basis vector
317 */
319
320 /**
321 * Creates a new HomogenousMatrixT4 object by three basis vectors and a translation vector.
322 * @param xAxis First basis vector
323 * @param yAxis Second basis vector
324 * @param zAxis Third basis vector
325 * @param translation The translation vector
326 */
328
329 /**
330 * Returns the x-axis of the transformation which is the first vector of the upper left 3x3 rotation matrix of this homogeneous 4x4 transformation.
331 * @return The x-axis of this transformation
332 */
333 inline VectorT3<T> xAxis() const;
334
335 /**
336 * Returns the y-axis of the transformation which is the second vector of the upper left 3x3 rotation matrix of this homogeneous 4x4 transformation.
337 * @return The y-axis of this transformation
338 */
339 inline VectorT3<T> yAxis() const;
340
341 /**
342 * Returns the z-axis of the transformation which is the third vector of the upper left 3x3 rotation matrix of this homogeneous 4x4 transformation.
343 * @return The z-axis of this transformation
344 */
345 inline VectorT3<T> zAxis() const;
346
347 /**
348 * Returns the translation of the transformation.
349 * @return Translation
350 */
351 inline VectorT3<T> translation() const;
352
353 /**
354 * Returns the rotation of the transformation as quaternion.
355 * @return Rotation
356 */
358
359 /**
360 * Returns the scale of the transformation.
361 * @return Transformation scale
362 */
364
365 /**
366 * Decomposes the transformation matrix into translation, rotation, scale and shear parameters.
367 * @param translation The returning translation parameter
368 * @param rotation The returning rotation parameter as quaternion
369 * @param scale The returning scale parameter
370 * @param shear The returning shear parameter with order (xy, xz, yz)
371 * @return True, if succeeded (otherwise the transformation matrix has a zero-scaling axis and the translation is decomposed only)
372 */
374
375 /**
376 * Returns the rotation matrix of the transformation.
377 * @return Rotation matrix containing scale
378 */
380
381 /**
382 * Copies the 3x3 rotation matrix elements of the 4x4 transformation.
383 * @param data The buffer receiving the nine rotation matrix elements, must be valid
384 * @param transposed True, to copy the transposed rotation matrix (to copy the array into a row major buffer); False, to copy the matrix into a column major buffer
385 */
386 inline void rotationMatrix(T* data, const bool transposed = false) const;
387
388 /**
389 * Returns the 3x3 orthonormal rotation matrix of the 4x4 transformation (by forcing a orthogonal and normalized rotation matrix).
390 * All vectors of the resulting rotation matrix have unit length.
391 * @return The normalized rotation matrix
392 */
394
395 /**
396 * Returns the transposed of this matrix.
397 * @return Transposed matrix as square 4x4 matrix
398 */
399 [[nodiscard]] SquareMatrixT4<T> transposed() const;
400
401 /**
402 * Returns the inverted of this matrix.
403 * This matrix must not be singular, ensure that the matrix is invertible before calling this function.<br>
404 * Even better: avoid the usage of this function and call invert() instead.<br>
405 * In case, this matrix is not invertible, this matrix will be returned instead.
406 * @return The inverted matrix
407 * see invert().
408 */
409 [[nodiscard]] HomogenousMatrixT4<T> inverted() const noexcept;
410
411 /**
412 * Inverts the matrix.
413 * @return True, if the matrix could be inverted (because the matrix was not singular)
414 */
415 bool invert();
416
417 /**
418 * Inverts the matrix and returns the result as parameter.
419 * @param invertedMatrix The resulting inverted matrix
420 * @return True, if the matrix could be inverted because the matrix is not singular
421 * @see inverted(), solve().
422 */
423 bool invert(HomogenousMatrixT4<T>& invertedMatrix) const;
424
425 /**
426 * Returns the determinant of the matrix.
427 * @return Matrix determinant
428 */
429 T determinant() const;
430
431 /**
432 * Returns the trace of the matrix which is the sum of the diagonal elements.
433 * @return Trace of the matrix
434 */
435 inline T trace() const;
436
437 /**
438 * Sets the translation of this transformation.
439 * @param translation The translation to set
440 * @return Reference to this transformation matrix
441 */
443
444 /**
445 * Sets the rotation of this transformation.
446 * @param rotation The rotation to set, must be valid
447 * @return Reference to this transformation matrix
448 */
450
451 /**
452 * Sets the rotation of this transformation.
453 * @param quaternion The quaternion rotation to set, must be valid
454 * @return Reference to this transformation matrix
455 */
456 HomogenousMatrixT4<T>& setRotation(const QuaternionT<T>& quaternion);
457
458 /**
459 * Sets the rotation of this transformation.
460 * @param matrix The 3x3 rotation matrix to set
461 * @return Reference to this transformation matrix
462 */
464
465 /**
466 * Applies new scale values.
467 * @param scale The new scale values which are applied to the inner 3x3 rotation matrix
468 * @return Reference to this transformation matrix
469 */
471
472 /**
473 * Sets the matrix to the identity matrix.
474 * @see isIdentity().
475 */
476 inline void toIdentity();
477
478 /**
479 * Sets the matrix to a zero matrix (including the lower right element).
480 * @see isNull();
481 */
482 inline void toNull();
483
484 /**
485 * Returns whether this matrix is a valid homogeneous transformation.
486 * @return True, if so
487 */
488 bool isValid() const;
489
490 /**
491 * Returns whether this matrix is an identity matrix.
492 * @return True, if so
493 * @see toIdentity().
494 */
495 bool isIdentity() const;
496
497 /**
498 * Returns whether two matrices are almost identical up to a specified epsilon.
499 * @param matrix Second matrix that will be checked
500 * @param epsilon The epsilon threshold to be used, with range [0, infinity)
501 * @return True, if so
502 */
503 inline bool isEqual(const HomogenousMatrixT4<T>& matrix, const T epsilon = NumericT<T>::eps()) const;
504
505 /**
506 * Returns whether this matrix is a zero matrix (with all elements equal to zero).
507 * @return True, if so
508 * @see toNull().
509 */
510 bool isNull() const;
511
512 /**
513 * Returns a pointer to the internal values.
514 * @return The pointer to the internal values, always valid
515 */
516 inline const T* data() const;
517
518 /**
519 * Returns a pointer to the internal values.
520 * @return The pointer to the internal values, always valid
521 */
522 inline T* data();
523
524 /**
525 * Copies the elements of this matrix to an array with floating point values of the same type T.
526 * @param arrayValues Array with 16 floating point values of type T receiving the elements of this matrix, must be valid
527 * @param valuesRowAligned True, if the target values are stored in a row aligned order; False, if the values are stored in a column aligned order (which is the default case for this matrix)
528 */
529 inline void copyElements(T* arrayValues, const bool valuesRowAligned = false) const;
530
531 /**
532 * Copies the elements of this matrix to an array with floating point values of the type U.
533 * @param arrayValues Array with 16 floating point values of type U receiving the elements of this matrix, must be valid
534 * @param valuesRowAligned True, if the target values are stored in a row aligned order; False, if the values are stored in a column aligned order (which is the default case for this matrix)
535 */
536 template <typename U>
537 inline void copyElements(U* arrayValues, const bool valuesRowAligned = false) const;
538
539 /**
540 * Transforms a 3D vector by application of only the inner rotation matrix (including scale and shearing) of this transformation.
541 * @param vector The vector to be transformed
542 * @return Transformed 3D vector
543 */
544 inline VectorT3<T> rotationMatrix(const VectorT3<T>& vector) const;
545
546 /**
547 * Transforms a 3D vector by application of only the inner transposed rotation matrix (including scale and shearing) of this transformation.
548 * @param vector The vector to be transformed
549 * @return Transformed 3D vector
550 */
551 inline VectorT3<T> transposedRotationMatrix(const VectorT3<T>& vector) const;
552
553 /**
554 * Default copy assignment operator.
555 * @return Reference to this object
556 */
557 HomogenousMatrixT4<T>& operator=(const HomogenousMatrixT4<T>&) = default;
558
559 /**
560 * Returns whether two transformations are identical up to a small epsilon.
561 * @param matrix Right operand
562 * @return True, if so
563 */
564 bool operator==(const HomogenousMatrixT4<T>& matrix) const;
565
566 /**
567 * Returns whether two transformations are not identical up to a small epsilon.
568 * @param matrix Right operand
569 * @return True, if so
570 */
571 inline bool operator!=(const HomogenousMatrixT4<T>& matrix) const;
572
573 /**
574 * Combines two transformation matrices.
575 * @param matrix Right transformation matrix
576 * @return Combined transformation matrix
577 */
578 HomogenousMatrixT4<T> operator*(const HomogenousMatrixT4<T>& matrix) const;
579
580 /**
581 * Combines and assigns two transformation matrices.
582 * @param matrix Right transformation matrix
583 * @return Reference to this transformation matrix
584 */
585 inline HomogenousMatrixT4<T>& operator*=(const HomogenousMatrixT4<T>& matrix);
586
587 /**
588 * Combines a transformation with a rotation.
589 * @param rotation The rotation to combine, must be valid
590 * @return Combined transformation matrix
591 */
592 HomogenousMatrixT4<T> operator*(const RotationT<T>& rotation) const;
593
594 /**
595 * Combines and assigns a transformation with a rotation.
596 * @param rotation The rotation to combine, must be valid
597 * @return Reference to this transformation matrix
598 */
599 inline HomogenousMatrixT4<T>& operator*=(const RotationT<T>& rotation);
600
601 /**
602 * Combines a transformation with a quaternion rotation.
603 * @param rotation The quaternion rotation to combine, must be valid
604 * @return Combined transformation matrix
605 */
606 HomogenousMatrixT4<T> operator*(const QuaternionT<T>& rotation) const;
607
608 /**
609 * Combines and assigns a transformation with a quaternion rotation.
610 * @param rotation The quaternion rotation to combine, must be valid
611 * @return Reference to this transformation matrix
612 */
613 inline HomogenousMatrixT4<T>& operator*=(const QuaternionT<T>& rotation);
614
615 /**
616 * Transforms a 3D vector.
617 * The vector will be extended with a 1.0 as fourth element and de-homogenized afterwards.
618 * @param vector The vector to transform
619 * @return Resulting transformed and homogenized 3D vector
620 */
621 inline VectorT3<T> operator*(const VectorT3<T>& vector) const;
622
623 /**
624 * Transforms a 4D vector.
625 * @param vector The vector to transform
626 * @return The resulting transformed 4D vector
627 */
628 inline VectorT4<T> operator*(const VectorT4<T>& vector) const;
629
630 /**
631 * Element operator.
632 * @param index The index of the element to return [0, 15]
633 * @return Specified element
634 */
635 inline T operator[](const unsigned int index) const;
636
637 /**
638 * Element operator.
639 * @param index The index of the element to return [0, 15]
640 * @return Specified element
641 */
642 inline T& operator[](const unsigned int index);
643
644 /**
645 * Element operator.
646 * @param row The row of the element to return [0, 3]
647 * @param column The column of the element to return [0, 3]
648 * @return Specified element
649 */
650 inline T operator()(const unsigned int row, const unsigned int column) const;
651
652 /**
653 * Element operator.
654 * @param row The row of the element to return [0, 3]
655 * @param column The column of the element to return [0, 3]
656 * @return Specified element
657 */
658 inline T& operator()(const unsigned int row, const unsigned int column);
659
660 /**
661 * Element operator.
662 * @param index The index of the element to return [0, 15]
663 * @return Specified element
664 */
665 inline T operator()(const unsigned int index) const;
666
667 /**
668 * Element operator.
669 * @param index The index of the element to return [0, 15]
670 * @return Specified element
671 */
672 inline T& operator()(const unsigned int index);
673
674 /**
675 * Access operator.
676 * @return Pointer to the internal values
677 */
678 inline const T* operator()() const;
679
680 /**
681 * Access operator.
682 * @return Pointer to the internal values
683 */
684 inline T* operator()();
685
686 /**
687 * Hash function.
688 * @param matrix The matrix for which the hash value will be determined
689 * @return The resulting hash value
690 */
691 inline size_t operator()(const HomogenousMatrixT4<T>& matrix) const;
692
693 /**
694 * Converts matrices with specific data type to matrices with different data type.
695 * @param matrices The matrices to convert
696 * @return The converted matrices
697 * @tparam U The element data type of the matrices to convert
698 */
699 template <typename U>
700 static inline std::vector< HomogenousMatrixT4<T> > matrices2matrices(const std::vector< HomogenousMatrixT4<U> >& matrices);
701
702 /**
703 * Converts matrices with specific data type to matrices with different data type.
704 * @param matrices The matrices to convert
705 * @param size The number of matrices to convert
706 * @return The converted matrices
707 * @tparam U The element data type of the matrices to convert
708 */
709 template <typename U>
710 static inline std::vector< HomogenousMatrixT4<T> > matrices2matrices(const HomogenousMatrixT4<U>* matrices, const size_t size);
711
712 protected:
713
714 /// The sixteen values of the transformation matrix.
715 T values_[16];
716};
717
718template <typename T>
720{
721 // nothing to do here
722}
723
724template <typename T>
725template <typename U>
727{
728 for (unsigned int n = 0u; n < 16u; ++n)
729 {
730 values_[n] = T(matrix.values_[n]);
731 }
732}
733
734template <typename T>
735inline HomogenousMatrixT4<T>::HomogenousMatrixT4(const bool setToIdentity)
736{
737 if (setToIdentity)
738 {
739 values_[ 0] = T(1.0);
740 values_[ 1] = T(0.0);
741 values_[ 2] = T(0.0);
742 values_[ 3] = T(0.0);
743
744 values_[ 4] = T(0.0);
745 values_[ 5] = T(1.0);
746 values_[ 6] = T(0.0);
747 values_[ 7] = T(0.0);
748
749 values_[ 8] = T(0.0);
750 values_[ 9] = T(0.0);
751 values_[10] = T(1.0);
752 values_[11] = T(0.0);
753
754 values_[12] = T(0.0);
755 values_[13] = T(0.0);
756 values_[14] = T(0.0);
757 values_[15] = T(1.0);
758
759 ocean_assert(isValid());
760 }
761 else
762 {
763 for (unsigned int n = 0u; n < 16u; ++n)
764 {
765 values_[n] = T(0);
766 }
767
768 ocean_assert(!isValid());
769 }
770}
771
772template <typename T>
773template <typename U>
775{
776 for (unsigned int n = 0u; n < 16u; ++n)
777 {
778 values_[n] = T(arrayValues[n]);
779 }
780}
781
782template <typename T>
784{
785 memcpy(values_, arrayValues, sizeof(T) * 16);
786}
787
788template <typename T>
789template <typename U>
790HomogenousMatrixT4<T>::HomogenousMatrixT4(const U* arrayValues, const bool valuesRowAligned)
791{
792 ocean_assert(arrayValues);
793
794 if (valuesRowAligned)
795 {
796 values_[ 0] = T(arrayValues[ 0]);
797 values_[ 1] = T(arrayValues[ 4]);
798 values_[ 2] = T(arrayValues[ 8]);
799 values_[ 3] = T(arrayValues[12]);
800 values_[ 4] = T(arrayValues[ 1]);
801 values_[ 5] = T(arrayValues[ 5]);
802 values_[ 6] = T(arrayValues[ 9]);
803 values_[ 7] = T(arrayValues[13]);
804 values_[ 8] = T(arrayValues[ 2]);
805 values_[ 9] = T(arrayValues[ 6]);
806 values_[10] = T(arrayValues[10]);
807 values_[11] = T(arrayValues[14]);
808 values_[12] = T(arrayValues[ 3]);
809 values_[13] = T(arrayValues[ 7]);
810 values_[14] = T(arrayValues[11]);
811 values_[15] = T(arrayValues[15]);
812 }
813 else
814 {
815 for (unsigned int n = 0u; n < 16u; ++n)
816 {
817 values_[n] = T(arrayValues[n]);
818 }
819 }
820}
821
822template <typename T>
823HomogenousMatrixT4<T>::HomogenousMatrixT4(const T* arrayValues, const bool valuesRowAligned)
824{
825 ocean_assert(arrayValues);
826
827 if (valuesRowAligned)
828 {
829 values_[ 0] = arrayValues[ 0];
830 values_[ 1] = arrayValues[ 4];
831 values_[ 2] = arrayValues[ 8];
832 values_[ 3] = arrayValues[12];
833 values_[ 4] = arrayValues[ 1];
834 values_[ 5] = arrayValues[ 5];
835 values_[ 6] = arrayValues[ 9];
836 values_[ 7] = arrayValues[13];
837 values_[ 8] = arrayValues[ 2];
838 values_[ 9] = arrayValues[ 6];
839 values_[10] = arrayValues[10];
840 values_[11] = arrayValues[14];
841 values_[12] = arrayValues[ 3];
842 values_[13] = arrayValues[ 7];
843 values_[14] = arrayValues[11];
844 values_[15] = arrayValues[15];
845 }
846 else
847 {
848 memcpy(values_, arrayValues, sizeof(T) * 16);
849 }
850}
851
852template <typename T>
854{
855 values_[ 0] = T(1.0);
856 values_[ 1] = T(0.0);
857 values_[ 2] = T(0.0);
858 values_[ 3] = T(0.0);
859
860 values_[ 4] = T(0.0);
861 values_[ 5] = T(1.0);
862 values_[ 6] = T(0.0);
863 values_[ 7] = T(0.0);
864
865 values_[ 8] = T(0.0);
866 values_[ 9] = T(0.0);
867 values_[10] = T(1.0);
868 values_[11] = T(0.0);
869
870 values_[12] = translation[0];
871 values_[13] = translation[1];
872 values_[14] = translation[2];
873 values_[15] = T(1.0);
874
875 ocean_assert(isValid());
876}
877
878template <typename T>
880{
881 ocean_assert(rotation.isValid());
882
883 //values[ 0] = T(1.0);
884 //values[ 1] = T(0.0);
885 //values[ 2] = T(0.0);
886 values_[ 3] = T(0.0);
887
888 //values[ 4] = T(0.0);
889 //values[ 5] = T(1.0);
890 //values[ 6] = T(0.0);
891 values_[ 7] = T(0.0);
892
893 //values[ 8] = T(0.0);
894 //values[ 9] = T(0.0);
895 //values[10] = T(1.0);
896 values_[11] = T(0.0);
897
898 values_[12] = T(0.0);
899 values_[13] = T(0.0);
900 values_[14] = T(0.0);
901 values_[15] = T(1.0);
902
904
905 ocean_assert(isValid());
906}
907
908template <typename T>
910{
911 ocean_assert(euler.isValid());
912
913 //values[ 0] = T(1.0);
914 //values[ 1] = T(0.0);
915 //values[ 2] = T(0.0);
916 values_[ 3] = T(0.0);
917
918 //values[ 4] = T(0.0);
919 //values[ 5] = T(1.0);
920 //values[ 6] = T(0.0);
921 values_[ 7] = T(0.0);
922
923 //values[ 8] = T(0.0);
924 //values[ 9] = T(0.0);
925 //values[10] = T(1.0);
926 values_[11] = T(0.0);
927
928 values_[12] = T(0.0);
929 values_[13] = T(0.0);
930 values_[14] = T(0.0);
931 values_[15] = T(1.0);
932
934
935 ocean_assert(isValid());
936}
937
938template <typename T>
940{
941 ocean_assert(rotation.isValid());
942
943 //values[ 0] = T(1.0);
944 //values[ 1] = T(0.0);
945 //values[ 2] = T(0.0);
946 values_[ 3] = T(0.0);
947
948 //values[ 4] = T(0.0);
949 //values[ 5] = T(1.0);
950 //values[ 6] = T(0.0);
951 values_[ 7] = T(0.0);
952
953 //values[ 8] = T(0.0);
954 //values[ 9] = T(0.0);
955 //values[10] = T(1.0);
956 values_[11] = T(0.0);
957
958 values_[12] = T(0.0);
959 values_[13] = T(0.0);
960 values_[14] = T(0.0);
961 values_[15] = T(1.0);
962
964
965 ocean_assert(isValid());
966}
967
968template <typename T>
970{
971 values_[ 0] = rotation()[0];
972 values_[ 1] = rotation()[1];
973 values_[ 2] = rotation()[2];
974 values_[ 3] = T(0.0);
975
976 values_[ 4] = rotation()[3];
977 values_[ 5] = rotation()[4];
978 values_[ 6] = rotation()[5];
979 values_[ 7] = T(0.0);
980
981 values_[ 8] = rotation()[6];
982 values_[ 9] = rotation()[7];
983 values_[10] = rotation()[8];
984 values_[11] = T(0.0);
985
986 values_[12] = T(0.0);
987 values_[13] = T(0.0);
988 values_[14] = T(0.0);
989 values_[15] = T(1.0);
990
991 ocean_assert(isValid());
992}
993
994template <typename T>
996{
997 memcpy(values_, matrix(), sizeof(T) * 16);
998
999 ocean_assert(isValid());
1000}
1001
1002template <typename T>
1004{
1005 ocean_assert(rotation.isValid());
1006
1007 //values[ 0] = T(1.0);
1008 //values[ 1] = T(0.0);
1009 //values[ 2] = T(0.0);
1010 values_[ 3] = T(0.0);
1011
1012 //values[ 4] = T(0.0);
1013 //values[ 5] = T(1.0);
1014 //values[ 6] = T(0.0);
1015 values_[ 7] = T(0.0);
1016
1017 //values[ 8] = T(0.0);
1018 //values[ 9] = T(0.0);
1019 //values[10] = T(1.0);
1020 values_[11] = T(0.0);
1021
1022 values_[12] = translation[0];
1023 values_[13] = translation[1];
1024 values_[14] = translation[2];
1025 values_[15] = T(1.0);
1026
1028
1029 ocean_assert(isValid());
1030}
1031
1032template <typename T>
1033HomogenousMatrixT4<T>::HomogenousMatrixT4(const std::pair< VectorT3<T>, RotationT<T> >& translationAndRotation)
1034{
1035 ocean_assert(translationAndRotation.second.isValid());
1036
1037 //values[ 0] = T(1.0);
1038 //values[ 1] = T(0.0);
1039 //values[ 2] = T(0.0);
1040 values_[ 3] = T(0.0);
1041
1042 //values[ 4] = T(0.0);
1043 //values[ 5] = T(1.0);
1044 //values[ 6] = T(0.0);
1045 values_[ 7] = T(0.0);
1046
1047 //values[ 8] = T(0.0);
1048 //values[ 9] = T(0.0);
1049 //values[10] = T(1.0);
1050 values_[11] = T(0.0);
1051
1052 values_[12] = translationAndRotation.first[0];
1053 values_[13] = translationAndRotation.first[1];
1054 values_[14] = translationAndRotation.first[2];
1055 values_[15] = T(1.0);
1056
1057 setRotation(translationAndRotation.second);
1058
1059 ocean_assert(isValid());
1060}
1061
1062template <typename T>
1064{
1065 ocean_assert(euler.isValid());
1066
1067 //values[ 0] = T(1.0);
1068 //values[ 1] = T(0.0);
1069 //values[ 2] = T(0.0);
1070 values_[ 3] = T(0.0);
1071
1072 //values[ 4] = T(0.0);
1073 //values[ 5] = T(1.0);
1074 //values[ 6] = T(0.0);
1075 values_[ 7] = T(0.0);
1076
1077 //values[ 8] = T(0.0);
1078 //values[ 9] = T(0.0);
1079 //values[10] = T(1.0);
1080 values_[11] = T(0.0);
1081
1082 values_[12] = translation[0];
1083 values_[13] = translation[1];
1084 values_[14] = translation[2];
1085 values_[15] = T(1.0);
1086
1088
1089 ocean_assert(isValid());
1090}
1091
1092template <typename T>
1094{
1095 ocean_assert(rotation.isValid());
1096
1097 //values[ 0] = T(1.0);
1098 //values[ 1] = T(0.0);
1099 //values[ 2] = T(0.0);
1100 values_[ 3] = T(0.0);
1101
1102 //values[ 4] = T(0.0);
1103 //values[ 5] = T(1.0);
1104 //values[ 6] = T(0.0);
1105 values_[ 7] = T(0.0);
1106
1107 //values[ 8] = T(0.0);
1108 //values[ 9] = T(0.0);
1109 //values[10] = T(1.0);
1110 values_[11] = T(0.0);
1111
1112 values_[12] = translation[0];
1113 values_[13] = translation[1];
1114 values_[14] = translation[2];
1115 values_[15] = T(1.0);
1116
1118
1119 ocean_assert(isValid());
1120}
1121
1122template <typename T>
1124{
1125 ocean_assert(translationAndRotation.second.isValid());
1126
1127 //values[ 0] = T(1.0);
1128 //values[ 1] = T(0.0);
1129 //values[ 2] = T(0.0);
1130 values_[ 3] = T(0.0);
1131
1132 //values[ 4] = T(0.0);
1133 //values[ 5] = T(1.0);
1134 //values[ 6] = T(0.0);
1135 values_[ 7] = T(0.0);
1136
1137 //values[ 8] = T(0.0);
1138 //values[ 9] = T(0.0);
1139 //values[10] = T(1.0);
1140 values_[11] = T(0.0);
1141
1142 values_[12] = translationAndRotation.first[0];
1143 values_[13] = translationAndRotation.first[1];
1144 values_[14] = translationAndRotation.first[2];
1145 values_[15] = T(1.0);
1146
1147 setRotation(translationAndRotation.second);
1148
1149 ocean_assert(isValid());
1150}
1151
1152template <typename T>
1154{
1155 values_[ 0] = rotation()[0];
1156 values_[ 1] = rotation()[1];
1157 values_[ 2] = rotation()[2];
1158 values_[ 3] = T(0.0);
1159
1160 values_[ 4] = rotation()[3];
1161 values_[ 5] = rotation()[4];
1162 values_[ 6] = rotation()[5];
1163 values_[ 7] = T(0.0);
1164
1165 values_[ 8] = rotation()[6];
1166 values_[ 9] = rotation()[7];
1167 values_[10] = rotation()[8];
1168 values_[11] = T(0.0);
1169
1170 values_[12] = translation[0];
1171 values_[13] = translation[1];
1172 values_[14] = translation[2];
1173 values_[15] = T(1.0);
1174
1175 ocean_assert(isValid());
1176}
1177
1178template <typename T>
1180{
1181 values_[ 0] = scale.x();
1182 values_[ 1] = T(0.0);
1183 values_[ 2] = T(0.0);
1184 values_[ 3] = T(0.0);
1185
1186 values_[ 4] = T(0.0);
1187 values_[ 5] = scale.y();
1188 values_[ 6] = T(0.0);
1189 values_[ 7] = T(0.0);
1190
1191 values_[ 8] = T(0.0);
1192 values_[ 9] = T(0.0);
1193 values_[10] = scale.z();
1194 values_[11] = T(0.0);
1195
1196 values_[12] = translation[0];
1197 values_[13] = translation[1];
1198 values_[14] = translation[2];
1199 values_[15] = T(1.0);
1200
1201 ocean_assert(isValid());
1202}
1203
1204template <typename T>
1206{
1207 ocean_assert(rotation.isValid());
1208
1209 //values[ 0] = T(1.0);
1210 //values[ 1] = T(0.0);
1211 //values[ 2] = T(0.0);
1212 values_[ 3] = T(0.0);
1213
1214 //values[ 4] = T(0.0);
1215 //values[ 5] = T(1.0);
1216 //values[ 6] = T(0.0);
1217 values_[ 7] = T(0.0);
1218
1219 //values[ 8] = T(0.0);
1220 //values[ 9] = T(0.0);
1221 //values[10] = T(1.0);
1222 values_[11] = T(0.0);
1223
1224 values_[12] = translation[0];
1225 values_[13] = translation[1];
1226 values_[14] = translation[2];
1227 values_[15] = T(1.0);
1228
1231
1232 ocean_assert(isValid());
1233}
1234
1235template <typename T>
1237{
1238 values_[3] = T(0.0);
1239 values_[7] = T(0.0);
1240 values_[11] = T(0.0);
1241 values_[15] = T(1.0);
1242
1244
1245 values_[12] = T(0.0);
1246 values_[13] = T(0.0);
1247 values_[14] = T(0.0);
1248
1249 HomogenousMatrixT4<T> shearMatrix(true);
1250 shearMatrix(0, 1) = shear(0);
1251 shearMatrix(0, 2) = shear(1);
1252 shearMatrix(1, 2) = shear(2);
1253 *this = *this * shearMatrix;
1254
1256
1257 memcpy(values_ + 12, translation(), sizeof(T) * 3);
1258
1259 ocean_assert(isValid());
1260}
1261
1262template <typename T>
1264{
1265 values_[3] = T(0.0);
1266 values_[7] = T(0.0);
1267 values_[11] = T(0.0);
1268 values_[15] = T(1.0);
1269
1271
1272 HomogenousMatrixT4<T> shearMatrix(true);
1273 shearMatrix(0, 1) = shear(0);
1274 shearMatrix(0, 2) = shear(1);
1275 shearMatrix(1, 2) = shear(2);
1276 *this = *this * shearMatrix;
1277
1279
1280 memcpy(values_ + 12, translation(), sizeof(T) * 3);
1281
1282 ocean_assert(isValid());
1283}
1284
1285template <typename T>
1287{
1288 memcpy(values_ + 12, translation(), sizeof(T) * 3);
1289
1290 values_[3] = T(0.0);
1291 values_[7] = T(0.0);
1292 values_[11] = T(0.0);
1293 values_[15] = T(1.0);
1294
1297
1298 ocean_assert(isValid());
1299}
1300
1301template <typename T>
1303{
1304 values_[ 0] = xAxis[0];
1305 values_[ 1] = xAxis[1];
1306 values_[ 2] = xAxis[2];
1307 values_[ 3] = T(0.0);
1308
1309 values_[ 4] = yAxis[0];
1310 values_[ 5] = yAxis[1];
1311 values_[ 6] = yAxis[2];
1312 values_[ 7] = T(0.0);
1313
1314 values_[ 8] = zAxis[0];
1315 values_[ 9] = zAxis[1];
1316 values_[10] = zAxis[2];
1317 values_[11] = T(0.0);
1318
1319 values_[12] = T(0.0);
1320 values_[13] = T(0.0);
1321 values_[14] = T(0.0);
1322 values_[15] = T(1.0);
1323
1324 ocean_assert(isValid());
1325}
1326
1327template <typename T>
1329{
1330 values_[ 0] = xAxis[0];
1331 values_[ 1] = xAxis[1];
1332 values_[ 2] = xAxis[2];
1333 values_[ 3] = T(0.0);
1334
1335 values_[ 4] = yAxis[0];
1336 values_[ 5] = yAxis[1];
1337 values_[ 6] = yAxis[2];
1338 values_[ 7] = T(0.0);
1339
1340 values_[ 8] = zAxis[0];
1341 values_[ 9] = zAxis[1];
1342 values_[10] = zAxis[2];
1343 values_[11] = T(0.0);
1344
1345 values_[12] = translation[0];
1346 values_[13] = translation[1];
1347 values_[14] = translation[2];
1348 values_[15] = T(1.0);
1349
1350 ocean_assert(isValid());
1351}
1352
1353template <typename T>
1355{
1356 ocean_assert(isValid());
1357 return VectorT3<T>(values_ + 0);
1358}
1359
1360template <typename T>
1362{
1363 ocean_assert(isValid());
1364 return VectorT3<T>(values_ + 4);
1365}
1366
1367template <typename T>
1369{
1370 ocean_assert(isValid());
1371 return VectorT3<T>(values_ + 8);
1372}
1373
1374template <typename T>
1376{
1377 ocean_assert(isValid());
1378 return VectorT3<T>(values_ + 12);
1379}
1380
1381template <typename T>
1383{
1384 ocean_assert(isValid());
1385 return QuaternionT<T>(*this);
1386}
1387
1388template <typename T>
1390{
1391 ocean_assert(isValid());
1392
1393 const VectorT3<T> x(values_);
1394 const VectorT3<T> y(values_ + 4);
1395 const VectorT3<T> z(values_ + 8);
1396
1397 return VectorT3<T>(x.length(), y.length(), z.length());
1398}
1399
1400template <typename T>
1402{
1403 ocean_assert(isValid());
1404
1406
1410
1411 // x scale factor and normalization of x-axis
1412 scale.x() = xAxis.length();
1414 {
1415 return false;
1416 }
1417
1418 xAxis /= scale.x();
1419
1420 // xy shear factor
1421 shear(0) = xAxis * yAxis;
1422 // make y-axis orthogonal to x-axis
1423 yAxis -= xAxis * shear(0);
1424
1425 // y scale factor and normalization of y-axis
1426 scale.y() = yAxis.length();
1428 {
1429 return false;
1430 }
1431
1432 const T invScaleY = T(1) / scale.y();
1433
1434 yAxis *= invScaleY;
1435
1436 // normalization of xy shear factor
1437 shear(0) *= invScaleY;
1438
1439 // xz shear factor and orthogonalization of z-axis
1440 shear(1) = xAxis * zAxis;
1441 zAxis -= xAxis * shear(1);
1442
1443 // yz shear factor and orthogonalization of z-axis
1444 shear(2) = yAxis * zAxis;
1445 zAxis -= yAxis * shear(2);
1446
1447 // z scale factor and normalization of z-axis
1448 scale.z() = zAxis.length();
1449
1451 {
1452 return false;
1453 }
1454
1455 const T invScaleZ = T(1) / scale.z();
1456
1457 zAxis *= invScaleZ;
1458
1459 // normalization of xz shear and yz shear
1460 shear(1) *= invScaleZ;
1461 shear(2) *= invScaleZ;
1462
1463 // check for a coordinate system flip
1464 if (xAxis * yAxis.cross(zAxis) < 0)
1465 {
1466 scale = -scale;
1467 xAxis = -xAxis;
1468 yAxis = -yAxis;
1469 zAxis = -zAxis;
1470 }
1471
1472 // no we have pairwise orthogonal base vectors
1473
1474#ifdef OCEAN_DEBUG
1475 const T epsilon = std::is_same<T, float>::value ? NumericT<T>::weakEps() : NumericT<T>::eps();
1476 ocean_assert(NumericT<T>::isEqual(xAxis * yAxis, 0, epsilon));
1477 ocean_assert(NumericT<T>::isEqual(xAxis * zAxis, 0, epsilon));
1478 ocean_assert(NumericT<T>::isEqual(yAxis * zAxis, 0, epsilon));
1479#endif
1480
1482
1483 return true;
1484}
1485
1486template <typename T>
1488{
1489 ocean_assert(isValid());
1490
1491 return SquareMatrixT3<T>(values_[0], values_[1], values_[2],
1492 values_[4], values_[5], values_[6],
1493 values_[8], values_[9], values_[10]);
1494}
1495
1496template <typename T>
1498{
1499 ocean_assert(data);
1500
1501 if (transposed)
1502 {
1503 data[0] = values_[0];
1504 data[1] = values_[4];
1505 data[2] = values_[8];
1506
1507 data[3] = values_[1];
1508 data[4] = values_[5];
1509 data[5] = values_[9];
1510
1511 data[6] = values_[2];
1512 data[7] = values_[6];
1513 data[8] = values_[10];
1514 }
1515 else
1516 {
1517 data[0] = values_[0];
1518 data[1] = values_[1];
1519 data[2] = values_[2];
1520
1521 data[3] = values_[4];
1522 data[4] = values_[5];
1523 data[5] = values_[6];
1524
1525 data[6] = values_[8];
1526 data[7] = values_[9];
1527 data[8] = values_[10];
1528 }
1529}
1530
1531template <typename T>
1533{
1534 ocean_assert(isValid());
1535 return rotationMatrix().orthonormalMatrix();
1536}
1537
1538template <typename T>
1540{
1541 ocean_assert(isValid());
1542
1543 SquareMatrixT4<T> result(*this);
1544
1545 result[1] = values_[4];
1546 result[4] = values_[1];
1547
1548 result[2] = values_[8];
1549 result[8] = values_[2];
1550
1551 result[3] = values_[12];
1552 result[12] = values_[3];
1553
1554 result[7] = values_[13];
1555 result[13] = values_[7];
1556
1557 result[11] = values_[14];
1558 result[14] = values_[11];
1559
1560 result[6] = values_[9];
1561 result[9] = values_[6];
1562
1563 ocean_assert(result == SquareMatrixT4<T>(*this).transposed());
1564
1565 return result;
1566}
1567
1568template <typename T>
1570{
1571 ocean_assert(isValid());
1572
1573 HomogenousMatrixT4<T> invertedMatrix;
1574
1575 if (!invert(invertedMatrix))
1576 {
1577 ocean_assert(false && "Could not invert the matrix.");
1578 return *this;
1579 }
1580
1581 return invertedMatrix;
1582}
1583
1584template <typename T>
1586{
1587 HomogenousMatrixT4<T> invertedMatrix;
1588
1589 if (!invert(invertedMatrix))
1590 {
1591 return false;
1592 }
1593
1594 *this = invertedMatrix;
1595
1596 return true;
1597}
1598
1599template <typename T>
1601{
1602 ocean_assert(isValid());
1603
1604 const T det = determinant();
1605
1606 if (NumericT<T>::isEqualEps(det))
1607 {
1608 return false;
1609 }
1610
1611 const T factor = T(1.0) / det;
1612
1613 invertedMatrix.values_[0] = (values_[5] * values_[10] - values_[6] * values_[9]) * factor;
1614 invertedMatrix.values_[1] = (values_[2] * values_[9] - values_[1] * values_[10]) * factor;
1615 invertedMatrix.values_[2] = (values_[1] * values_[6] - values_[2] * values_[5]) * factor;
1616 invertedMatrix.values_[4] = (values_[8] * values_[6] - values_[4] * values_[10]) * factor;
1617 invertedMatrix.values_[5] = (values_[0] * values_[10] - values_[8] * values_[2]) * factor;
1618 invertedMatrix.values_[6] = (values_[4] * values_[2] - values_[0] * values_[6]) * factor;
1619 invertedMatrix.values_[8] = (values_[4] * values_[9] - values_[8] * values_[5]) * factor;
1620 invertedMatrix.values_[9] = (values_[8] * values_[1] - values_[0] * values_[9]) * factor;
1621 invertedMatrix.values_[10] = (values_[0] * values_[5] - values_[4] * values_[1]) * factor;
1622
1623 invertedMatrix.values_[12] = -(invertedMatrix.values_[0] * values_[12] + invertedMatrix.values_[4] * values_[13] + invertedMatrix.values_[8] * values_[14]);
1624 invertedMatrix.values_[13] = -(invertedMatrix.values_[1] * values_[12] + invertedMatrix.values_[5] * values_[13] + invertedMatrix.values_[9] * values_[14]);
1625 invertedMatrix.values_[14] = -(invertedMatrix.values_[2] * values_[12] + invertedMatrix.values_[6] * values_[13] + invertedMatrix.values_[10] * values_[14]);
1626
1627 invertedMatrix.values_[3] = T(0.0);
1628 invertedMatrix.values_[7] = T(0.0);
1629 invertedMatrix.values_[11] = T(0.0);
1630 invertedMatrix.values_[15] = T(1.0);
1631
1632 return true;
1633}
1634
1635template <typename T>
1637{
1638 return values_[0] * (values_[5] * values_[10] - values_[6] * values_[9])
1639 + values_[1] * (values_[6] * values_[8] - values_[4] * values_[10])
1640 + values_[2] * (values_[4] * values_[9] - values_[5] * values_[8]);
1641}
1642
1643template <typename T>
1645{
1646 ocean_assert(isValid());
1647 return values_[0] + values_[5] + values_[10] + T(1.0);
1648}
1649
1650template <typename T>
1652{
1653 values_[12] = translation[0];
1654 values_[13] = translation[1];
1655 values_[14] = translation[2];
1656
1657 return *this;
1658}
1659
1660template <typename T>
1662{
1663 // R(n, angle) = cos(angle) * I + (1 - cos(angle) * nn^T - sin(angle) * X(n)
1664
1665 ocean_assert(rotation.isValid());
1666
1667 const T cosValue = NumericT<T>::cos(rotation.angle());
1668 const T cosValue1 = T(1.0) - cosValue;
1669 const T sinValue = NumericT<T>::sin(rotation.angle());
1670
1671 const VectorT3<T> axis(rotation.axis());
1672
1673 const T xx = axis.x() * axis.x() * cosValue1;
1674 const T yy = axis.y() * axis.y() * cosValue1;
1675 const T zz = axis.z() * axis.z() * cosValue1;
1676 const T xy = axis.x() * axis.y() * cosValue1;
1677 const T xz = axis.x() * axis.z() * cosValue1;
1678 const T yz = axis.y() * axis.z() * cosValue1;
1679
1680 const T nx = axis.x() * sinValue;
1681 const T ny = axis.y() * sinValue;
1682 const T nz = axis.z() * sinValue;
1683
1684 values_[0] = xx + cosValue;
1685 values_[1] = xy + nz;
1686 values_[2] = xz - ny;
1687
1688 values_[4] = xy - nz;
1689 values_[5] = yy + cosValue;
1690 values_[6] = yz + nx;
1691
1692 values_[8] = xz + ny;
1693 values_[9] = yz - nx;
1694 values_[10] = zz + cosValue;
1695
1696 ocean_assert(isValid() && NumericT<T>::isEqual(determinant(), T(1.0)));
1697 return *this;
1698}
1699
1700template <typename T>
1702{
1703 ocean_assert(quaternion.isValid());
1704
1705 const T xx = quaternion.x() * quaternion.x();
1706 const T yy = quaternion.y() * quaternion.y();
1707 const T zz = quaternion.z() * quaternion.z();
1708
1709 const T wx = quaternion.w() * quaternion.x();
1710 const T wy = quaternion.w() * quaternion.y();
1711 const T wz = quaternion.w() * quaternion.z();
1712 const T xy = quaternion.x() * quaternion.y();
1713 const T xz = quaternion.x() * quaternion.z();
1714 const T yz = quaternion.y() * quaternion.z();
1715
1716 values_[ 0] = T(1.0) - T(2.0) * (yy + zz);
1717 values_[ 1] = T(2.0) * (wz + xy);
1718 values_[ 2] = T(2.0) * (xz - wy);
1719
1720 values_[ 4] = T(2.0) * (xy - wz);
1721 values_[ 5] = T(1.0) - T(2.0) * (xx + zz);
1722 values_[ 6] = T(2.0) * (wx + yz);
1723
1724 values_[ 8] = T(2.0) * (wy + xz);
1725 values_[ 9] = T(2.0) * (yz - wx);
1726 values_[10] = T(1.0) - T(2.0) * (xx + yy);
1727
1728 ocean_assert(isValid() && NumericT<T>::isWeakEqual(determinant(), T(1.0)));
1729 return *this;
1730}
1731
1732template <typename T>
1734{
1735 memcpy(values_, matrix(), sizeof(T) * 3);
1736 memcpy(values_ + 4, matrix() + 3, sizeof(T) * 3);
1737 memcpy(values_ + 8, matrix() + 6, sizeof(T) * 3);
1738
1739 return *this;
1740}
1741
1742template <typename T>
1744{
1745 ocean_assert(isValid());
1746
1747 values_[0] *= scale(0);
1748 values_[1] *= scale(0);
1749 values_[2] *= scale(0);
1750
1751 values_[4] *= scale(1);
1752 values_[5] *= scale(1);
1753 values_[6] *= scale(1);
1754
1755 values_[8] *= scale(2);
1756 values_[9] *= scale(2);
1757 values_[10] *= scale(2);
1758
1759 return *this;
1760}
1761
1762template <typename T>
1764{
1765 values_[ 0] = T(1.0);
1766 values_[ 1] = T(0.0);
1767 values_[ 2] = T(0.0);
1768 values_[ 3] = T(0.0);
1769
1770 values_[ 4] = T(0.0);
1771 values_[ 5] = T(1.0);
1772 values_[ 6] = T(0.0);
1773 values_[ 7] = T(0.0);
1774
1775 values_[ 8] = T(0.0);
1776 values_[ 9] = T(0.0);
1777 values_[10] = T(1.0);
1778 values_[11] = T(0.0);
1779
1780 values_[12] = T(0.0);
1781 values_[13] = T(0.0);
1782 values_[14] = T(0.0);
1783 values_[15] = T(1.0);
1784
1785 ocean_assert(isValid());
1786}
1787
1788template <typename T>
1790{
1791 for (unsigned int n = 0u; n < 16u; ++n)
1792 {
1793 values_[n] = T(0);
1794 }
1795
1796 ocean_assert(!isValid());
1797}
1798
1799template <typename T>
1804
1805template <typename T>
1813
1814template <typename T>
1815inline bool HomogenousMatrixT4<T>::isEqual(const HomogenousMatrixT4<T>& matrix, const T epsilon) const
1816{
1817 return NumericT<T>::isEqual(values_[0], matrix.values_[0], epsilon) && NumericT<T>::isEqual(values_[1], matrix.values_[1], epsilon)
1818 && NumericT<T>::isEqual(values_[2], matrix.values_[2], epsilon) && NumericT<T>::isEqual(values_[3], matrix.values_[3], epsilon)
1819 && NumericT<T>::isEqual(values_[4], matrix.values_[4], epsilon) && NumericT<T>::isEqual(values_[5], matrix.values_[5], epsilon)
1820 && NumericT<T>::isEqual(values_[6], matrix.values_[6], epsilon) && NumericT<T>::isEqual(values_[7], matrix.values_[7], epsilon)
1821 && NumericT<T>::isEqual(values_[8], matrix.values_[8], epsilon) && NumericT<T>::isEqual(values_[9], matrix.values_[9], epsilon)
1822 && NumericT<T>::isEqual(values_[10], matrix.values_[10], epsilon) && NumericT<T>::isEqual(values_[11], matrix.values_[11], epsilon)
1823 && NumericT<T>::isEqual(values_[12], matrix.values_[12], epsilon) && NumericT<T>::isEqual(values_[13], matrix.values_[13], epsilon)
1824 && NumericT<T>::isEqual(values_[14], matrix.values_[14], epsilon) && NumericT<T>::isEqual(values_[15], matrix.values_[15], epsilon);
1825}
1826
1827template <typename T>
1835
1836template <typename T>
1837inline const T* HomogenousMatrixT4<T>::data() const
1838{
1839 return values_;
1840}
1841
1842template <typename T>
1844{
1845 return values_;
1846}
1847
1848template <typename T>
1849inline void HomogenousMatrixT4<T>::copyElements(T* arrayValues, const bool valuesRowAligned) const
1850{
1851 ocean_assert(arrayValues != nullptr);
1852
1853 if (valuesRowAligned)
1854 {
1855 // this matrix is column aligned but the provided data is row aligned
1856
1857 arrayValues[ 0] = values_[ 0];
1858 arrayValues[ 1] = values_[ 4];
1859 arrayValues[ 2] = values_[ 8];
1860 arrayValues[ 3] = values_[12];
1861
1862 arrayValues[ 4] = values_[ 1];
1863 arrayValues[ 5] = values_[ 5];
1864 arrayValues[ 6] = values_[ 9];
1865 arrayValues[ 7] = values_[13];
1866
1867 arrayValues[ 8] = values_[ 2];
1868 arrayValues[ 9] = values_[ 6];
1869 arrayValues[10] = values_[10];
1870 arrayValues[11] = values_[14];
1871
1872 arrayValues[12] = values_[ 3];
1873 arrayValues[13] = values_[ 7];
1874 arrayValues[14] = values_[11];
1875 arrayValues[15] = values_[15];
1876 }
1877 else
1878 {
1879 // this matrix and the provided array are both column aligned
1880 // thus, we can simply copy the data
1881
1882 memcpy(arrayValues, values_, sizeof(T) * 16);
1883 }
1884}
1885
1886template <typename T>
1887template <typename U>
1888inline void HomogenousMatrixT4<T>::copyElements(U* arrayValues, const bool valuesRowAligned) const
1889{
1890 ocean_assert(arrayValues != nullptr);
1891
1892 if (valuesRowAligned)
1893 {
1894 // this matrix is column aligned but the provided data is row aligned
1895
1896 arrayValues[ 0] = U(values_[ 0]);
1897 arrayValues[ 1] = U(values_[ 4]);
1898 arrayValues[ 2] = U(values_[ 8]);
1899 arrayValues[ 3] = U(values_[12]);
1900
1901 arrayValues[ 4] = U(values_[ 1]);
1902 arrayValues[ 5] = U(values_[ 5]);
1903 arrayValues[ 6] = U(values_[ 9]);
1904 arrayValues[ 7] = U(values_[13]);
1905
1906 arrayValues[ 8] = U(values_[ 2]);
1907 arrayValues[ 9] = U(values_[ 6]);
1908 arrayValues[10] = U(values_[10]);
1909 arrayValues[11] = U(values_[14]);
1910
1911 arrayValues[12] = U(values_[ 3]);
1912 arrayValues[13] = U(values_[ 7]);
1913 arrayValues[14] = U(values_[11]);
1914 arrayValues[15] = U(values_[15]);
1915 }
1916 else
1917 {
1918 // this matrix and the provided array are both column aligned
1919 // thus, we can simply copy the data
1920
1921 for (unsigned int n = 0u; n < 16u; ++n)
1922 {
1923 arrayValues[n] = U(values_[n]);
1924 }
1925 }
1926}
1927
1928template <typename T>
1930{
1931 ocean_assert(isValid());
1932
1933 return VectorT3<T>(values_[0] * vector[0] + values_[4] * vector[1] + values_[8] * vector[2],
1934 values_[1] * vector[0] + values_[5] * vector[1] + values_[9] * vector[2],
1935 values_[2] * vector[0] + values_[6] * vector[1] + values_[10] * vector[2]);
1936}
1937
1938template <typename T>
1940{
1941 ocean_assert(isValid());
1942
1943 return VectorT3<T>(values_[0] * vector[0] + values_[1] * vector[1] + values_[2] * vector[2],
1944 values_[4] * vector[0] + values_[5] * vector[1] + values_[6] * vector[2],
1945 values_[8] * vector[0] + values_[9] * vector[1] + values_[10] * vector[2]);
1946}
1947
1948template <typename T>
1950{
1951 return isEqual(matrix);
1952}
1953
1954template <typename T>
1956{
1957 return !(*this == matrix);
1958}
1959
1960template <typename T>
1962{
1963 ocean_assert(isValid() && matrix.isValid());
1964
1965 HomogenousMatrixT4<T> result;
1966
1967 result.values_[0] = values_[0] * matrix.values_[0] + values_[4] * matrix.values_[1] + values_[8] * matrix.values_[2] + values_[12] * matrix.values_[3];
1968 result.values_[1] = values_[1] * matrix.values_[0] + values_[5] * matrix.values_[1] + values_[9] * matrix.values_[2] + values_[13] * matrix.values_[3];
1969 result.values_[2] = values_[2] * matrix.values_[0] + values_[6] * matrix.values_[1] + values_[10] * matrix.values_[2] + values_[14] * matrix.values_[3];
1970 result.values_[3] = T(0.0);
1971
1972 result.values_[4] = values_[0] * matrix.values_[4] + values_[4] * matrix.values_[5] + values_[8] * matrix.values_[6] + values_[12] * matrix.values_[7];
1973 result.values_[5] = values_[1] * matrix.values_[4] + values_[5] * matrix.values_[5] + values_[9] * matrix.values_[6] + values_[13] * matrix.values_[7];
1974 result.values_[6] = values_[2] * matrix.values_[4] + values_[6] * matrix.values_[5] + values_[10] * matrix.values_[6] + values_[14] * matrix.values_[7];
1975 result.values_[7] = T(0.0);
1976
1977 result.values_[8] = values_[0] * matrix.values_[8] + values_[4] * matrix.values_[9] + values_[8] * matrix.values_[10] + values_[12] * matrix.values_[11];
1978 result.values_[9] = values_[1] * matrix.values_[8] + values_[5] * matrix.values_[9] + values_[9] * matrix.values_[10] + values_[13] * matrix.values_[11];
1979 result.values_[10] = values_[2] * matrix.values_[8] + values_[6] * matrix.values_[9] + values_[10] * matrix.values_[10] + values_[14] * matrix.values_[11];
1980 result.values_[11] = T(0.0);
1981
1982 result.values_[12] = values_[0] * matrix.values_[12] + values_[4] * matrix.values_[13] + values_[8] * matrix.values_[14] + values_[12] * matrix.values_[15];
1983 result.values_[13] = values_[1] * matrix.values_[12] + values_[5] * matrix.values_[13] + values_[9] * matrix.values_[14] + values_[13] * matrix.values_[15];
1984 result.values_[14] = values_[2] * matrix.values_[12] + values_[6] * matrix.values_[13] + values_[10] * matrix.values_[14] + values_[14] * matrix.values_[15];
1985 result.values_[15] = T(1.0);
1986
1987 ocean_assert(result.isValid());
1988
1989 return result;
1990}
1991
1992template <typename T>
1994{
1995 *this = *this * matrix;
1996 return *this;
1997}
1998
1999template <typename T>
2004
2005
2006template <typename T>
2008{
2009 *this = *this * rotation;
2010 return *this;
2011}
2012
2013template <typename T>
2018
2019template <typename T>
2021{
2022 *this = *this * rotation;
2023 return *this;
2024}
2025
2026template <typename T>
2028{
2029 ocean_assert(isValid());
2030
2031 return VectorT3<T>(values_[0] * vector[0] + values_[4] * vector[1] + values_[8] * vector[2] + values_[12],
2032 values_[1] * vector[0] + values_[5] * vector[1] + values_[9] * vector[2] + values_[13],
2033 values_[2] * vector[0] + values_[6] * vector[1] + values_[10] * vector[2] + values_[14]);
2034}
2035
2036template <typename T>
2038{
2039 ocean_assert(isValid());
2040
2041 return VectorT4<T>(values_[0] * vector[0] + values_[4] * vector[1] + values_[8] * vector[2] + values_[12] * vector[3],
2042 values_[1] * vector[0] + values_[5] * vector[1] + values_[9] * vector[2] + values_[13] * vector[3],
2043 values_[2] * vector[0] + values_[6] * vector[1] + values_[10] * vector[2] + values_[14] * vector[3],
2044 vector[3]);
2045}
2046
2047template <typename T>
2048inline T HomogenousMatrixT4<T>::operator[](const unsigned int index) const
2049{
2050 ocean_assert(index < 16);
2051 return values_[index];
2052}
2053
2054template <typename T>
2055inline T& HomogenousMatrixT4<T>::operator[](const unsigned int index)
2056{
2057 ocean_assert(index < 16u);
2058 return values_[index];
2059}
2060
2061template <typename T>
2062inline T HomogenousMatrixT4<T>::operator()(const unsigned int row, const unsigned int column) const
2063{
2064 ocean_assert(row < 4u && column < 4u);
2065 return values_[column * 4u + row];
2066}
2067
2068template <typename T>
2069inline T& HomogenousMatrixT4<T>::operator()(const unsigned int row, const unsigned int column)
2070{
2071 ocean_assert(row < 4u && column < 4u);
2072 return values_[column * 4u + row];
2073}
2074
2075template <typename T>
2076inline T HomogenousMatrixT4<T>::operator()(const unsigned int index) const
2077{
2078 ocean_assert(index < 16u);
2079 return values_[index];
2080}
2081
2082template <typename T>
2083inline T& HomogenousMatrixT4<T>::operator()(const unsigned int index)
2084{
2085 ocean_assert(index < 16u);
2086 return values_[index];
2087}
2088
2089template <typename T>
2091{
2092 return values_;
2093}
2094
2095template <typename T>
2097{
2098 return values_;
2099}
2100
2101template <typename T>
2103{
2104 // we skip the value of the lower matrix row, as these values are always [0, 0, 0, 1]
2105
2106 size_t seed = std::hash<T>{}(matrix.values_[0]);
2107 seed ^= std::hash<T>{}(matrix.values_[1]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2108 seed ^= std::hash<T>{}(matrix.values_[2]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2109
2110 seed ^= std::hash<T>{}(matrix.values_[4]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2111 seed ^= std::hash<T>{}(matrix.values_[5]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2112 seed ^= std::hash<T>{}(matrix.values_[6]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2113
2114 seed ^= std::hash<T>{}(matrix.values_[8]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2115 seed ^= std::hash<T>{}(matrix.values_[9]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2116 seed ^= std::hash<T>{}(matrix.values_[10]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2117
2118 seed ^= std::hash<T>{}(matrix.values_[12]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2119 seed ^= std::hash<T>{}(matrix.values_[13]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2120 seed ^= std::hash<T>{}(matrix.values_[14]) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
2121
2122 return seed;
2123}
2124
2125template <typename T>
2126template <typename U>
2127inline std::vector< HomogenousMatrixT4<T> > HomogenousMatrixT4<T>::matrices2matrices(const std::vector< HomogenousMatrixT4<U> >& matrices)
2128{
2129 std::vector< HomogenousMatrixT4<T> > result;
2130 result.reserve(matrices.size());
2131
2132 for (typename std::vector< HomogenousMatrixT4<U> >::const_iterator i = matrices.begin(); i != matrices.end(); ++i)
2133 {
2134 result.push_back(HomogenousMatrixT4<T>(*i));
2135 }
2136
2137 return result;
2138}
2139
2140template <>
2141template <>
2142inline std::vector< HomogenousMatrixT4<float> > HomogenousMatrixT4<float>::matrices2matrices(const std::vector< HomogenousMatrixT4<float> >& matrices)
2143{
2144 return matrices;
2145}
2146
2147template <>
2148template <>
2149inline std::vector< HomogenousMatrixT4<double> > HomogenousMatrixT4<double>::matrices2matrices(const std::vector< HomogenousMatrixT4<double> >& matrices)
2150{
2151 return matrices;
2152}
2153
2154template <typename T>
2155template <typename U>
2156inline std::vector< HomogenousMatrixT4<T> > HomogenousMatrixT4<T>::matrices2matrices(const HomogenousMatrixT4<U>* matrices, const size_t size)
2157{
2158 std::vector< HomogenousMatrixT4<T> > result;
2159 result.reserve(size);
2160
2161 for (size_t n = 0; n < size; ++n)
2162 {
2163 result.push_back(HomogenousMatrixT4<T>(matrices[n]));
2164 }
2165
2166 return result;
2167}
2168
2169template <typename T>
2170std::ostream& operator<<(std::ostream& stream, const HomogenousMatrixT4<T>& matrix)
2171{
2172 stream << "|" << matrix(0, 0) << ", " << matrix(0, 1) << ", " << matrix(0, 2) << ", " << matrix(0, 3) << "|" << std::endl;
2173 stream << "|" << matrix(1, 0) << ", " << matrix(1, 1) << ", " << matrix(1, 2) << ", " << matrix(1, 3) << "|" << std::endl;
2174 stream << "|" << matrix(2, 0) << ", " << matrix(2, 1) << ", " << matrix(2, 2) << ", " << matrix(2, 3) << "|" << std::endl;
2175 stream << "|" << matrix(3, 0) << ", " << matrix(3, 1) << ", " << matrix(3, 2) << ", " << matrix(3, 3) << "|";
2176
2177 return stream;
2178}
2179
2180template <bool tActive, typename T>
2181MessageObject<tActive>& operator<<(MessageObject<tActive>& messageObject, const HomogenousMatrixT4<T>& matrix)
2182{
2183 return messageObject << "|" << matrix(0, 0) << ", " << matrix(0, 1) << ", " << matrix(0, 2) << ", " << matrix(0, 3) << "|\n|"
2184 << matrix(1, 0) << ", " << matrix(1, 1) << ", " << matrix(1, 2) << ", " << matrix(1, 3) << "|\n|"
2185 << matrix(2, 0) << ", " << matrix(2, 1) << ", " << matrix(2, 2) << ", " << matrix(2, 3) << "|\n|"
2186 << matrix(3, 0) << ", " << matrix(3, 1) << ", " << matrix(3, 2) << ", " << matrix(3, 3) << "|";
2187}
2188
2189template <bool tActive, typename T>
2190MessageObject<tActive>& operator<<(MessageObject<tActive>&& messageObject, const HomogenousMatrixT4<T>& matrix)
2191{
2192 return messageObject << "|" << matrix(0, 0) << ", " << matrix(0, 1) << ", " << matrix(0, 2) << ", " << matrix(0, 3) << "|\n|"
2193 << matrix(1, 0) << ", " << matrix(1, 1) << ", " << matrix(1, 2) << ", " << matrix(1, 3) << "|\n|"
2194 << matrix(2, 0) << ", " << matrix(2, 1) << ", " << matrix(2, 2) << ", " << matrix(2, 3) << "|\n|"
2195 << matrix(3, 0) << ", " << matrix(3, 1) << ", " << matrix(3, 2) << ", " << matrix(3, 3) << "|";
2196}
2197
2198}
2199
2200#endif // META_OCEAN_MATH_HOMOGENOUS_MATRIX_4_H
This class implements an euler rotation with angles: yaw, pitch and roll.
Definition Euler.h:82
bool isValid() const
Returns whether the euler rotation holds valid parameters.
Definition Euler.h:360
HomogenousMatrixT4()
Creates a new default HomogenousMatrixT4 object with undefined elements.
Definition HomogenousMatrix4.h:719
bool invert()
Inverts the matrix.
Definition HomogenousMatrix4.h:1585
const T * data() const
Returns a pointer to the internal values.
Definition HomogenousMatrix4.h:1837
HomogenousMatrixT4(const U *arrayValues, const bool valuesRowAligned)
Creates a new HomogenousMatrixT4 object by an array of at least sixteen elements of float type U.
Definition HomogenousMatrix4.h:790
friend class HomogenousMatrixT4
Definition HomogenousMatrix4.h:111
HomogenousMatrixT4(const EulerT< T > &euler)
Creates a new HomogenousMatrixT4 object with only a rotation given as Euler rotation.
Definition HomogenousMatrix4.h:909
HomogenousMatrixT4(const VectorT3< T > &translation, const QuaternionT< T > &rotation, const VectorT3< T > &scale)
Creates a new HomogenousMatrixT4 object by a translation, rotation and scale.
Definition HomogenousMatrix4.h:1286
HomogenousMatrixT4(const SquareMatrixT4< T > &matrix)
Creates a new HomogenousMatrixT4 object from a 4x4 square matrix.
Definition HomogenousMatrix4.h:995
HomogenousMatrixT4< T > inverted() const noexcept
Returns the inverted of this matrix.
Definition HomogenousMatrix4.h:1569
HomogenousMatrixT4(const HomogenousMatrixT4< T > &matrix)=default
Copy constructor.
VectorT3< T > scale() const
Returns the scale of the transformation.
Definition HomogenousMatrix4.h:1389
HomogenousMatrixT4< T > & setRotation(const RotationT< T > &rotation)
Sets the rotation of this transformation.
Definition HomogenousMatrix4.h:1661
VectorT3< T > transposedRotationMatrix(const VectorT3< T > &vector) const
Transforms a 3D vector by application of only the inner transposed rotation matrix (including scale a...
Definition HomogenousMatrix4.h:1939
SquareMatrixT3< T > rotationMatrix() const
Returns the rotation matrix of the transformation.
Definition HomogenousMatrix4.h:1487
void copyElements(T *arrayValues, const bool valuesRowAligned=false) const
Copies the elements of this matrix to an array with floating point values of the same type T.
Definition HomogenousMatrix4.h:1849
HomogenousMatrixT4(const VectorT3< T > &translation)
Creates a new HomogenousMatrixT4 object with only a translation.
Definition HomogenousMatrix4.h:853
T trace() const
Returns the trace of the matrix which is the sum of the diagonal elements.
Definition HomogenousMatrix4.h:1644
HomogenousMatrixT4(const T *arrayValues, const bool valuesRowAligned)
Creates a new HomogenousMatrixT4 object by an array of at least sixteen elements.
Definition HomogenousMatrix4.h:823
HomogenousMatrixT4(const VectorT3< T > &translation, const VectorT3< T > &scale)
Creates a new HomogenousMatrixT4 object by a translation and a scale.
Definition HomogenousMatrix4.h:1179
VectorT3< T > yAxis() const
Returns the y-axis of the transformation which is the second vector of the upper left 3x3 rotation ma...
Definition HomogenousMatrix4.h:1361
HomogenousMatrixT4< T > & applyScale(const VectorT3< T > &scale)
Applies new scale values.
Definition HomogenousMatrix4.h:1743
static std::vector< HomogenousMatrixT4< T > > matrices2matrices(const std::vector< HomogenousMatrixT4< U > > &matrices)
Converts matrices with specific data type to matrices with different data type.
Definition HomogenousMatrix4.h:2127
HomogenousMatrixT4(const VectorT3< T > &translation, const SquareMatrixT3< T > &rotation)
Creates a new HomogenousMatrixT4 object with a translation and rotation matrix.
Definition HomogenousMatrix4.h:1153
T values_[16]
The sixteen values of the transformation matrix.
Definition HomogenousMatrix4.h:715
HomogenousMatrixT4(const std::pair< VectorT3< T >, RotationT< T > > &translationAndRotation)
Creates a new HomogenousMatrixT4 object with a translation and rotation.
Definition HomogenousMatrix4.h:1033
HomogenousMatrixT4< T > & setTranslation(const VectorT3< T > &translation)
Sets the translation of this transformation.
Definition HomogenousMatrix4.h:1651
T operator[](const unsigned int index) const
Element operator.
Definition HomogenousMatrix4.h:2048
void toNull()
Sets the matrix to a zero matrix (including the lower right element).
Definition HomogenousMatrix4.h:1789
HomogenousMatrixT4(const VectorT3< T > &translation, const RotationT< T > &rotation, const VectorT3< T > &scale)
Creates a new HomogenousMatrixT4 object by a translation, rotation and scale.
Definition HomogenousMatrix4.h:1205
HomogenousMatrixT4< T > & operator*=(const HomogenousMatrixT4< T > &matrix)
Combines and assigns two transformation matrices.
Definition HomogenousMatrix4.h:1993
T determinant() const
Returns the determinant of the matrix.
Definition HomogenousMatrix4.h:1636
HomogenousMatrixT4(const QuaternionT< T > &rotation)
Creates a new HomogenousMatrixT4 object with only a rotation given as quaternion.
Definition HomogenousMatrix4.h:939
HomogenousMatrixT4(const VectorT3< T > &translation, const EulerT< T > &euler)
Creates a new HomogenousMatrixT4 object with a translation and rotation.
Definition HomogenousMatrix4.h:1063
HomogenousMatrixT4(const VectorT3< T > &xAxis, const VectorT3< T > &yAxis, const VectorT3< T > &zAxis)
Creates a new HomogenousMatrixT4 object by three basis vectors.
Definition HomogenousMatrix4.h:1302
bool isNull() const
Returns whether this matrix is a zero matrix (with all elements equal to zero).
Definition HomogenousMatrix4.h:1828
void rotationMatrix(T *data, const bool transposed=false) const
Copies the 3x3 rotation matrix elements of the 4x4 transformation.
Definition HomogenousMatrix4.h:1497
VectorT3< T > xAxis() const
Returns the x-axis of the transformation which is the first vector of the upper left 3x3 rotation mat...
Definition HomogenousMatrix4.h:1354
HomogenousMatrixT4(const RotationT< T > &rotation)
Creates a new HomogenousMatrixT4 object with only a rotation.
Definition HomogenousMatrix4.h:879
HomogenousMatrixT4(const VectorT3< T > &translation, const QuaternionT< T > &rotation)
Creates a new HomogenousMatrixT4 object with a translation and rotation.
Definition HomogenousMatrix4.h:1093
VectorT3< T > translation() const
Returns the translation of the transformation.
Definition HomogenousMatrix4.h:1375
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1800
HomogenousMatrixT4(const VectorT3< T > &translation, const RotationT< T > &rotation, const VectorT3< T > &scale, const VectorT3< T > &shear)
Creates a new HomogenousMatrixT4 object by a translation, rotation, scale and shear.
Definition HomogenousMatrix4.h:1263
bool decompose(VectorT3< T > &translation, QuaternionT< T > &rotation, VectorT3< T > &scale, VectorT3< T > &shear) const
Decomposes the transformation matrix into translation, rotation, scale and shear parameters.
Definition HomogenousMatrix4.h:1401
HomogenousMatrixT4< T > operator*(const HomogenousMatrixT4< T > &matrix) const
Combines two transformation matrices.
Definition HomogenousMatrix4.h:1961
HomogenousMatrixT4(const U *arrayValues)
Creates a new HomogenousMatrixT4 object by 16 given floating point values of type U.
Definition HomogenousMatrix4.h:774
QuaternionT< T > rotation() const
Returns the rotation of the transformation as quaternion.
Definition HomogenousMatrix4.h:1382
T Type
Definition of the used data type.
Definition HomogenousMatrix4.h:118
bool operator!=(const HomogenousMatrixT4< T > &matrix) const
Returns whether two transformations are not identical up to a small epsilon.
Definition HomogenousMatrix4.h:1955
void toIdentity()
Sets the matrix to the identity matrix.
Definition HomogenousMatrix4.h:1763
bool operator==(const HomogenousMatrixT4< T > &matrix) const
Returns whether two transformations are identical up to a small epsilon.
Definition HomogenousMatrix4.h:1949
bool isIdentity() const
Returns whether this matrix is an identity matrix.
Definition HomogenousMatrix4.h:1806
bool isEqual(const HomogenousMatrixT4< T > &matrix, const T epsilon=NumericT< T >::eps()) const
Returns whether two matrices are almost identical up to a specified epsilon.
Definition HomogenousMatrix4.h:1815
HomogenousMatrixT4(const SquareMatrixT3< T > &rotation)
Creates a new HomogenousMatrixT4 object with only a rotation given as 3x3 rotation matrix.
Definition HomogenousMatrix4.h:969
HomogenousMatrixT4(const VectorT3< T > &translation, const RotationT< T > &rotation)
Creates a new HomogenousMatrixT4 object with a translation and rotation.
Definition HomogenousMatrix4.h:1003
SquareMatrixT4< T > transposed() const
Returns the transposed of this matrix.
Definition HomogenousMatrix4.h:1539
SquareMatrixT3< T > orthonormalRotationMatrix() const
Returns the 3x3 orthonormal rotation matrix of the 4x4 transformation (by forcing a orthogonal and no...
Definition HomogenousMatrix4.h:1532
HomogenousMatrixT4(const bool setToIdentity)
Creates a new HomogenousMatrixT4.
Definition HomogenousMatrix4.h:735
HomogenousMatrixT4(const VectorT3< T > &xAxis, const VectorT3< T > &yAxis, const VectorT3< T > &zAxis, const VectorT3< T > &translation)
Creates a new HomogenousMatrixT4 object by three basis vectors and a translation vector.
Definition HomogenousMatrix4.h:1328
HomogenousMatrixT4(const std::pair< VectorT3< T >, QuaternionT< T > > &translationAndRotation)
Creates a new HomogenousMatrixT4 object with a translation and rotation.
Definition HomogenousMatrix4.h:1123
const T * operator()() const
Access operator.
Definition HomogenousMatrix4.h:2090
HomogenousMatrixT4(const HomogenousMatrixT4< U > &matrix)
Copy constructor for a matrix with difference element data type than T.
Definition HomogenousMatrix4.h:726
HomogenousMatrixT4(const VectorT3< T > &translation, const QuaternionT< T > &rotation, const VectorT3< T > &scale, const VectorT3< T > &shear)
Creates a new HomogenousMatrixT4 object by a translation, rotation, scale and shear.
Definition HomogenousMatrix4.h:1236
VectorT3< T > zAxis() const
Returns the z-axis of the transformation which is the third vector of the upper left 3x3 rotation mat...
Definition HomogenousMatrix4.h:1368
HomogenousMatrixT4(const T *arrayValues)
Creates a new HomogenousMatrixT4 object by 16 given floating point values.
Definition HomogenousMatrix4.h:783
This class provides basic numeric functionalities.
Definition Numeric.h:57
static constexpr T weakEps()
Returns a weak epsilon.
static T sin(const T value)
Returns the sine of a given value.
Definition Numeric.h:1572
static constexpr T eps()
Returns a small epsilon.
static bool isEqual(const T first, const T second)
Returns whether two values are equal up to a small epsilon.
Definition Numeric.h:2395
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition Numeric.h:2096
static T cos(const T value)
Returns the cosine of a given value.
Definition Numeric.h:1588
This class implements a unit quaternion rotation.
Definition Quaternion.h:100
const T & x() const
Returns the x value of the quaternion.
Definition Quaternion.h:900
bool isValid() const
Returns whether this quaternion is a valid unit quaternion.
Definition Quaternion.h:882
const T & w() const
Returns the w value of the quaternion.
Definition Quaternion.h:888
const T & y() const
Returns the y value of the quaternion.
Definition Quaternion.h:912
const T & z() const
Returns the z value of the quaternion.
Definition Quaternion.h:924
This class implements a axis-angle rotation using floating point values.
Definition Rotation.h:73
This class implements a 3x3 square matrix.
Definition SquareMatrix3.h:89
This class implements a 4x4 square matrix.
Definition SquareMatrix4.h:85
SquareMatrixT4< T > transposed() const
Returns the transposed of this matrix.
Definition SquareMatrix4.h:762
This class implements a vector with three elements.
Definition Vector3.h:97
const T & y() const noexcept
Returns the y value.
Definition Vector3.h:816
const T & x() const noexcept
Returns the x value.
Definition Vector3.h:804
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:828
T length() const
Returns the length of the vector.
Definition Vector3.h:668
This class implements a vector with four elements.
Definition Vector4.h:97
std::vector< HomogenousMatrixT4< T > > HomogenousMatricesT4
Definition of a typename alias for vectors with HomogenousMatrixT4 objects.
Definition HomogenousMatrix4.h:66
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition HomogenousMatrix4.h:73
std::vector< HomogenousMatrixF4 > HomogenousMatricesF4
Definition of a vector holding HomogenousMatrixF4 objects.
Definition HomogenousMatrix4.h:85
std::vector< HomogenousMatrixD4 > HomogenousMatricesD4
Definition of a vector holding HomogenousMatrixD4 objects.
Definition HomogenousMatrix4.h:79
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
std::ostream & operator<<(std::ostream &stream, const HighPerformanceStatistic &highPerformanceStatistic)
Definition HighPerformanceTimer.h:963