Plasma Engine  2.0
Loading...
Searching...
No Matches
SimdMat4f_inl.h
1#pragma once
2
3PL_ALWAYS_INLINE plSimdMat4f::plSimdMat4f() = default;
4
5inline plSimdMat4f plSimdMat4f::MakeFromValues(float f1r1, float f2r1, float f3r1, float f4r1, float f1r2, float f2r2, float f3r2, float f4r2, float f1r3,
6 float f2r3, float f3r3, float f4r3, float f1r4, float f2r4, float f3r4, float f4r4)
7{
8 plSimdMat4f res;
9 res.m_col0.Set(f1r1, f1r2, f1r3, f1r4);
10 res.m_col1.Set(f2r1, f2r2, f2r3, f2r4);
11 res.m_col2.Set(f3r1, f3r2, f3r3, f3r4);
12 res.m_col3.Set(f4r1, f4r2, f4r3, f4r4);
13 return res;
14}
15
16inline plSimdMat4f plSimdMat4f::MakeFromColumns(const plSimdVec4f& vCol0, const plSimdVec4f& vCol1, const plSimdVec4f& vCol2, const plSimdVec4f& vCol3)
17{
18 plSimdMat4f res;
19 res.m_col0 = vCol0;
20 res.m_col1 = vCol1;
21 res.m_col2 = vCol2;
22 res.m_col3 = vCol3;
23 return res;
24}
25
26inline plSimdMat4f plSimdMat4f::MakeFromRowMajorArray(const float* const pData)
27{
28 plSimdMat4f res;
29 res.m_col0.Load<4>(pData + 0);
30 res.m_col1.Load<4>(pData + 4);
31 res.m_col2.Load<4>(pData + 8);
32 res.m_col3.Load<4>(pData + 12);
33 res.Transpose();
34 return res;
35}
36
37inline plSimdMat4f plSimdMat4f::MakeFromColumnMajorArray(const float* const pData)
38{
39 plSimdMat4f res;
40 res.m_col0.Load<4>(pData + 0);
41 res.m_col1.Load<4>(pData + 4);
42 res.m_col2.Load<4>(pData + 8);
43 res.m_col3.Load<4>(pData + 12);
44 return res;
45}
46
47inline void plSimdMat4f::GetAsArray(float* out_pData, plMatrixLayout::Enum layout) const
48{
49 plSimdMat4f tmp = *this;
50
51 if (layout == plMatrixLayout::RowMajor)
52 {
53 tmp.Transpose();
54 }
55
56 tmp.m_col0.Store<4>(out_pData + 0);
57 tmp.m_col1.Store<4>(out_pData + 4);
58 tmp.m_col2.Store<4>(out_pData + 8);
59 tmp.m_col3.Store<4>(out_pData + 12);
60}
61
63{
64 plSimdMat4f res;
65 res.m_col0.SetZero();
66 res.m_col1.SetZero();
67 res.m_col2.SetZero();
68 res.m_col3.SetZero();
69 return res;
70}
71
73{
74 plSimdMat4f res;
75 res.m_col0.Set(1, 0, 0, 0);
76 res.m_col1.Set(0, 1, 0, 0);
77 res.m_col2.Set(0, 0, 1, 0);
78 res.m_col3.Set(0, 0, 0, 1);
79 return res;
80}
81
82PL_ALWAYS_INLINE plSimdMat4f plSimdMat4f::GetTranspose() const
83{
84 plSimdMat4f result = *this;
85 result.Transpose();
86 return result;
87}
88
89PL_ALWAYS_INLINE plSimdMat4f plSimdMat4f::GetInverse(const plSimdFloat& fEpsilon) const
90{
91 plSimdMat4f result = *this;
92 result.Invert(fEpsilon).IgnoreResult();
93 return result;
94}
95
96inline bool plSimdMat4f::IsEqual(const plSimdMat4f& rhs, const plSimdFloat& fEpsilon) const
97{
98 return (m_col0.IsEqual(rhs.m_col0, fEpsilon) && m_col1.IsEqual(rhs.m_col1, fEpsilon) && m_col2.IsEqual(rhs.m_col2, fEpsilon) &&
99 m_col3.IsEqual(rhs.m_col3, fEpsilon))
100 .AllSet<4>();
101}
102
103inline bool plSimdMat4f::IsIdentity(const plSimdFloat& fEpsilon) const
104{
105 return (m_col0.IsEqual(plSimdVec4f(1, 0, 0, 0), fEpsilon) && m_col1.IsEqual(plSimdVec4f(0, 1, 0, 0), fEpsilon) &&
106 m_col2.IsEqual(plSimdVec4f(0, 0, 1, 0), fEpsilon) && m_col3.IsEqual(plSimdVec4f(0, 0, 0, 1), fEpsilon))
107 .AllSet<4>();
108}
109
110inline bool plSimdMat4f::IsValid() const
111{
112 return m_col0.IsValid<4>() && m_col1.IsValid<4>() && m_col2.IsValid<4>() && m_col3.IsValid<4>();
113}
114
115inline bool plSimdMat4f::IsNaN() const
116{
117 return m_col0.IsNaN<4>() || m_col1.IsNaN<4>() || m_col2.IsNaN<4>() || m_col3.IsNaN<4>();
118}
119
120PL_ALWAYS_INLINE void plSimdMat4f::SetRows(const plSimdVec4f& vRow0, const plSimdVec4f& vRow1, const plSimdVec4f& vRow2, const plSimdVec4f& vRow3)
121{
122 m_col0 = vRow0;
123 m_col1 = vRow1;
124 m_col2 = vRow2;
125 m_col3 = vRow3;
126
127 Transpose();
128}
129
130PL_ALWAYS_INLINE void plSimdMat4f::GetRows(plSimdVec4f& ref_vRow0, plSimdVec4f& ref_vRow1, plSimdVec4f& ref_vRow2, plSimdVec4f& ref_vRow3) const
131{
132 plSimdMat4f tmp = *this;
133 tmp.Transpose();
134
135 ref_vRow0 = tmp.m_col0;
136 ref_vRow1 = tmp.m_col1;
137 ref_vRow2 = tmp.m_col2;
138 ref_vRow3 = tmp.m_col3;
139}
140
142{
143 plSimdVec4f result;
144 result = m_col0 * v.x();
145 result += m_col1 * v.y();
146 result += m_col2 * v.z();
147 result += m_col3;
148
149 return result;
150}
151
153{
154 plSimdVec4f result;
155 result = m_col0 * v.x();
156 result += m_col1 * v.y();
157 result += m_col2 * v.z();
158
159 return result;
160}
161
162PL_ALWAYS_INLINE plSimdMat4f plSimdMat4f::operator*(const plSimdMat4f& rhs) const
163{
164 plSimdMat4f result;
165
166 result.m_col0 = m_col0 * rhs.m_col0.x();
167 result.m_col0 += m_col1 * rhs.m_col0.y();
168 result.m_col0 += m_col2 * rhs.m_col0.z();
169 result.m_col0 += m_col3 * rhs.m_col0.w();
170
171 result.m_col1 = m_col0 * rhs.m_col1.x();
172 result.m_col1 += m_col1 * rhs.m_col1.y();
173 result.m_col1 += m_col2 * rhs.m_col1.z();
174 result.m_col1 += m_col3 * rhs.m_col1.w();
175
176 result.m_col2 = m_col0 * rhs.m_col2.x();
177 result.m_col2 += m_col1 * rhs.m_col2.y();
178 result.m_col2 += m_col2 * rhs.m_col2.z();
179 result.m_col2 += m_col3 * rhs.m_col2.w();
180
181 result.m_col3 = m_col0 * rhs.m_col3.x();
182 result.m_col3 += m_col1 * rhs.m_col3.y();
183 result.m_col3 += m_col2 * rhs.m_col3.z();
184 result.m_col3 += m_col3 * rhs.m_col3.w();
185
186 return result;
187}
188
189PL_ALWAYS_INLINE void plSimdMat4f::operator*=(const plSimdMat4f& rhs)
190{
191 *this = *this * rhs;
192}
193
194PL_ALWAYS_INLINE bool plSimdMat4f::operator==(const plSimdMat4f& other) const
195{
196 return (m_col0 == other.m_col0 && m_col1 == other.m_col1 && m_col2 == other.m_col2 && m_col3 == other.m_col3).AllSet<4>();
197}
198
199PL_ALWAYS_INLINE bool plSimdMat4f::operator!=(const plSimdMat4f& other) const
200{
201 return !(*this == other);
202}
Definition SimdFloat.h:7
A 4x4 matrix class.
Definition SimdMat4f.h:7
static plSimdMat4f MakeFromRowMajorArray(const float *const pData)
Creates a matrix from 16 values that are in row-major layout.
Definition SimdMat4f_inl.h:26
plSimdMat4f GetInverse(const plSimdFloat &fEpsilon=plMath::SmallEpsilon< float >()) const
Returns the inverse of this matrix.
Definition SimdMat4f_inl.h:89
static plSimdMat4f MakeFromColumns(const plSimdVec4f &vCol0, const plSimdVec4f &vCol1, const plSimdVec4f &vCol2, const plSimdVec4f &vCol3)
Creates a matrix from 4 column vectors.
Definition SimdMat4f_inl.h:16
bool IsValid() const
Checks whether all components are finite numbers.
Definition SimdMat4f_inl.h:110
bool IsNaN() const
Checks whether any component is NaN.
Definition SimdMat4f_inl.h:115
plResult Invert(const plSimdFloat &fEpsilon=plMath::SmallEpsilon< float >())
Inverts this matrix. Return value indicates whether the matrix could be inverted.
Definition SimdMat4f.cpp:8
static plSimdMat4f MakeFromColumnMajorArray(const float *const pData)
Creates a matrix from 16 values that are in column-major layout.
Definition SimdMat4f_inl.h:37
static plSimdMat4f MakeFromValues(float f1r1, float f2r1, float f3r1, float f4r1, float f1r2, float f2r2, float f3r2, float f4r2, float f1r3, float f2r3, float f3r3, float f4r3, float f1r4, float f2r4, float f3r4, float f4r4)
Creates a matrix from 16 values. Naming is "column-n row-m".
Definition SimdMat4f_inl.h:5
plSimdMat4f GetTranspose() const
Returns the transpose of this matrix.
Definition SimdMat4f_inl.h:82
void Transpose()
Transposes this matrix.
Definition FPUMat4f_inl.h:3
plSimdVec4f TransformPosition(const plSimdVec4f &v) const
Matrix-vector multiplication, assuming the 4th component of the vector is one (default behavior).
Definition SimdMat4f_inl.h:141
bool IsIdentity(const plSimdFloat &fEpsilon=plMath::DefaultEpsilon< float >()) const
Checks whether this is an identity matrix.
Definition SimdMat4f_inl.h:103
plSimdVec4f TransformDirection(const plSimdVec4f &v) const
Matrix-vector multiplication, assuming the 4th component of the vector is zero. So,...
Definition SimdMat4f_inl.h:152
static plSimdMat4f MakeZero()
Returns a zero matrix.
Definition SimdMat4f_inl.h:62
static plSimdMat4f MakeIdentity()
Returns an identity matrix.
Definition SimdMat4f_inl.h:72
bool IsEqual(const plSimdMat4f &rhs, const plSimdFloat &fEpsilon) const
Equality Check with epsilon.
Definition SimdMat4f_inl.h:96
A 4-component SIMD vector class.
Definition SimdVec4f.h:8
Enum
Definition Declarations.h:65
@ RowMajor
The matrix is stored in row-major format.
Definition Declarations.h:66
PL_ALWAYS_INLINE void IgnoreResult()
Used to silence compiler warnings, when success or failure doesn't matter.
Definition Types.h:69