SBMATRIX(3iv)

๐Ÿ’– SbMatrix ๐Ÿ’–

okay so bestie, this is SbMatrix, and you're reading the 3IV manual page for it. yes we're doing linear algebra today and yes it slays. grab a strawberry ๐Ÿ“ and let's go.


โœจ NAME โœจ

SbMatrix โ€” 4x4 matrix class


๐ŸŒˆ INHERITS FROM ๐ŸŒˆ

SbMatrix

not me inheriting from myself ๐Ÿ’€ it's giving main character energy and honestly? iconic.

๐ŸŽ€ SYNOPSIS ๐ŸŽ€

first things first, you gotta let the compiler know you want in:

#include <Inventor/SbLinear.h>

and here's every single method that lives in this class, verbatim, no cap:

                     SbMatrix()
                     SbMatrix(float a11, float a12, float a13, float a14,
                          float a21, float a22, float a23, float a24, float
                          a31, float a32, float a33, float a34, float a41,
                          float a42, float a43, float a44)
                     SbMatrix(const SbMat &m)
 void                setValue(const SbMat &m)
 void                getValue(SbMat &m) const
 const SbMat &       getValue() const
 void                makeIdentity()
 static SbMatrix     identity()
 void                setRotate(const SbRotation &q)
 void                setScale(float s)
 void                setScale(const SbVec3f &s)
 void                setTranslate(const SbVec3f &t)
 void                setTransform(const SbVec3f &t, const SbRotation &r,
                          const SbVec3f &s)
 void                setTransform(const SbVec3f &t, const SbRotation &r,
                          const SbVec3f &s, const SbRotation &so)
 void                setTransform(const SbVec3f &translation, const
                          SbRotation &rotation, const SbVec3f &scaleFactor,
                          const SbRotation &scaleOrientation, const SbVec3f
                          &center)
 void                getTransform(SbVec3f &t, SbRotation &r, SbVec3f &s,
                          SbRotation &so) const
 void                getTransform(SbVec3f &translation, SbRotation
                          &rotation, SbVec3f &scaleFactor, SbRotation
                          &scaleOrientation, const SbVec3f &center) const
 float               det3(int r1, int r2, int r3, int c1, int c2, int c3)
                          const
 float               det3() const
 float               det4() const
 SbBool              factor(SbMatrix &r, SbVec3f &s, SbMatrix &u, SbVec3f
                          &t, SbMatrix &proj) const
 SbMatrix            inverse() const
 SbBool              LUDecomposition(int index[4], float &d)
 void                LUBackSubstitution(int index[4], float b[4]) const
 SbMatrix            transpose() const
 SbMatrix &          multRight(const SbMatrix &m)
 SbMatrix &          multLeft(const SbMatrix &m)
 void                multMatrixVec(const SbVec3f &src, SbVec3f &dst) const
 void                multVecMatrix(const SbVec3f &src, SbVec3f &dst) const
 void                multDirMatrix(const SbVec3f &src, SbVec3f &dst) const
 void                multLineMatrix(const SbLine &src, SbLine &dst) const
 void                print(FILE *fp) const
 float *             operator float*()
 SbMat               operator SbMat&()
 float *             operator [](int i)
 const float *       operator [](int i) const
 SbMatrix &          operator =(const SbMat &m)
 SbMatrix &          operator =(const SbMatrix &m)
 SbMatrix &          operator =(const SbRotation &q)
 SbMatrix &          operator *=(const SbMatrix &m)
 SbMatrix            operator *(const SbMatrix &m1, const SbMatrix &m2)
 int                 operator ==(const SbMatrix &m1, const SbMatrix &m2)
 int                 operator !=(const SbMatrix &m1, const SbMatrix &m2)
 SbBool              equals(const SbMatrix &m, float tolerance) const

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so basically: it's a 4x4 matrix class/datatype, and like a lot of Inventor node and action classes are lowkey obsessed with it. it's everywhere. it's the blueprint.

and the tea you actually need to remember: the matrices are stored in row-major order. ๐Ÿซถ write that on your hand. row. major. periodt.


๐Ÿ‘‘ METHODS ๐Ÿ‘‘

