SbMatrix Structure |
Namespace: OIV.Inventor
The SbMatrix type exposes the following members.
Name | Description | |
---|---|---|
SbMatrix(Single) |
Constructor.
| |
SbMatrix(Single) |
Constructor.
| |
SbMatrix(Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single, Single) |
Constructor given each matrix element.
|
Name | Description | |
---|---|---|
Det3 |
Returns determinant of upper-left 3x3 sub matrix.
| |
Det3(Int32, Int32, Int32, Int32, Int32, Int32) |
Returns determinant of 3x3 sub matrix composed of given row and column indices
(0-3 for each).
| |
Det4 |
Returns determinant of entire matrix.
| |
Equals(Object) |
Returns true if this instance is equal to a specified object.
(Overrides ValueTypeEquals(Object).) | |
Equals(Object, Single) |
Returns true if this instance is equal to a specified object
with given tolerance.
| |
Factor |
Factors a matrix m into 5 pieces: m = rsr^ ut, 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.
| |
GetHashCode |
Returns the hash code for the value of this instance.
(Overrides ValueTypeGetHashCode.) | |
GetTransform(SbVec3f, SbRotation, SbVec3f, SbRotation) |
Return translation, rotation, scale, and scale orientation components of the
matrix.
.
| |
GetTransform(SbVec3f, SbRotation, SbVec3f, SbRotation, SbVec3f) |
Decomposes the matrix into a translation, rotation, scale, and scale
orientation. Any projection information is discarded. The decomposition depends
upon choice of center point for rotation and scaling, which is optional as the
last parameter. Note that if the center is 0, this method is the same as
Factor(SbMatrix, SbVec3f, SbMatrix, SbVec3f, SbMatrix) where t is translation, u is rotation,
s is scaleFactor and r is scaleOrientation.
| |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
Identity |
Returns an identity matrix.
| |
Inverse |
Returns inverse of matrix. Results are undefined for singular matrices.
Uses LU decomposition.
| |
LUBackSubstitution |
Perform back-substitution on LU-decomposed matrix. index
is permutation of rows from original matrix.
| |
LUDecomposition |
Perform in-place LU decomposition of matrix. index is index of rows in
matrix. d is the parity of row swaps.
| |
MakeIdentity |
Sets matrix to be identity.
| |
MultDirMatrix(SbVec3f, SbVec3f) |
Pre-multiplies matrix by given row vector, giving vector result.
| |
MultDirMatrix(SbVec3f, SbVec3f) |
Pre-multiplies matrix by given row vector, giving vector result.
| |
MultLeft(SbMatrix) |
Pre-multiplies the matrix by the given matrix.
| |
MultLeft(SbMatrix) |
Pre-multiplies the matrix by the given matrix.
| |
MultLineMatrix(SbLine, SbLine) |
Multiplies the given line's origin by the matrix, and the line's direction by
the rotation portion of the matrix.
| |
MultLineMatrix(SbLine, SbLine) |
Multiplies the given line's origin by the matrix, and the line's direction by
the rotation portion of the matrix.
| |
MultMatrixVec(SbVec3f, SbVec3f) |
Post-multiplies matrix by given column vector, giving vector result.
| |
MultMatrixVec(SbVec3f, SbVec4f) |
Post-multiplies matrix by given column vector, giving vector result in homogeneous coordinates.
| |
MultMatrixVec(SbVec3f, SbVec3f) |
Post-multiplies matrix by given column vector, giving vector result.
| |
MultMatrixVec(SbVec3f, SbVec4f) |
Post-multiplies matrix by given column vector, giving vector result in homogeneous coordinates.
| |
MultRight(SbMatrix) |
Post-multiplies the matrix by the given matrix.
| |
MultRight(SbMatrix) |
Post-multiplies the matrix by the given matrix.
| |
MultVecMatrix(SbVec3f, SbVec3f) |
Pre-multiplies matrix by given row vector, giving vector result.
| |
MultVecMatrix(SbVec3f, SbVec4f) |
Pre-multiplies matrix by given row vector, giving vector result in homogeneous coordinates.
| |
MultVecMatrix(SbVec3f, SbVec3f) |
Pre-multiplies matrix by given row vector, giving vector result.
| |
MultVecMatrix(SbVec3f, SbVec4f) |
Pre-multiplies matrix by given row vector, giving vector result in homogeneous coordinates.
| |
Scale |
Scales this matrix by the given vector.
| |
SetRotate(SbRotation) |
Sets matrix to rotate by given rotation.
| |
SetRotate(SbRotation) |
Sets matrix to rotate by given rotation.
| |
SetScale(Single) |
Sets matrix to scale by given uniform factor.
| |
SetScale(SbVec3f) |
Sets matrix to scale by given vector.
| |
SetScale(SbVec3f) |
Sets matrix to scale by given vector.
| |
SetTransform(SbVec3f, SbRotation, SbVec3f) |
Composes the matrix based on a translation, rotation, and scale.
A scale orientation value of (0,0,0,1) is used.
The center point for scaling and rotation is (0,0,0).
| |
SetTransform(SbVec3f, SbRotation, SbVec3f) |
Composes the matrix based on a translation, rotation, and scale.
A scale orientation value of (0,0,0,1) is used.
The center point for scaling and rotation is (0,0,0).
| |
SetTransform(SbVec3f, SbRotation, SbVec3f, SbRotation) |
Composes the matrix based on a translation, rotation, scale, and orientation
for scale. The so chooses the primary axes for the scale. The
center point for scaling and rotation is (0,0,0).
| |
SetTransform(SbVec3f, SbRotation, SbVec3f, SbRotation) |
Composes the matrix based on a translation, rotation, scale, and orientation
for scale. The so chooses the primary axes for the scale. The
center point for scaling and rotation is (0,0,0).
| |
SetTransform(SbVec3f, SbRotation, SbVec3f, SbRotation, SbVec3f) |
Composes the matrix based on a translation, rotation, scale, orientation for
scale, and center.
| |
SetTransform(SbVec3f, SbRotation, SbVec3f, SbRotation, SbVec3f) |
Composes the matrix based on a translation, rotation, scale, orientation for
scale, and center.
| |
SetTranslate(SbVec3f) |
Sets matrix to translate by given vector.
| |
SetTranslate(SbVec3f) |
Sets matrix to translate by given vector.
| |
SetValue(Single) |
Sets value from an array of 16 single components.
| |
SetValue(Single) |
Sets value from an array of 16 single components.
| |
SetValue(SbMatrixd) |
Sets value from a double precision matrix.
| |
SetValue(SbMatrixd) |
Sets value from a double precision matrix.
| |
ToString | Returns the fully qualified type name of this instance. (Inherited from ValueType.) | |
Translate |
Translates this matrix by the given vector.
| |
Transpose |
Returns transpose of matrix.
|
Name | Description | |
---|---|---|
Equality |
The equality operator.
| |
Inequality |
The inequality operator.
| |
Multiply |
The multiplication operator (*).
Operates binary multiplication of matrices.
|
Name | Description | |
---|---|---|
Item |
Gets or sets the element at the specified index.
Make it look like a usual matrix (so you can do m[i,j]).
|
The Open Inventor API uses the convention that positions and directions in 3D space are represented by row vectors. Therefore, to apply a transform matrix, the vector is post-multiplied by the matrix as shown in the following figure. Many mathematics and computer graphics books use column vector notation, however there is no functional difference between these two approaches.
Note that the commonly used terms "row major" and "column major" refer to the storage order of the matrix components in memory. This has nothing to do with how you use matrices and vectors with the Open Inventor API. Internally Open Inventor uses the same storage order as OpenGL to allow matrices to be passed efficiently to/from the GPU. When using the Open Inventor API just remember that positions are row vectors, as shown here.
[X' Y' Z' 1] = [X Y Z 1] * | m11 m12 m13 m14 | | m21 m22 m23 m24 | | m31 m32 m33 m34 | | m41 m42 m43 m44 |
Some common 4x4 transform matrices look like this:
Identity | 1 0 0 0 | Translate | 1 0 0 0 | Scale | Sx 0 0 0 | RotateX | 1 0 0 0 | | 0 1 0 0 | | 0 1 0 0 | | 0 Sy 0 0 | | 0 cosT -sinT 0 | | 0 0 1 0 | | 0 0 1 0 | | 0 0 Sz 0 | | 0 sinT cosT 0 | | 0 0 0 1 | | Tx Ty Tz 1 | | 0 0 0 1 | | 0 0 0 1 |
Therefore, to create a translation matrix you could initialize the SbMatrix object like this (or you could simply use the SetTranslate() convenience method):
SbMatrix( 1,0,0,0, 0,1,0,0, 0,0,1,0, Tx,Ty,Tz,1 )
For convenience SbMatrix allows its values to be accessed using 2D array syntax, like this:
value = matrix[row,column];
For example, the translation X, Y, Z values in the above example can be retrieved using:
float Tx = matrix[3,0] // Row 3, Column 0 float Ty = matrix[3,1] // Row 3, Column 1 float Tz = matrix[3,2] // Row 3, Column 2
Multiplying points
Points (positions in 3D space) are transformed by post-multiplying the row vector with the transform matrix like this (symbolically):
P' = P * M
If you need to transform a point by a matrix use the MultVecMatrix() method as shown here (initialization of variables not shown):
SbMatrix M ... SbVec3f src, dst ... M.MultVecMatrix( src, dst );
Note that it is safe to use the same SbVec3f object as both src and dst.
In the class SbViewVolume, for example, the ProjectToScreen() method first calls the GetMatrix() method to get the combined model/view/projection matrix, then calls the matrix object's MultVecMatrix() method to transform the 3D point into normalized clipping space (-1 to 1). (It then does one more step to convert that position to 0..1 normalized screen space but that's not important here.)
Multiplying directions
Vectors that represent a direction in 3D space rather than a position, for example surface normal vectors for geometry, can also be transformed. But in this case the translation portion of the matrix (if any) must not be used. For example, if a matrix contains the translation [10, 20, 30], then transforming the normal vector [0, 0, 1] using multVecMatrix() would produce the result [10, 20, 31]. However the correct result is still [0, 0, 1] because translation has no meaning for a direction vector. The method MultDirMatrix() is provided to transform direction vectors ignoring the translation portion of the matrix.
Generally normals should be transformed by the inverse transpose of the matrix as shown here (initialization of variables is not shown). See standard computer graphic references for the explanation.
SbMatrix M ...
SbVec3f src, dst ...
M.Transpose().Inverse().MultDirMatrix( src, out dst );
Note that if the matrix is orthonormal, i.e. purely rotational with no scaling or shearing, then the inverse transpose is the same as the original matrix and it is not necessary to compute the inverse transpose.
Multiplying matrices
A series of transforms, for example scale, rotate and translate can be combined into a single transform matrix by multiplying the matrices together. The result of such a multiplication is order dependent. Using the row vector convention, we can say that transforms are applied from "left to right". We normally want scaling applied first, then rotation, then translation, as shown here (symbolically):
P' = P * S * R * T
So we would build the combined transform matrix M from scale, rotate and translate matrices S, R and T like this (symbolically):
M = S * R * T
Note that convenience nodes like SoTransform do this (combine the scale, rotate and translate) for you automatically. So you don't necessarily need to remember all the details.
If you need to combine matrices yourself, you can use the MultLeft() or MultRight() method to multiple each matrix with the combined matrix. The name “multLeft” means to pre-multiply the SbMatrix object with the specified SbMatrix parameter, so we would combine the matrices like this (initialization of variables not shown):
SbMatrix M, S, R, T ... M = T; M.MultLeft( R ); M.MultLeft( S );
Note that MultLeft() overwrites the matrix currently in the SbMatrix object. So usually (as shown) you will start by making a copy of the first matrix as the starting point for accumulation.
The name “multRight” means to post-multiply the SbMatrix object with the specified SbMatrix parameter. So we would combine the matrices like this (initialization of variables not shown):
SbMatrix M, S, R, T ... M = S; M.MultRight( R ); M.MultRight( T );
Note that MultRight() also overwrites the matrix currently in the SbMatrix object. So usually (as shown) you will start by making a copy of the first matrix as the starting point for accumulation.