#include smlmath.h
SMLMatrix3f class defines 3x3 matrix of single precision floats. It includes data and methods which allow to form matrices, multiply two matrices, transpose them, define matrix of rotation with a certain angle around some given axis, and on the base of given rotation matrix obtain coordinates of the axis, around which this rotation is carried out, and angle of rotation.
Default SMLmatrix3f object constructor. This matrix is initialized as identity (1.0 on main diagonal, 0.0 for other elements).
Example:
SMLMatrix3f A();
No.
[top]
SMLLIBENTRY SMLMatrix3f(float* src);
SMLMatrix3f object constructor. Matrix data is initialized by float array src assuming row-wise representation.
Example:
float src[9] = {1,2,3,4,5,6,7,8,9};
SMLMatrix3f A(src);
src - pointer to a float-type object.
[top]
SMLLIBENTRY SMLMatrix3f(const SMLMatrix3f& src);
SMLmatrix3f object copy-constructor. This matrix is initialized by src data.
Example:
float src[9] = {1,2,3,4,5,6,7,8,9};
SMLMatrix3f A(src);
SMLMatrix3f B(A);
src - reference to SMLMatrix3f-type object.
[top]
Destructor for SMLmatrix3f object (it is empty).
No.
[top]
SMLLIBENTRY const SMLMatrix3f& operator=(const SMLMatrix3f& src);
Method is an overloaded operator-function. It makes elements of matrix equal to those of matrix src.
Example:
float src[9] = {1,2,3,4,5,6,7,8,9};
SMLMatrix3f A(src);
SMLMatrix3f B();
B = A;
src - object of SMLMatrix3f type.
Returns reference to current object of SMLMatrix3f type.
[top]
SMLLIBENTRY void Set(int i1, int i2, float v);
Method sets matrix element with index i1, i2 equal to value of v.
Example:
SMLMatrix3f A();
A.Set(1, 2, 3.0f);
i1, i2 - index of matrix element
v - new value of matrix element.
[top]
SMLLIBENTRY float Get(int i1, int i2) const;
Method gets value of the matrix element with index i1, i2 .
Example:
float src[9] = {1,2,3,4,5,6,7,8,9};
float fvalue;
SMLMatrix3f A(src);
fvalue = A.Get(1, 1); // fvalue = 5
i1, i2 - index of matrix element
Returns the value of the matrix element with index i1, i2 .
[top]
SMLLIBENTRY void TransformPoint(const SMLVec3f& src, SMLVec3f& src) const;
Method computes product of this matrix and vector src. Result of transformation is written into vector src.
Example:
float src[9] = {1,2,3,4,5,6,7,8,9};
SMLMatrix3f A(src);
SMLVec3f B(2, 4, 6);
SMLVec3f C();
A.TransformPoint(B, C);
src - reference to a vector to be transformed.
src - result of transformation.
[top]
SMLLIBENTRY void TransformPoint(const SMLVec3f& src, SMLVec3f& src, int transpose) const;
Method transforms vector src in accordance with component this matrix. If transpose is zero, method computes product of this matrix and vector src. If transpose is not zero method computes product of transposed this matrix and vector src. Result of transformation is written into vector src.
src - reference to a vector to be transformed.
transpose - a transformation flag.
src - result of transformation.
[top]
SMLLIBENTRY void TransformPoint1(const SMLVec3f& src, SMLVec3f& src) const;
Method computes product of transposed this matrix and vector src. Result of transformation is written into vector src.
src - reference to a vector to be transformed.
src - result of transformation.
[top]
SMLLIBENTRY const SMLMatrix3f& Multiply(const SMLMatrix3f& a, const SMLMatrix3f& b);
Computes this = a b (matrix multiplication).
Example:
float src1[9] = {1,2,3,4,5,6,7,8,9};
float src2[9] = {11,12,13,14,15,16,17,18,19};
SMLMatrix3f A(src1);
SMLMatrix3f B(src2);
SMLMatrix3f C();
C.Mult(A, B);
a - first operand.
b - second operand.
Returns reference to the current object of SMLMatrix3f type.
[top]
SMLLIBENTRY const SMLMatrix3f& Multiply(const SMLMatrix3f& a, const SMLMatrix3f& b, int ta, int tb);
Computes multiplication of matrices a and b and writes it into this matrix as follows
this = a b for ta == 0 && tb == 0, or
this = aT b for ta != 0 && tb == 0, or
this = a bT for ta == 0 && tb != 0, or
this = aT bT for ta != 0 && tb != 0
a - first operand.
b - second operand.
ta - transposition flag for first operand.
tb - transposition flag for second operand.
Returns reference to the current object of SMLMatrix3f type.
[top]
SMLLIBENTRY float** GetMatrix();
Method returns this matrix as row-wise 2 dimensional array of floats.
Example:
float src[9] = {1,2,3,4,5,6,7,8,9};
float dst[3][3];
SMLMatrix3f A(src);
dst = A.GetMatrix();
No.
Pointer to matrix data.
[top]
SMLLIBENTRY void Copy(const SMLMatrix3f&src);
Method makes elements of this matrix equal to those of this matrix of object src.
Example:
float src[9] = {1,2,3,4,5,6,7,8,9};
SMLMatrix3f A(src);
SMLMatrix3f B();
B.Copy(A);
src - reference to SMLMatrix3f-type object whose this matrix is to be copied.
[top]
SMLLIBENTRY void Identity();
Method overwrites this matrix with unit diagonal matrix.
Example:
SMLMatrix3f A();
A.Identity();
No.
SMLLIBENTRY void Zero();
Method initializes all this matrix with 0.
Example:
SMLMatrix3f A();
A.Zero();
No.
[top]
SMLLIBENTRY void Cross(const SMLVec3f& v);
It is convenient to represent the cross product of 2 vectors in matrix equations where the cross product operation is separated from the vector it operates on. The cross operator ^ may be defined by - b = a X b. Notice that transpose of cross operation is its negation.
Method creates cross this matrix from coordinates of vector v as follows
| 0 | -v.z | v.y |
| v.z | 0 | -v.y |
| -v.y | v.x | 0 |
Example:
SMLMatrix3f A();
SMLVec3f B(2, 4, 6);
A.Cross(B);
vec - SMLVec3f-type object whose coordinates are used for the cross matrix.
[top]
SMLLIBENTRY void Rotate(float radians, float x, float y, float z);
Method creates transformation this matrix, which describes the coordinate system rotation with angle radians around the axis defined by coordinates x, y, z.
Example:
SMLMatrix3f A();
A.Rotate(0.65f, 2.0f, 1.0f, 3.0f);
radians - angle of rotation.
x, y, z - coordinates of axis of rotation.
[top]
SMLLIBENTRY void Rotate(float radians, const SMLVec3f& axis);
Method creates transformation this matrix, which describes the coordinate system rotation with angle radians around the axis defined by vector axis.
Example:
SMLMatrix3f A();
SMLVec3f B(2, 4, 6);
A.Rotate(0.65f, B);
radians - angle of rotation.
axis - SMLVec3f-type object whose coordinates are used for the transformation matrix.
[top]
SMLLIBENTRY void GetMatrix4f(SMLMatrix4f& m);
Method creates this matrix of SMLMatrix4f-type object. This matrix is obtained from current SMLMatrix3f-type object-s this matrix. Elements of the last row and the last column of the formed matrix are set to zero, and element with index (4,4) is set to 1.
Example:
float src[9] = {1,2,3,4,5,6,7,8,9};
SMLMatrix3f A(src);
SMLMatrix4f B();
A.GetMatrix4f(B);
m - reference to SMLMatrix4f-type object.
[top]
SMLLIBENTRY void SetByMatrix4f(SMLMatrix4f& m);
Method creates this matrix on the base of matrix of SMLMatrix4f-type object. New matrix is the matrix of SMLMatrix4f-type object without elements of its last row and column.
Example:
float src[16] = {1,2,3,4,5,6,7,8,9,2,4,5,7,3,8,9};
SMLMatrix3f A();
SMLMatrix4f B(src);
A.SetByMatrix4f(B);
m - reference to SMLMatrix4f-type object.
[top]
void Output(char* label1 = NULL, char* label2 = NULL);
Print out matrix data using OutputDebugString function with caption formed by concatenation of label1 and label2. This method may be used for application debugging under VC integrated environment.
label1,label2 - strings for formed caption.
[top]
SMLLIBENTRY void Transpose();
Method transposes this matrix.
Example:
float src[9] = {1,2,3,4,5,6,7,8,9};
SMLMatrix3f A(src);
A.Transpose();
No.
[top]
SMLLIBENTRY void QuaternionMatrix(const SMLVec4f& quat);
Method is used to create matrix, which corresponds to quaternion quat.
Example:
SMLMatrix3f A();
SMLVec4f B(2, 4, 6, 3);
A.QuaternionMatrix(B);
axis- SMLVec4f-type object whose coordinates are used for the create matrix.
[top]