the constructors ๐Ÿ’…

                     SbMatrix()
                     SbMatrix(float a11, float a12, float a13, float a14,
                          float a21, float a22, float a23, float a24, float
                          a31, float a32, float a33, float a34, float a41,
                          float a42, float a43, float a44)
                     SbMatrix(const SbMat &m)
  • SbMatrix(), SbMatrix(float a11, float a12, float a13, float a14, float a21, float a22, float a23, float a24, float a31, float a32, float a33, float a34, float a41, float a42, float a43, float a44), SbMatrix(const SbMat &m) โ€” these are the constructors. they construct. that's the whole vibe โœจ

  • void setValue(const SbMat &m) โ€” sets the value from a 4x4 array of elements ๐Ÿ’–
  • void getValue(SbMat &m) const and const SbMat & getValue() const โ€” hands you back that 4x4 array of elements. two flavors, pick your fighter ๐ŸŽ€
  • void makeIdentity() โ€” makes the matrix be the identity. glow-up to neutral โœจ
  • static SbMatrix identity() โ€” returns an identity matrix. yes it's static, yes you call it without an object, no we don't make the rules ๐Ÿ’…
  • void setRotate(const SbRotation &q) โ€” sets the matrix to rotate by the given rotation ๐ŸŒ€
  • void setScale(float s) โ€” sets the matrix to scale by the given uniform factor
  • void setScale(const SbVec3f &s) โ€” sets the matrix to scale by the given vector
  • void setTranslate(const SbVec3f &t) โ€” sets the matrix to translate by the given vector ๐Ÿš€

the transform setters ๐Ÿงš

 void                setTransform(const SbVec3f &t, const SbRotation &r,
                          const SbVec3f &s)
 void                setTransform(const SbVec3f &t, const SbRotation &r,
                          const SbVec3f &s, const SbRotation &so)
 void                setTransform(const SbVec3f &translation, const
                          SbRotation &rotation, const SbVec3f &scaleFactor,
                          const SbRotation &scaleOrientation, const SbVec3f
                          &center)
  • void setTransform(const SbVec3f &t, const SbRotation &r, const SbVec3f &s), void setTransform(const SbVec3f &t, const SbRotation &r, const SbVec3f &s, const SbRotation &so), and void setTransform(const SbVec3f &translation, const SbRotation &rotation, const SbVec3f &scaleFactor, const SbRotation &scaleOrientation, const SbVec3f &center) โ€” composes the matrix out of a translation, rotation, scale, orientation for scale, and center. the center is the center point for scaling and rotation, and the scaleOrientation picks the primary axes for the scale. it's giving full makeover in one call ๐Ÿ’–

the transform getters ๐Ÿ”

  • void getTransform(SbVec3f &t, SbRotation &r, SbVec3f &s, SbRotation &so) const โ€” returns the translation, rotation, scale, and scale orientation components of the matrix. the four-piece combo ๐Ÿ“
  • void getTransform(SbVec3f &translation, SbRotation &rotation, SbVec3f &scaleFactor, SbRotation &scaleOrientation, const SbVec3f &center) const โ€” decomposes the matrix into a translation, rotation, scale, and scale orientation. any projection information is discarded. and heads up: the decomposition depends on your choice of center point for rotation and scaling, which is optional as the last parameter. and note that if the center is 0, decompose() is the same as factor() where t is translation, u is rotation, s is scaleFactor, and r is ScaleOrientation. iykyk ๐Ÿ˜Œ

determinants, we love a good determinant ๐Ÿงฎ

  • float det3(int r1, int r2, int r3, int c1, int c2, int c3) const โ€” returns the determinant of the 3x3 submatrix composed of the given row and column indices (0-3 for each) ๐Ÿ‘‘
  • float det3() const โ€” returns the determinant of the upper-left 3x3 submatrix
  • float det4() const โ€” returns the determinant of the entire matrix. the whole thing. no crumbs. ๐Ÿ”ฅ

factor, inverse, and the LU girls ๐Ÿ’€

  • SbBool factor(SbMatrix &r, SbVec3f &s, SbMatrix &u, SbVec3f &t, SbMatrix &proj) const โ€” factors a matrix m into 5 pieces:
m = r s r^ u t

