11#ifndef PXR_BASE_GF_MATRIX4F_H
12#define PXR_BASE_GF_MATRIX4F_H
18#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/matrixData.h"
22#include "pxr/base/gf/traits.h"
32PXR_NAMESPACE_OPEN_SCOPE
73 typedef float ScalarType;
75 static const size_t numRows = 4;
76 static const size_t numColumns = 4;
85 float m10,
float m11,
float m12,
float m13,
86 float m20,
float m21,
float m22,
float m23,
87 float m30,
float m31,
float m32,
float m33) {
88 Set(m00, m01, m02, m03,
119 explicit GfMatrix4f(
const std::vector< std::vector<double> >& v);
128 explicit GfMatrix4f(
const std::vector< std::vector<float> >& v);
138 const std::vector<double>& r1,
139 const std::vector<double>& r2,
140 const std::vector<double>& r3);
150 const std::vector<float>& r1,
151 const std::vector<float>& r2,
152 const std::vector<float>& r3);
187 return GfVec4f(_mtx[i][0], _mtx[i][1], _mtx[i][2], _mtx[i][3]);
192 return GfVec4f(_mtx[0][i], _mtx[1][i], _mtx[2][i], _mtx[3][i]);
199 float m10,
float m11,
float m12,
float m13,
200 float m20,
float m21,
float m22,
float m23,
201 float m30,
float m31,
float m32,
float m33) {
202 _mtx[0][0] = m00; _mtx[0][1] = m01; _mtx[0][2] = m02; _mtx[0][3] = m03;
203 _mtx[1][0] = m10; _mtx[1][1] = m11; _mtx[1][2] = m12; _mtx[1][3] = m13;
204 _mtx[2][0] = m20; _mtx[2][1] = m21; _mtx[2][2] = m22; _mtx[2][3] = m23;
205 _mtx[3][0] = m30; _mtx[3][1] = m31; _mtx[3][2] = m32; _mtx[3][3] = m33;
212 _mtx[0][0] = m[0][0];
213 _mtx[0][1] = m[0][1];
214 _mtx[0][2] = m[0][2];
215 _mtx[0][3] = m[0][3];
216 _mtx[1][0] = m[1][0];
217 _mtx[1][1] = m[1][1];
218 _mtx[1][2] = m[1][2];
219 _mtx[1][3] = m[1][3];
220 _mtx[2][0] = m[2][0];
221 _mtx[2][1] = m[2][1];
222 _mtx[2][2] = m[2][2];
223 _mtx[2][3] = m[2][3];
224 _mtx[3][0] = m[3][0];
225 _mtx[3][1] = m[3][1];
226 _mtx[3][2] = m[3][2];
227 _mtx[3][3] = m[3][3];
252 float*
Get(
float m[4][4])
const;
321 return !(*
this == m);
327 return !(*
this == m);
356 return GfVec3f(_mtx[i][0], _mtx[i][1], _mtx[i][2]);
363 return _GetDeterminant3(0, 1, 2, 0, 1, 2);
477 return GfVec4f(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[0][1] + vec[2] * m._mtx[0][2] + vec[3] * m._mtx[0][3],
478 vec[0] * m._mtx[1][0] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[1][2] + vec[3] * m._mtx[1][3],
479 vec[0] * m._mtx[2][0] + vec[1] * m._mtx[2][1] + vec[2] * m._mtx[2][2] + vec[3] * m._mtx[2][3],
480 vec[0] * m._mtx[3][0] + vec[1] * m._mtx[3][1] + vec[2] * m._mtx[3][2] + vec[3] * m._mtx[3][3]);
485 return GfVec4f(vec[0] * m._mtx[0][0] + vec[1] * m._mtx[1][0] + vec[2] * m._mtx[2][0] + vec[3] * m._mtx[3][0],
486 vec[0] * m._mtx[0][1] + vec[1] * m._mtx[1][1] + vec[2] * m._mtx[2][1] + vec[3] * m._mtx[3][1],
487 vec[0] * m._mtx[0][2] + vec[1] * m._mtx[1][2] + vec[2] * m._mtx[2][2] + vec[3] * m._mtx[3][2],
488 vec[0] * m._mtx[0][3] + vec[1] * m._mtx[1][3] + vec[2] * m._mtx[2][3] + vec[3] * m._mtx[3][3]);
597 float eps = 1e-5)
const;
602 return GfVec3f(_mtx[3][0], _mtx[3][1], _mtx[3][2]);
644 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
645 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
646 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2],
647 vec[0] * _mtx[0][3] + vec[1] * _mtx[1][3] + vec[2] * _mtx[2][3] + _mtx[3][3]));
656 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
657 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
658 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2],
659 vec[0] * _mtx[0][3] + vec[1] * _mtx[1][3] + vec[2] * _mtx[2][3] + _mtx[3][3])));
668 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0],
669 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1],
670 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2]);
681 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0],
682 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1],
683 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2]);
692 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
693 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
694 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2]);
703 vec[0] * _mtx[0][0] + vec[1] * _mtx[1][0] + vec[2] * _mtx[2][0] + _mtx[3][0],
704 vec[0] * _mtx[0][1] + vec[1] * _mtx[1][1] + vec[2] * _mtx[2][1] + _mtx[3][1],
705 vec[0] * _mtx[0][2] + vec[1] * _mtx[1][2] + vec[2] * _mtx[2][2] + _mtx[3][2]);
713 double _GetDeterminant3(
size_t row1,
size_t row2,
size_t row3,
714 size_t col1,
size_t col2,
size_t col3)
const;
717 void _Jacobi3(
GfVec3d *eigenvalues,
GfVec3d eigenvectors[3])
const;
721 void _SetRotateFromQuat(
float r,
const GfVec3f& i);
743PXR_NAMESPACE_CLOSE_SCOPE
Stores a 3x3 matrix of float elements.
Stores a 4x4 matrix of double elements.
Stores a 4x4 matrix of float elements.
GF_API GfMatrix4f & SetLookAt(const GfVec3f &eyePoint, const GfRotation &orientation)
Sets the matrix to specify a viewing matrix from a world-space eyePoint and a world-space rotation th...
const float * GetArray() const
Returns vector components as a const array of float values.
GF_API GfQuatf ExtractRotationQuat() const
Return the rotation corresponding to this matrix as a quaternion.
GF_API GfMatrix4f(const std::vector< float > &r0, const std::vector< float > &r1, const std::vector< float > &r2, const std::vector< float > &r3)
Constructor.
GfMatrix4f & Set(const float m[4][4])
Sets the matrix from a 4x4 array of float values, specified in row-major order.
bool HasOrthogonalRows3() const
Returns true, if the row vectors of the upper 3x3 matrix form an orthogonal basis.
float * data()
Returns raw access to components of matrix as an array of float values.
GF_API GfMatrix4f & SetTranslateOnly(const GfVec3f &t)
Sets matrix to specify a translation by the vector trans, without clearing the rotation.
GfVec3d Transform(const GfVec3d &vec) const
Transforms the row vector vec by the matrix, returning the result.
GF_API GfMatrix4f GetOrthonormalized(bool issueWarning=true) const
Returns an orthonormalized copy of the matrix.
GF_API GfMatrix4f & operator*=(const GfMatrix4f &m)
Post-multiplies matrix m into this matrix.
GfMatrix4f & SetIdentity()
Sets the matrix to the identity matrix.
GF_API GfMatrix4f & SetTranslate(const GfVec3f &trans)
Sets matrix to specify a translation by the vector trans, and clears the rotation.
GF_API GfMatrix4f & SetRotate(const GfRotation &rot)
Sets the matrix to specify a rotation equivalent to rot, and clears the translation.
GF_API GfMatrix4f & SetTransform(const GfRotation &rotate, const GfVec3f &translate)
Sets matrix to specify a rotation by rotate and a translation by translate.
friend GfMatrix4f operator*(const GfMatrix4f &m1, double d)
Returns the product of a matrix and a float.
GF_API GfMatrix4f GetTranspose() const
Returns the transpose of the matrix.
GfVec3f ExtractTranslation() const
Returns the translation part of the matrix, defined as the first three elements of the last row.
GfVec3d TransformDir(const GfVec3d &vec) const
Transforms row vector vec by the matrix, returning the result.
GF_API GfMatrix4f & operator-=(const GfMatrix4f &m)
Subtracts matrix m from this matrix.
GfMatrix4f & Set(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
Sets the matrix from 16 independent float values, specified in row-major order.
GF_API GfMatrix4f(const std::vector< double > &r0, const std::vector< double > &r1, const std::vector< double > &r2, const std::vector< double > &r3)
Constructor.
GF_API GfMatrix4f & SetScale(float scaleFactor)
Sets matrix to specify a uniform scaling by scaleFactor.
GF_API GfMatrix4f & SetDiagonal(const GfVec4f &)
Sets the matrix to have diagonal (v[0], v[1], v[2], v[3]).
GF_API GfMatrix4f & SetRotateOnly(const GfQuatf &rot)
Sets the matrix to specify a rotation equivalent to rot, without clearing the translation.
void SetRow3(int i, const GfVec3f &v)
Sets a row of the matrix from a Vec3.
const float * data() const
Returns const raw access to components of matrix as an array of float values.
GF_API GfMatrix4f & SetRotateOnly(const GfRotation &rot)
Sets the matrix to specify a rotation equivalent to rot, without clearing the translation.
GF_API GfMatrix4f & operator+=(const GfMatrix4f &m)
Adds matrix m to this matrix.
GfMatrix4f & SetZero()
Sets the matrix to zero.
friend GfMatrix4f operator/(const GfMatrix4f &m1, const GfMatrix4f &m2)
Divides matrix m1 by m2 (that is, m1 * inv(m2)).
GF_API double GetDeterminant() const
Returns the determinant of the matrix.
GF_API GfVec3f DecomposeRotation(const GfVec3f &axis0, const GfVec3f &axis1, const GfVec3f &axis2) const
Decompose the rotation corresponding to this matrix about 3 orthogonal axes.
GfVec3f GetRow3(int i) const
Gets a row of the matrix as a Vec3.
GF_API GfMatrix4f GetInverse(double *det=NULL, double eps=0) const
Returns the inverse of the matrix, or FLT_MAX * SetIdentity() if the matrix is singular.
friend size_t hash_value(GfMatrix4f const &m)
Hash.
GF_API GfMatrix4f & SetRotateOnly(const GfMatrix3f &mx)
Sets the matrix to specify a rotation equivalent to mx, without clearing the translation.
GF_API bool Factor(GfMatrix4f *r, GfVec3f *s, GfMatrix4f *u, GfVec3f *t, GfMatrix4f *p, float eps=1e-5) const
Factors the matrix into 5 components:
GF_API GfMatrix4f(const std::vector< std::vector< double > > &v)
Constructor.
GF_API float * Get(float m[4][4]) const
Fills a 4x4 array of float values with the values in the matrix, specified in row-major order.
GF_API GfMatrix4f(const std::vector< std::vector< float > > &v)
Constructor.
bool operator!=(const GfMatrix4d &m) const
Tests for element-wise matrix inequality.
friend GfMatrix4f operator+(const GfMatrix4f &m1, const GfMatrix4f &m2)
Adds matrix m2 to m1.
GF_API GfMatrix4f & SetRotate(const GfQuatf &rot)
Sets the matrix to specify a rotation equivalent to rot, and clears the translation.
GF_API GfMatrix4f(const GfRotation &rotate, const GfVec3f &translate)
Constructor.
GF_API friend GfMatrix4f operator-(const GfMatrix4f &m)
Returns the unary negation of matrix m.
float * operator[](int i)
Accesses an indexed row i of the matrix as an array of 4 float values so that standard indexing (such...
GF_API bool operator==(const GfMatrix4d &m) const
Tests for element-wise matrix equality.
GfMatrix4f(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
Constructor.
GF_API GfMatrix3f ExtractRotationMatrix() const
Returns the rotation corresponding to this matrix.
GF_API double GetHandedness() const
Returns the sign of the determinant of the upper 3x3 matrix, i.e.
GfVec3f TransformDir(const GfVec3f &vec) const
Transforms row vector vec by the matrix, returning the result.
void SetRow(int i, const GfVec4f &v)
Sets a row of the matrix from a Vec4.
float * GetArray()
Returns vector components as an array of float values.
GF_API GfMatrix4f & SetScale(const GfVec3f &scaleFactors)
Sets the matrix to specify a nonuniform scaling in x, y, and z by the factors in vector scaleFactors.
GfMatrix4f(const float m[4][4])
Constructor.
GF_API GfMatrix4f(const GfMatrix3f &rotmx, const GfVec3f &translate)
Constructor.
GF_API GfMatrix4f & SetLookAt(const GfVec3f &eyePoint, const GfVec3f ¢erPoint, const GfVec3f &upDirection)
Sets the matrix to specify a viewing matrix from parameters similar to those used by gluLookAt(3G).
GfVec3d TransformAffine(const GfVec3d &vec) const
Transforms the row vector vec by the matrix, returning the result.
GF_API bool Orthonormalize(bool issueWarning=true)
Makes the matrix orthonormal in place.
bool IsLeftHanded() const
Returns true if the vectors in the upper 3x3 matrix form a left-handed coordinate system.
GfMatrix4f(float s)
Constructor.
GF_API GfMatrix4f(const class GfMatrix4d &m)
This explicit constructor converts a "double" matrix to a "float" matrix.
GfMatrix4f()=default
Default constructor. Leaves the matrix component values undefined.
double GetDeterminant3() const
Returns the determinant of the upper 3x3 matrix.
GF_API GfMatrix4f & SetTransform(const GfMatrix3f &rotmx, const GfVec3f &translate)
Sets matrix to specify a rotation by rotmx and a translation by translate.
GfVec3f Transform(const GfVec3f &vec) const
Transforms the row vector vec by the matrix, returning the result.
GfMatrix4f(const GfVec4f &v)
Constructor.
bool IsRightHanded() const
Returns true if the vectors in the upper 3x3 matrix form a right-handed coordinate system.
void SetColumn(int i, const GfVec4f &v)
Sets a column of the matrix from a Vec4.
GF_API GfMatrix4f & SetRotate(const GfMatrix3f &mx)
Sets the matrix to specify a rotation equivalent to mx, and clears the translation.
GfVec4f GetColumn(int i) const
Gets a column of the matrix as a Vec4.
GfVec4f GetRow(int i) const
Gets a row of the matrix as a Vec4.
GfVec3f TransformAffine(const GfVec3f &vec) const
Transforms the row vector vec by the matrix, returning the result.
GF_API GfRotation ExtractRotation() const
Returns the rotation corresponding to this matrix.
GF_API GfMatrix4f RemoveScaleShear() const
Returns the matrix with any scaling or shearing removed, leaving only the rotation and translation.
GF_API GfMatrix4f & SetDiagonal(float s)
Sets the matrix to s times the identity matrix.
A class template used by GfMatrixXX to store values.
T * GetData()
Return a pointer to the start of all the data.
Basic type: a quaternion, a complex number with a real coefficient and three imaginary coefficients,...
Basic type: 3-space rotation specification.
Basic type for a vector of 3 double components.
Basic type for a vector of 3 float components.
Basic type for a vector of 4 double components.
Basic type for a vector of 4 float components.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
double GfDot(const GfDualQuatd &dq1, const GfDualQuatd &dq2)
Return the dot (inner) product of two dual quaternions.
Assorted mathematical utility functions.
double GfAbs(double f)
Return abs(f).
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
#define GF_MIN_ORTHO_TOLERANCE
This constant is used to determine when a set of basis vectors is close to orthogonal.
Utility functions for GfVec4f and GfVec4d as homogeneous vectors.
GfVec3f GfProject(const GfVec4f &v)
Projects homogeneous v into Euclidean space and returns the result as a Vec3f.
Defines useful mathematical limits.
GF_API bool GfIsClose(GfMatrix4f const &m1, GfMatrix4f const &m2, double tolerance)
Tests for equality within a given tolerance, returning true if the difference between each component ...
A metafunction with a static const bool member 'value' that is true for GfMatrix types,...