| 1 |
NAME SbMatrix SbMx "" { 4x4 matrix class } |
| 2 |
INCLUDE SbLinear.h |
| 3 |
DESC { |
| 4 |
4x4 matrix class/datatype used by many Inventor node and action classes. |
| 5 |
The matrices are stored in row-major order. |
| 6 |
\- |
| 7 |
Note that this class should be declared and/or malloc'd as an standard |
| 8 |
C struct: |
| 9 |
\b\k |
| 10 |
/* This is defined in Inventor_c/SbMatrix.h: */ |
| 11 |
struct SbMatrix \{ |
| 12 |
float mx[4][4]; |
| 13 |
\}; |
| 14 |
typedef SbMatrix SbMx |
| 15 |
|
| 16 |
/* Your code should look like this: */ |
| 17 |
SbMx mx, mx_t; |
| 18 |
|
| 19 |
mx = SbMxIdent(); |
| 20 |
mx.mx[0][0] = mx.mx[1][1] = mx.mx[2][2] = 3.0; |
| 21 |
mx_t = SbMxTranspose( &mx ); |
| 22 |
|
| 23 |
\.\. |
| 24 |
\. |
| 25 |
} |
| 26 |
BEGIN C++ |
| 27 |
METHOD "" SbMatrix(){ } |
| 28 |
METHOD "" SbMatrix(float a11, float a12, float a13, float a14, |
| 29 |
float a21, float a22, float a23, float a24, |
| 30 |
float a31, float a32, float a33, float a34, |
| 31 |
float a41, float a42, float a43, float a44) {} |
| 32 |
METHOD "" SbMatrix(const SbMat &m) { |
| 33 |
Constructors. |
| 34 |
} |
| 35 |
METHOD "" void setValue(const SbMat &m) { |
| 36 |
Sets value from 4x4 array of elements. |
| 37 |
} |
| 38 |
METHOD "" void getValue(SbMat &m) const {} |
| 39 |
METHOD "" const SbMat & getValue() const { |
| 40 |
Returns 4x4 array of elements. |
| 41 |
} |
| 42 |
END |
| 43 |
METHOD makeIdent void makeIdentity() { |
| 44 |
Sets matrix to be identity. |
| 45 |
} |
| 46 |
METHOD ident static SbMatrix identity() { |
| 47 |
Returns an identity matrix. |
| 48 |
} |
| 49 |
METHOD setRot void setRotate(const SbRotation &q) { |
| 50 |
Sets matrix to rotate by given rotation. |
| 51 |
} |
| 52 |
METHOD "" void setScale(float s) { |
| 53 |
Sets matrix to scale by given uniform factor. |
| 54 |
} |
| 55 |
METHOD scaleVec void setScale(const SbVec3f &s) { |
| 56 |
Sets matrix to scale by given vector. |
| 57 |
} |
| 58 |
METHOD setXlate void setTranslate(const SbVec3f &t) { |
| 59 |
Sets matrix to translate by given vector. |
| 60 |
} |
| 61 |
BEGIN C++ |
| 62 |
METHOD "" void setTransform(const SbVec3f &t, const SbRotation &r, |
| 63 |
const SbVec3f &s) {} |
| 64 |
METHOD "" void setTransform(const SbVec3f &t, const SbRotation &r, |
| 65 |
const SbVec3f &s, const SbRotation &so) {} |
| 66 |
END |
| 67 |
METHOD setXform void setTransform( |
| 68 |
const SbVec3f &translation, |
| 69 |
const SbRotation &rotation, |
| 70 |
const SbVec3f &scaleFactor, |
| 71 |
const SbRotation &scaleOrientation, |
| 72 |
const SbVec3f ¢er) { |
| 73 |
Composes the matrix based on a translation, rotation, scale, |
| 74 |
orientation for scale, and center. The \acenter\. is the |
| 75 |
center point for scaling and rotation. The \ascaleOrientation\. |
| 76 |
chooses the primary axes for the scale. |
| 77 |
} |
| 78 |
BEGIN C++ |
| 79 |
METHOD "" void getTransform(SbVec3f &t, SbRotation &r, |
| 80 |
SbVec3f &s, SbRotation &so) const { |
| 81 |
Return translation, rotation, scale, and scale orientation |
| 82 |
components of the matrix. |
| 83 |
} |
| 84 |
END |
| 85 |
METHOD getXform void getTransform(SbVec3f &translation, |
| 86 |
SbRotation &rotation, |
| 87 |
SbVec3f &scaleFactor, |
| 88 |
SbRotation &scaleOrientation, |
| 89 |
const SbVec3f ¢er) const { |
| 90 |
Decomposes the matrix into a translation, rotation, scale, |
| 91 |
and scale orientation. Any projection information is discarded. |
| 92 |
The decomposition depends upon choice of center point for |
| 93 |
rotation and scaling, which is optional as the last parameter. |
| 94 |
Note that if the center is 0, decompose() is the same as |
| 95 |
factor() where \at\. is translation, \au\. is rotation, \as\. is scaleFactor, |
| 96 |
and \ar\. is ScaleOrientation. |
| 97 |
} |
| 98 |
METHOD det3Mx float det3(int r1, int r2, int r3, int c1, int c2, int c3) const { |
| 99 |
Returns determinant of 3x3 submatrix composed of given row and |
| 100 |
column indices (0-3 for each). |
| 101 |
} |
| 102 |
METHOD "" float det3() const { |
| 103 |
Returns determinant of upper-left 3x3 submatrix. |
| 104 |
} |
| 105 |
METHOD "" float det4() const { |
| 106 |
Returns determinant of entire matrix. |
| 107 |
} |
| 108 |
METHOD "" SbBool factor(SbMatrix &r, SbVec3f &s, SbMatrix &u, |
| 109 |
SbVec3f &t, SbMatrix &proj) const { |
| 110 |
Factors a matrix m into 5 pieces: m = r s r^ u t, where r^ |
| 111 |
means transpose of r, and r and u are rotations, s is a scale, |
| 112 |
and t is a translation. Any projection information is returned |
| 113 |
in \aproj\.. |
| 114 |
NOTE: the projection matrix is always set to identity. |
| 115 |
} |
| 116 |
METHOD "" SbMatrix inverse() const { |
| 117 |
Returns inverse of matrix. Results are undefined for |
| 118 |
singular matrices. Uses LU decomposition. |
| 119 |
} |
| 120 |
METHOD LUDecomp SbBool LUDecomposition(int index[4], float &d) { |
| 121 |
Perform in-place LU decomposition of matrix. \aindex\. is index of rows |
| 122 |
in matrix. \ad\. is the parity of row swaps. Returns FALSE if singular. |
| 123 |
} |
| 124 |
METHOD LUBackSub void LUBackSubstitution(int index[4], |
| 125 |
float b[4]) const { |
| 126 |
Perform back-substitution on LU-decomposed matrix. Index is |
| 127 |
permutation of rows from original matrix. |
| 128 |
} |
| 129 |
METHOD "" SbMatrix transpose() const { |
| 130 |
Returns transpose of matrix. |
| 131 |
} |
| 132 |
METHOD "" SbMatrix & multRight(const SbMatrix &m) {} |
| 133 |
METHOD "" SbMatrix & multLeft(const SbMatrix &m) { |
| 134 |
Multiplies matrix by given matrix on right or left. |
| 135 |
} |
| 136 |
METHOD multMxVec void multMatrixVec(const SbVec3f &src, |
| 137 |
SbVec3f &dst) const { |
| 138 |
Multiplies matrix by given column vector, giving vector result. |
| 139 |
} |
| 140 |
METHOD multVecMx void multVecMatrix(const SbVec3f &src, |
| 141 |
SbVec3f &dst) const { |
| 142 |
Multiplies given row vector by matrix, giving vector result. |
| 143 |
} |
| 144 |
METHOD multDirMx void multDirMatrix(const SbVec3f &src, |
| 145 |
SbVec3f &dst) const { |
| 146 |
Multiplies given row vector by matrix, giving vector result. |
| 147 |
\asrc\. is assumed to be a direction vector, so translation part of |
| 148 |
matrix is ignored. Note: if you wish to transform surface points and normals |
| 149 |
by a matrix, call |
| 150 |
\+\mmultVecMatrix()\.\. |
| 151 |
\-\mSbMxMultVecMatrix()\.\. |
| 152 |
for the points and call |
| 153 |
\+\mmultDirMatrix()\.\. |
| 154 |
\-\mSbMxMultDirMatrix()\.\. |
| 155 |
on the inverse transpose of the matrix for the normals. |
| 156 |
} |
| 157 |
METHOD multLineMx void multLineMatrix(const SbLine &src, |
| 158 |
SbLine &dst) const { |
| 159 |
Multiplies the given line's origin by the matrix, and the |
| 160 |
line's direction by the rotation portion of the matrix. |
| 161 |
} |
| 162 |
METHOD "" void print(FILE *fp) const { |
| 163 |
Prints a formatted version of the matrix to the given file pointer. |
| 164 |
} |
| 165 |
BEGIN C++ |
| 166 |
METHOD "" float * operator float\|*() { |
| 167 |
Cast: returns pointer to storage of first element. |
| 168 |
} |
| 169 |
METHOD "" SbMat operator SbMat\|&() { |
| 170 |
Cast: returns reference to 4x4 array. |
| 171 |
} |
| 172 |
METHOD "" float * operator [\|](int i) {} |
| 173 |
METHOD "" const float * operator [\|](int i) const { |
| 174 |
Make it look like a usual matrix (so you can do m[3][2]). |
| 175 |
} |
| 176 |
METHOD "" SbMatrix & operator =(const SbMat &m) { |
| 177 |
Sets value from 4x4 array of elements. |
| 178 |
} |
| 179 |
END |
| 180 |
METHOD "" SbMatrix & operator =(const SbMatrix &m) { |
| 181 |
Set the matrix from another \cSbMatrix\.. |
| 182 |
} |
| 183 |
BEGIN C++ |
| 184 |
METHOD "" SbMatrix & operator =(const SbRotation &q) { |
| 185 |
Set the matrix from an \cSbRotation\.. |
| 186 |
} |
| 187 |
END |
| 188 |
METHOD "" SbMatrix & operator *=(const SbMatrix &m) { |
| 189 |
Performs right multiplication with another matrix. |
| 190 |
} |
| 191 |
METHOD "" SbMatrix operator *(const SbMatrix &m1, const SbMatrix &m2) { |
| 192 |
Binary multiplication of matrices. |
| 193 |
} |
| 194 |
METHOD "" int operator ==(const SbMatrix &m1, const SbMatrix &m2) {} |
| 195 |
METHOD "" int operator !=(const SbMatrix &m1, const SbMatrix &m2) { |
| 196 |
Equality comparison operators. |
| 197 |
} |
| 198 |
METHOD "" SbBool equals(const SbMatrix &m, float tolerance) const { |
| 199 |
Equality comparison within given tolerance, for each component. |
| 200 |
} |
| 201 |
ALSO { SbVec3f, SbRotation } |
| 202 |
|