#include "smlmath.h"
SMLMatrix4f class defines 4x4 matrix of single precision floats. It includes data and methods which allow to form matrices, multiply two matrices, perform some other operations.
SMLLIBENTRY SMLMatrix4f();
Default SMLMatrix4f object constructor. This matrix is initialized as identity (1.0 on main diagonal, 0.0 for other elements).
Example:
SMLMatrix4f A();
No.
[top]
SMLLIBENTRY SMLMatrix4f(float* src);
SMLMatrix4f object constructor. Matrix data is initialized by float array src assuming row-wise representation.
Example:
float src[16] = {1,2,3,4,5,6,7,8,9,-4,-3,-2,-1,0,1,2};
SMLMatrix4f A(src);
src - pointer to a float-type object.
[top]
SMLLIBENTRY SMLMatrix4f(const SMLMatrix4f& src);
SMLMatrix4f object copy-constructor. This matrix is initialized by src data.
Example:
float src[16] = {1,2,3,4,5,6,7,8,9,-4,-3,-2,-1,0,1,2};
SMLMatrix4f A(src);
SMLMatrix4f B(A);
src - reference to SMLMatrix4f-type object.
[top]
Destructor for SMLMatrix4f object (it is empty).
No.
[top]
SMLLIBENTRY const SMLMatrix4f& operator=(const SMLMatrix4f& src);
Method is an overloaded operator-function. It makes elements of matrix equal to those of matrix src.
Example:
float src[16] = {1,2,3,4,5,6,7,8,9,-4,-3,-2,-1,0,1,2};
SMLMatrix4f A(src);
SMLMatrix4f B();
B = A;
src - object of SMLMatrix4f type.
Returns reference to current object of SMLMatrix4f type.
[top]
SMLLIBENTRY void Set(int i1, int i2, float elem);
Method sets matrix element with index i1, i2 equal to value of elem.
Example:
SMLMatrix4f A();
A.Set(1, 2, 3.0f);
i1, i2 - index of matrix element
elem - 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[16] = {1,2,3,4,5,6,7,8,9,-4,-3,-2,-1,0,1,2};
float fvalue;
SMLMatrix4f A(src);
fvalue = A.Get(1, 1); // fvalue = 6
i1, i2 - index of matrix element
Returns the value of the matrix element with index i1 , i2.
[top]
SMLLIBENTRY void Copy(const SMLMatrix4f& src);
Method makes elements of this matrix data equal to those of matrix data of object src.
Example:
float src[16] = {1,2,3,4,5,6,7,8,9,-4,-3,-2,-1,0,1,2};
SMLMatrix4f A(src);
SMLMatrix4f B();
B.Copy(A);
src - reference to SMLMatrix4f-type object whose matrix data is to be copied.
[top]
SMLLIBENTRY void Identity();
Method overwrites this matrix data with unit diagonal matrix.
Example:
SMLMatrix4f A();
A.Identity();
No.
[top]
SMLLIBENTRY void Zero();
Method initializes all matrix data with 0.
Example:
SMLMatrix4f A();
A.Zero();
No.
[top]
SMLLIBENTRY void Add(const SMLMatrix4f& m1, const SMLMatrix4f& m2);
Method creates matrix which is equal to sum of corresponding matrices of objects m1 and m2.
Example:
float src1[16] = {1,2,3,4,5,6,7,8,9,-4,-3,-2,-1,0,1,2};
float src2[16] = {7,2,3,-3,5,-1,7,8,0,-4,3,-2,1,0,1,-5};
SMLMatrix4f A(src1), B(src2), C;
C.Add(A, B); // C = A + B
m1 - first operand.
m2 - second operand.
[top]
SMLLIBENTRY void Sub(const SMLMatrix4f& m1, const SMLMatrix4f& m2);
Method creates matrix which is equal to difference of matrix m1 and matrix m2.
Example:
float src1[16] = {1,2,3,4,5,6,7,8,9,-4,-3,-2,-1,0,1,2};
float src2[16] = {7,2,3,-3,5,-1,7,8,0,-4,3,-2,1,0,1,-5};
SMLMatrix4f A(src1), B(src2), C;
C.Sub(A, B); // C = A - B
m1 - first operand.
m2 - second operand.
[top]
SMLLIBENTRY void Invert(SMLMatrix4f& m);
Replace this matrix with inverse of m.
Example:
float src[16] = {1,0,3,1,1,2,1,0,2,0,1,0,1,0,2,1};
SMLMatrix4f A(src);
A.Invert();
m - reference to matrix to be inverted.
[top]
SMLLIBENTRY void Transpose();
Method transposes this matrix data.
Example:
float src[16] = {1,0,3,1,1,2,1,0,2,0,1,0,1,0,2,1};
SMLMatrix4f A(src);
A.Transpose();
No.
[top]
SMLLIBENTRY void ScaleMatrix(const SMLVec3f& vect);
Method creates matrix representing scale trasformation. Its first three diagonal elements are the coordinates x, y, z of object vect and the last element is 1.0. Other elements of the matrix are set to zero.
Example:
SMLVec3f vec(2, 3, 1);
SMLMatrix4f A();
A.ScaleMatrix(vec);
| 2 | 0 | 0 | 0 |
| 0 | 3 | 0 | 0 |
| 0 | 0 | 1 | 0 |
| 0 | 0 | 0 | 1 |
vect - reference to vector defining this matrix.
[top]
SMLLIBENTRY void TranslationMatrix(const SMLVec3f& vect);
Method creates matrix data with units on the main diagonal and elements of the last column equal to coordinates x, y, z of the object vect correspondingly. Other elements of the matrix are set to zero.
Example:
SMLVec3f vec(2, 3, 1);
SMLMatrix4f A();
A.TranslationMatrix(vec);
| 1 | 0 | 0 | 2 |
| 0 | 1 | 0 | 3 |
| 0 | 0 | 1 | 1 |
| 0 | 0 | 0 | 1 |
vect - reference to vector defining this matrix.
[top]
SMLLIBENTRY void RotationMatrix(float theta, float x, float y, float z);
Method creates transformation matrix data which describes the coordinate system rotation at angle theta radians around the axis defined by coordinates x, y, z. The right hand rule indicates the direction of positive theta rotations.
Example:
SMLMatrix4f A();
A.RotationMatrix(0.34f, 2, 3, 1);
theta - angle of rotation.
x, y, z - coordinates of axis of rotation.
[top]
SMLLIBENTRY void RotationMatrix(const SMLVec4f& vect);
Method creates transformation matrix data which describes the coordinate system rotation at angle vect.w around the axis defined by coordinates vect.x, vect.y, vect.z.
vect - reference to object of SMLVec4f type.
[top]
SMLLIBENTRY void Multiply(const SMLMatrix4f& m1, const SMLMatrix4f& m2);
Computes this = m1 m2(matrix multiplication).
Example:
float src1[16] = {1,2,3,4,5,6,7,8,9,-4,-3,-2,-1,0,1,2};
float src2[16] = {7,2,3,-3,5,-1,7,8,0,-4,3,-2,1,0,1,-5};
SMLMatrix4f A(src1), B(src2), C;
C.Multiply(A, B); // C = A * B
m1, m2 - references to matrices to be multiplied.
[top]
void Output(char* label1 = NULL, char* label2 = NULL);
Print out matrix data using OutputDebugString function.
[top]
SMLLIBENTRY void TransformPoint(const SMLVec3f& src, SMLVec3f& dst) const;
Method transforms vector src using this matrix and writes it into dst.
src - reference to a point to be transformed.
dst - reference to transformed point.
[top]
SMLLIBENTRY void TransformVector(const SMLVec3f& src, SMLVec3f& dst) const;
Method obtains product of 3x3 submatrix of this matrix and vector src and writes it into dst.
src - reference to a vector to be transformed.
dst - reference to transformed vector.
[top]
SMLLIBENTRY void Transform(const SMLVec4f& src, SMLVec4f& dst) const;
Method obtains product of this matrix and vector src. Result of transformation is written into vector dst.
src - reference to a vector to be transformed.
dst - reference to transformed vector.
[top]
SMLLIBENTRY void Transform(const SMLVec3f& src, SMLVec4f& dst) const;
Methods writes into vector dst result of multiplication of this matrix and vector SMLVec4f (src.x, src.y, src.z, 1).
src - reference to a vector to be transformed.
dst - reference to transformed vector.
[top]
SMLLIBENTRY void Transform(const SMLSphereBound& src, SMLSphereBound& dst) const;
Method transforms the center of sphere src in accordance with this matrix and sets new value of the radius. Radius is set to maximum absolute value of all matrix elements. It is defined in such manner, that any object within bound src, after transformation by this matrix will be covered by dst.
src - reference to a sphere to be transformed.
dst - reference to transformed sphere.
[top]
SMLLIBENTRY SMLVec4f GetRotationVector() const;
Method obtains coordinates of the axis around which the matrix carries out rotation transformation, assuming this matrix is matrix of rotation.
No.
Returns object of SMLVec4f type. Variables x, y, z of the object are set to coordinates of the rotation axis, variable w is the angle of rotation.
[top]
SMLLIBENTRY bool IsIdentity();
Method returns trueif matrix was initialized with the help of Identity() function and was not changed after that.
No.
Returns the value of variable identity (true or false).
[top]