143 return det3(this->v[1][
col1], this->v[1][
col2], this->v[1][
col3], this->v[2][
col1], this->v[2][
col2],
179 this->v[0] = this->v[1] = this->v[2] = this->v[3] =
Tvec4<DT>(0);
185 this->v[0][0] = this->v[1][1] = this->v[2][2] = this->v[3][3] =
diagValue;
186 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;
187 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;
203 this->v[0] =
mat.
v[0];
204 this->v[1] =
mat.v[1];
205 this->v[2] =
mat.v[2];
206 this->v[3] =
mat.v[3];
224 return Tmat4<DT>(val, val, val, val, val, val, val, val, val, val, val, val, val, val, val, val);
232 matrix[0][3] = matrix[1][3] = matrix[2][3] = 0;
237 for (
i = 0;
i < 3;
i++) {
238 for (
j = 0;
j < 3;
j++) {
242 for (
j = 0;
j < 3;
j++) {
252 this->v[0] = this->v[1] = this->v[2] = this->v[3] =
Tvec4<DT>(val);
270 this->v[0] +=
m.
v[0];
271 this->v[1] +=
m.v[1];
272 this->v[2] +=
m.v[2];
273 this->v[3] +=
m.v[3];
280 this->v[0] -=
m.
v[0];
281 this->v[1] -=
m.v[1];
282 this->v[2] -=
m.v[2];
283 this->v[3] -=
m.v[3];
311 this->v[1].apply(
fct);
312 this->v[2].apply(
fct);
313 this->v[3].apply(
fct);
323#define _ML_MAT4_RC(i, j) a[i][0] * b[0][j] + a[i][1] * b[1][j] + a[i][2] * b[2][j] + a[i][3] * b[3][j]
342 return ((a[0] == b[0]) && (a[1] == b[1]) && (a[2] == b[2]) && (a[3] == b[3]));
360 return Tmat4<DT>(a) *=
static_cast<DT
>(-1.0);
409 this->v[0][0] =
n0[0];
410 this->v[1][0] =
n0[1];
411 this->v[2][0] =
n0[2];
413 this->v[0][1] =
n1[0];
414 this->v[1][1] =
n1[1];
415 this->v[2][1] =
n1[2];
417 this->v[0][2] =
n2[0];
418 this->v[1][2] =
n2[1];
419 this->v[2][2] =
n2[2];
421 this->v[0][3] = t[0];
422 this->v[1][3] = t[1];
423 this->v[2][3] = t[2];
439 this->v[0][0] =
static_cast<DT
>(
in00);
440 this->v[0][1] =
static_cast<DT
>(
in01);
441 this->v[0][2] =
static_cast<DT
>(
in02);
442 this->v[0][3] =
static_cast<DT
>(
in03);
443 this->v[1][0] =
static_cast<DT
>(
in10);
444 this->v[1][1] =
static_cast<DT
>(
in11);
445 this->v[1][2] =
static_cast<DT
>(
in12);
446 this->v[1][3] =
static_cast<DT
>(
in13);
447 this->v[2][0] =
static_cast<DT
>(
in20);
448 this->v[2][1] =
static_cast<DT
>(
in21);
449 this->v[2][2] =
static_cast<DT
>(
in22);
450 this->v[2][3] =
static_cast<DT
>(
in23);
451 this->v[3][0] =
static_cast<DT
>(
in30);
452 this->v[3][1] =
static_cast<DT
>(
in31);
453 this->v[3][2] =
static_cast<DT
>(
in32);
454 this->v[3][3] =
static_cast<DT
>(
in33);
462 this->v[0][0] =
mat[0];
463 this->v[0][1] =
mat[1];
464 this->v[0][2] =
mat[2];
465 this->v[0][3] =
mat[3];
466 this->v[1][0] =
mat[4];
467 this->v[1][1] =
mat[5];
468 this->v[1][2] =
mat[6];
469 this->v[1][3] =
mat[7];
470 this->v[2][0] =
mat[8];
471 this->v[2][1] =
mat[9];
472 this->v[2][2] =
mat[10];
473 this->v[2][3] =
mat[11];
474 this->v[3][0] =
mat[12];
475 this->v[3][1] =
mat[13];
476 this->v[3][2] =
mat[14];
477 this->v[3][3] =
mat[15];
487 mat[0] =
static_cast<float>(this->v[0][0]);
488 mat[1] =
static_cast<float>(this->v[0][1]);
489 mat[2] =
static_cast<float>(this->v[0][2]);
490 mat[3] =
static_cast<float>(this->v[0][3]);
491 mat[4] =
static_cast<float>(this->v[1][0]);
492 mat[5] =
static_cast<float>(this->v[1][1]);
493 mat[6] =
static_cast<float>(this->v[1][2]);
494 mat[7] =
static_cast<float>(this->v[1][3]);
495 mat[8] =
static_cast<float>(this->v[2][0]);
496 mat[9] =
static_cast<float>(this->v[2][1]);
497 mat[10] =
static_cast<float>(this->v[2][2]);
498 mat[11] =
static_cast<float>(this->v[2][3]);
499 mat[12] =
static_cast<float>(this->v[3][0]);
500 mat[13] =
static_cast<float>(this->v[3][1]);
501 mat[14] =
static_cast<float>(this->v[3][2]);
502 mat[15] =
static_cast<float>(this->v[3][3]);
510 this->v[0][0] =
static_cast<DT
>(
mat[0]);
511 this->v[0][1] =
static_cast<DT
>(
mat[1]);
512 this->v[0][2] =
static_cast<DT
>(
mat[2]);
513 this->v[0][3] =
static_cast<DT
>(
mat[3]);
514 this->v[1][0] =
static_cast<DT
>(
mat[4]);
515 this->v[1][1] =
static_cast<DT
>(
mat[5]);
516 this->v[1][2] =
static_cast<DT
>(
mat[6]);
517 this->v[1][3] =
static_cast<DT
>(
mat[7]);
518 this->v[2][0] =
static_cast<DT
>(
mat[8]);
519 this->v[2][1] =
static_cast<DT
>(
mat[9]);
520 this->v[2][2] =
static_cast<DT
>(
mat[10]);
521 this->v[2][3] =
static_cast<DT
>(
mat[11]);
522 this->v[3][0] =
static_cast<DT
>(
mat[12]);
523 this->v[3][1] =
static_cast<DT
>(
mat[13]);
524 this->v[3][2] =
static_cast<DT
>(
mat[14]);
525 this->v[3][3] =
static_cast<DT
>(
mat[15]);
535 mat[0] =
static_cast<double>(this->v[0][0]);
536 mat[1] =
static_cast<double>(this->v[0][1]);
537 mat[2] =
static_cast<double>(this->v[0][2]);
538 mat[3] =
static_cast<double>(this->v[0][3]);
539 mat[4] =
static_cast<double>(this->v[1][0]);
540 mat[5] =
static_cast<double>(this->v[1][1]);
541 mat[6] =
static_cast<double>(this->v[1][2]);
542 mat[7] =
static_cast<double>(this->v[1][3]);
543 mat[8] =
static_cast<double>(this->v[2][0]);
544 mat[9] =
static_cast<double>(this->v[2][1]);
545 mat[10] =
static_cast<double>(this->v[2][2]);
546 mat[11] =
static_cast<double>(this->v[2][3]);
547 mat[12] =
static_cast<double>(this->v[3][0]);
548 mat[13] =
static_cast<double>(this->v[3][1]);
549 mat[14] =
static_cast<double>(this->v[3][2]);
550 mat[15] =
static_cast<double>(this->v[3][3]);
558 this->v[0][0] = scale;
563 this->v[1][1] = scale;
568 this->v[2][2] = scale;
573 this->v[3][3] = scale;
579template <
class DT>
inline DT
Tmat4<DT>::det3(
const DT
A,
const DT
B,
const DT
C,
const DT
D,
const DT
E,
const DT
F,
580 const DT
G,
const DT
H,
const DT
I)
const
591 return (this->v[0][0] * determinantLower3(1u, 2u, 3u) - this->v[0][1] * determinantLower3(0u, 2u, 3u) +
592 this->v[0][2] * determinantLower3(0u, 1u, 3u) - this->v[0][3] * determinantLower3(0u, 1u, 2u));
600 return Tmat4<DT>(this->v[0][0], this->v[1][0], this->v[2][0], this->v[3][0], this->v[0][1], this->v[1][1],
601 this->v[2][1], this->v[3][1], this->v[0][2], this->v[1][2], this->v[2][2], this->v[3][2],
602 this->v[0][3], this->v[1][3], this->v[2][3], this->v[3][3]);
610 return Tmat4<DT>(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
629 return Tmat4<DT>(
Tvec4<DT>(1.0, 0.0, 0.0, v[0]),
Tvec4<DT>(0.0, 1.0, 0.0, v[1]),
Tvec4<DT>(0.0, 0.0, 1.0, v[2]),
641 const DT t = 1.0 - c;
693 static const DT
Epsilon =
static_cast<DT
>(10e-14);
697 "Tmat4<DT> Tmat4<DT>::inverse(bool* isInvertible) const, matrix not invertable",
726 template <
class DT>
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];
732 template <
class DT>
inline std::istream&
operator>>(std::istream& is, ML_LA_NAMESPACE::Tmat4<DT>&
m)
734 ML_LA_NAMESPACE::Tmat4<DT>
m_tmp;
A class to administrate an axis coordinate system drawable in OpenGL.
Base class of all matrix classes that holds the data buffer and provides some general access methods.
VectorT v[size]
The rows constituting the matrix.
A 4x4 matrix class consisting of four 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
Determines the (sub)determinant of columns given by col1, col2, and col3.
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 val.
Tmat4< DT > inverse(bool *isInvertible=nullptr) const
Returns the inverse.
Tmat4(const Tvec3< DT > &n0, const Tvec3< DT > &n1, const Tvec3< DT > &n3, const Tvec3< DT > &t)
Constructs a matrix from three base vectors n0, ... n3 and a translation t, all given as column vecto...
Tmat4(const Tvec4< DT > &row0, const Tvec4< DT > &row1, const Tvec4< DT > &row2, const Tvec4< DT > &row3)
Composes a matrix from the four row 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 a 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' that 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 from double array 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, filling it 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 the diagonal.
const Tmat4< DT > & operator+=(const Tmat4< DT > &m)
Increments by a Tmat4.
void setValues(const float mat[16])
Copies the contents from float array mat into *this, row by row.
const Tmat4< DT > & operator*=(const DT d)
Multiplies by a constant d.
Tmat4(const DT diagValue)
Builds a matrix that has the argument diagValue as the diagonal values, zero otherwise.
const Tmat4< DT > & apply(MLDblFuncPtr fct)
Applies the function fct to each component.
void getValues(double mat[16]) const
Copies the contents of *this into into double matrix 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 that 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 ? Returns 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 ? Returns 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.