13template <u
int Rows, u
int Cols>
28 for (
uint c = 0; c < Cols; ++c)
37 for (
uint c = 0; c < Cols; ++c)
38 if (!mCol[c].IsZero())
51 for (
uint rc = 0, min_rc = min(Rows, Cols); rc < min_rc; ++rc)
52 mCol[rc].mF32[rc] = 1.0f;
67 for (
uint rc = 0, min_rc = min(Rows, Cols); rc < min_rc; ++rc)
68 mCol[rc].mF32[rc] = inV[rc];
79 template <
class OtherMatrix>
82 for (
uint c = 0; c < inNumCols; ++c)
83 for (
uint r = 0; r < inNumRows; ++r)
84 mCol[inDestCol + c].mF32[inDestRow + r] = inM(inSourceRow + r, inSourceCol + c);
88 inline float operator () (
uint inRow,
uint inColumn)
const
92 return mCol[inColumn].mF32[inRow];
95 inline float & operator () (
uint inRow,
uint inColumn)
99 return mCol[inColumn].mF32[inRow];
103 inline bool operator == (
const Matrix &inM2)
const
105 for (
uint c = 0; c < Cols; ++c)
106 if (mCol[c] != inM2.
mCol[c])
111 inline bool operator != (
const Matrix &inM2)
const
113 for (
uint c = 0; c < Cols; ++c)
114 if (mCol[c] != inM2.
mCol[c])
122 for (
uint c = 0; c < Cols; ++c)
123 mCol[c] = inM2.
mCol[c];
128 template <u
int OtherCols>
132 for (
uint c = 0; c < OtherCols; ++c)
133 for (
uint r = 0; r < Rows; ++r)
136 for (
uint i = 0; i < Cols; ++i)
137 dot += mCol[i].mF32[r] * inM.
mCol[c].mF32[i];
138 m.
mCol[c].mF32[r] = dot;
147 for (
uint r = 0; r < Rows; ++r)
150 for (
uint c = 0; c < Cols; ++c)
151 dot += mCol[c].mF32[r] * inV.
mF32[c];
161 for (
uint c = 0; c < Cols; ++c)
162 m.
mCol[c] = mCol[c] * inV;
175 for (
uint c = 0; c < Cols; ++c)
184 for (
uint c = 0; c < Cols; ++c)
193 for (
uint r = 0; r < Rows; ++r)
194 for (
uint c = 0; c < Cols; ++c)
195 m.
mCol[r].mF32[c] = mCol[c].mF32[r];
202 if constexpr (Rows != Cols)
JPH_ASSERT(
false);
216 friend ostream & operator << (ostream &inStream,
const Matrix &inM)
218 for (
uint i = 0; i < Cols - 1; ++i)
219 inStream << inM.
mCol[i] <<
", ";
220 inStream << inM.
mCol[Cols - 1];
232#ifndef JPH_PLATFORM_DOXYGEN
239 float a = inM.
mCol[0].mF32[0];
240 float b = inM.
mCol[1].mF32[0];
241 float c = inM.
mCol[0].mF32[1];
242 float d = inM.
mCol[1].mF32[1];
245 float det = a * d - b * c;
250 mCol[0].mF32[0] = d / det;
251 mCol[1].mF32[0] = -b / det;
252 mCol[0].mF32[1] = -c / det;
253 mCol[1].mF32[1] = a / det;
unsigned int uint
Definition: Core.h:452
#define JPH_NAMESPACE_END
Definition: Core.h:378
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
DVec3 operator*(double inV1, DVec3Arg inV2)
Definition: DVec3.inl:451
JPH_NAMESPACE_BEGIN bool GaussianElimination(MatrixA &ioA, MatrixB &ioB, float inTolerance=1.0e-16f)
Definition: GaussianElimination.h:19
#define JPH_ASSERT(...)
Definition: IssueReporting.h:33
Templatized matrix class.
Definition: Matrix.h:15
static Matrix sZero()
Definition: Matrix.h:32
bool SetInversed(const Matrix &inM)
Inverse matrix.
Definition: Matrix.h:200
uint GetRows() const
Dimensions.
Definition: Matrix.h:22
bool IsIdentity() const
Check if this matrix is identity.
Definition: Matrix.h:58
uint GetCols() const
Definition: Matrix.h:23
Vector< Rows > mCol[Cols]
Column.
Definition: Matrix.h:228
void CopyPart(const OtherMatrix &inM, uint inSourceRow, uint inSourceCol, uint inNumRows, uint inNumCols, uint inDestRow, uint inDestCol)
Copy a (part) of another matrix into this matrix.
Definition: Matrix.h:80
Matrix()=default
Constructor.
void SetZero()
Zero matrix.
Definition: Matrix.h:26
static Matrix sIdentity()
Definition: Matrix.h:55
Vector< Rows > & GetColumn(int inIdx)
Definition: Matrix.h:226
bool IsZero() const
Check if this matrix consists of all zeros.
Definition: Matrix.h:35
Matrix(const Matrix &inM2)
Definition: Matrix.h:19
const Vector< Rows > & GetColumn(int inIdx) const
Column access.
Definition: Matrix.h:225
void SetIdentity()
Identity matrix.
Definition: Matrix.h:45
void SetDiagonal(const Vector< Rows< Cols? Rows :Cols > &inV)
Diagonal matrix.
Definition: Matrix.h:61
static Matrix sDiagonal(const Vector< Rows< Cols? Rows :Cols > &inV)
Definition: Matrix.h:71
Matrix Inversed() const
Definition: Matrix.h:208
Matrix< Cols, Rows > Transposed() const
Transpose matrix.
Definition: Matrix.h:190
Templatized vector class.
Definition: Vector.h:12
float mF32[Rows]
Definition: Vector.h:208