[SML Overview]

class SMLMatrix4f

#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.


Public Interface

Constructors and Destructor

constructors

destructor

Access elements

operator=

Set

Get

Copy

Identity

Zero

Add

Sub

Invert

Transpose

ScaleMatrix

TranslationMatrix

RotationMatrix

IsIdentity

Multiply

Output

Transformations for points, vectors and spheres

TransformPoint

TransformVector

Transform

GetRotationVector


SMLLIBENTRY SMLMatrix4f();

Discussion

Default SMLMatrix4f object constructor. This matrix is initialized as identity (1.0 on main diagonal, 0.0 for other elements).

Example:

SMLMatrix4f A();

Parameters

No.

[top]


SMLLIBENTRY SMLMatrix4f(float* src);

Discussion

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);

Parameters

src - pointer to a float-type object.

[top]


SMLLIBENTRY SMLMatrix4f(const SMLMatrix4f& src);

Discussion

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);

Parameters

src - reference to SMLMatrix4f-type object.

[top]


SKINLIBENTRY ~SMLMatrix4f();

Discussion

Destructor for SMLMatrix4f object (it is empty).

Parameters

No.

[top]


SMLLIBENTRY const SMLMatrix4f& operator=(const SMLMatrix4f& src);

Discussion

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;

Parameters

src - object of SMLMatrix4f type.

Return Value

Returns reference to current object of SMLMatrix4f type.

[top]


SMLLIBENTRY void Set(int i1, int i2, float elem);

Discussion

Method sets matrix element with index i1, i2 equal to value of elem.

Example:

SMLMatrix4f A();
A.Set(1, 2, 3.0f);

Parameters

i1, i2 - index of matrix element

elem - new value of matrix element.

[top]


SMLLIBENTRY float Get(int i1, int i2) const;

Discussion

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

Parameters

i1, i2 - index of matrix element

Return Value

Returns the value of the matrix element with index i1 , i2.

[top]


SMLLIBENTRY void Copy(const SMLMatrix4f& src);

Discussion

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);

Parameters

src - reference to SMLMatrix4f-type object whose matrix data is to be copied.

[top]


SMLLIBENTRY void Identity();

Discussion

Method overwrites this matrix data with unit diagonal matrix.

Example:

SMLMatrix4f A();
A.Identity();

Parameters

No.

[top]


SMLLIBENTRY void Zero();

Discussion

Method initializes all matrix data with 0.

Example:

SMLMatrix4f A();
A.Zero();

Parameters

No.

[top]


SMLLIBENTRY void Add(const SMLMatrix4f& m1, const SMLMatrix4f& m2);

Discussion

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

Parameters

m1 - first operand.

m2 - second operand.

[top]


SMLLIBENTRY void Sub(const SMLMatrix4f& m1, const SMLMatrix4f& m2);

Discussion

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

Parameters

m1 - first operand.

m2 - second operand.

[top]


SMLLIBENTRY void Invert(SMLMatrix4f& m);

Discussion

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();

Parameters

m - reference to matrix to be inverted.

[top]


SMLLIBENTRY void Transpose();

Discussion

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();

Parameters

No.

[top]


SMLLIBENTRY void ScaleMatrix(const SMLVec3f& vect);

Discussion

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 000
0300
0010
0001

Parameters

vect - reference to vector defining this matrix.

[top]


SMLLIBENTRY void TranslationMatrix(const SMLVec3f& vect);

Discussion

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);
1002
0103
0011
0001

Parameters

vect - reference to vector defining this matrix.

[top]


SMLLIBENTRY void RotationMatrix(float theta, float x, float y, float z);

Discussion

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);

Parameters

theta - angle of rotation.

x, y, z - coordinates of axis of rotation.

[top]


SMLLIBENTRY void RotationMatrix(const SMLVec4f& vect);

Discussion

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.

Parameters

vect - reference to object of SMLVec4f type.

[top]


SMLLIBENTRY void Multiply(const SMLMatrix4f& m1, const SMLMatrix4f& m2);

Discussion

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

Parameters

m1, m2 - references to matrices to be multiplied.

[top]


void Output(char* label1 = NULL, char* label2 = NULL);

Discussion

Print out matrix data using OutputDebugString function.

[top]


SMLLIBENTRY void TransformPoint(const SMLVec3f& src, SMLVec3f& dst) const;

Discussion

Method transforms vector src using this matrix and writes it into dst.

Parameters

src - reference to a point to be transformed.

Output Parameters

dst - reference to transformed point.

[top]


SMLLIBENTRY void TransformVector(const SMLVec3f& src, SMLVec3f& dst) const;

Discussion

Method obtains product of 3x3 submatrix of this matrix and vector src and writes it into dst.

Parameters

src - reference to a vector to be transformed.

Output Parameters

dst - reference to transformed vector.

[top]


SMLLIBENTRY void Transform(const SMLVec4f& src, SMLVec4f& dst) const;

Discussion

Method obtains product of this matrix and vector src. Result of transformation is written into vector dst.

Parameters

src - reference to a vector to be transformed.

Output Parameters

dst - reference to transformed vector.

[top]


SMLLIBENTRY void Transform(const SMLVec3f& src, SMLVec4f& dst) const;

Discussion

Methods writes into vector dst result of multiplication of this matrix and vector SMLVec4f (src.x, src.y, src.z, 1).

Parameters

src - reference to a vector to be transformed.

Output Parameters

dst - reference to transformed vector.

[top]


SMLLIBENTRY void Transform(const SMLSphereBound& src, SMLSphereBound& dst) const;

Discussion

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.

Parameters

src - reference to a sphere to be transformed.

Output Parameters

dst - reference to transformed sphere.

[top]


SMLLIBENTRY SMLVec4f GetRotationVector() const;

Discussion

Method obtains coordinates of the axis around which the matrix carries out rotation transformation, assuming this matrix is matrix of rotation.

Parameters

No.

Return Value

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();

Discussion

Method returns trueif matrix was initialized with the help of Identity() function and was not changed after that.

Parameters

No.

Return Value

Returns the value of variable identity (true or false).

[top]