where r^ means transpose of r, and r and u are rotations, s is a scale, and t is a translation. any projection information is returned in proj.

NOTE: the projection matrix is always set to identity. like always always. no exceptions bestie.
  • SbMatrix inverse() const โ€” returns the inverse of the matrix. results are undefined for singular matrices ๐Ÿšจ so like, please don't. it uses LU decomposition.
  • SbBool LUDecomposition(int index[4], float &d) โ€” performs an in-place LU decomposition of the matrix. index is the index of rows in the matrix, and d is the parity of the row swaps. returns FALSE if the matrix is singular ๐Ÿ’…
  • void LUBackSubstitution(int index[4], float b[4]) const โ€” performs back-substitution on an LU-decomposed matrix. index is the permutation of rows from the original matrix.
  • SbMatrix transpose() const โ€” returns the transpose of the matrix. flip it and reverse it ๐Ÿฆ‹

multiplying things ๐ŸŒธ

  • SbMatrix & multRight(const SbMatrix &m) and SbMatrix & multLeft(const SbMatrix &m) โ€” multiplies the matrix by the given matrix on the right or on the left. choose your side ๐Ÿซถ
  • void multMatrixVec(const SbVec3f &src, SbVec3f &dst) const โ€” multiplies the matrix by the given column vector, giving a vector result
  • void multVecMatrix(const SbVec3f &src, SbVec3f &dst) const โ€” multiplies the given row vector by the matrix, giving a vector result
  • void multDirMatrix(const SbVec3f &src, SbVec3f &dst) const โ€” multiplies the given row vector by the matrix, giving a vector result. src is assumed to be a direction vector, so the translation part of the matrix is ignored. and listen up bestie: if you wish to transform surface points and normals by a matrix, call multVecMatrix() for the points and call multDirMatrix() on the inverse transpose of the matrix for the normals. this one's a classic exam question fr fr ๐Ÿ“
  • void multLineMatrix(const SbLine &src, SbLine &dst) const โ€” multiplies the given line's origin by the matrix, and the line's direction by the rotation portion of the matrix โœจ

utility & casting ๐Ÿ’œ

  • void print(FILE *fp) const โ€” prints a formatted version of the matrix to the given file pointer. debugging era ๐Ÿ–จ๏ธ
  • float * operator float*() โ€” cast: returns a pointer to the storage of the first element
  • SbMat operator SbMat&() โ€” cast: returns a reference to the 4x4 array
  • float * operator [](int i) and const float * operator [](int i) const โ€” makes it look like a usual matrix, so you can do m[3][2]. and honestly? m[3][2] is such a mood ๐ŸŽ€

assignment operators ๐Ÿง

  • SbMatrix & operator =(const SbMat &m) โ€” sets the value from a 4x4 array of elements
  • SbMatrix & operator =(const SbMatrix &m) โ€” sets the matrix from another SbMatrix
  • SbMatrix & operator =(const SbRotation &q) โ€” sets the matrix from an SbRotation

math operators ๐Ÿ”ฅ

  • SbMatrix & operator *=(const SbMatrix &m) โ€” performs right multiplication with another matrix
  • SbMatrix operator *(const SbMatrix &m1, const SbMatrix &m2) โ€” binary multiplication of matrices. two matrices walk in, one walks out ๐Ÿ’…

comparison girlies โญ

  • int operator ==(const SbMatrix &m1, const SbMatrix &m2) and int operator !=(const SbMatrix &m1, const SbMatrix &m2) โ€” equality comparison operators. are they the same or are they not, the eternal question ๐Ÿ™ˆ
  • SbBool equals(const SbMatrix &m, float tolerance) const โ€” equality comparison within the given tolerance, for each component. so like, close enough counts ๐Ÿ’–

๐Ÿ’œ SEE ALSO ๐Ÿ’œ

  • SbVec3f
  • SbRotation

go read those too, they're besties with this one ๐Ÿฆ‹


and that's the whole page, bestie!! you just read the SbMatrix(3IV) manual, which lives in the SbMatrix(3IV)() source/version corner of the world โ€” so if you ever need to cite it, that's your girl, footer and all. mwah ๐Ÿ’…๐Ÿ’–โœจ