16 #ifndef AGX_AFFINEMATRIX4X4_H
17 #define AGX_AFFINEMATRIX4X4_H
20 # pragma warning(push)
21 # pragma warning(disable: 4714)
24 #include <agx/config/AGX_USE_SSE.h>
33 #define AGX_AFFINEMATRIX4X4_SET_ROW(row, v1, v2, v3 ) \
34 this->m_data[(row)][0] = (v1); \
35 this->m_data[(row)][1] = (v2); \
36 this->m_data[(row)][2] = (v3);
38 #define AGX_AFFINEMATRIX4X4_INNER_PRODUCT_3(a,b,r,c) \
39 ((a).m_data[r][0] * (b).m_data[0][c]) \
40 +((a).m_data[r][1] * (b).m_data[1][c]) \
41 +((a).m_data[r][2] * (b).m_data[2][c])
65 template <
typename T2>
83 T a10, T a11, T a12, T a13,
84 T a20, T a21, T a22, T a23,
85 T a30, T a31, T a32, T a33 );
145 T a10, T a11, T a12, T a13,
146 T a20, T a21, T a22, T a23,
147 T a30, T a31, T a32, T a33);
405 template <
typename T>
411 template <
typename T>
template <
typename T2>
416 template <
typename T>
418 T a10, T a11, T a12, T a13,
419 T a20, T a21, T a22, T a23,
420 T a30, T a31, T a32, T a33 ) :
Matrix4x4T<T>(a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, a30, a31, a32, a33)
425 template <
typename T>
432 template <
typename T>
437 template <
typename T>
442 template <
typename T>
454 template <
typename T>
462 template <
typename T>
465 T x = this->m_data[3][0];
466 T y = this->m_data[3][1];
467 T z = this->m_data[3][2];
471 invTranslate[0] = -( x * this->m_data[0][0] + y* this->m_data[0][1] + z * this->m_data[0][2]);
472 invTranslate[1] = -( x * this->m_data[1][0] + y* this->m_data[1][1] + z * this->m_data[1][2]);
473 invTranslate[2] = -( x * this->m_data[2][0] + y* this->m_data[2][1] + z * this->m_data[2][2]);
478 template <
typename T>
481 const int bitCompare = memcmp(this->m_data, m.
m_data,
sizeof(this->m_data));
482 return (bitCompare == 0);
485 template <
typename T>
488 const int bitCompare = memcmp(this->m_data, m.
m_data,
sizeof(this->m_data));
489 return (bitCompare != 0);
496 template <
typename T>
500 #if defined(__GNUC__) && !defined(__clang__)
501 #pragma GCC diagnostic push
502 #pragma GCC diagnostic ignored "-Wstringop-overflow"
505 memcpy(this->m_data, ptr,
sizeof(T)*16);
507 #if defined(__GNUC__) && !defined(__clang__)
508 #pragma GCC diagnostic pop
511 agxAssert(this->isRigidTransformation());
516 template <
typename T>
518 T a10, T a11, T a12, T a13,
519 T a20, T a21, T a22, T a23,
520 T a30, T a31, T a32, T a33 )
523 Matrix4x4T<T>::set(a00, a01, a02, a03, a10, a11, a12, a13, a20, a21, a22, a23, a30, a31, a32, a33);
527 template <
typename T>
531 this->setTranslate(0.0, 0.0, 0.0);
537 template <
typename T>
541 this->setTranslate(0.0, 0.0, 0.0);
546 template <
typename T>
554 template <
typename T>
557 (*this)(0,0) = (T)m3(0,0);
558 (*this)(0,1) = (T)m3(0,1);
559 (*this)(0,2) = (T)m3(0,2);
561 (*this)(1,0) = (T)m3(1,0);
562 (*this)(1,1) = (T)m3(1,1);
563 (*this)(1,2) = (T)m3(1,2);
565 (*this)(2,0) = (T)m3(2,0);
566 (*this)(2,1) = (T)m3(2,1);
567 (*this)(2,2) = (T)m3(2,2);
572 template <
typename T>
577 this->setRotate(quat);
581 template <
typename T>
586 this->setRotate(quat);
590 template <
typename T>
595 this->setRotate(quat);
599 template <
typename T>
608 this->setRotate(quat);
612 template <
typename T>
615 this->m_data[3][0] = t[0];
616 this->m_data[3][1] = t[1];
617 this->m_data[3][2] = t[2];
622 template <
typename T>
625 this->m_data[3][0] = tx;
626 this->m_data[3][1] = ty;
627 this->m_data[3][2] = tz;
633 template <
typename T>
636 this->set(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);
645 template <
typename T>
649 0, -vec.
z(), vec.
y(), 0,
650 vec.
z(), 0, -vec.
x(), 0,
651 -vec.
y(), vec.
x(), 0, 0,
656 template <
typename T>
664 template <
typename T>
672 template <
typename T>
680 template <
typename T>
688 template <
typename T>
696 template <
typename T>
702 m.
setRotate(angle1, axis1, angle2, axis2, angle3, axis3);
710 template <
typename T>
713 agx::prefetch<agx::L1>( lhs.
m_data );
714 agx::prefetch<agx::L1>( rhs.
m_data );
745 template <
typename T>
751 for(
size_t col=0; col<3; ++col) {
756 this->m_data[0][col] = t[0];
757 this->m_data[1][col] = t[1];
758 this->m_data[2][col] = t[2];
759 this->m_data[3][col] = t[3] + this->m_data[3][col];
763 template <
typename T>
769 for(
size_t row=0; row<3; ++row)
784 template <
typename T>
787 for (
unsigned i = 0; i < 3; ++i)
789 this->m_data[3][0] += v[i]*this->m_data[i][0];
790 this->m_data[3][1] += v[i]*this->m_data[i][1];
791 this->m_data[3][2] += v[i]*this->m_data[i][2];
792 this->m_data[3][3] += v[i]*this->m_data[i][3];
797 template <
typename T>
800 for (
unsigned i = 0; i < 3; ++i)
802 this->m_data[0][i] += v[i]*this->m_data[0][3];
803 this->m_data[1][i] += v[i]*this->m_data[1][3];
804 this->m_data[2][i] += v[i]*this->m_data[2][3];
805 this->m_data[3][i] += v[i]*this->m_data[3][3];
812 template <
typename T>
816 this->set( rhs.
ptr() );
822 template <
typename T>
830 template <
typename T>
839 template <
typename T>
842 if (
this == &other )
847 else postMult( other );
851 template <
typename T>
857 template <
typename T>
863 template <
typename T>
868 template <
typename T>
877 template <
typename T>
883 this->m_data[0][0] = rhs.
m_data[0][0];
884 this->m_data[1][1] = rhs.
m_data[1][1];
885 this->m_data[2][2] = rhs.
m_data[2][2];
888 this->m_data[0][1] = rhs.
m_data[1][0];
889 this->m_data[1][0] = rhs.
m_data[0][1];
890 this->m_data[0][2] = rhs.
m_data[2][0];
891 this->m_data[2][0] = rhs.
m_data[0][2];
892 this->m_data[1][2] = rhs.
m_data[2][1];
893 this->m_data[2][1] = rhs.
m_data[1][2];
900 this->m_data[3][0] = -( x * this->m_data[0][0] + y* this->m_data[1][0] + z * this->m_data[2][0]);
901 this->m_data[3][1] = -( x * this->m_data[0][1] + y* this->m_data[1][1] + z * this->m_data[2][1]);
902 this->m_data[3][2] = -( x * this->m_data[0][2] + y* this->m_data[1][2] + z * this->m_data[2][2]);
907 template <
typename T>
934 multSSE32Implementation(this->ptr(), lhs.
ptr(), rhs.
ptr());
944 multSSE64Implementation(this->ptr(), lhs.
ptr(), rhs.
ptr());
965 template <
typename T>
968 return Real((*
this)(i,j));
971 template <
typename T>
974 (*this)(i,j) = T(val);
978 template <
typename T>
981 return point * (*this);
984 template <
typename T>
987 return this->transform3x3(vector);
1000 # pragma warning(pop)
#define AGX_AFFINEMATRIX4X4_SET_ROW(row, v1, v2, v3)
#define AGX_AFFINEMATRIX4X4_INNER_PRODUCT_3(a, b, r, c)
#define AGX_TYPE_BINDING(_Type, _Name)
Matrix class for rigid transformations (translation, rotation).
~AffineMatrix4x4T()=default
Destructor.
AffineMatrix4x4T< T > & setRotate(T angle, const Vec3T< T > &axis)
Set the rotational part of a matrix which rotate angle radians around vector axis.
static AffineMatrix4x4T< T > rotate(T angle, T x, T y, T z)
Return a matrix which rotate angle radians around vector [x,y,z].
AffineMatrix4x4T< T > & setRotate(const OrthoMatrix3x3 &m3)
Set the rotational part of the matrix using the specified rotation matrix leaving the translational p...
AffineMatrix4x4T< T > & setRotate(T angle, T x, T y, T z)
Set the rotational part of a matrix which rotate angle radians around vector x y z.
Real at(size_t i, size_t j) const
static AffineMatrix4x4T< T > rotate(T angle1, const Vec3T< T > &axis1, T angle2, const Vec3T< T > &axis2, T angle3, const Vec3T< T > &axis3)
Return a matrix which rotate angle1 radians around vector axis1 and angle2 radians around vector axis...
AffineMatrix4x4T()
Creates a new matrix, initialized to be an identity matrix.
AffineMatrix4x4T< T > & setRotate(const QuatT< T > &q)
Set the rotational part of the matrix using the specified quaternion leaving the translational part u...
bool operator==(const AffineMatrix4x4T< T > &m) const
static AffineMatrix4x4T< T > rotate(const Vec3T< T > &from, const Vec3T< T > &to)
Return a matrix which rotate a vector from from to to.
static AffineMatrix4x4T< T > translate(const Vec3T< T > &dv)
Return a matrix which translates according to dv.
AffineMatrix4x4T< T > operator*(const AffineMatrix4x4T< T > &m) const
void postMult(const AffineMatrix4x4T< T > &)
AffineMatrix4x4T< T > & setRotate(const EulerAngles &euler)
Set the rotational part of the matrix using the specified euler angles leaving the translational part...
static AffineMatrix4x4T< T > crossMatrix(const Vec3T< T > &vec)
Generates a new matrix of a specific type.
static AffineMatrix4x4T< T > rotate(const EulerAngles &euler)
AffineMatrix4x4T(const QuatT< T > &rotation, const Vec3T< T > &translation=Vec3T< T >())
Create a matrix from a quaternion.
bool invert(const AffineMatrix4x4T< T > &rhs)
AffineMatrix4x4T< T > & setRotate(T angle1, const Vec3T< T > &axis1, T angle2, const Vec3T< T > &axis2, T angle3, const Vec3T< T > &axis3)
Set the rotational part of a matrix which rotate angle1 radians around vector axis1 and angle2 radian...
void preMult(const AffineMatrix4x4T< T > &)
AffineMatrix4x4T< T > & set(T const *const ptr)
Set the entire matrix using values from the array with 16 elements using the following order:
AffineMatrix4x4T< T > & operator=(const AffineMatrix4x4T< T > &rhs)
AffineMatrix4x4T(const AffineMatrix4x4T< T2 > &mat)
Copy constructor.
AffineMatrix4x4T< T > & set(const EulerAngles &euler)
Set the rotational part of the matrix using the specified euler angles and the translational part to ...
Vec3T< T > getInvTranslate() const
agx::Vec3T< T > transformVector(const agx::Vec3T< T > &vector) const
Transforms a (mathematical) vector, using only rotation.
AffineMatrix4x4T(T const *const ptr)
Create a matrix from a vector of 16 reals.
void multSSE(const AffineMatrix4x4T< T > &lhs, const AffineMatrix4x4T< T > &rhs)
AffineMatrix4x4T< T > & setTranslate(const Vec3T< T > &t)
Set the translational part of the matrix using the vector t.
AffineMatrix4x4T(const OrthoMatrix3x3 &rotation, const Vec3T< T > &translation=Vec3T< T >())
Create a matrix from a 3x3 rotation matrix.
AffineMatrix4x4T< T > & set(const OrthoMatrix3x3 &m3)
Set the rotational part of the matrix using the specified rotation matrix and the translational part ...
AffineMatrix4x4T(const EulerAngles &rotation, const Vec3T< T > &translation=Vec3T< T >())
Create a matrix from Euler angles.
AffineMatrix4x4T< T > inverse() const
Quick inverse, transpose rotation part, and change sign of translation part.
AffineMatrix4x4T< T > & setTranslate(T tx, T ty, T tz)
Set the translational part of the matrix using the vector x, y, z.
AffineMatrix4x4T< T > & set(T a00, T a01, T a02, T a03, T a10, T a11, T a12, T a13, T a20, T a21, T a22, T a23, T a30, T a31, T a32, T a33)
Set the entire matrix using values from the 16 elements using the following order:
void set(Real val, size_t i, size_t j)
Set the value of element i,j.
AffineMatrix4x4T< T > & preMultTranslate(const Vec3T< T > &v)
AffineMatrix4x4T< T > & setIdentity()
Set the value of the matrix to the identity matrix.
void mult(const AffineMatrix4x4T< T > &, const AffineMatrix4x4T< T > &)
bool operator!=(const AffineMatrix4x4T< T > &m) const
static AffineMatrix4x4T< T > rotate(T angle, const Vec3T< T > &axis)
Return a matrix which rotate angle radians around vector axis.
AffineMatrix4x4T< T > & setRotate(const Vec3T< T > &from, const Vec3T< T > &to)
Set the rotational part of the matrix using the specified two vectors.
AffineMatrix4x4T< T > & set(const QuatT< T > &q)
Set the rotational part of the matrix using the specified quaternion and the translational part to 0,...
agx::Vec3T< T > transformPoint(const agx::Vec3T< T > &point) const
Transforms a (mathematical) point, using both rotation and translation.
AffineMatrix4x4T(T a00, T a01, T a02, T a03, T a10, T a11, T a12, T a13, T a20, T a21, T a22, T a23, T a30, T a31, T a32, T a33)
Create a matrix from 16 T scalars.
AffineMatrix4x4T< T > & postMultTranslate(const Vec3T< T > &v)
static AffineMatrix4x4T< T > translate(T x, T y, T z)
Return a matrix which translates according to vector [x,y,z].
void operator*=(const AffineMatrix4x4T< T > &other)
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Matrix class for affine transformations.
void mult(const Matrix4x4T< T > &, const Matrix4x4T< T > &)
Matrix4x4T< T > & set(T const *const ptr)
Matrix4x4T< T > & setRotate(const QuatT< T > &q)
bool isRigidTransformation() const
Specialized types of matrices for holding orthogonal transformation matrices.
The object holding quaternions and providing operations on these.
void setRotate(T angle, T x, T y, T z)
Set the rotation of the Quaternion as a rotation angle radians around the vector (x,...
A class holding 3 dimensional vectors and providing basic arithmetic.
A class holding 4 dimensional vectors and providing basic arithmetic.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
AffineMatrix4x4T< Real32 > AffineMatrix4x4f
AffineMatrix4x4d inverse< AffineMatrix4x4d >(const AffineMatrix4x4d &value)
Real mult(const Jacobian6DOFElementT< T > &G1, const Jacobian6DOFElementT< T > &G2)
AffineMatrix4x4T< Real64 > AffineMatrix4x4d
Vec3T< T > operator*(const Vec3T< T > &v, const AffineMatrix4x4T< T > &m)
const Real AGX_EQUIVALENT_EPSILON
AffineMatrix4x4T< Real > AffineMatrix4x4
AffineMatrix4x4f inverse< AffineMatrix4x4f >(const AffineMatrix4x4f &value)
AGXPHYSICS_EXPORT agx::Bool equivalent(const agx::AddedMassInteraction::Matrix6x6 &lhs, const agx::AddedMassInteraction::Matrix6x6 &rhs, agx::Real eps=agx::RealEpsilon)