139 template <
class IDX_TYP>
143 return det3(this->v[1][
col1], this->v[1][
col2], this->v[1][
col3],
181 this->v[0] = this->v[1] = this->v[2] = this->v[3] =
Tvec4<DT>(0);
188 this->v[0][0] = this->v[1][1] = this->v[2][2] = this->v[3][3] =
diagValue;
189 this->v[1][0] = this->v[2][0] = this->v[3][0] = this->v[2][1] = this->v[3][1] = this->v[3][2] = 0;
190 this->v[0][1] = this->v[0][2] = this->v[0][3] = this->v[1][2] = this->v[1][3] = this->v[2][3] = 0;
207 this->v[0] =
mat.
v[0];
208 this->v[1] =
mat.v[1];
209 this->v[2] =
mat.v[2];
210 this->v[3] =
mat.v[3];
243 matrix[0][3] = matrix[1][3] = matrix[2][3] = 0;
248 for (
i = 0;
i < 3;
i++)
250 for (
j = 0;
j < 3;
j++)
255 for (
j = 0;
j < 3;
j++)
267 this->v[0] = this->v[1] = this->v[2] = this->v[3] =
Tvec4<DT>(val);
287 this->v[0] +=
m.
v[0];
288 this->v[1] +=
m.v[1];
289 this->v[2] +=
m.v[2];
290 this->v[3] +=
m.v[3];
298 this->v[0] -=
m.
v[0];
299 this->v[1] -=
m.v[1];
300 this->v[2] -=
m.v[2];
301 this->v[3] -=
m.v[3];
332 this->v[1].apply(
fct);
333 this->v[2].apply(
fct);
334 this->v[3].apply(
fct);
344#define _ML_MAT4_RC(i, j) a[i][0]*b[0][j] + a[i][1]*b[1][j] + \
345a[i][2]*b[2][j] + a[i][3]*b[3][j]
368 return ((a[0] == b[0]) &&
391 return Tmat4<DT>(a) *=
static_cast<DT
>(-1.0);
476 this->v[0][0]=
static_cast<DT
>(
in00); this->v[0][1]=
static_cast<DT
>(
in01); this->v[0][2]=
static_cast<DT
>(
in02); this->v[0][3]=
static_cast<DT
>(
in03);
477 this->v[1][0]=
static_cast<DT
>(
in10); this->v[1][1]=
static_cast<DT
>(
in11); this->v[1][2]=
static_cast<DT
>(
in12); this->v[1][3]=
static_cast<DT
>(
in13);
478 this->v[2][0]=
static_cast<DT
>(
in20); this->v[2][1]=
static_cast<DT
>(
in21); this->v[2][2]=
static_cast<DT
>(
in22); this->v[2][3]=
static_cast<DT
>(
in23);
479 this->v[3][0]=
static_cast<DT
>(
in30); this->v[3][1]=
static_cast<DT
>(
in31); this->v[3][2]=
static_cast<DT
>(
in32); this->v[3][3]=
static_cast<DT
>(
in33);
488 this->v[0][0] =
mat[ 0]; this->v[0][1] =
mat[ 1]; this->v[0][2] =
mat[ 2]; this->v[0][3] =
mat[ 3];
489 this->v[1][0] =
mat[ 4]; this->v[1][1] =
mat[ 5]; this->v[1][2] =
mat[ 6]; this->v[1][3] =
mat[ 7];
490 this->v[2][0] =
mat[ 8]; this->v[2][1] =
mat[ 9]; this->v[2][2] =
mat[10]; this->v[2][3] =
mat[11];
491 this->v[3][0] =
mat[12]; this->v[3][1] =
mat[13]; this->v[3][2] =
mat[14]; this->v[3][3] =
mat[15];
502 mat[ 0] =
static_cast<float>(this->v[0][0]);
mat[ 1] =
static_cast<float>(this->v[0][1]);
mat[ 2] =
static_cast<float>(this->v[0][2]);
mat[ 3] =
static_cast<float>(this->v[0][3]);
503 mat[ 4] =
static_cast<float>(this->v[1][0]);
mat[ 5] =
static_cast<float>(this->v[1][1]);
mat[ 6] =
static_cast<float>(this->v[1][2]);
mat[ 7] =
static_cast<float>(this->v[1][3]);
504 mat[ 8] =
static_cast<float>(this->v[2][0]);
mat[ 9] =
static_cast<float>(this->v[2][1]);
mat[10] =
static_cast<float>(this->v[2][2]);
mat[11] =
static_cast<float>(this->v[2][3]);
505 mat[12] =
static_cast<float>(this->v[3][0]);
mat[13] =
static_cast<float>(this->v[3][1]);
mat[14] =
static_cast<float>(this->v[3][2]);
mat[15] =
static_cast<float>(this->v[3][3]);
514 this->v[0][0] =
static_cast<DT
>(
mat[ 0]); this->v[0][1] =
static_cast<DT
>(
mat[ 1]); this->v[0][2] =
static_cast<DT
>(
mat[ 2]); this->v[0][3] =
static_cast<DT
>(
mat[ 3]);
515 this->v[1][0] =
static_cast<DT
>(
mat[ 4]); this->v[1][1] =
static_cast<DT
>(
mat[ 5]); this->v[1][2] =
static_cast<DT
>(
mat[ 6]); this->v[1][3] =
static_cast<DT
>(
mat[ 7]);
516 this->v[2][0] =
static_cast<DT
>(
mat[ 8]); this->v[2][1] =
static_cast<DT
>(
mat[ 9]); this->v[2][2] =
static_cast<DT
>(
mat[10]); this->v[2][3] =
static_cast<DT
>(
mat[11]);
517 this->v[3][0] =
static_cast<DT
>(
mat[12]); this->v[3][1] =
static_cast<DT
>(
mat[13]); this->v[3][2] =
static_cast<DT
>(
mat[14]); this->v[3][3] =
static_cast<DT
>(
mat[15]);
528 mat[ 0] =
static_cast<double>(this->v[0][0]);
mat[ 1] =
static_cast<double>(this->v[0][1]);
mat[ 2] =
static_cast<double>(this->v[0][2]);
mat[ 3] =
static_cast<double>(this->v[0][3]);
529 mat[ 4] =
static_cast<double>(this->v[1][0]);
mat[ 5] =
static_cast<double>(this->v[1][1]);
mat[ 6] =
static_cast<double>(this->v[1][2]);
mat[ 7] =
static_cast<double>(this->v[1][3]);
530 mat[ 8] =
static_cast<double>(this->v[2][0]);
mat[ 9] =
static_cast<double>(this->v[2][1]);
mat[10] =
static_cast<double>(this->v[2][2]);
mat[11] =
static_cast<double>(this->v[2][3]);
531 mat[12] =
static_cast<double>(this->v[3][0]);
mat[13] =
static_cast<double>(this->v[3][1]);
mat[14] =
static_cast<double>(this->v[3][2]);
mat[15] =
static_cast<double>(this->v[3][3]);
540 this->v[0][0] = scale; this->v[0][1] = 0; this->v[0][2] = 0; this->v[0][3] = 0;
541 this->v[1][0] = 0; this->v[1][1] = scale; this->v[1][2] = 0; this->v[1][3] = 0;
542 this->v[2][0] = 0; this->v[2][1] = 0; this->v[2][2] = scale; this->v[2][3] = 0;
543 this->v[3][0] = 0; this->v[3][1] = 0; this->v[3][2] = 0; this->v[3][3] = scale;
550inline DT
Tmat4<DT>::det3(
const DT
A,
const DT
B,
const DT
C,
const DT
D,
const DT
E,
const DT
F,
const DT
G,
const DT
H,
const DT
I)
const
562 return ( this->v[0][0] * determinantLower3(1u, 2u, 3u)
563 - this->v[0][1] * determinantLower3(0u, 2u, 3u)
564 + this->v[0][2] * determinantLower3(0u, 1u, 3u)
565 - this->v[0][3] * determinantLower3(0u, 1u, 2u));
574 return Tmat4<DT>(this->v[0][0], this->v[1][0], this->v[2][0], this->v[3][0],
575 this->v[0][1], this->v[1][1], this->v[2][1], this->v[3][1],
576 this->v[0][2], this->v[1][2], this->v[2][2], this->v[3][2],
577 this->v[0][3], this->v[1][3], this->v[2][3], this->v[3][3]);
626 const DT t = 1.0 - c;
689 static const DT
Epsilon =
static_cast<DT
>(10e-14);
695 "Tmat4<DT> Tmat4<DT>::inverse(bool* isInvertible) const, matrix not invertable",
726 inline std::ostream &
operator<<(std::ostream &
os,
const ML_LA_NAMESPACE::Tmat4<DT> &
m)
728 return os <<
m[0] <<
'\n' <<
m[1] <<
'\n' <<
m[2] <<
'\n' <<
m[3];
733 inline std::istream &
operator>>(std::istream &is, ML_LA_NAMESPACE::Tmat4<DT> &
m)
735 ML_LA_NAMESPACE::Tmat4<DT>
m_tmp;
A class to administrate an axis coordinate system drawable in OpenGL.
Base class of all matrix classes which holds the data buffer and provides some general access methods...
VectorT v[size]
The rows constituting the matrix.
A four by four matrix class consisting of 4 row vectors.
Tmat4(const double mat[16])
Constructor from 16 double values in an array given by mat, row by row.
DT determinantLower3(const IDX_TYP col1, const IDX_TYP col2, const IDX_TYP col3) const
Tvec3< DT > transformPoint(const Tvec3< DT > &sourceVec) const
Transforms the given sourceVec and returns the result vector.
void set(const DT val)
Sets all values to double val.
Tmat4< DT > inverse(bool *isInvertible=nullptr) const
Returns the inverse Gauss-Jordan elimination with partial pivoting.
Tmat4(const Tvec3< DT > &n0, const Tvec3< DT > &n1, const Tvec3< DT > &n3, const Tvec3< DT > &t)
Constructs a matrix from three base vectors and translation (as COLUMN vectors)
Tmat4(const Tvec4< DT > &row0, const Tvec4< DT > &row1, const Tvec4< DT > &row2, const Tvec4< DT > &row3)
Composes a matrix from the four vectors row0, row1, row2 and row3.
void getValues(float mat[16]) const
Copies the contents of *this into floating point matrix mat, row by row.
Tmat4(const float mat[16])
Constructor from 16 floating point values in an array given by mat, row by row.
const Tmat4< DT > & operator/=(const DT d)
Divides by an MLdouble constant d. Division by zero is not handled and must be avoided by caller.
static Tmat4< DT > getIdentity()
Returns the identity matrix.
DT det() const
Returns the determinant of *this.
bool operator<(const Tmat4< DT > &) const
Dummy "lesser than operator" which always returns false.
DT det3(DT A, DT B, DT C, DT D, DT E, DT F, DT G, DT H, DT I) const
Determines the determinant of a 3x3 matrix given by A,B,C,D,E,F,G,H,I.
void setValues(const double mat[16])
Copies the contents of mat into *this, row by row.
Tmat4< DT > transpose() const
Returns the transposed *this.
Tmat4(const double in00, const double in01, const double in02, const double in03, const double in10, const double in11, const double in12, const double in13, const double in20, const double in21, const double in22, const double in23, const double in30, const double in31, const double in32, const double in33)
Initializes all matrix elements explicitly with scalars, row by row.
static Tmat4< DT > getMat(const double val)
Returns a matrix filled with values val.
const Tmat4< DT > & operator=(const Tmat4< DT > &m)
Assigns from a Tmat4.
Tmat4(const Tmat4< DT > &mat)
Copy constructor from the Tmat4 mat.
Tmat4< DT > getRotationMatrix() const
Returns the rotational part of the matrix (removes scaling and translation).
void setScaleMatrix(const DT scale)
Sets a diagonal matrix with scale on diagonal.
const Tmat4< DT > & operator+=(const Tmat4< DT > &m)
Increments by a Tmat4.
void setValues(const float mat[16])
Copies the contents of mat into *this, row by row.
const Tmat4< DT > & operator*=(const DT d)
Multiplies by an MLdouble constant d.
Tmat4(const DT diagValue)
const Tmat4< DT > & apply(MLDblFuncPtr fct)
Applies the function fct to all vectors of *this and return the matrix.
void getValues(double mat[16]) const
Copies the contents of *this into mat, row by row.
const Tmat4< DT > & operator-=(const Tmat4< DT > &m)
Decrements by a Tmat4.
DT ComponentType
A typedef to "export" the type of components.
Tmat4()
Constructs a matrix from 16 zero elements.
Forward declarations to resolve header file dependencies.
Forward declarations to resolve header file dependencies.
#define ML_CHECK_FLOAT_THROW(x)
#define _ML_MAT4_RC(i, j)
Helper macro only locally defined for Tmat4 matrix multiplication.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
double(* MLDblFuncPtr)(double)
A function pointer type to a function which returns a double and takes a double as argument.
FloatingPointVector< T, size, DataContainer > operator/(FloatingPointVector< T, size, DataContainer > lhs, MLdouble rhs)
Component wise division of lhs by specialized rhs of type MLdouble.
Tmat4< DT > scaling3D(const Tvec3< DT > &scaleVector)
Scaling 3D.
Tmat4< DT > perspective3D(const DT d)
Creates a 4x4 homogeneous perspective projection matrix with perspective shortening value given by d ...
bool operator==(const Tmat2< DT > &a, const Tmat2< DT > &b)
a == b ? Return true if yes.
T operator*(const FloatingPointVector< T, size, DataContainer > &a, const FloatingPointVector< T, size, DataContainer > &b)
Dot product, returns a.dot(b).
bool operator!=(const Tmat2< DT > &a, const Tmat2< DT > &b)
a != b ? Return true if yes.
Tmat4< DT > identity3D()
Returns a 4x4 homogeneous identity3D matrix; synonym for Tmat4<DT>::getIdentity().
Tmat4< DT > translation3D(const Tvec3< DT > &v)
Returns a 4x4 homogeneous translation matrix with default identity matrix contents and the upper thre...
FloatingPointVector< T, size, DataContainer > operator-(FloatingPointVector< T, size, DataContainer > lhs, const FloatingPointVector< T, size, DataContainer > &rhs)
Return value is the component wise subtraction of rhs from lhs.
BASE_TYPE MLInverseMatHelper(const BASE_TYPE &origMat, bool *isInvertible, const typename BASE_TYPE::ComponentType, const char *const ZeroDetErrString, const BASE_TYPE &Identity, const size_t Dim)
Computes an N dimensional inverse from given default parameters.
Tmat4< DT > rotation3D(Tvec3< DT > Axis, const DT angleRad)
Returns a 4x4 homogeneous 3D rotation matrix describing a rotation with angle angleRad around axis Ax...
MLEXPORT std::ostream & operator<<(std::ostream &s, const ml::Field &v)
Overloads the operator "<<" for stream output of Field objects.
istream & operator>>(istream &is, ml::FloatingPointVector< T, size, DataContainer > &v)
Reads a vector from std::istream.