SA_Maths
Sapphire Suite's C++ Maths Library
Loading...
Searching...
No Matches
Matrix3.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Sapphire development team. All Rights Reserved.
2
3#pragma once
4
5#ifndef SAPPHIRE_MATHS_MATRIX3_GUARD
6#define SAPPHIRE_MATHS_MATRIX3_GUARD
7
8#include <limits>
9
10#include <SA/Maths/Debug.hpp>
11#include <SA/Maths/Config.hpp>
12
13#include <SA/Maths/Matrix/Matrix3Base.hpp>
14
17
18#if SA_MATHS_MATRIX3_SIMD
19
20 #include <SA/Support/Intrinsics.hpp>
21 #include <SA/Support/Pragma.hpp>
22
23#endif
24
35namespace SA
36{
37 template <typename T>
38 struct Vec3;
39
40 template <typename T>
41 struct Quat;
42
43 template <typename T, MatrixMajor major>
44 struct Mat4;
45
46
55#if SA_MATHS_MATRIX3_SIMD && SA_INTRISC
56
57 // Disable padding struct warning.
58 SA_PRAGMA_SDWARN_MSVC(4324)
59
60 template <typename T, MatrixMajor major = MatrixMajor::Default>
61 struct alignas(32) Mat3 : public Intl::Mat3_Base<T, major>
62
63#else
64
65 template <typename T, MatrixMajor major = MatrixMajor::Default>
66 struct Mat3 : public Intl::Mat3_Base<T, major>
67
68#endif
69 {
70 using Intl::Mat3_Base<T, major>::e00;
71 using Intl::Mat3_Base<T, major>::e01;
72 using Intl::Mat3_Base<T, major>::e02;
73
74 using Intl::Mat3_Base<T, major>::e10;
75 using Intl::Mat3_Base<T, major>::e11;
76 using Intl::Mat3_Base<T, major>::e12;
77
78 using Intl::Mat3_Base<T, major>::e20;
79 using Intl::Mat3_Base<T, major>::e21;
80 using Intl::Mat3_Base<T, major>::e22;
81
82
83//{ Constants
84
92 static const Mat3 Zero;
93
101 static const Mat3 Identity;
102
103//}
104
105//{ Constructors
106
107 using Intl::Mat3_Base<T, major>::Mat3_Base;
108
117 template <typename TIn, MatrixMajor majorIn>
118 constexpr Mat3(const Mat3<TIn, majorIn>& _other) noexcept;
119
128 template <typename TIn, MatrixMajor majorIn>
129 constexpr Mat3(const Mat4<TIn, majorIn>& _other) noexcept;
130
131//}
132
133//{ Equals
134
140 constexpr bool IsZero() const noexcept;
141
147 constexpr bool IsIdentity() const noexcept;
148
149
158 constexpr bool Equals(const Mat3& _other, T _epsilon = std::numeric_limits<T>::epsilon()) const noexcept;
159
160
168 constexpr bool operator==(const Mat3& _rhs) const noexcept;
169
177 constexpr bool operator!=(const Mat3& _rhs) const noexcept;
178//}
179
180//{ Accessors
181
187 T* Data() noexcept;
188
194 const T* Data() const noexcept;
195
196
204 T& At(uint32_t _index);
205
213 const T& At(uint32_t _index) const;
214
223 T& At(uint32_t _x, uint32_t _y);
224
233 const T& At(uint32_t _x, uint32_t _y) const;
234
235
243 T& operator[](uint32_t _index);
244
252 const T& operator[](uint32_t _index) const;
253//}
254
255//{ Transpose
256
262 Mat3& Transpose() noexcept;
263
269 constexpr Mat3 GetTransposed() const noexcept;
270
271//}
272
273//{ Inverse
274
280 T Determinant() const noexcept;
281
288
295
296//}
297
298//{ Lerp
299
311 static Mat3 Lerp(const Mat3& _start, const Mat3& _end, float _alpha) noexcept;
312
324 static Mat3 LerpUnclamped(const Mat3& _start, const Mat3& _end, float _alpha) noexcept;
325
326//}
327
328//{ Transform
329
337 static Mat3 MakeRotation(const Quat<T>& _rot) noexcept;
338
346 static Mat3 MakeScale(const Vec3<T>& _scale) noexcept;
347
348//}
349
350//{ Operators
351
360 template <typename TIn, MatrixMajor majorIn>
361 Mat3& operator=(const Mat3<TIn, majorIn> _rhs) noexcept;
362
368 constexpr Mat3 operator-() const noexcept;
369
379 template <typename TIn>
380 Mat3 operator*(TIn _scale) const noexcept;
381
391 template <typename TIn>
392 Mat3 operator/(TIn _scale) const;
393
401 Mat3 operator+(const Mat3& _rhs) const noexcept;
402
410 Mat3 operator-(const Mat3& _rhs) const noexcept;
411
419 Mat3 operator*(const Mat3& _rhs) const noexcept;
420
428 Mat3 operator/(const Mat3& _rhs) const;
429
430
438 Vec3<T> operator*(const Vec3<T>&_rhs) const noexcept;
439
440
450 template <typename TIn>
451 Mat3& operator*=(TIn _scale) noexcept;
452
462 template <typename TIn>
463 Mat3& operator/=(TIn _scale);
464
472 Mat3& operator+=(const Mat3& _rhs) noexcept;
473
481 Mat3& operator-=(const Mat3& _rhs) noexcept;
482
490 Mat3& operator*=(const Mat3& _rhs) noexcept;
491
499 Mat3& operator/=(const Mat3& _rhs);
500
501//}
502
503
504#if SA_LOGGING
505
514 std::string ToString() const noexcept;
515
516#endif
517 };
518
519#if SA_MATHS_MATRIX3_SIMD && SA_INTRISC
520
521 // Disable padding struct warning.
522 SA_PRAGMA_EDWARN_MSVC()
523
524#endif
525
526
537 template <typename TIn, typename T, MatrixMajor major>
538 Mat3<T, major> operator*(TIn _lhs, const Mat3<T, major>& _rhs) noexcept;
539
550 template <typename TIn, typename T, MatrixMajor major>
552
553
554#if SA_LOGGER_IMPL
555
567 template <typename T>
568 std::string ToString(const Mat3<T>& _m);
569
570#endif
571
572
573//{ Aliases
574
577
580
583
584
586 template <typename T, MatrixMajor major = MatrixMajor::Default>
588
591
594
597
598
601
604
607
608
611
614
617
618//}
619
621
622#if SA_MATHS_MATRIX3_SIMD && SA_INTRISC_AVX // SIMD int32
623
624//{ Row Major
625
626 template <>
627 template <>
628 RMat3i RMat3i::operator*(int32_t _scale) const noexcept;
629
630#if SA_INTRISC_SVML
631 template <>
632 template <>
633 RMat3i RMat3i::operator/(int32_t _scale) const;
634#endif
635
636 template <>
637 RMat3i RMat3i::operator+(const RMat3i& _rhs) const noexcept;
638
639 template <>
640 RMat3i RMat3i::operator-(const RMat3i& _rhs) const noexcept;
641
642 template <>
643 RMat3i RMat3i::operator*(const RMat3i& _rhs) const noexcept;
644
645
646 template <>
647 Vec3<int32_t> RMat3i::operator*(const Vec3<int32_t>& _rhs) const noexcept;
648
649
650 template <>
651 template <>
652 RMat3i& RMat3i::operator*=(int32_t _scale) noexcept;
653
654#if SA_INTRISC_SVML
655 template <>
656 template <>
657 RMat3i& RMat3i::operator/=(int32_t _scale);
658#endif
659
660 template <>
661 RMat3i& RMat3i::operator+=(const RMat3i& _rhs) noexcept;
662
663 template <>
664 RMat3i& RMat3i::operator-=(const RMat3i& _rhs) noexcept;
665
666//}
667
668//{ Column Major
669
670 template <>
671 template <>
672 CMat3i CMat3i::operator*(int32_t _scale) const noexcept;
673
674#if SA_INTRISC_SVML
675 template <>
676 template <>
677 CMat3i CMat3i::operator/(int32_t _scale) const;
678#endif
679
680 template <>
681 CMat3i CMat3i::operator+(const CMat3i& _rhs) const noexcept;
682
683 template <>
684 CMat3i CMat3i::operator-(const CMat3i& _rhs) const noexcept;
685
686 template <>
687 CMat3i CMat3i::operator*(const CMat3i& _rhs) const noexcept;
688
689
690 template <>
691 Vec3<int32_t> CMat3i::operator*(const Vec3<int32_t>& _rhs) const noexcept;
692
693
694 template <>
695 template <>
696 CMat3i& CMat3i::operator*=(int32_t _scale) noexcept;
697
698#if SA_INTRISC_SVML
699 template <>
700 template <>
701 CMat3i& CMat3i::operator/=(int32_t _scale);
702#endif
703
704 template <>
705 CMat3i& CMat3i::operator+=(const CMat3i& _rhs) noexcept;
706
707 template <>
708 CMat3i& CMat3i::operator-=(const CMat3i& _rhs) noexcept;
709
710//}
711
712#endif
713
714#if SA_MATHS_MATRIX3_SIMD && SA_INTRISC_SSE // SIMD float
715
716//{ Row Major
717
718 template <>
719 float RMat3f::Determinant() const noexcept;
720
721 template <>
722 RMat3f RMat3f::GetInversed() const;
723
724
725 template <>
726 RMat3f RMat3f::MakeRotation(const Quat<float>& _rot) noexcept;
727
728
729 template <>
730 template <>
731 RMat3f RMat3f::operator*(float _scale) const noexcept;
732
733 template <>
734 template <>
735 RMat3f RMat3f::operator/(float _scale) const;
736
737 template <>
738 RMat3f RMat3f::operator+(const RMat3f& _rhs) const noexcept;
739
740 template <>
741 RMat3f RMat3f::operator-(const RMat3f& _rhs) const noexcept;
742
743 template <>
744 RMat3f RMat3f::operator*(const RMat3f& _rhs) const noexcept;
745
746
747 template <>
748 Vec3<float> RMat3f::operator*(const Vec3<float>& _rhs) const noexcept;
749
750
751 template <>
752 template <>
753 RMat3f& RMat3f::operator*=(float _scale) noexcept;
754
755 template <>
756 template <>
757 RMat3f& RMat3f::operator/=(float _scale);
758
759 template <>
760 RMat3f& RMat3f::operator+=(const RMat3f& _rhs) noexcept;
761
762 template <>
763 RMat3f& RMat3f::operator-=(const RMat3f& _rhs) noexcept;
764
765
766 template <>
767 Mat3f operator/(float _lhs, const Mat3f& _rhs);
768
769//}
770
771//{ Column Major
772
773 template <>
774 float CMat3f::Determinant() const noexcept;
775
776 template <>
777 CMat3f CMat3f::GetInversed() const;
778
779
780 template <>
781 CMat3f CMat3f::MakeRotation(const Quat<float>& _rot) noexcept;
782
783
784 template <>
785 template <>
786 CMat3f CMat3f::operator*(float _scale) const noexcept;
787
788 template <>
789 template <>
790 CMat3f CMat3f::operator/(float _scale) const;
791
792 template <>
793 CMat3f CMat3f::operator+(const CMat3f& _rhs) const noexcept;
794
795 template <>
796 CMat3f CMat3f::operator-(const CMat3f& _rhs) const noexcept;
797
798 template <>
799 CMat3f CMat3f::operator*(const CMat3f& _rhs) const noexcept;
800
801
802 template <>
803 Vec3<float> CMat3f::operator*(const Vec3<float>& _rhs) const noexcept;
804
805
806 template <>
807 template <>
808 CMat3f& CMat3f::operator*=(float _scale) noexcept;
809
810 template <>
811 template <>
812 CMat3f& CMat3f::operator/=(float _scale);
813
814 template <>
815 CMat3f& CMat3f::operator+=(const CMat3f& _rhs) noexcept;
816
817 template <>
818 CMat3f& CMat3f::operator-=(const CMat3f& _rhs) noexcept;
819
820
821 template <>
822 CMat3f operator/(float _lhs, const CMat3f& _rhs);
823
824//}
825
826#endif
827
828#if SA_MATHS_MATRIX3_SIMD && SA_INTRISC_AVX // SIMD double
829
830//{ Row Major
831
832 template <>
833 double RMat3d::Determinant() const noexcept;
834
835 template <>
836 RMat3d RMat3d::GetInversed() const;
837
838
839 template <>
840 RMat3d RMat3d::MakeRotation(const Quat<double>& _rot) noexcept;
841
842
843 template <>
844 template <>
845 RMat3d RMat3d::operator*(double _scale) const noexcept;
846
847 template <>
848 template <>
849 RMat3d RMat3d::operator/(double _scale) const;
850
851 template <>
852 RMat3d RMat3d::operator+(const RMat3d& _rhs) const noexcept;
853
854 template <>
855 RMat3d RMat3d::operator-(const RMat3d& _rhs) const noexcept;
856
857 template <>
858 RMat3d RMat3d::operator*(const RMat3d& _rhs) const noexcept;
859
860
861 template <>
862 Vec3<double> RMat3d::operator*(const Vec3<double>& _rhs) const noexcept;
863
864
865 template <>
866 template <>
867 RMat3d& RMat3d::operator*=(double _scale) noexcept;
868
869 template <>
870 template <>
871 RMat3d& RMat3d::operator/=(double _scale);
872
873 template <>
874 RMat3d& RMat3d::operator+=(const RMat3d& _rhs) noexcept;
875
876 template <>
877 RMat3d& RMat3d::operator-=(const RMat3d& _rhs) noexcept;
878
879
880 template <>
881 RMat3d operator/(double _lhs, const RMat3d& _rhs);
882
883//}
884
885//{ Column Major
886
887 template <>
888 double CMat3d::Determinant() const noexcept;
889
890 template <>
891 CMat3d CMat3d::GetInversed() const;
892
893
894 template <>
895 CMat3d CMat3d::MakeRotation(const Quat<double>& _rot) noexcept;
896
897
898 template <>
899 template <>
900 CMat3d CMat3d::operator*(double _scale) const noexcept;
901
902 template <>
903 template <>
904 CMat3d CMat3d::operator/(double _scale) const;
905
906 template <>
907 CMat3d CMat3d::operator+(const CMat3d& _rhs) const noexcept;
908
909 template <>
910 CMat3d CMat3d::operator-(const CMat3d& _rhs) const noexcept;
911
912 template <>
913 CMat3d CMat3d::operator*(const CMat3d& _rhs) const noexcept;
914
915
916 template <>
917 Vec3<double> CMat3d::operator*(const Vec3<double>& _rhs) const noexcept;
918
919
920 template <>
921 template <>
922 CMat3d& CMat3d::operator*=(double _scale) noexcept;
923
924 template <>
925 template <>
926 CMat3d& CMat3d::operator/=(double _scale);
927
928 template <>
929 CMat3d& CMat3d::operator+=(const CMat3d& _rhs) noexcept;
930
931 template <>
932 CMat3d& CMat3d::operator-=(const CMat3d& _rhs) noexcept;
933
934
935 template <>
936 CMat3d operator/(double _lhs, const CMat3d& _rhs);
937
938//}
939
940#endif
941
943}
944
953#include <SA/Maths/Matrix/Matrix3.inl>
954
955#endif // GUARD
Maths specific config file.
Maths module Debug compatibility definition.
Equals method implementation.
Lerp algorithms implementation.
Mat3< T, major > operator*(TIn _lhs, const Mat3< T, major > &_rhs) noexcept
Scale each matrix components by _lhs.
Mat3< T, major > operator/(TIn _lhs, const Mat3< T, major > &_rhs)
Inverse Scale each matrix components by _lhs.
MatrixMajor
Matrix major enum.
Definition MatrixMajor.hpp:24
Matrix 3x3 Sapphire-Maths class.
Definition Matrix3.hpp:69
constexpr Mat3(const Mat4< TIn, majorIn > &_other) noexcept
Value constructor from another Mat4 type.
T Determinant() const noexcept
Compute the determinant of the matrix.
constexpr Mat3(const Mat3< TIn, majorIn > &_other) noexcept
Value constructor from another Mat3 type.
Mat3 operator+(const Mat3 &_rhs) const noexcept
Add term by term matrix values.
constexpr Mat3 operator-() const noexcept
Getter of the opposite signed matrix.
static Mat3 MakeRotation(const Quat< T > &_rot) noexcept
Make rotation matrix from quaternion.
static const Mat3 Zero
Zero Mat3 constant.
Definition Matrix3.hpp:92
Mat3 operator/(TIn _scale) const
Inverse Scale each matrix component by _scale.
constexpr Mat3 GetTransposed() const noexcept
Transpose this matrix.
Mat3 & operator/=(TIn _scale)
Inverse Scale each matrix component by _scale.
static const Mat3 Identity
Identity Mat3 constant.
Definition Matrix3.hpp:101
Mat3 GetInversed() const
Inverse this matrix.
Mat3 & operator+=(const Mat3 &_rhs) noexcept
Add term by term matrix values.
Mat3 & Transpose() noexcept
Transpose this matrix.
Mat3 & operator*=(TIn _scale) noexcept
Scale each matrix component by _scale.
T * Data() noexcept
Getter of matrix data
Mat3 & Inverse()
Inverse this matrix.
Mat3 & operator-=(const Mat3 &_rhs) noexcept
Subtract term by term matrix values.
constexpr bool Equals(const Mat3 &_other, T _epsilon=std::numeric_limits< T >::epsilon()) const noexcept
Compare 2 Matrix.
constexpr bool IsIdentity() const noexcept
Whether this matrix is an identity matrix.
Mat3 operator*(TIn _scale) const noexcept
Scale each matrix component by _scale.
static Mat3 MakeScale(const Vec3< T > &_scale) noexcept
Make scale matrix from vector3.
static Mat3 Lerp(const Mat3 &_start, const Mat3 &_end, float _alpha) noexcept
Clamped Lerp from _start to _end at _alpha.
static Mat3 LerpUnclamped(const Mat3 &_start, const Mat3 &_end, float _alpha) noexcept
Unclamped Lerp from _start to _end at _alpha.
T & At(uint32_t _index)
Getter of Value at index.
constexpr bool IsZero() const noexcept
Whether this matrix is a zero matrix.
Matrix 4x4 Sapphire-Maths class.
Definition Matrix4.hpp:68
Quaternion Sapphire-Maths class.
Definition Quaternion.hpp:53
Vector 3 Sapphire-Maths class.
Definition Vector3.hpp:43